From d93b02887d1a3688f2e6b88c4ff1363cc5e4a106 Mon Sep 17 00:00:00 2001 From: paisley <8197966+su8su@users.noreply.github.com> Date: Fri, 6 Mar 2026 14:06:48 +0800 Subject: [PATCH] fix windows install --- scripts/installer.nsh | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/scripts/installer.nsh b/scripts/installer.nsh index 74ea8c5..d06256d 100644 --- a/scripts/installer.nsh +++ b/scripts/installer.nsh @@ -8,6 +8,14 @@ !endif !macro customCheckAppRunning + ; Pre-emptively remove old shortcuts to prevent the Windows "Missing Shortcut" + ; dialog during upgrades. The built-in NSIS uninstaller deletes ClawX.exe + ; *before* removing shortcuts; Windows Shell link tracking can detect the + ; broken target in that brief window and pop a resolver dialog. + ; Delete is a silent no-op when the file doesn't exist (safe for fresh installs). + Delete "$DESKTOP\${PRODUCT_NAME}.lnk" + Delete "$SMPROGRAMS\${PRODUCT_NAME}.lnk" + ${nsProcess::FindProcess} "${APP_EXECUTABLE_FILENAME}" $R0 ${if} $R0 == 0 @@ -73,7 +81,15 @@ ; Add resources\cli to the current user's PATH for openclaw CLI. ; Read current PATH, skip if already present, append otherwise. + ; + ; ReadRegStr silently returns "" when the value exceeds the NSIS string + ; buffer (8192 chars for the electron-builder large-strings build). + ; Without an error-flag check we would overwrite the entire user PATH with + ; only our CLI directory, destroying every other PATH entry. + ClearErrors ReadRegStr $0 HKCU "Environment" "Path" + IfErrors _ci_readFailed + StrCmp $0 "" _ci_setNew ; Check if our CLI dir is already in PATH @@ -94,6 +110,12 @@ WriteRegExpandStr HKCU "Environment" "Path" $0 ; Broadcast WM_SETTINGCHANGE so running Explorer/terminals pick up the change SendMessage ${HWND_BROADCAST} ${WM_SETTINGCHANGE} 0 "STR:Environment" /TIMEOUT=500 + Goto _ci_done + + _ci_readFailed: + ; PATH value could not be read (likely exceeds NSIS buffer). + ; Skip modification to avoid destroying existing entries. + DetailPrint "Warning: Could not read user PATH (may exceed 8192 chars). Skipping PATH update." _ci_done: !macroend @@ -137,7 +159,9 @@ FunctionEnd !macro customUnInstall ; Remove resources\cli from user PATH + ClearErrors ReadRegStr $0 HKCU "Environment" "Path" + IfErrors _cu_pathDone StrCmp $0 "" _cu_pathDone ; Remove our entry (with leading or trailing semicolons) @@ -145,8 +169,17 @@ FunctionEnd Push "$INSTDIR\resources\cli" Call un._cu_RemoveFromPath Pop $0 + + ; If PATH is now empty, delete the registry value instead of writing "" + StrCmp $0 "" _cu_deletePath WriteRegExpandStr HKCU "Environment" "Path" $0 - SendMessage ${HWND_BROADCAST} ${WM_SETTINGCHANGE} 0 "STR:Environment" /TIMEOUT=500 + Goto _cu_pathBroadcast + + _cu_deletePath: + DeleteRegValue HKCU "Environment" "Path" + + _cu_pathBroadcast: + SendMessage ${HWND_BROADCAST} ${WM_SETTINGCHANGE} 0 "STR:Environment" /TIMEOUT=500 _cu_pathDone: