ref Env namespace for win32/reg stuff / startup toggle
Bigger than usual commit, but all of this had to be done simultaneously
This commit is contained in:
parent
94d2ebf1c2
commit
047808c89f
8 changed files with 293 additions and 103 deletions
|
|
@ -7,13 +7,16 @@
|
|||
|
||||
OverseerHandler *osh = nullptr;
|
||||
ini::UserSettings *set = nullptr;
|
||||
|
||||
QApplication* createApplication(int &argc, char *argv[])
|
||||
{
|
||||
|
||||
bool startupRun = false;
|
||||
bool onStartup = false;
|
||||
char* userSettingsPath = nullptr;
|
||||
|
||||
QApplication* createApplication(int &argc, char *argv[]) {
|
||||
return new QApplication(argc, argv);
|
||||
}
|
||||
|
||||
bool isSingleInstanceRunning(QString appName) {
|
||||
bool isInstanceRunning(QString appName) {
|
||||
QLocalSocket socket;
|
||||
socket.connectToServer(appName);
|
||||
bool isOpen = socket.isOpen();
|
||||
|
|
@ -21,7 +24,7 @@ bool isSingleInstanceRunning(QString appName) {
|
|||
return isOpen;
|
||||
}
|
||||
|
||||
QLocalServer* startSingleInstanceServer(QString appName) {
|
||||
QLocalServer* startInstanceServer(QString appName) {
|
||||
QLocalServer* server = new QLocalServer;
|
||||
server->setSocketOptions(QLocalServer::WorldAccessOption);
|
||||
server->listen(appName);
|
||||
|
|
@ -32,12 +35,34 @@ void closeDebugFileLog() {
|
|||
close_file_log_buffer();
|
||||
}
|
||||
|
||||
char* parseCmdArgs(int argc, char* argv[]) {
|
||||
if(argc == 1) return nullptr;
|
||||
char arg[] = "--config-path=";
|
||||
if(strstr(argv[1], arg)) {
|
||||
return argv[1] + (sizeof(arg) / sizeof(arg[0])) - 1;
|
||||
} else return nullptr;
|
||||
void parseCmdArgs(int argc, char* argv[]) {
|
||||
if(argc == 1) return;
|
||||
//char* configPath = nullptr;
|
||||
char* arg[] = { (char*)"--config-path=", (char*)"--change-startup" };
|
||||
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if(strstr(argv[i], arg[0])) {
|
||||
userSettingsPath = argv[i] + strlen(arg[0]);
|
||||
}
|
||||
|
||||
if(strstr(argv[i], arg[1])) {
|
||||
if (++i >= argc) return;
|
||||
switch (argv[i][0]) {
|
||||
case '0':
|
||||
startupRun = true;
|
||||
onStartup = false;
|
||||
break;
|
||||
case '1':
|
||||
startupRun = true;
|
||||
onStartup = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* set_terminate
|
||||
|
|
@ -48,41 +73,49 @@ char* parseCmdArgs(int argc, char* argv[]) {
|
|||
*/
|
||||
|
||||
int main (int argc, char* argv[]) {
|
||||
|
||||
/*
|
||||
* QStringList styles = QStyleFactory::keys();
|
||||
* for(QString a : styles) {
|
||||
* log_debugcpp(a.toStdString());
|
||||
* }
|
||||
* Debug: logging report file
|
||||
*/
|
||||
char* userSettingsPath = parseCmdArgs(argc, argv);
|
||||
if (userSettingsPath)
|
||||
set = ini::UserSettings::createSettings(userSettingsPath, true);
|
||||
|
||||
if (set)
|
||||
OverseerHandler::settingsPath = std::string(userSettingsPath);
|
||||
else setConfigDirToDefaults();
|
||||
|
||||
initialize_file_log();
|
||||
atexit(closeDebugFileLog);
|
||||
|
||||
//Check if running
|
||||
//https://stackoverflow.com/questions/48060989/qt-show-application-if-currently-running
|
||||
//std::set_terminate(closeDebugFileLog2);
|
||||
if (!isSingleInstanceRunning("Mixer"))
|
||||
startSingleInstanceServer("Mixer");
|
||||
else exit(0);
|
||||
|
||||
|
||||
QApplication::setStyle(new MixerStyle(QStyleFactory::create("Fusion")));
|
||||
//QApplication::setFont(font);
|
||||
//QPalette palette = QGuiApplication::palette();
|
||||
//todo: ez full apply os accent colorw
|
||||
|
||||
//palette.setColor(QPalette::Active, QPalette::Highlight, QColor(255, 192, 203, 200));
|
||||
//QColor(30,30,30,100));
|
||||
//QGuiApplication::setPalette(palette);
|
||||
osh = new OverseerHandler();
|
||||
osh->populateSystemValues();
|
||||
|
||||
/*
|
||||
* Arg parsing: (admin?) startup change run
|
||||
*/
|
||||
parseCmdArgs(argc, argv);
|
||||
if (startupRun) {
|
||||
if (!isInstanceRunning(PIPE_NAME)) exit(-1);
|
||||
//if (startupChangeInfo->permissionChangeScope == NONE) exit(-1);
|
||||
osh->updateStartupConfig(onStartup);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
//Check if running
|
||||
//https://stackoverflow.com/questions/48060989/qt-show-application-if-currently-running
|
||||
if (!isInstanceRunning(PIPE_NAME))
|
||||
startInstanceServer(PIPE_NAME);
|
||||
else exit(0);
|
||||
|
||||
/*
|
||||
* Config file init
|
||||
*/
|
||||
if (userSettingsPath)
|
||||
set = ini::UserSettings::createSettings(userSettingsPath, true);
|
||||
|
||||
if (set)
|
||||
OverseerHandler::settingsPath = std::string(userSettingsPath);
|
||||
else setConfigDirToDefaults();
|
||||
|
||||
StylingHelper::setBackgroundColor(osh->isLightMode());
|
||||
//qRegisterMetaType<EndpointWidgetEvent>();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue