-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
71 lines (56 loc) · 1.72 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
/*#ifdef _WIN32
#include <windows.h>
#include <winuser.h>
#elif defined __unix__
#endif*/
#include "emudiscer.h"
#include "Utilities.h"
#include <QtWidgets/QApplication>
#include <QCommandLineParser>
#include <QDebug>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
app.setApplicationName("EmuDiscer");
app.setApplicationVersion(EMUDISCER_APP_VERSION);
// command line
QCommandLineParser parser;
parser.addHelpOption();
parser.addVersionOption();
QCommandLineOption settingsOption(
{ "s", "open-settings" },
"Open settings window at launch"
);
parser.addOption(settingsOption);
QCommandLineOption multiInstanceOption(
{ "m", "multi-instance" },
"Run program even if another instance is running"
);
parser.addOption(multiInstanceOption);
parser.process(app);
// single instance
QSharedMemory sharedMemory;
sharedMemory.setKey (QString("EmuDiscerSharedData_")+getUsername());
qDebug() << sharedMemory.nativeKey() << "\n";
if (!sharedMemory.create(sizeof(SharedMemData)) && !parser.isSet(multiInstanceOption))
{
qDebug() << "Already running" << "\n";
sharedMemory.attach();
sharedMemory.lock();
((SharedMemData*)sharedMemory.data())->raiseWindow = true;
sharedMemory.unlock();
sharedMemory.detach();
return 0;
}
// options window
EmuDiscer w(&sharedMemory);
if (parser.isSet(settingsOption))
w.show();
// attach to shared data
sharedMemory.attach();
sharedMemory.lock();
((SharedMemData*)sharedMemory.data())->raiseWindow = false;
sharedMemory.unlock();
// finally, execute qt app
return app.exec();
}