forked from simulationcraft/simc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
141 lines (120 loc) · 3.89 KB
/
main.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include "MainWindow.hpp"
#include "class_modules/class_module.hpp"
#include "dbc/dbc.hpp"
#include "player/unique_gear.hpp"
#include "interfaces/bcp_api.hpp"
#include "sc_SimulateTab.hpp"
#include "simulationcraftqt.hpp"
#if 0
#include <fstream>
#endif
/* Parse additional arguments
* 1. Argument is parsed as a file name, complete content goes into simulate tab.
* Following arguments are appended as new lines.
*/
void parse_additional_args( SC_MainWindow& w, QStringList args )
{
if ( args.size() > 1 )
{
for ( int i = 1; i < args.size(); ++i )
{
QFile file( args[ i ] );
if ( file.open( QIODevice::ReadOnly | QIODevice::Text ) )
{
QTextStream ts( &file );
ts.setAutoDetectUnicode( true );
w.simulateTab->add_Text( ts.readAll(), args[ i ] );
file.close();
}
}
w.mainTab->setCurrentTab( TAB_SIMULATE );
}
}
#if 0
namespace
{
std::ofstream debugStream("debug.log");
void messageOutput(QtMsgType /* type */, const QMessageLogContext& context, const QString& message)
{
debugStream << context.file << ":" << context.line << ": " << message.toStdString() << std::endl;
}
}
#endif
int main( int argc, char* argv[] )
{
#if 0
qInstallMessageHandler(messageOutput);
#endif
#if ( QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) )
QCoreApplication::setAttribute( Qt::AA_EnableHighDpiScaling );
qputenv( "QT_AUTO_SCREEN_SCALE_FACTOR", "1" );
#endif
QApplication a( argc, argv );
QLocale::setDefault( QLocale( "C" ) );
std::locale::global( std::locale( "C" ) );
setlocale( LC_ALL, "C" );
dbc::init();
module_t::init();
unique_gear::register_hotfixes();
unique_gear::register_special_effects();
unique_gear::sort_special_effects();
#ifndef SC_NO_NETWORKING
bcp_api::token_load();
#endif
hotfix::apply();
QApplication::setStyle( QStyleFactory::create( "Fusion" ) );
QCoreApplication::setApplicationName( "SimulationCraft" );
QCoreApplication::setApplicationVersion( SC_VERSION );
QCoreApplication::setOrganizationDomain( "org.simulationcraft" );
QCoreApplication::setOrganizationName( "SimulationCraft" );
QSettings::setDefaultFormat( QSettings::IniFormat ); // Avoid Registry entries on Windows
QNetworkProxyFactory::setUseSystemConfiguration( true );
// Localization
QTranslator qtTranslator;
qtTranslator.load( "qt_" + QLocale::system().name(), QLibraryInfo::location( QLibraryInfo::TranslationsPath ) );
a.installTranslator( &qtTranslator );
QString lang;
QSettings settings;
lang = settings.value( "options/gui_localization", "auto" ).toString();
qDebug() << "[Localization]: Selected gui language: " << lang;
if ( lang == "auto" )
{
QString langName = QLocale::system().name();
QStringList spl = langName.split( '_' );
if ( spl.length() >= 2 )
{
lang = spl[ 1 ].toLower();
}
qDebug() << "[Localization]: QLocale system language: " << lang;
}
QTranslator myappTranslator;
if ( !lang.isEmpty() && !lang.startsWith( "en" ) )
{
for ( const auto& path : SC_PATHS::getDataPaths() )
{
QString path_to_locale = path + "/locale";
QString qm_file = QString( "sc_" ) + lang;
qDebug() << "[Localization]: Trying to load local file from: " << path_to_locale << "/" << qm_file << ".qm";
if ( myappTranslator.load( qm_file, path_to_locale ) )
{
break;
}
qDebug() << "[Localization]: Loaded translator isEmpty(): " << myappTranslator.isEmpty();
}
}
else
{
qDebug() << "[Localization]: No specific translator chosen, using English.";
}
a.installTranslator( &myappTranslator );
QString iconlocation =
QStandardPaths::locate( QStandardPaths::AppDataLocation, QString( "icon" ), QStandardPaths::LocateDirectory );
QDir::addSearchPath( "icon", iconlocation );
SC_MainWindow w;
parse_additional_args( w, a.arguments() );
auto ret = a.exec();
#ifndef SC_NO_NETWORKING
bcp_api::token_save();
#endif
return ret;
}