diff --git a/desktop/tauri/src-tauri/tauri.conf.json5 b/desktop/tauri/src-tauri/tauri.conf.json5 index 52b2f25a..c95b4684 100644 --- a/desktop/tauri/src-tauri/tauri.conf.json5 +++ b/desktop/tauri/src-tauri/tauri.conf.json5 @@ -123,11 +123,12 @@ }, "wix": { "fragmentPaths": [ - "templates/service.wxs", - "templates/files.wxs" + "templates/wix/files.wxs", + "templates/wix/old_service_check.wxs", + "templates/wix/migration.wxs", ], "componentGroupRefs": ["BinaryAndIntelFiles"], - "template": "templates/main.wxs" + "template": "templates/wix/main.wxs" } }, "targets": [ diff --git a/desktop/tauri/src-tauri/templates/service.wxs b/desktop/tauri/src-tauri/templates/service.wxs deleted file mode 100644 index 3e829bd7..00000000 --- a/desktop/tauri/src-tauri/templates/service.wxs +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - REMOVE - - - REMOVE - - - - diff --git a/desktop/tauri/src-tauri/templates/wix/CheckServiceStatus.vbs b/desktop/tauri/src-tauri/templates/wix/CheckServiceStatus.vbs new file mode 100644 index 00000000..b1801ac3 --- /dev/null +++ b/desktop/tauri/src-tauri/templates/wix/CheckServiceStatus.vbs @@ -0,0 +1,44 @@ +Option Explicit + +Dim objShell, objExec, strOutput, arrLines, i, arrStatus + +' Create an instance of the WScript.Shell object +Set objShell = CreateObject("WScript.Shell") + +' Run the sc.exe command to query the service +Set objExec = objShell.Exec("cmd /c sc.exe query PortmasterCore") + +' Initialize an empty string to store the output +strOutput = "" + +' Read all output from the command line +Do While Not objExec.StdOut.AtEndOfStream + strOutput = strOutput & objExec.StdOut.ReadLine() & vbCrLf +Loop + +' Split the output into lines +arrLines = Split(strOutput, vbCrLf) + +' Example Output +' SERVICE_NAME: PortmasterCore +' TYPE : 10 WIN32_OWN_PROCESS +' STATE : 1 STOPPED +' WIN32_EXIT_CODE : 1077 (0x435) +' SERVICE_EXIT_CODE : 0 (0x0) +' CHECKPOINT : 0x0 +' WAIT_HINT : 0x0 + +For i = LBound(arrLines) To UBound(arrLines) + ' Example line: STATE : 1 STOPPED + If InStr(arrLines(i), "STATE") > 0 Then + ' Extract and display the service state + ' Example string: "1 STOPPED" + arrStatus = Split(Trim(Mid(arrLines(i), InStr(arrLines(i), ":") + 1)), " ") + ' Anything other the STOPPED consider as running + If Not arrStatus(2) = "STOPPED" Then + MsgBox("Portmaster service is running. Stop it and run the installer again.") + ' Notify the installer that it should fail. + WScript.Quit 1 + End If + End If +Next \ No newline at end of file diff --git a/desktop/tauri/src-tauri/templates/wix/Migration.vbs b/desktop/tauri/src-tauri/templates/wix/Migration.vbs new file mode 100644 index 00000000..26b96d93 --- /dev/null +++ b/desktop/tauri/src-tauri/templates/wix/Migration.vbs @@ -0,0 +1,78 @@ +Dim FSO +Set FSO = CreateObject("Scripting.FileSystemObject") + +Dim customData, args, oldInstallationDir, migrationFlagFile, newDataDir, doMigration +customData = Session.Property("CustomActionData") + +' Split the string by commas +args = Split(customData, ",") + +' Access individual arguments +Dim commonAppDataFolder, programMenuFolder, startupFolder, appDataFolder +commonAppDataFolder = Trim(args(0)) +programMenuFolder = Trim(args(1)) +startupFolder = Trim(args(2)) +appDataFolder = Trim(args(3)) + +' Read variables from the session object +oldInstallationDir = commonAppDataFolder & "Safing\Portmaster\" +newDataDir = commonAppDataFolder & "Portmaster" +migrationFlagFile = oldInstallationDir & "migrated.txt" +doMigration = true + +' Check for existing installtion +If Not fso.FolderExists(oldInstallationDir) Then + doMigration = false +End If + +' Check if migration was already done +If fso.FileExists(migrationFlagFile) Then + doMigration = false +End If + +If doMigration Then + ' Copy the config file + dim configFile + configFile = "config.json" + If fso.FileExists(oldInstallationDir & configFile) Then + fso.CopyFile oldInstallationDir & configFile, newDataDir & configFile + End If + + ' Copy the database folder + dim databaseFolder + databaseFolder = "databases" + If fso.FolderExists(oldInstallationDir & databaseFolder) Then + fso.CopyFolder oldInstallationDir & databaseFolder, newDataDir & databaseFolder + End If + + ' Delete shortcuts + dim shortcutsFolder + notifierShortcut = programMenuFolder & "Portmaster/Portmaster Notifier.lnk" + If fso.FileExists(notifierShortcut) Then + fso.DeleteFile notifierShortcut, True + End If + + ' Delete startup shortcut + dim srartupFile + srartupFile = startupFolder & "Portmaster Notifier.lnk" + If fso.FileExists(srartupFile) Then + fso.DeleteFile srartupFile, True + End If + + ' Delete shortuct in user folder + dim userShortcut + userShortcut = appDataFolder & "Microsoft\Windows\Start Menu\Programs\Portmaster.lnk" + If fso.FileExists(userShortcut) Then + fso.DeleteFile userShortcut, True + End If + + ' Delete the old installer + dim oldUninstaller + oldUninstaller = oldInstallationDir & "portmaster-uninstaller.exe" + If fso.FileExists(oldUninstaller) Then + fso.DeleteFile oldUninstaller, True + End If + + ' Set the migration flag file + fso.CreateTextFile(migrationFlagFile).Close +End If \ No newline at end of file diff --git a/desktop/tauri/src-tauri/templates/files.wxs b/desktop/tauri/src-tauri/templates/wix/files.wxs similarity index 70% rename from desktop/tauri/src-tauri/templates/files.wxs rename to desktop/tauri/src-tauri/templates/wix/files.wxs index 14159aa8..0fd5a801 100644 --- a/desktop/tauri/src-tauri/templates/files.wxs +++ b/desktop/tauri/src-tauri/templates/wix/files.wxs @@ -13,7 +13,6 @@ - @@ -30,12 +29,37 @@ + + + + + + + + \ No newline at end of file diff --git a/desktop/tauri/src-tauri/templates/main.wxs b/desktop/tauri/src-tauri/templates/wix/main.wxs similarity index 94% rename from desktop/tauri/src-tauri/templates/main.wxs rename to desktop/tauri/src-tauri/templates/wix/main.wxs index f62f27a3..f0d261ce 100644 --- a/desktop/tauri/src-tauri/templates/main.wxs +++ b/desktop/tauri/src-tauri/templates/wix/main.wxs @@ -70,9 +70,12 @@ {{/if}} - - + + + + + @@ -161,6 +164,7 @@ + @@ -323,6 +327,7 @@ Execute="commit" Impersonate="yes" ExeCommand="powershell.exe -WindowStyle hidden .\install-task.ps1" /> + NOT(REMOVE) @@ -348,9 +353,11 @@ - - - + + + + + \ No newline at end of file diff --git a/desktop/tauri/src-tauri/templates/main_original.wxs b/desktop/tauri/src-tauri/templates/wix/main_original.wxs similarity index 97% rename from desktop/tauri/src-tauri/templates/main_original.wxs rename to desktop/tauri/src-tauri/templates/wix/main_original.wxs index b1d2672a..136c89ad 100644 --- a/desktop/tauri/src-tauri/templates/main_original.wxs +++ b/desktop/tauri/src-tauri/templates/wix/main_original.wxs @@ -70,9 +70,12 @@ {{/if}} - - + + + + + diff --git a/desktop/tauri/src-tauri/templates/wix/migration.wxs b/desktop/tauri/src-tauri/templates/wix/migration.wxs new file mode 100644 index 00000000..dd713e5a --- /dev/null +++ b/desktop/tauri/src-tauri/templates/wix/migration.wxs @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + NOT(REMOVE) + NOT(REMOVE) + + + + diff --git a/desktop/tauri/src-tauri/templates/wix/old_service_check.wxs b/desktop/tauri/src-tauri/templates/wix/old_service_check.wxs new file mode 100644 index 00000000..78e24c25 --- /dev/null +++ b/desktop/tauri/src-tauri/templates/wix/old_service_check.wxs @@ -0,0 +1,20 @@ + + + + + + + + + + + + NOT(REMOVE) + + + +