General improvements and bug fixes

This commit is contained in:
driftingsun 2020-12-26 23:17:20 +03:00
parent 15730b470e
commit 43028953e2
19 changed files with 208 additions and 114 deletions

View file

@ -1,33 +1,42 @@
#include <QSettings>
#include <QDir>
#include "systemservice.h"
#include "log.h"
#include "defines.h"
#include "localserver.h"
#include "log.h"
#include "systemservice.h"
#include "utils.h"
int runApplication(int argc, char** argv)
{
QCoreApplication app(argc,argv);
LocalServer localServer;
if (!localServer.isRunning()) {
return -1;
}
return app.exec();
}
int main(int argc, char **argv)
{
#if !defined(Q_OS_WIN)
// QtService stores service settings in SystemScope, which normally require root privileges.
// To allow testing this example as non-root, we change the directory of the SystemScope settings file.
QSettings::setPath(QSettings::NativeFormat, QSettings::SystemScope, QDir::tempPath());
qWarning("(Example uses dummy settings file: %s/QtSoftware.conf)", QDir::tempPath().toLatin1().constData());
#endif
Utils::initializePath(Utils::systemLogPath());
Log::initialize();
if (argc == 2) {
qInfo() << "Started as console application";
QCoreApplication app(argc,argv);
LocalServer localServer(SERVICE_NAME);
if (!localServer.isRunning()) {
return -1;
}
return app.exec();
return runApplication(argc, argv);
} else {
qInfo() << "Started as system service";
#ifdef Q_OS_WIN
SystemService systemService(argc, argv);
return systemService.exec();
#else
//daemon(0,0);
return runApplication(argc, argv);
#endif
}
// Never reached
return 0;
}