1
+
1
2
#include " main.h"
2
3
#include " mainwindow.h"
3
4
#include " iniedit.h"
4
5
5
6
#include < QApplication>
6
7
#include < QtGui>
7
- #include < QSplashScreen>
8
8
#include < QTextStream>
9
9
#include < QStandardPaths>
10
10
@@ -46,6 +46,49 @@ namespace GpxUiInfo
46
46
}
47
47
}
48
48
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
+
49
92
int main (int argc, char *argv[])
50
93
{
51
94
QApplication::setStyle (" Fusion" );
@@ -56,8 +99,50 @@ int main(int argc, char *argv[])
56
99
a.setApplicationName (" GpxUi" );
57
100
GpxUiInfo::init ();
58
101
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
+
61
146
/*
62
147
QString szPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
63
148
QDir dir(szPath);
0 commit comments