fix windows installer (#3979)

* add loop detection Clash Verge Lnk

* add delete the window-state.json file .window-state.json file

* add cycle through the registry and delete useless registry entries

* add delete the specified registry path

* update logs
This commit is contained in:
Dyna
2025-07-04 12:28:15 +08:00
committed by GitHub
parent 941921904c
commit 553438d219
2 changed files with 161 additions and 40 deletions

View File

@@ -691,8 +691,6 @@ SectionEnd
app_check_done:
!macroend
Var VC_REDIST_URL
Var VC_REDIST_EXE
@@ -701,25 +699,25 @@ Section CheckAndInstallVSRuntime
${If} ${IsNativeARM64}
StrCpy $VC_REDIST_URL "https://aka.ms/vs/17/release/vc_redist.arm64.exe"
StrCpy $VC_REDIST_EXE "vc_redist.arm64.exe"
; 检查关键DLL
IfFileExists "$SYSDIR\vcruntime140.dll" 0 checkInstall
IfFileExists "$SYSDIR\msvcp140.dll" Done checkInstall
${ElseIf} ${RunningX64}
StrCpy $VC_REDIST_URL "https://aka.ms/vs/17/release/vc_redist.x64.exe"
StrCpy $VC_REDIST_EXE "vc_redist.x64.exe"
; 检查关键DLL
IfFileExists "$SYSDIR\vcruntime140.dll" 0 checkInstall
IfFileExists "$SYSDIR\msvcp140.dll" Done checkInstall
${Else}
StrCpy $VC_REDIST_URL "https://aka.ms/vs/17/release/vc_redist.x86.exe"
StrCpy $VC_REDIST_EXE "vc_redist.x86.exe"
; 检查关键DLL
IfFileExists "$SYSDIR\vcruntime140.dll" 0 checkInstall
IfFileExists "$SYSDIR\vcruntime140.dll" 0 checkInstall
IfFileExists "$SYSDIR\msvcp140.dll" Done checkInstall
${EndIf}
@@ -754,30 +752,34 @@ Section CheckAndInstallVSRuntime
${Else}
DetailPrint "Visual C++ Redistributable 下载失败"
${EndIf}
Done:
SectionEnd
Section Install
SetOutPath $INSTDIR
nsExec::Exec 'netsh int tcp res'
!insertmacro CheckIfAppIsRunning
!insertmacro CheckAllVergeProcesses
; 删除 window-state.json 文件 .window-state.json 文件
DetailPrint "开始删除删除 window-state.json or .window-state.json"
SetShellVarContext current
Delete "$APPDATA\io.github.clash-verge-rev.clash-verge-rev\window-state.json"
Delete "$APPDATA\io.github.clash-verge-rev.clash-verge-rev\.window-state.json"
; 清理自启动注册表项
DetailPrint "Cleaning auto-launch registry entries..."
StrCpy $R1 "Software\Microsoft\Windows\CurrentVersion\Run"
SetRegView 64
SetRegView 64
; 清理旧版本的注册表项 (Clash Verge)
ReadRegStr $R2 HKCU "$R1" "Clash Verge"
${If} $R2 != ""
DeleteRegValue HKCU "$R1" "Clash Verge"
${EndIf}
ReadRegStr $R2 HKLM "$R1" "Clash Verge"
${If} $R2 != ""
DeleteRegValue HKLM "$R1" "Clash Verge"
@@ -788,7 +790,7 @@ Section Install
${If} $R2 != ""
DeleteRegValue HKCU "$R1" "clash-verge"
${EndIf}
ReadRegStr $R2 HKLM "$R1" "clash-verge"
${If} $R2 != ""
DeleteRegValue HKLM "$R1" "clash-verge"
@@ -798,7 +800,7 @@ Section Install
; Delete clash-verge.desktop
IfFileExists "$INSTDIR\Clash Verge.exe" 0 +2
Delete "$INSTDIR\Clash Verge.exe"
; Copy main executable
File "${MAINBINARYSRCPATH}"
@@ -916,26 +918,29 @@ FunctionEnd
!macroend
Section Uninstall
;删除 window-state.json 文件
SetShellVarContext current
Delete "$APPDATA\io.github.clash-verge-rev.clash-verge-rev\window-state.json"
!insertmacro CheckIfAppIsRunning
!insertmacro CheckAllVergeProcesses
!insertmacro RemoveVergeService
; 删除 window-state.json 文件 .window-state.json 文件
DetailPrint "开始删除删除 window-state.json or .window-state.json"
SetShellVarContext current
Delete "$APPDATA\io.github.clash-verge-rev.clash-verge-rev\window-state.json"
Delete "$APPDATA\io.github.clash-verge-rev.clash-verge-rev\.window-state.json"
; 清理自启动注册表项
DetailPrint "Cleaning auto-launch registry entries..."
StrCpy $R1 "Software\Microsoft\Windows\CurrentVersion\Run"
SetRegView 64
; 清理旧版本的注册表项 (Clash Verge)
ReadRegStr $R2 HKCU "$R1" "Clash Verge"
${If} $R2 != ""
DeleteRegValue HKCU "$R1" "Clash Verge"
${EndIf}
ReadRegStr $R2 HKLM "$R1" "Clash Verge"
${If} $R2 != ""
DeleteRegValue HKLM "$R1" "Clash Verge"
@@ -946,7 +951,7 @@ Section Uninstall
${If} $R2 != ""
DeleteRegValue HKCU "$R1" "clash-verge"
${EndIf}
ReadRegStr $R2 HKLM "$R1" "clash-verge"
${If} $R2 != ""
DeleteRegValue HKLM "$R1" "clash-verge"
@@ -978,24 +983,144 @@ Section Uninstall
{{/each}}
RMDir "$INSTDIR"
; 删除固定栏
!insertmacro DeleteAppUserModelId
!insertmacro UnpinShortcut "$SMPROGRAMS\$AppStartMenuFolder\${PRODUCTNAME}.lnk"
!insertmacro UnpinShortcut "$DESKTOP\${PRODUCTNAME}.lnk"
; 兼容旧名称快捷方式
!insertmacro UnpinShortcut "$SMPROGRAMS\$AppStartMenuFolder\clash-verge.lnk"
!insertmacro UnpinShortcut "$DESKTOP\clash-verge.lnk"
!insertmacro UnpinShortcut "$SMPROGRAMS\$AppStartMenuFolder\${MAINBINARYNAME}.lnk"
!insertmacro UnpinShortcut "$DESKTOP\${MAINBINARYNAME}.lnk"
; Remove start menu shortcut
!insertmacro MUI_STARTMENU_GETFOLDER Application $AppStartMenuFolder
; 删除所有用户的桌面快捷方式
DetailPrint "开始删除所有用户桌面的 Clash Verge 快捷方式..."
; 删除公共桌面快捷方式
Delete "C:\Users\Public\Desktop\Clash Verge.lnk"
Delete "C:\Users\Public\Desktop\clash-verge.lnk"
; 枚举所有用户配置文件目录
SetRegView 64
ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" ""
; 初始化循环
StrCpy $R1 0
Loop:
EnumRegKey $R2 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" $R1
${If} $R2 == ""
Goto Done
${EndIf}
; 读取用户配置文件路径
ReadRegStr $R3 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$R2" "ProfileImagePath"
${If} $R3 != ""
; 构建用户桌面路径
StrCpy $R4 "$R3\Desktop"
; 删除该用户桌面的快捷方式
Delete "$R4\Clash Verge.lnk"
Delete "$R4\clash-verge.lnk"
DetailPrint "尝试删除用户 '$R3' 桌面的 Clash Verge 快捷方式"
${EndIf}
; 递增循环计数器
IntOp $R1 $R1 + 1
Goto Loop
Done:
DetailPrint "所有用户桌面快捷方式删除完成"
; 删除用户开始菜单文件夹
Delete "$SMPROGRAMS\$AppStartMenuFolder\${PRODUCTNAME}.lnk"
; 兼容旧名称快捷方式
Delete "$SMPROGRAMS\$AppStartMenuFolder\clash-verge.lnk"
RMDir "$SMPROGRAMS\$AppStartMenuFolder"
Delete "$SMPROGRAMS\$AppStartMenuFolder\${MAINBINARYNAME}.lnk"
RMDir /r /REBOOTOK "$SMPROGRAMS\$AppStartMenuFolder"
; 删除系统级开始菜单中的 Clash Verge
Delete "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Clash Verge\Clash Verge.lnk"
Delete "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Clash Verge\clash-verge.lnk"
RMDir /r /REBOOTOK "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Clash Verge"
; 删除所有带 Clash Verge 或 clash-verge 的注册表项
DetailPrint "开始清理所有 Clash Verge 相关的注册表项..."
; 设置注册表查看模式 (64位)
SetRegView 64
; 清理 CurrentVersion\Run 中的自启动项
StrCpy $R1 "Software\Microsoft\Windows\CurrentVersion\Run"
DeleteRegValue HKCU "$R1" "Clash Verge"
DeleteRegValue HKCU "$R1" "clash-verge"
DeleteRegValue HKLM "$R1" "Clash Verge"
DeleteRegValue HKLM "$R1" "clash-verge"
; 清理 App Paths
DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Clash Verge.exe"
DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\clash-verge.exe"
; 删除指定的注册表路径
DeleteRegKey HKLM "Software\Clash Verge Rev"
DeleteRegKey HKCU "Software\Clash Verge Rev"
DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\ClashVerge"
DeleteRegKey HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Clash Verge"
; 清理 Uninstall 信息
StrCpy $R1 0
EnumUninstallLoop:
EnumRegKey $R2 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" $R1
${If} $R2 == ""
Goto EnumUninstallDone
${EndIf}
ReadRegStr $R3 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$R2" "DisplayName"
${If} $R3 != ""
StrCmp $R3 "Clash Verge" 0 +3
StrCmp $R3 "clash-verge" 0 +2
DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$R2"
${EndIf}
IntOp $R1 $R1 + 1
Goto EnumUninstallLoop
EnumUninstallDone:
; 清理用户特定的注册表项
StrCpy $R1 0
EnumHKCULoop:
EnumRegKey $R2 HKCU "SOFTWARE" $R1
${If} $R2 == ""
Goto EnumHKCUDone
${EndIf}
ReadRegStr $R3 HKCU "SOFTWARE\$R2" ""
${If} $R3 != ""
StrCmp $R3 "Clash Verge" 0 +3
StrCmp $R3 "clash-verge" 0 +2
DeleteRegKey HKCU "SOFTWARE\$R2"
${EndIf}
IntOp $R1 $R1 + 1
Goto EnumHKCULoop
EnumHKCUDone:
; 清理系统范围的注册表项
StrCpy $R1 0
EnumHKLMLoop:
EnumRegKey $R2 HKLM "SOFTWARE" $R1
${If} $R2 == ""
Goto EnumHKLMDone
${EndIf}
ReadRegStr $R3 HKLM "SOFTWARE\$R2" ""
${If} $R3 != ""
StrCmp $R3 "Clash Verge" 0 +3
StrCmp $R3 "clash-verge" 0 +2
DeleteRegKey HKLM "SOFTWARE\$R2"
${EndIf}
IntOp $R1 $R1 + 1
Goto EnumHKLMLoop
EnumHKLMDone:
DetailPrint "注册表清理完成"
; Remove desktop shortcuts
Delete "$DESKTOP\${PRODUCTNAME}.lnk"
; 兼容旧名称快捷方式
Delete "$DESKTOP\clash-verge.lnk"
; Remove registry information for add/remove programs
!if "${INSTALLMODE}" == "both"
@@ -1015,10 +1140,6 @@ Section Uninstall
RmDir /r "$LOCALAPPDATA\${BUNDLEID}"
${EndIf}
;删除 window-state.json 文件
SetShellVarContext current
Delete "$APPDATA\io.github.clash-verge-rev.clash-verge-rev\window-state.json"
${GetOptions} $CMDLINE "/P" $R0
IfErrors +2 0
SetAutoClose true
@@ -1051,7 +1172,6 @@ FunctionEnd
System::Free $4
System::Free $5
${IPropertyStore::Commit} $2 ""
${IUnknown::Release} $2 ""
${IPersistFile::Save} $1 '("${shortcut}",1)'
${EndIf}
${IUnknown::Release} $1 ""