fix: address Gemini code review feedback

- Define UnStrStr macro for uninstaller string functions
- Use un.StrStr instead of StrStr in uninstaller context
- Rewrite un.RemoveFromPath with correct offset calculations
  and semicolon handling to prevent PATH corruption
- Use dynamic version fetch from GitHub API in CLASSROOM_INSTALL.md
This commit is contained in:
songzhenrui
2026-05-25 12:24:40 +08:00
committed by Hunter B
parent c2c36cca11
commit e6de6f47d5
2 changed files with 38 additions and 40 deletions
+1 -1
View File
@@ -51,7 +51,7 @@ $binDir = "$env:LOCALAPPDATA\Programs\CodeWhale\bin"
New-Item -ItemType Directory -Force -Path $binDir
# 2. Download binaries (adjust URL to your mirror or release tag)
$tag = "v0.9.0" # replace with desired version
$tag = (Invoke-RestMethod -Uri "https://api.github.com/repos/Hmbown/CodeWhale/releases/latest").tag_name
Invoke-WebRequest -Uri "https://github.com/Hmbown/CodeWhale/releases/download/$tag/codewhale-x64.exe" -OutFile "$binDir\codewhale.exe"
Invoke-WebRequest -Uri "https://github.com/Hmbown/CodeWhale/releases/download/$tag/codewhale-tui-x64.exe" -OutFile "$binDir\codewhale-tui.exe"
+29 -31
View File
@@ -25,6 +25,7 @@
!include "StrFunc.nsh"
${StrStr}
${UnStrStr}
;--------------------------------
; General
@@ -127,11 +128,9 @@ Section "Uninstall"
; Remove from current-user PATH
ReadRegStr $0 HKCU "Environment" "Path"
${StrStr} $1 $0 "$INSTDIR\bin"
${un.StrStr} $1 $0 "$INSTDIR\bin"
StrCmp $1 "" path_clean_done
; Remove the entry
; Build new PATH without the install dir
; This handles: "...\path;$INSTDIR\bin" and "$INSTDIR\bin;...\path" and standalone
Push "$0"
Push "$INSTDIR\bin"
Call un.RemoveFromPath
@@ -146,7 +145,7 @@ Section "Uninstall"
SectionEnd
;--------------------------------
; Helper: Remove a directory from PATH
; Helper: Remove a directory from PATH (uninstaller version)
; Input: PATH string (on stack), directory to remove (on stack)
; Output: cleaned PATH (on stack)
;--------------------------------
@@ -154,44 +153,43 @@ Function un.RemoveFromPath
Exch $R0 ; directory to remove
Exch
Exch $R1 ; original PATH
Push $R2
Push $R3
Push $R4
Push $R2 ; prefix
Push $R3 ; suffix
Push $R4 ; match result
StrCpy $R2 ""
StrCpy $R3 ""
loop:
${StrStr} $R4 $R1 $R0
${un.StrStr} $R4 $R1 $R0
StrCmp $R4 "" done
; Found — get substring before match
StrLen $R4 $R4
StrLen $R3 $R1
IntOp $R3 $R3 - $R4
StrCpy $R2 $R1 $R3
; Get substring after match + dir length
StrLen $R3 $R0
IntOp $R4 $R4 - $R3
StrCpy $R3 $R1 "" $R4
; Strip leading semicolon from remainder
; Calculate prefix
StrLen $R2 $R1
StrLen $R3 $R4
IntOp $R3 $R2 - $R3 ; Match offset
StrCpy $R2 $R1 $R3 ; Prefix string
; Calculate suffix
StrLen $R4 $R0
IntOp $R4 $R3 + $R4 ; Suffix offset = Match offset + Dir length
StrCpy $R3 $R1 "" $R4 ; Suffix string
; Clean up semicolons
StrCpy $R4 $R3 1
StrCmp $R4 ";" 0 +2
StrCpy $R3 $R3 "" 1
; Strip trailing semicolon from prefix
StrCpy $R3 $R3 "" 1 ; Strip leading semicolon from suffix
StrLen $R4 $R2
IntOp $R4 $R4 - 1
StrCpy $R4 $R2 1 $R4
StrCmp $R4 ";" 0 +2
StrCpy $R2 $R2 $R4
StrCpy $R0 $R2 1 $R4
StrCmp $R0 ";" 0 +2
StrCpy $R2 $R2 $R4 ; Strip trailing semicolon from prefix
; Concatenate
StrCmp $R2 "" 0 +2
StrCpy $R2 $R3
StrCmp $R2 "" 0 +3
StrCpy $R1 $R3
Goto done
StrCmp $R3 "" 0 +2
StrCmp $R3 "" 0 +3
StrCpy $R1 $R2
Goto done
StrCpy $R1 "$R2;$R3"
Goto done
done:
Pop $R4