-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.cpp
More file actions
74 lines (63 loc) · 1.77 KB
/
main.cpp
File metadata and controls
74 lines (63 loc) · 1.77 KB
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
#include "OutputHooker.h"
#include <QApplication>
#include <QSharedMemory>
#include <QSystemSemaphore>
#include <QStyleFactory>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QString programName = QCoreApplication::applicationName();
QString sharedMemoryName = programName+"2323POLYBIUS";
QString semaphoreName = programName+"POLYBIUS2323";
QSystemSemaphore semaphore(semaphoreName, 1);
semaphore.acquire();
QSharedMemory sharedMemory(sharedMemoryName);
bool isRunning;
if (sharedMemory.create(1))
isRunning = false;
else
isRunning = true;
semaphore.release();
if(!isRunning)
{
if (argc > 1)
{
OutputHooker w;
QStringList args;
for (int i = 1; i < argc; ++i)
{
args << QString::fromLocal8Bit(argv[i]);
}
w.processCommandLineArgs(args);
QTimer::singleShot(500, &a, &QCoreApplication::quit);
return a.exec();
}
else
{
QApplication::setStyle(QStyleFactory::create("Fusion"));
OutputHooker w;
return a.exec();
}
}
else
{
if (argc > 1)
{
QLocalSocket socket;
socket.connectToServer("OutputHooker_CommandLine_Server");
if (socket.waitForConnected(1000))
{
QStringList args;
for (int i = 1; i < argc; ++i)
{
args << QString::fromLocal8Bit(argv[i]);
}
QDataStream out(&socket);
out << args;
socket.waitForBytesWritten(1000);
socket.disconnectFromServer();
}
}
return 0;
}
}