-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
40 lines (32 loc) · 1.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
#include "QuickSoundSwitcher.h"
#include <QApplication>
#include <QTranslator>
#include <QLocale>
#include <QProcess>
bool isAnotherInstanceRunning(const QString& processName)
{
QProcess process;
process.start("tasklist", QStringList() << "/FI" << QString("IMAGENAME eq %1").arg(processName));
process.waitForFinished();
QString output = process.readAllStandardOutput();
int count = output.count(processName, Qt::CaseInsensitive);
return count > 1;
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setQuitOnLastWindowClosed(false);
const QString processName = "QuickSoundSwitcher.exe";
if (isAnotherInstanceRunning(processName)) {
qDebug() << "Another instance is already running. Exiting...";
return 0;
}
QLocale locale;
QString languageCode = locale.name().section('_', 0, 0);
QTranslator translator;
if (translator.load(":/translations/QuickSoundSwitcher_" + languageCode + ".qm")) {
a.installTranslator(&translator);
}
QuickSoundSwitcher w;
return a.exec();
}