-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
96 lines (74 loc) · 3.15 KB
/
main.cpp
File metadata and controls
96 lines (74 loc) · 3.15 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "mainwindow.h"
#include "gui.h"
//#include "room.h"
//#include "asterisk.h"
//#include <iostream>
#include <QApplication>
//#include <QVBoxLayout>
//#include <QPushButton>
//#include <QGroupBox>
#include <QString>
#include <QSystemSemaphore>
#include <QSharedMemory>
#include <QMessageBox>
#include <QDebug>
//#include <vector>
#include <QDate>
int main(int argc, char *argv[])
{
static const std::string hide_cmd="tray";
qDebug("Starting app");
QApplication a(argc, argv);
// Settings settings;
QSystemSemaphore semaphore("asteriskconfmon_sem", 1); // создаём семафор
semaphore.acquire(); // Поднимаем семафор, запрещая другим экземплярам работать с разделяемой памятью
#ifdef WIN64
// в linux/unix разделяемая память не освобождается при аварийном завершении приложения,
// поэтому необходимо избавиться от данного мусора
QSharedMemory nix_fix_shared_memory("asteriskconfmon");
if(nix_fix_shared_memory.attach()){
nix_fix_shared_memory.detach();
}
#endif
QSharedMemory sharedMemory("asteriskconfmon"); // Создаём экземпляр разделяемой памяти
bool is_running; // переменную для проверки ууже запущенного приложения
if (sharedMemory.attach()){ // пытаемся присоединить экземпляр разделяемой памяти
// к уже существующему сегменту
is_running = true; // Если успешно, то определяем, что уже есть запущенный экземпляр
}else{
sharedMemory.create(1); // В противном случае выделяем 1 байт памяти
is_running = false; // И определяем, что других экземпляров не запущено
}
semaphore.release(); // Опускаем семафор
if(is_running){
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Warning);
msgBox.setText(QString::fromUtf8("Приложение уже запущено.\n"
"Вы можете запустить только один экземпляр приложения."));
msgBox.exec();
return 1;
}
/*
QDate date;
date=QDate::currentDate();
if (date>QDate(2022,12,31)) {
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Warning);
msgBox.setText(QString::fromUtf8("Системный сбой.\n"
"Обратитесь к разработчику."));
msgBox.exec();
return 1;
}
*/
a.setQuitOnLastWindowClosed(false);
SettingsDialog *settings = new SettingsDialog(nullptr);
MainWindow w;
w.setSettings(settings);
Gui gui(&w);
gui.setSettings(settings);
w.show();
for (int i=0;i<argc;i++){
if (hide_cmd.find(argv[i])==0) w.tray();
}
return a.exec();
}