diff --git a/scripts/installer.nsh b/scripts/installer.nsh new file mode 100644 index 00000000..2f061f5e --- /dev/null +++ b/scripts/installer.nsh @@ -0,0 +1,82 @@ +!include 'LogicLib.nsh' + +; The following is used to add the "/SD" flag to MessageBox so that the +; machine can restart if the uninstaller fails. +!macro customUnInstallCheckCommon + IfErrors 0 +3 + DetailPrint `Uninstall was not successful. Not able to launch uninstaller!` + Return + + ${if} $R0 != 0 + MessageBox MB_OK|MB_ICONEXCLAMATION "$(uninstallFailed): $R0" /SD IDOK + DetailPrint `Uninstall was not successful. Uninstaller error code: $R0.` + SetErrorLevel 2 + Quit + ${endif} +!macroend + +!macro customUnInstallCheck + !insertmacro customUnInstallCheckCommon +!macroend + +!macro customUnInstallCheckCurrentUser + !insertmacro customUnInstallCheckCommon +!macroend + +!macro customRemoveFiles + ${ifNot} ${isUpdated} + ClearErrors + FileOpen $0 "$APPDATA\ComfyUI\extra_models_config.yaml" r + var /global line + var /global lineLength + var /global prefix + var /global prefixLength + var /global prefixFirstLetter + + FileRead $0 $line + + StrCpy $prefix "base_path: " ; Space at the end is important to strip away correct number of letters + StrLen $prefixLength $prefix + StrCpy $prefixFirstLetter $prefix 1 + + StrCpy $R3 $R0 + StrCpy $R0 -1 + IntOp $R0 $R0 + 1 + StrCpy $R2 $R3 1 $R0 + StrCmp $R2 "" +2 + StrCmp $R2 $R1 +2 -3 + + StrCpy $R0 -1 + + ${DoUntil} ${Errors} + StrCpy $R3 0 ; Whitespace padding counter + StrLen $lineLength $line + + ${Do} ; Find first letter of prefix + StrCpy $R4 $line 1 $R3 + + ${IfThen} $R4 == $prefixFirstLetter ${|} ${ExitDo} ${|} + ${IfThen} $R3 > $lineLength ${|} ${ExitDo} ${|} + + IntOp $R3 $R3 + 1 + ${Loop} + + StrCpy $R2 $line $prefixLength $R3 ; Copy part from first letter to length of prefix + + ${If} $R2 == $prefix + StrCpy $2 $line 1024 $R3 ; Strip off whitespace padding + StrCpy $3 $2 1024 $prefixLength ; Strip off prefix + + ; $3 now contains value of base_path + RMDir /r /REBOOTOK "$3\.venv" + RMDir /r /REBOOTOK "$3\uv-cache" + + ${ExitDo} ; No need to continue, break the cycle + ${EndIf} + FileRead $0 $line + ${LoopUntil} 1 = 0 + + FileClose $0 + Delete "$APPDATA\ComfyUI\extra_models_config.yaml" + ${endIf} +!macroend \ No newline at end of file diff --git a/todesktop.json b/todesktop.json index 37640b65..6f42c0e5 100644 --- a/todesktop.json +++ b/todesktop.json @@ -21,5 +21,8 @@ "filesForDistribution": ["!assets/**", "!dist/**", "!src/**", "!scripts/**", "!.yarn/**", "!.yarnrc.yml"], "mac": { "additionalBinariesToSign": ["./assets/uv/macos/uv", "./assets/uv/macos/uvx"] + }, + "windows": { + "nsisInclude": "./scripts/installer.nsh" } }