Skip to content

Commit

Permalink
Add squirrel command line events
Browse files Browse the repository at this point in the history
  • Loading branch information
markwal committed Aug 20, 2015
1 parent 3c82090 commit 9e3a216
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 3 deletions.
19 changes: 19 additions & 0 deletions gpxui.rc
Original file line number Diff line number Diff line change
@@ -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
91 changes: 88 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

#include "main.h"
#include "mainwindow.h"
#include "iniedit.h"

#include <QApplication>
#include <QtGui>
#include <QSplashScreen>
#include <QTextStream>
#include <QStandardPaths>

Expand Down Expand Up @@ -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");
Expand All @@ -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);
Expand Down

0 comments on commit 9e3a216

Please sign in to comment.