Skip to content

Commit 9e3a216

Browse files
committed
Add squirrel command line events
1 parent 3c82090 commit 9e3a216

File tree

2 files changed

+107
-3
lines changed

2 files changed

+107
-3
lines changed

gpxui.rc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,20 @@
1+
#include "build/version.h"
2+
13
IDI_ICON1 ICON DISCARDABLE "gpx.ico"
4+
1 VERSIONINFO
5+
BEGIN
6+
BLOCK "StringFileInfo"
7+
BEGIN
8+
BLOCK "040904b0"
9+
BEGIN
10+
VALUE "FileDescription", "File converter from .gcode to .x3g"
11+
VALUE "FileVersion", GPXUI_VERSION
12+
VALUE "InternalName", "GpxUi.exe"
13+
VALUE "LegalCopyright", "Copyright (c) 2015"
14+
VALUE "OriginalFilename", "GpxUi.exe"
15+
VALUE "ProductName", "GpxUi"
16+
VALUE "ProductVersion", GPXUI_VERSION
17+
VALUE "SquirrelAwareVersion", "1"
18+
END
19+
END
20+
END

main.cpp

Lines changed: 88 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
12
#include "main.h"
23
#include "mainwindow.h"
34
#include "iniedit.h"
45

56
#include <QApplication>
67
#include <QtGui>
7-
#include <QSplashScreen>
88
#include <QTextStream>
99
#include <QStandardPaths>
1010

@@ -46,6 +46,49 @@ namespace GpxUiInfo
4646
}
4747
}
4848

49+
static void runUpdate(const QString sParam)
50+
{
51+
QDir dir(QApplication::instance()->applicationDirPath());
52+
dir.cdUp();
53+
QStringList sArgs;
54+
sArgs << sParam;
55+
QProcess::startDetached(dir.filePath("Update.exe"), sArgs);
56+
}
57+
58+
static void addAppDirToPath()
59+
{
60+
QCoreApplication &a = *QApplication::instance();
61+
QDir dir(a.applicationDirPath());
62+
dir.cdUp();
63+
64+
QSettings settings("HKEY_CURRENT_USER\\Environment", QSettings::NativeFormat);
65+
QString sPath = settings.value("PATH", QString()).toString();
66+
if (sPath.isEmpty())
67+
settings.setValue("PATH", a.applicationDirPath());
68+
else if (!sPath.contains(a.applicationDirPath()))
69+
settings.setValue("PATH", sPath + ";" + a.applicationDirPath());
70+
PostMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)L"Environment");
71+
PostMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)"Environment");
72+
}
73+
74+
static void removeAppDirFromPath()
75+
{
76+
QCoreApplication &a = *QApplication::instance();
77+
QDir dir(a.applicationDirPath());
78+
dir.cdUp();
79+
80+
QSettings settings("HKEY_CURRENT_USER\\Environment", QSettings::NativeFormat);
81+
QString sPath = settings.value("PATH", QString()).toString();
82+
sPath = sPath.remove(QString(";") + a.applicationDirPath());
83+
sPath = sPath.remove(a.applicationDirPath());
84+
if (sPath.isEmpty())
85+
settings.remove("PATH");
86+
else
87+
settings.setValue("PATH", sPath);
88+
PostMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)L"Environment");
89+
PostMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)"Environment");
90+
}
91+
4992
int main(int argc, char *argv[])
5093
{
5194
QApplication::setStyle("Fusion");
@@ -56,8 +99,50 @@ int main(int argc, char *argv[])
5699
a.setApplicationName("GpxUi");
57100
GpxUiInfo::init();
58101

59-
// QSplashScreen splash;
60-
// splash.show();
102+
if (argc > 1) {
103+
QCommandLineParser clp;
104+
clp.setApplicationDescription("GpxUi is a graphical user interface for running GPX, a command line utility that converts .gcode to .x3g");
105+
clp.addHelpOption();
106+
clp.addVersionOption();
107+
QCommandLineOption cloInstall("squirrel-install", "Perform squirrel post install action", "version");
108+
clp.addOption(cloInstall);
109+
QCommandLineOption cloFirstRun("squirrel-firstrun", "First run after squirrel install");
110+
clp.addOption(cloFirstRun);
111+
QCommandLineOption cloUpdated("squirrel-updated", "Perform squirrel post update action", "version");
112+
clp.addOption(cloUpdated);
113+
QCommandLineOption cloObsolete("squirrel-obsolete", "Perform squirrel post update cleanup action", "version");
114+
clp.addOption(cloObsolete);
115+
QCommandLineOption cloUninstall("squirrel-uninstall", "Perform squirrel pre uninstall action", "version");
116+
clp.addOption(cloUninstall);
117+
clp.process(a);
118+
119+
if (clp.isSet(cloInstall)) {
120+
addAppDirToPath();
121+
runUpdate("--createShortcut=GpxUi.exe");
122+
return 0;
123+
}
124+
else if(clp.isSet(cloUpdated)) {
125+
addAppDirToPath();
126+
return 0;
127+
}
128+
else if (clp.isSet(cloObsolete)) {
129+
removeAppDirFromPath();
130+
return 0;
131+
}
132+
else if (clp.isSet(cloUninstall)) {
133+
removeAppDirFromPath();
134+
runUpdate("--removeShortcut=GpxUi.exe");
135+
return 0;
136+
}
137+
else if (clp.isSet(cloFirstRun)) {
138+
}
139+
else {
140+
clp.showHelp();
141+
Q_UNREACHABLE();
142+
return 0;
143+
}
144+
}
145+
61146
/*
62147
QString szPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
63148
QDir dir(szPath);

0 commit comments

Comments
 (0)