forked from Mogara/QSanguosha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
88 lines (64 loc) · 1.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
#include <QApplication>
#include <QCoreApplication>
#include <QTranslator>
#include <QDir>
#include <cstring>
#include <QDateTime>
#include "mainwindow.h"
#include "settings.h"
#include "banpair.h"
#include "server.h"
#include "audio.h"
int main(int argc, char *argv[])
{
if(argc > 1 && strcmp(argv[1], "-server") == 0)
new QCoreApplication(argc, argv);
else
new QApplication(argc, argv);
GlobalConfig = new Settings();
#ifdef Q_OS_MAC
#ifdef QT_NO_DEBUG
QDir::setCurrent(qApp->applicationDirPath());
#endif
#endif
// initialize random seed for later use
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
QTranslator qt_translator, translator;
qt_translator.load("qt_zh_CN.qm");
translator.load("sanguosha.qm");
qApp->installTranslator(&qt_translator);
qApp->installTranslator(&translator);
Sanguosha = new Engine;
Config.init();
BanPair::loadBanPairs();
if(qApp->arguments().contains("-server")){
Server *server = new Server(qApp);
printf("Server is starting on port %u\n", Config.ServerPort);
if(server->listen())
printf("Starting successfully\n");
else
printf("Starting failed!\n");
return qApp->exec();
}
QFile file("sanguosha.qss");
if(file.open(QIODevice::ReadOnly)){
QTextStream stream(&file);
qApp->setStyleSheet(stream.readAll());
}
#ifdef AUDIO_SUPPORT
Audio::init();
#endif
MainWindow *main_window = new MainWindow;
Sanguosha->setParent(main_window);
main_window->show();
foreach(QString arg, qApp->arguments()){
if(arg.startsWith("-connect:")){
arg.remove("-connect:");
Config.HostAddress = arg;
Config.setValue("HostAddress", arg);
main_window->on_actionRestart_game_triggered();
break;
}
}
return qApp->exec();
}