-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
127 lines (114 loc) · 4.06 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
/***************************************************************************
*
* RamseyX Client: client program of distributed computing project RamseyX
*
* Copyright (C) 2013-2014 Zizheng Tai <[email protected]>, et al.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
***************************************************************************/
#include "mainwindow.h"
#include <QApplication>
#include <QSplashScreen>
#include <QPixmap>
#include <QThread>
#include <QSharedMemory>
#include <QSettings>
#include <QMessageBox>
extern "C"
{
#include "dhry.h"
}
#if defined(_WIN32)
#include <wtypes.h>
#include <processthreadsapi.h>
#elif defined(__unix__) || defined(__linux__) || defined(__APPLE__) || defined(__MACH__) //try "defined(__POSIX__)" since these files are part of POSIX standards.
#include <sys/time.h>
#include <sys/resource.h>
#else
#error Unsupported OS
#endif
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setStyle("Fusion");
// Prevent multiple instances
QSharedMemory sharedMemory("RamseyX Client");
if (!sharedMemory.create(1))
{
QMessageBox::information(
nullptr,
QObject::tr("RamseyX Client"),
QObject::tr("Application is already running.") + "\t\t\n",
QMessageBox::Ok);
return 0;
}
a.setOrganizationName("RamseyX");
a.setOrganizationDomain("www.ramseyx.org");
a.setApplicationName("RamseyX Client");
a.setApplicationVersion(APP_VERSION);
// Parse parameters
bool isAuto = a.arguments().contains("--auto");
// Load benchmark record
QSettings settings;
double DMIPS = settings.value("benchmark").toDouble();
// Show splash screen
QSplashScreen splash(QPixmap(":/bmp/splash"));
if (!isAuto)
{
splash.show();
if (DMIPS <= 1.0) // Assuming all modern computers' benchmark result greater than 1.0 DMIPS
splash.showMessage(QObject::tr("Initializing...") + "\n" +
QObject::tr("No benchmark record exists. Benchmarking..."),
Qt::AlignRight | Qt::AlignBottom,
Qt::white);
else
splash.showMessage(QObject::tr("Initializing..."),
Qt::AlignRight | Qt::AlignBottom,
Qt::white);
}
if (DMIPS <= 1.0)
settings.setValue("benchmark", Benchmark());
MainWindow w(nullptr, isAuto);
if (!w.isInitialized())
return 1;
// Show main window
if (!isAuto)
{
QThread::sleep(2);
w.show();
splash.finish(&w);
}
// Set process priority
#if defined(_WIN32)
SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS);
#elif defined(__unix__) || defined(__linux__) || defined(__APPLE__) || defined(__MACH__)
setpriority(PRIO_PROCESS, 0, 20);
#else
#error Unsupported OS
#endif
int ret = a.exec();
if (w.shouldUpdateRamseyXClient())
{
#if defined(_WIN32)
ShellExecute(nullptr, TEXT("runas"), TEXT(".\\update_script.bat"), nullptr, nullptr, SW_SHOWNORMAL);
#elif (defined(__unix__) || defined(__linux__) || defined(__APPLE__) || defined(__MACH__)) && defined (UPDATE_RAMSEYX) //Let qmake define this...
//NEVER USE THIS!!! This breaks package managers and we don't have release for these systems!
/execlp("sh", "sh", "./update_script.sh", nullptr); //Maybe bash?
#else
#error Unsupported OS
#endif
}
return ret;
}