vibechat: single-instance (QLockFile) + переименование Chat→vibechat (бинарник, конфиг, hostname node name)
This commit is contained in:
1 parent
f82dca3185
commit
f347dc8edc
7 files changed
+35
-21
No files matched your search
@@ -2,6 +2,9 @@
|
||||
#include <QPalette>
|
||||
#include <QStyleFactory>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QLockFile>
|
||||
#include <QMessageBox>
|
||||
#include <cstdio>
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
@@ -55,9 +58,16 @@ static struct ShutdownSentinel {
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
QApplication app(argc, argv);
|
||||
app.setApplicationName("Chat");
|
||||
app.setApplicationName("vibechat");
|
||||
app.setQuitOnLastWindowClosed(false);
|
||||
|
||||
/* single-instance: лог/БД/сокеты конфликтуют при втором запуске */
|
||||
QLockFile lock(QCoreApplication::applicationDirPath() + "/vibechat.lock");
|
||||
if (!lock.tryLock()) {
|
||||
QMessageBox::warning(nullptr, "vibechat", "vibechat is already running.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
app.setStyle(QStyleFactory::create("Fusion"));
|
||||
QPalette p;
|
||||
p.setColor(QPalette::Window, QColor(53, 53, 53));
|
||||
@@ -77,13 +87,17 @@ int main(int argc, char *argv[]) {
|
||||
p.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(127, 127, 127));
|
||||
app.setPalette(p);
|
||||
|
||||
QString cfgPath = QCoreApplication::applicationDirPath() + "/chatgui.cfg";
|
||||
QString cfgDir = QCoreApplication::applicationDirPath();
|
||||
QString cfgPath = cfgDir + "/vibechat.cfg";
|
||||
/* миграция: старый конфиг chatgui.cfg → vibechat.cfg */
|
||||
if (!QFile::exists(cfgPath) && QFile::exists(cfgDir + "/chatgui.cfg"))
|
||||
QFile::rename(cfgDir + "/chatgui.cfg", cfgPath);
|
||||
|
||||
NodeConfig cfg(cfgPath);
|
||||
bool needSave = false;
|
||||
|
||||
if (!cfg.exists()) {
|
||||
if (!cfg.create("chatgui", 1333)) {
|
||||
if (!cfg.create("", 1333)) {
|
||||
qCritical("Failed to create config: %s", qPrintable(cfgPath));
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user