forked from simulationcraft/simc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sc_ImportThread.cpp
99 lines (87 loc) · 2.84 KB
/
sc_ImportThread.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// ==========================================================================
// Dedmonwakeen's Raid DPS/TPS Simulator.
// Send questions to [email protected]
// ==========================================================================
#include "simulationcraft.hpp"
#include "simulationcraftqt.hpp"
#include "sc_OptionsTab.hpp"
#ifdef Q_OS_MAC
#include <CoreFoundation/CoreFoundation.h>
#endif
// ==========================================================================
// Import
// ==========================================================================
namespace {
/**
* Print chained exceptions, separated by ' :'.
*/
void print_exception( std::string& output, const std::exception& e, int level = 0)
{
std::string tmp = fmt::format("{}{}", level > 0 ? ": " : "", e.what());
output += tmp;
try {
std::rethrow_if_nested(e);
} catch(const std::exception& e) {
print_exception(output, e, level+1);
} catch(...) {}
}
}
void SC_ImportThread::start( std::shared_ptr<sim_t> s, const QString& reg, const QString& rea, const QString& cha, const QString& spe )
{
mainWindow -> soloChar -> start( 50 );
tab = TAB_IMPORT_NEW;
item_db_sources = mainWindow -> optionsTab -> get_db_order();
api = mainWindow -> optionsTab -> get_api_key();
m_role = mainWindow -> optionsTab -> get_player_role();
error = "";
sim = s;
region = reg;
realm = rea;
character = cha;
spec = spe;
QThread::start();
}
void SC_ImportThread::importWidget()
{
// Windows 7 64bit somehow cannot handle straight toStdString() conversion, so
// do it in a silly way as a workaround for now.
std::string cpp_r = region.toUtf8().constData();
std::string cpp_s = realm.toUtf8().constData();
std::string cpp_c = character.toUtf8().constData();
std::string cpp_sp = spec.toUtf8().constData();
player = bcp_api::download_player( sim.get(), cpp_r, cpp_s, cpp_c, cpp_sp );
}
void SC_ImportThread::run()
{
try
{
cache::advance_era();
sim -> parse_option( "item_db_source", item_db_sources.toUtf8().constData() );
if ( api.size() == 32 ) // api keys are 32 characters long.
sim -> parse_option( "apikey", api.toUtf8().constData() );
switch ( tab )
{
case TAB_IMPORT_NEW: importWidget(); break;
default: assert( 0 ); break;
}
if ( player )
{
player -> role = util::parse_role_type( m_role.toUtf8().constData() );
sim->init();
if (sim->canceled)
{
player = nullptr;
return;
}
std::string buffer = player -> create_profile();
profile = QString::fromUtf8( buffer.c_str() );
}
}
catch (const std::exception& e)
{
std::string error_str_;
print_exception(error_str_, e);
error = QString::fromStdString(error_str_);
player = nullptr;
}
}