diff --git a/gpxui.rc b/gpxui.rc index cc69ab3..770c71c 100644 --- a/gpxui.rc +++ b/gpxui.rc @@ -1 +1,20 @@ +#include "build/version.h" + IDI_ICON1 ICON DISCARDABLE "gpx.ico" +1 VERSIONINFO +BEGIN +BLOCK "StringFileInfo" +BEGIN + BLOCK "040904b0" + BEGIN + VALUE "FileDescription", "File converter from .gcode to .x3g" + VALUE "FileVersion", GPXUI_VERSION + VALUE "InternalName", "GpxUi.exe" + VALUE "LegalCopyright", "Copyright (c) 2015" + VALUE "OriginalFilename", "GpxUi.exe" + VALUE "ProductName", "GpxUi" + VALUE "ProductVersion", GPXUI_VERSION + VALUE "SquirrelAwareVersion", "1" + END +END +END diff --git a/main.cpp b/main.cpp index 62cc0b6..196d499 100644 --- a/main.cpp +++ b/main.cpp @@ -1,10 +1,10 @@ + #include "main.h" #include "mainwindow.h" #include "iniedit.h" #include #include -#include #include #include @@ -46,6 +46,49 @@ namespace GpxUiInfo } } +static void runUpdate(const QString sParam) +{ + QDir dir(QApplication::instance()->applicationDirPath()); + dir.cdUp(); + QStringList sArgs; + sArgs << sParam; + QProcess::startDetached(dir.filePath("Update.exe"), sArgs); +} + +static void addAppDirToPath() +{ + QCoreApplication &a = *QApplication::instance(); + QDir dir(a.applicationDirPath()); + dir.cdUp(); + + QSettings settings("HKEY_CURRENT_USER\\Environment", QSettings::NativeFormat); + QString sPath = settings.value("PATH", QString()).toString(); + if (sPath.isEmpty()) + settings.setValue("PATH", a.applicationDirPath()); + else if (!sPath.contains(a.applicationDirPath())) + settings.setValue("PATH", sPath + ";" + a.applicationDirPath()); + PostMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)L"Environment"); + PostMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)"Environment"); +} + +static void removeAppDirFromPath() +{ + QCoreApplication &a = *QApplication::instance(); + QDir dir(a.applicationDirPath()); + dir.cdUp(); + + QSettings settings("HKEY_CURRENT_USER\\Environment", QSettings::NativeFormat); + QString sPath = settings.value("PATH", QString()).toString(); + sPath = sPath.remove(QString(";") + a.applicationDirPath()); + sPath = sPath.remove(a.applicationDirPath()); + if (sPath.isEmpty()) + settings.remove("PATH"); + else + settings.setValue("PATH", sPath); + PostMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)L"Environment"); + PostMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)"Environment"); +} + int main(int argc, char *argv[]) { QApplication::setStyle("Fusion"); @@ -56,8 +99,50 @@ int main(int argc, char *argv[]) a.setApplicationName("GpxUi"); GpxUiInfo::init(); -// QSplashScreen splash; -// splash.show(); + if (argc > 1) { + QCommandLineParser clp; + clp.setApplicationDescription("GpxUi is a graphical user interface for running GPX, a command line utility that converts .gcode to .x3g"); + clp.addHelpOption(); + clp.addVersionOption(); + QCommandLineOption cloInstall("squirrel-install", "Perform squirrel post install action", "version"); + clp.addOption(cloInstall); + QCommandLineOption cloFirstRun("squirrel-firstrun", "First run after squirrel install"); + clp.addOption(cloFirstRun); + QCommandLineOption cloUpdated("squirrel-updated", "Perform squirrel post update action", "version"); + clp.addOption(cloUpdated); + QCommandLineOption cloObsolete("squirrel-obsolete", "Perform squirrel post update cleanup action", "version"); + clp.addOption(cloObsolete); + QCommandLineOption cloUninstall("squirrel-uninstall", "Perform squirrel pre uninstall action", "version"); + clp.addOption(cloUninstall); + clp.process(a); + + if (clp.isSet(cloInstall)) { + addAppDirToPath(); + runUpdate("--createShortcut=GpxUi.exe"); + return 0; + } + else if(clp.isSet(cloUpdated)) { + addAppDirToPath(); + return 0; + } + else if (clp.isSet(cloObsolete)) { + removeAppDirFromPath(); + return 0; + } + else if (clp.isSet(cloUninstall)) { + removeAppDirFromPath(); + runUpdate("--removeShortcut=GpxUi.exe"); + return 0; + } + else if (clp.isSet(cloFirstRun)) { + } + else { + clp.showHelp(); + Q_UNREACHABLE(); + return 0; + } + } + /* QString szPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); QDir dir(szPath);