From 406f603015230c4c9b1f6cfe929e30d5d6617466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98=E9=98=BF=E6=B1=9F=28Relakkes?= =?UTF-8?q?=29?= Date: Tue, 14 Jul 2026 04:31:01 +0800 Subject: [PATCH] fix(desktop): skip legacy recovery on fresh install --- desktop/build/installer.nsh | 71 +++++++++++++++++++---------- scripts/pr/release-workflow.test.ts | 3 ++ 2 files changed, 51 insertions(+), 23 deletions(-) diff --git a/desktop/build/installer.nsh b/desktop/build/installer.nsh index 14fa3a67..9d765a47 100644 --- a/desktop/build/installer.nsh +++ b/desktop/build/installer.nsh @@ -6,6 +6,10 @@ Var pid !ifndef BUILD_UNINSTALLER Var ccHahaRecoveryDone +Var ccHahaPerUserInstallLocation +Var ccHahaPerMachineInstallLocation +Var ccHahaPerUserUninstallString +Var ccHahaPerMachineUninstallString Function CcHahaUninstallerParent Exch $R0 @@ -155,31 +159,52 @@ FunctionEnd !macro CcHahaRunLegacyRecovery ${If} $ccHahaRecoveryDone != "1" - StrCpy $8 "trusted-user" - ${If} ${UAC_IsAdmin} - ${AndIfNot} ${UAC_IsInnerInstance} - StrCpy $8 "untrusted-elevated" - ${EndIf} - - ${If} ${UAC_IsInnerInstance} - StrCpy $8 "trusted-uac-outer" - !insertmacro UAC_AsUser_Call Function CcHahaRecoverLegacy ${UAC_SYNCREGISTERS}|${UAC_SYNCOUTDIR}|${UAC_SYNCINSTDIR} - ${Else} - Call CcHahaRecoverLegacy - ${EndIf} - - ${If} $0 != "0" - DetailPrint "Legacy data recovery stopped the installer (helper exit code: $0; output: $1)" - ${If} $1 == "" - StrCpy $1 "Recovery helper failed without diagnostic output (exit code $0)" + ReadRegStr $ccHahaPerUserInstallLocation HKCU "${INSTALL_REGISTRY_KEY}" InstallLocation + ReadRegStr $ccHahaPerMachineInstallLocation HKLM "${INSTALL_REGISTRY_KEY}" InstallLocation + ReadRegStr $ccHahaPerUserUninstallString HKCU "${UNINSTALL_REGISTRY_KEY}" UninstallString + ReadRegStr $ccHahaPerMachineUninstallString HKLM "${UNINSTALL_REGISTRY_KEY}" UninstallString + !ifdef UNINSTALL_REGISTRY_KEY_2 + ${If} $ccHahaPerUserUninstallString == "" + ReadRegStr $ccHahaPerUserUninstallString HKCU "${UNINSTALL_REGISTRY_KEY_2}" UninstallString ${EndIf} - StrCpy $R2 "$1" 360 - MessageBox MB_ICONSTOP|MB_OK "Claude Code Haha stopped setup before removing the old version. Reason: $R2$\r$\n$\r$\nClose the app and retry. If the reason mentions an elevated installer, launch setup normally instead of using Run as administrator.$\r$\n$\r$\nClaude Code Haha 已在删除旧版本前停止安装。原因:$R2$\r$\n$\r$\n请关闭旧程序后重试;如果原因提到安装器权限过高,请直接双击运行,不要使用“以管理员身份运行”。旧版本和原数据尚未删除。" - SetErrorLevel 20 - Quit + ${If} $ccHahaPerMachineUninstallString == "" + ReadRegStr $ccHahaPerMachineUninstallString HKLM "${UNINSTALL_REGISTRY_KEY_2}" UninstallString + ${EndIf} + !endif + + ${If} $ccHahaPerUserInstallLocation == "" + ${AndIf} $ccHahaPerMachineInstallLocation == "" + ${AndIf} $ccHahaPerUserUninstallString == "" + ${AndIf} $ccHahaPerMachineUninstallString == "" + StrCpy $ccHahaRecoveryDone "1" + DetailPrint "No registered installation needs legacy data recovery" + ${Else} + StrCpy $8 "trusted-user" + ${If} ${UAC_IsAdmin} + ${AndIfNot} ${UAC_IsInnerInstance} + StrCpy $8 "untrusted-elevated" + ${EndIf} + + ${If} ${UAC_IsInnerInstance} + StrCpy $8 "trusted-uac-outer" + !insertmacro UAC_AsUser_Call Function CcHahaRecoverLegacy ${UAC_SYNCREGISTERS}|${UAC_SYNCOUTDIR}|${UAC_SYNCINSTDIR} + ${Else} + Call CcHahaRecoverLegacy + ${EndIf} + + ${If} $0 != "0" + DetailPrint "Legacy data recovery stopped the installer (helper exit code: $0; output: $1)" + ${If} $1 == "" + StrCpy $1 "Recovery helper failed without diagnostic output (exit code $0)" + ${EndIf} + StrCpy $R2 "$1" 360 + MessageBox MB_ICONSTOP|MB_OK "Claude Code Haha stopped setup before removing the old version. Reason: $R2$\r$\n$\r$\nClose the app and retry. If the reason mentions an elevated installer, launch setup normally instead of using Run as administrator.$\r$\n$\r$\nClaude Code Haha 已在删除旧版本前停止安装。原因:$R2$\r$\n$\r$\n请关闭旧程序后重试;如果原因提到安装器权限过高,请直接双击运行,不要使用“以管理员身份运行”。旧版本和原数据尚未删除。" + SetErrorLevel 20 + Quit + ${EndIf} + StrCpy $ccHahaRecoveryDone "1" + DetailPrint "Legacy Claude Code Haha data safety check completed" ${EndIf} - StrCpy $ccHahaRecoveryDone "1" - DetailPrint "Legacy Claude Code Haha data safety check completed" ${EndIf} !macroend !endif diff --git a/scripts/pr/release-workflow.test.ts b/scripts/pr/release-workflow.test.ts index 083a68c3..4350322d 100644 --- a/scripts/pr/release-workflow.test.ts +++ b/scripts/pr/release-workflow.test.ts @@ -510,6 +510,9 @@ describe('release desktop workflow', () => { expect(installerHook).toContain('ReadEnvStr $6 CLAUDE_CONFIG_DIR') expect(installerHook).toContain('ReadEnvStr $7 CC_HAHA_APP_PORTABLE_DIR') expect(installerHook).toContain('No registered installation needs legacy data recovery') + expect(installerHook).toContain('Var ccHahaPerUserInstallLocation') + expect(installerHook).toContain('Var ccHahaPerMachineInstallLocation') + expect(installerHook).toMatch(/!macro CcHahaRunLegacyRecovery[\s\S]*ReadRegStr \$ccHahaPerUserInstallLocation[\s\S]*\$ccHahaPerUserUninstallString == ""[\s\S]*No registered installation needs legacy data recovery[\s\S]*Call CcHahaRecoverLegacy/) expect(installerHook).toContain('SetErrorLevel 20') expect(installerHook).toContain('Quit') expect(recoveryHelper).toContain('function Get-LegacyActiveSource')