installer.nsh 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834
  1. !include nsDialogs.nsh
  2. !include FileFunc.nsh
  3. !ifndef ZCODE_INSTALLER_DEFAULT_LOG_PATH
  4. !define ZCODE_INSTALLER_DEFAULT_LOG_PATH "$TEMP\ZCode-installer.log"
  5. !endif
  6. !ifndef ZCODE_INSTALLER_ELEVATED_LOG_PATH
  7. !define ZCODE_INSTALLER_ELEVATED_LOG_PATH "$WINDIR\Logs\ZCode-installer.log"
  8. !endif
  9. !ifndef ZCODE_INSTALLER_IS_ELEVATED_INNER
  10. ; 修复原因:来源只在测试夹具模拟内层,正式默认恒假会让提权进程继续使用调用方 /LOG。
  11. ; 使用 electron-builder 同一 UAC 判据;隔离夹具仍可显式替换,不改变真正的提权流程。
  12. !include UAC.nsh
  13. !define ZCODE_INSTALLER_IS_ELEVATED_INNER `${UAC_IsInnerInstance}`
  14. !endif
  15. !ifndef ZCODE_INSTALLER_PROCESS_HELPER
  16. ; CR-01 修复原因:普通 NSIS 只有 APP_64/APP_ARM64(压缩包路径),没有 APP_DIR_*;
  17. ; 正式构建由 afterPack 落盘按架构的 helper define 文件(见 electron-builder.config.js),
  18. ; 编译时按目标架构 include;缺失不在此报错,宏内在真正使用处明确失败。
  19. !ifdef APP_ARM64
  20. !include /NONFATAL "${__FILEDIR__}\generated\zcode-process-helper-arm64.nsh"
  21. !else
  22. !include /NONFATAL "${__FILEDIR__}\generated\zcode-process-helper-x64.nsh"
  23. !endif
  24. !endif
  25. !ifndef ZCODE_INSTALL_MANIFEST_NAME
  26. !define ZCODE_INSTALL_MANIFEST_NAME ".zcode-install-manifest"
  27. !endif
  28. !ifndef ZCODE_UNINSTALLER_LOG_PATH
  29. !define ZCODE_UNINSTALLER_LOG_PATH "$TEMP\ZCode-uninstaller.log"
  30. !endif
  31. !ifndef ZCODE_UNINSTALLER_FUNCTION_PREFIX
  32. !define ZCODE_UNINSTALLER_FUNCTION_PREFIX "un."
  33. !endif
  34. !ifdef BUILD_UNINSTALLER
  35. Var ZCodeUninstallerLogUnavailable
  36. ; 卸载器只在更新时删除旧文件;单独记录清理阶段,避免外层把权限/空间错误误报成应用仍在运行。
  37. !macro ZCodeReportUninstallerStage MESSAGE
  38. DetailPrint "ZCode: ${MESSAGE}"
  39. Push "${MESSAGE}"
  40. Call ${ZCODE_UNINSTALLER_FUNCTION_PREFIX}ZCodeWriteUninstallerLog
  41. !macroend
  42. Function ${ZCODE_UNINSTALLER_FUNCTION_PREFIX}ZCodeWriteUninstallerLog
  43. Exch $R9
  44. Push $R0
  45. Push $R1
  46. Push $R2
  47. StrCmp $ZCodeUninstallerLogUnavailable "1" zcodeUninstallerLogDone
  48. ClearErrors
  49. FileOpen $R1 "${ZCODE_UNINSTALLER_LOG_PATH}" a
  50. IfErrors zcodeUninstallerLogFailed zcodeUninstallerLogWrite
  51. zcodeUninstallerLogWrite:
  52. System::Call "kernel32::GetCurrentProcessId() i.R0"
  53. FileSeek $R1 0 END
  54. FileWrite $R1 "[pid=$R0] $R9$\r$\n"
  55. FileClose $R1
  56. Goto zcodeUninstallerLogDone
  57. zcodeUninstallerLogFailed:
  58. ; 日志不可写不应改变卸载结果,保留原始清理错误供外层处理。
  59. StrCpy $ZCodeUninstallerLogUnavailable "1"
  60. ClearErrors
  61. zcodeUninstallerLogDone:
  62. Pop $R2
  63. Pop $R1
  64. Pop $R0
  65. Pop $R9
  66. FunctionEnd
  67. !macro customRemoveFilesDiagnosticsStart
  68. !insertmacro ZCodeReportUninstallerStage "cleanup-started"
  69. !macroend
  70. !macro customRemoveFilesDiagnosticsComplete
  71. !insertmacro ZCodeReportUninstallerStage "cleanup-completed"
  72. !macroend
  73. !endif
  74. !macro customRemoveFiles
  75. ; Bugfix:electron-builder 默认在更新时递归删除整个 $INSTDIR,用户放入的无关文件也会被清掉。
  76. ; 只按上一版本随包生成的所有权清单删除,清单缺失时迁移旧版本采用 fail-open 保留策略。
  77. ${if} ${isUpdated}
  78. !ifdef BUILD_UNINSTALLER
  79. !insertmacro customRemoveFilesDiagnosticsStart
  80. !endif
  81. ClearErrors
  82. FileOpen $R0 "$INSTDIR\${ZCODE_INSTALL_MANIFEST_NAME}" r
  83. IfErrors zcodeManifestMissing
  84. zcodeManifestRead:
  85. ClearErrors
  86. FileRead $R0 $R1
  87. IfErrors zcodeManifestClose
  88. ; NSIS FileRead 保留行尾 CRLF;打包清单统一使用换行结尾,先去掉两个行尾字符。
  89. StrCpy $R1 $R1 -2
  90. StrCmp $R1 "" zcodeManifestRead
  91. ; 拒绝绝对路径和 .. 前缀,避免损坏或篡改清单越界删除。
  92. StrCpy $R2 $R1 1
  93. StrCmp $R2 "\\" zcodeManifestRead
  94. StrCmp $R2 "/" zcodeManifestRead
  95. StrCpy $R2 $R1 2
  96. StrCmp $R2 ".." zcodeManifestRead
  97. StrCmp $R1 "${UNINSTALL_FILENAME}" zcodeManifestRead
  98. ; 清单是当前打开的元数据,自引用条目不能当作普通载荷删除。
  99. StrCmp $R1 "${ZCODE_INSTALL_MANIFEST_NAME}" zcodeManifestRead
  100. GetFullPathName $R2 "$INSTDIR\$R1"
  101. StrCmp $R2 "$INSTDIR\$R1" 0 zcodeManifestRead
  102. ; 当前版本卸载器与外层安装器是两个进程;逐项记录到卸载器日志,便于核对真正尝试删除的文件。
  103. !ifdef BUILD_UNINSTALLER
  104. !insertmacro ZCodeReportUninstallerStage "cleanup-file path=$R1"
  105. !endif
  106. ClearErrors
  107. Delete "$INSTDIR\$R1"
  108. IfErrors zcodeManifestDeleteFailed
  109. Goto zcodeManifestRead
  110. zcodeManifestDeleteFailed:
  111. System::Call 'kernel32::GetLastError() i.R2'
  112. FileClose $R0
  113. !ifdef BUILD_UNINSTALLER
  114. !insertmacro ZCodeReportUninstallerStage "cleanup-failed reason=delete-failed path=$R1 win32-error=$R2"
  115. !endif
  116. Abort "无法删除旧版本文件:$INSTDIR\$R1(Win32 错误 $R2)"
  117. zcodeManifestClose:
  118. FileClose $R0
  119. Goto zcodeManifestDone
  120. zcodeManifestMissing:
  121. ; 首次从旧版本升级时没有清单,不能猜测所有权并删除用户文件。
  122. !ifdef BUILD_UNINSTALLER
  123. !insertmacro ZCodeReportUninstallerStage "cleanup-skipped reason=manifest-missing action=preserve"
  124. !endif
  125. ClearErrors
  126. zcodeManifestDone:
  127. !ifdef BUILD_UNINSTALLER
  128. !insertmacro customRemoveFilesDiagnosticsComplete
  129. !endif
  130. ${else}
  131. ; 普通卸载仍保持 electron-builder 的全量删除语义;ownership 清单只约束覆盖更新。
  132. SetOutPath $TEMP
  133. RMDir /r $INSTDIR
  134. ${endIf}
  135. !macroend
  136. !ifndef BUILD_UNINSTALLER
  137. Var ZCodeInstallerLogPath
  138. Var ZCodeInstallerLogUnavailable
  139. Var ZCodeInstallerProcessRole
  140. Var ZCodeUninstallerDetailsUnavailable
  141. Var ZCodePreviousUninstallerSupportsManifest
  142. ; 详情面板和文件日志共用同一条阶段事件,避免静默安装丢失关键上下文。
  143. !macro ZCodeReportInstallerStage MESSAGE
  144. SetDetailsPrint listonly
  145. DetailPrint "ZCode: ${MESSAGE}"
  146. Push "${MESSAGE}"
  147. Call ZCodeWriteInstallerLog
  148. !macroend
  149. Function ZCodeWriteInstallerLog
  150. Exch $R9
  151. Push $R0
  152. Push $R1
  153. Push $R2
  154. StrCmp $ZCodeInstallerLogPath "" zcodeInstallerLogDone
  155. StrCmp $ZCodeInstallerLogUnavailable "1" zcodeInstallerLogDone
  156. StrCpy $R2 0
  157. zcodeInstallerLogOpen:
  158. ClearErrors
  159. FileOpen $R1 $ZCodeInstallerLogPath a
  160. IfErrors zcodeInstallerLogRetry zcodeInstallerLogWrite
  161. zcodeInstallerLogRetry:
  162. IntOp $R2 $R2 + 1
  163. IntCmp $R2 3 zcodeInstallerLogFailed zcodeInstallerLogWait zcodeInstallerLogFailed
  164. zcodeInstallerLogWait:
  165. Sleep 50
  166. Goto zcodeInstallerLogOpen
  167. zcodeInstallerLogWrite:
  168. System::Call "kernel32::GetCurrentProcessId() i.R0"
  169. FileSeek $R1 0 END
  170. FileWrite $R1 "[pid=$R0] $R9$\r$\n"
  171. FileClose $R1
  172. Goto zcodeInstallerLogDone
  173. zcodeInstallerLogFailed:
  174. StrCpy $ZCodeInstallerLogUnavailable "1"
  175. ClearErrors
  176. zcodeInstallerLogDone:
  177. Pop $R2
  178. Pop $R1
  179. Pop $R0
  180. Pop $R9
  181. FunctionEnd
  182. Function ZCodeResetUninstallerLog
  183. StrCpy $ZCodeUninstallerDetailsUnavailable ""
  184. ClearErrors
  185. FileOpen $R0 "${ZCODE_UNINSTALLER_LOG_PATH}" w
  186. IfErrors zcodeUninstallerDetailsResetFailed zcodeUninstallerDetailsResetSucceeded
  187. zcodeUninstallerDetailsResetSucceeded:
  188. FileClose $R0
  189. Goto zcodeUninstallerDetailsResetDone
  190. zcodeUninstallerDetailsResetFailed:
  191. ; 外层详情不能读取旧卸载器日志时仍继续安装,文件日志和退出码仍是最终依据。
  192. StrCpy $ZCodeUninstallerDetailsUnavailable "1"
  193. ClearErrors
  194. zcodeUninstallerDetailsResetDone:
  195. FunctionEnd
  196. Function ZCodeShowUninstallerCleanupDetails
  197. Push $R0
  198. Push $R1
  199. Push $R2
  200. StrCmp $ZCodeUninstallerDetailsUnavailable "1" zcodeShowUninstallerDetailsDone
  201. ClearErrors
  202. FileOpen $R0 "${ZCODE_UNINSTALLER_LOG_PATH}" r
  203. IfErrors zcodeShowUninstallerDetailsDone
  204. zcodeShowUninstallerDetailsRead:
  205. ClearErrors
  206. FileRead $R0 $R1
  207. IfErrors zcodeShowUninstallerDetailsClose
  208. StrCmp $R1 "" zcodeShowUninstallerDetailsRead
  209. SetDetailsPrint listonly
  210. DetailPrint "ZCode: cleanup-log $R1"
  211. Goto zcodeShowUninstallerDetailsRead
  212. zcodeShowUninstallerDetailsClose:
  213. FileClose $R0
  214. zcodeShowUninstallerDetailsDone:
  215. Pop $R2
  216. Pop $R1
  217. Pop $R0
  218. FunctionEnd
  219. !macro preInit
  220. Call ZCodeInitializeInstallerLog
  221. !macroend
  222. !macro customInit
  223. IfSilent zcodeInstallerInitSilent zcodeInstallerInitInteractive
  224. zcodeInstallerInitSilent:
  225. !insertmacro ZCodeReportInstallerStage "installer-initialized mode=silent"
  226. Goto zcodeInstallerInitDone
  227. zcodeInstallerInitInteractive:
  228. !insertmacro ZCodeReportInstallerStage "installer-initialized mode=interactive"
  229. zcodeInstallerInitDone:
  230. !macroend
  231. ; 这些宏由打包时的 electron-builder installSection.nsh 补丁按安装顺序调用。
  232. ; 只有阶段 marker 写入详情和日志,解压文件明细由 NSIS 的 File 命令在 listonly 模式输出。
  233. !macro customInstallSectionStarted
  234. !insertmacro ZCodeReportInstallerStage "install-started"
  235. !macroend
  236. !macro customInstallCleanupStarted
  237. Call ZCodeResetUninstallerLog
  238. !insertmacro ZCodeReportInstallerStage "cleanup-started"
  239. !macroend
  240. !macro customInstallCleanupCompleted
  241. !insertmacro ZCodeReportInstallerStage "cleanup-completed"
  242. Call ZCodeShowUninstallerCleanupDetails
  243. !macroend
  244. !macro customInstallExtractStarted
  245. !insertmacro ZCodeReportInstallerStage "extract-started"
  246. !macroend
  247. !macro customInstallExtractCompleted
  248. !insertmacro ZCodeReportInstallerStage "extract-completed"
  249. !macroend
  250. !macro customInstallShortcutsStarted
  251. !insertmacro ZCodeReportInstallerStage "shortcuts-started"
  252. !macroend
  253. !macro customInstallShortcutsCompleted
  254. !insertmacro ZCodeReportInstallerStage "shortcuts-completed"
  255. !macroend
  256. Function ZCodeDetectPreviousUninstallerCapabilities
  257. StrCpy $ZCodePreviousUninstallerSupportsManifest "0"
  258. ; manifest 是卸载器能力标记:存在即表示旧卸载器会按清单选择性删除。
  259. IfFileExists "$INSTDIR\${ZCODE_INSTALL_MANIFEST_NAME}" 0 zcodePreviousUninstallerCapabilityCheckNested
  260. StrCpy $ZCodePreviousUninstallerSupportsManifest "1"
  261. Return
  262. zcodePreviousUninstallerCapabilityCheckNested:
  263. ; assisted installer 的目录页会在后续 instfilesPre 才补上 APP_FILENAME 子目录,提前兼容两种形态。
  264. IfFileExists "$INSTDIR\${APP_FILENAME}\${ZCODE_INSTALL_MANIFEST_NAME}" 0 zcodePreviousUninstallerCapabilityDone
  265. StrCpy $ZCodePreviousUninstallerSupportsManifest "1"
  266. zcodePreviousUninstallerCapabilityDone:
  267. FunctionEnd
  268. !macro ZCodeCleanupErrorMessage CHINESE ENGLISH
  269. ${If} $LANGUAGE == 2052
  270. MessageBox MB_OK|MB_ICONSTOP "${CHINESE}" /SD IDOK
  271. ${Else}
  272. MessageBox MB_OK|MB_ICONSTOP "${ENGLISH}" /SD IDOK
  273. ${EndIf}
  274. !macroend
  275. Var ZCodeCleanupSource
  276. Var ZCodeCleanupBackup
  277. Var ZCodeCleanupMode
  278. Var ZCodeCleanupFailed
  279. Var ZCodeCleanupManifest
  280. Var ZCodeCleanupManifestHasSelf
  281. ; 修复原因:PowerShell 或 Add-Type 被禁用时不能阻断已退出应用的更新;随包 helper 按路径验证句柄。
  282. !macro ZCodeStopPreviousInstallProcesses
  283. InitPluginsDir
  284. SetOutPath "$PLUGINSDIR"
  285. ; CR-01 修复原因:普通 NSIS 只有 APP_64/APP_ARM64(压缩包路径),没有 APP_DIR_*;
  286. ; helper 来源由文件顶层的生成 define 提供,缺失在此明确失败,不得回退压缩包宏。
  287. !ifndef ZCODE_INSTALLER_PROCESS_HELPER
  288. !error "Installer process helper requires ZCODE_INSTALLER_PROCESS_HELPER or generated define"
  289. !endif
  290. File /oname=zcode-installer-process-helper.exe "${ZCODE_INSTALLER_PROCESS_HELPER}"
  291. nsExec::ExecToStack /TIMEOUT=30000 `"$PLUGINSDIR\zcode-installer-process-helper.exe" "$installationDir\${APP_EXECUTABLE_FILENAME}"`
  292. Pop $R1
  293. Pop $R2
  294. StrCmp $R1 "0" zcodePreviousProcessesStopped
  295. !insertmacro ZCodeReportInstallerStage "process-cleanup-failed exit-code=$R1 install-dir=$installationDir details=$R2"
  296. !insertmacro ZCodeCleanupErrorMessage "无法验证或关闭旧版本进程,安装已停止。请关闭 ZCode 后重试。进程信息:$R2" "Cannot verify or close previous-version processes. Setup stopped. Close ZCode and retry. Process details: $R2"
  297. SetErrorLevel 2
  298. Quit
  299. zcodePreviousProcessesStopped:
  300. !insertmacro ZCodeReportInstallerStage "process-cleanup-completed install-dir=$installationDir details=$R2"
  301. !macroend
  302. ; 旧卸载器已删除的文件不会自行恢复。新安装器在调用旧代码前尽力保存受管文件,
  303. ; 只有完整备份才能用于清理失败后的恢复;备份失败不阻断安装。
  304. ; 自定义 include 先于 common.nsh;延迟展开,确保卸载器名称已定义,避免正式打包 warning 6000。
  305. !macro ZCodeDefineCleanupSnapshot
  306. Function ZCodeCleanupSnapshot
  307. Push $R0
  308. Push $R1
  309. Push $R2
  310. Push $R3
  311. Push $R4
  312. Push $R5
  313. StrCpy $R5 ""
  314. StrCpy $ZCodeCleanupFailed "0"
  315. StrCmp $ZCodeCleanupMode "restore" zcodeSnapshotRead
  316. StrCpy $ZCodeCleanupBackup ""
  317. StrCpy $ZCodeCleanupManifestHasSelf "0"
  318. IfFileExists "$ZCodeCleanupSource\${ZCODE_INSTALL_MANIFEST_NAME}" 0 zcodeSnapshotDone
  319. ${GetParent} $ZCodeCleanupSource $R0
  320. ClearErrors
  321. GetTempFileName $ZCodeCleanupBackup $R0
  322. IfErrors zcodeSnapshotFailed
  323. Delete "$ZCodeCleanupBackup"
  324. CreateDirectory "$ZCodeCleanupBackup"
  325. IfErrors zcodeSnapshotFailed
  326. System::Call 'kernel32::CopyFileW(w "$ZCodeCleanupSource\${ZCODE_INSTALL_MANIFEST_NAME}", w "$ZCodeCleanupBackup\${ZCODE_INSTALL_MANIFEST_NAME}", i 1) i.R3 ?e'
  327. Pop $R4
  328. StrCmp $R3 "0" zcodeSnapshotFailed
  329. GetTempFileName $ZCodeCleanupManifest "$ZCodeCleanupBackup"
  330. IfErrors zcodeSnapshotFailed
  331. FileOpen $R5 "$ZCodeCleanupManifest" w
  332. IfErrors zcodeSnapshotFailed
  333. zcodeSnapshotRead:
  334. StrCmp $ZCodeCleanupBackup "" zcodeSnapshotDone
  335. ClearErrors
  336. FileOpen $R0 "$ZCodeCleanupBackup\${ZCODE_INSTALL_MANIFEST_NAME}" r
  337. IfErrors zcodeSnapshotFailed
  338. zcodeSnapshotNext:
  339. ClearErrors
  340. FileRead $R0 $R1
  341. IfErrors zcodeSnapshotClose
  342. StrCpy $R1 $R1 -2
  343. StrCmp $R1 "" zcodeSnapshotNext
  344. StrCmp $ZCodeCleanupMode "restore" zcodeSnapshotValidateEntry
  345. StrCmp $R1 "${ZCODE_INSTALL_MANIFEST_NAME}" zcodeSnapshotSelfEntry
  346. FileWrite $R5 "$R1$\r$\n"
  347. IfErrors zcodeSnapshotFailedClose
  348. Goto zcodeSnapshotValidateEntry
  349. zcodeSnapshotSelfEntry:
  350. StrCpy $ZCodeCleanupManifestHasSelf "1"
  351. Goto zcodeSnapshotNext
  352. zcodeSnapshotFailedClose:
  353. StrCpy $ZCodeCleanupFailed "1"
  354. Goto zcodeSnapshotClose
  355. zcodeSnapshotValidateEntry:
  356. ; 只接受清单中规范的相对路径,拒绝越界、通配符和卸载器自身。
  357. StrCpy $R2 $R1 1
  358. StrCmp $R2 "\" zcodeSnapshotNext
  359. StrCmp $R2 "/" zcodeSnapshotNext
  360. StrCpy $R2 $R1 2
  361. StrCmp $R2 ".." zcodeSnapshotNext
  362. StrCmp $R1 "${UNINSTALL_FILENAME}" zcodeSnapshotNext
  363. ; 清单已在循环前单独备份;自引用时再次排他复制会因目标存在而中止更新。
  364. StrCmp $R1 "${ZCODE_INSTALL_MANIFEST_NAME}" zcodeSnapshotNext
  365. ; Windows NSIS 对已删除的目标返回空路径;恢复时校验仍存在的备份,不能跳过待补回文件。
  366. StrCpy $R3 "$ZCodeCleanupSource"
  367. StrCmp $ZCodeCleanupMode "restore" 0 +2
  368. StrCpy $R3 "$ZCodeCleanupBackup"
  369. GetFullPathName $R2 "$R3\$R1"
  370. StrCmp $R2 "$R3\$R1" 0 zcodeSnapshotNext
  371. StrCpy $R2 0
  372. zcodeSnapshotValidate:
  373. StrCpy $R3 $R1 1 $R2
  374. StrCmp $R3 "" zcodeSnapshotCopy
  375. StrCmp $R3 "*" zcodeSnapshotInvalidPath
  376. StrCmp $R3 "?" zcodeSnapshotInvalidPath
  377. StrCmp $R3 ":" zcodeSnapshotInvalidPath
  378. IntOp $R2 $R2 + 1
  379. Goto zcodeSnapshotValidate
  380. zcodeSnapshotInvalidPath:
  381. StrCpy $ZCodeCleanupFailed "1"
  382. Goto zcodeSnapshotClose
  383. zcodeSnapshotCopy:
  384. StrCmp $ZCodeCleanupMode "restore" zcodeSnapshotRestore
  385. IfFileExists "$ZCodeCleanupSource\$R1" 0 zcodeSnapshotNext
  386. ${GetParent} "$ZCodeCleanupBackup\$R1" $R2
  387. CreateDirectory "$R2"
  388. System::Call 'kernel32::CopyFileW(w "$ZCodeCleanupSource\$R1", w "$ZCodeCleanupBackup\$R1", i 1) i.R3 ?e'
  389. Pop $R4
  390. Goto zcodeSnapshotCopyResult
  391. zcodeSnapshotRestore:
  392. IfFileExists "$ZCodeCleanupBackup\$R1" 0 zcodeSnapshotNext
  393. IfFileExists "$ZCodeCleanupSource\$R1" 0 zcodeSnapshotRestoreMissing
  394. ; 同名目录不能充当恢复后的文件,否则会误报已恢复主程序。
  395. System::Call 'kernel32::GetFileAttributesW(w "$ZCodeCleanupSource\$R1") i.R3'
  396. IntOp $R3 $R3 & 0x10
  397. StrCmp $R3 0 zcodeSnapshotNext
  398. StrCpy $ZCodeCleanupFailed "1"
  399. Goto zcodeSnapshotNext
  400. zcodeSnapshotRestoreMissing:
  401. ${GetParent} "$ZCodeCleanupSource\$R1" $R2
  402. CreateDirectory "$R2"
  403. System::Call 'kernel32::CopyFileW(w "$ZCodeCleanupBackup\$R1", w "$ZCodeCleanupSource\$R1", i 1) i.R3 ?e'
  404. Pop $R4
  405. zcodeSnapshotCopyResult:
  406. ; System 的 ?e 在 CopyFileW 返回时保存 Win32 错误,避免插件后续调用覆盖 GetLastError。
  407. StrCmp $R3 "0" 0 zcodeSnapshotNext
  408. !insertmacro ZCodeReportInstallerStage "cleanup-$ZCodeCleanupMode-file-failed path=$R1 win32-error=$R4"
  409. StrCpy $ZCodeCleanupFailed "1"
  410. StrCmp $ZCodeCleanupMode "restore" zcodeSnapshotNext
  411. zcodeSnapshotClose:
  412. FileClose $R0
  413. StrCmp $ZCodeCleanupMode "restore" zcodeSnapshotRestoreManifest
  414. FileClose $R5
  415. StrCpy $R5 ""
  416. StrCmp $ZCodeCleanupFailed "1" zcodeSnapshotDone
  417. StrCmp $ZCodeCleanupManifestHasSelf "1" 0 zcodeSnapshotDone
  418. ; 旧卸载器也会删除打开中的清单。完整备份后,仅原子移除自引用项供旧代码读取。
  419. System::Call 'kernel32::MoveFileExW(w "$ZCodeCleanupManifest", w "$ZCodeCleanupSource\${ZCODE_INSTALL_MANIFEST_NAME}", i 9) i.R3 ?e'
  420. Pop $R4
  421. StrCmp $R3 "0" zcodeSnapshotFailed zcodeSnapshotDone
  422. zcodeSnapshotRestoreManifest:
  423. ; 旧清单可能仍存在但已去掉自引用;失败回滚须恢复原始字节,而非仅补不存在的文件。
  424. System::Call 'kernel32::CopyFileW(w "$ZCodeCleanupBackup\${ZCODE_INSTALL_MANIFEST_NAME}", w "$ZCodeCleanupSource\${ZCODE_INSTALL_MANIFEST_NAME}", i 0) i.R3 ?e'
  425. Pop $R4
  426. StrCmp $R3 "0" zcodeSnapshotFailed zcodeSnapshotDone
  427. zcodeSnapshotFailed:
  428. StrCpy $ZCodeCleanupFailed "1"
  429. zcodeSnapshotDone:
  430. StrCmp $R5 "" +2
  431. FileClose $R5
  432. !insertmacro ZCodeReportInstallerStage "cleanup-$ZCodeCleanupMode-completed failed=$ZCodeCleanupFailed backup=$ZCodeCleanupBackup"
  433. Pop $R5
  434. Pop $R4
  435. Pop $R3
  436. Pop $R2
  437. Pop $R1
  438. Pop $R0
  439. FunctionEnd
  440. !macroend
  441. !macro customOldUninstallPrepare
  442. StrCpy $ZCodeCleanupSource "$installationDir"
  443. !insertmacro ZCodeStopPreviousInstallProcesses
  444. StrCpy $ZCodeCleanupMode "backup"
  445. Call ZCodeCleanupSnapshot
  446. ${If} $ZCodeCleanupFailed == "1"
  447. ; 修复原因:备份是可选保护;失败时弃用半份备份,避免旧卸载失败后误用它恢复。
  448. !insertmacro ZCodeReportInstallerStage "cleanup-backup-skipped path=$ZCodeCleanupBackup"
  449. StrCmp $ZCodeCleanupBackup "" zcodePreviousBackupCleanupDone
  450. ClearErrors
  451. RMDir /r "$ZCodeCleanupBackup"
  452. IfErrors zcodePreviousBackupCleanupFailed
  453. Goto zcodePreviousBackupCleanupDone
  454. zcodePreviousBackupCleanupFailed:
  455. !insertmacro ZCodeReportInstallerStage "cleanup-backup-delete-failed path=$ZCodeCleanupBackup"
  456. zcodePreviousBackupCleanupDone:
  457. StrCpy $ZCodeCleanupBackup ""
  458. ${EndIf}
  459. !macroend
  460. !macro customOldUninstallRetryFailed
  461. ; 上游把任意卸载非零都显示成应用未关闭;实际进程检查仍由 CHECK_APP_RUNNING 负责。
  462. ; 备份失败被弃用后没有可恢复的完整备份;提示必须与能否恢复一致,不能在无备份时承诺恢复。
  463. StrCmp $ZCodeCleanupBackup "" zcodeRetryExhaustedNoBackup
  464. !insertmacro ZCodeReportInstallerStage "cleanup-retries-exhausted exit-code=$R0 recoverable=1"
  465. ${If} $LANGUAGE == 2052
  466. MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION "旧版本清理失败(错误码 $R0)。请排除文件占用或权限问题后重试,或取消以恢复旧版本。日志:$ZCodeInstallerLogPath" /SD IDCANCEL IDRETRY OneMoreAttempt
  467. ${Else}
  468. MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION "Previous version cleanup failed (exit code $R0). Resolve file locks or permissions and retry, or cancel to restore the previous version. Log: $ZCodeInstallerLogPath" /SD IDCANCEL IDRETRY OneMoreAttempt
  469. ${EndIf}
  470. Goto zcodeRetryExhaustedDone
  471. zcodeRetryExhaustedNoBackup:
  472. !insertmacro ZCodeReportInstallerStage "cleanup-retries-exhausted exit-code=$R0 recoverable=0"
  473. ${If} $LANGUAGE == 2052
  474. MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION "旧版本清理失败(错误码 $R0)。本次更新没有完整备份:排除占用后可重试,取消将退出安装且无法自动恢复旧版本文件。日志:$ZCodeInstallerLogPath" /SD IDCANCEL IDRETRY OneMoreAttempt
  475. ${Else}
  476. MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION "Previous version cleanup failed (exit code $R0). No complete backup exists for this update: retry after resolving file locks, or cancel to exit setup without automatic restore. Log: $ZCodeInstallerLogPath" /SD IDCANCEL IDRETRY OneMoreAttempt
  477. ${EndIf}
  478. zcodeRetryExhaustedDone:
  479. !macroend
  480. Function ZCodeFinishOldUninstall
  481. ${If} $R0 != 0
  482. ; 修复原因:没有完整备份时不能用半份文件恢复,旧卸载失败仍由原流程报告。
  483. StrCmp $ZCodeCleanupBackup "" zcodeFinishOldUninstallDone
  484. StrCpy $ZCodeCleanupMode "restore"
  485. Call ZCodeCleanupSnapshot
  486. ${If} $ZCodeCleanupFailed == "1"
  487. !insertmacro ZCodeCleanupErrorMessage "旧版本文件恢复失败,备份已保留:$ZCodeCleanupBackup。详细日志:$ZCodeInstallerLogPath" "Cannot restore the previous version. Backup retained: $ZCodeCleanupBackup. Log: $ZCodeInstallerLogPath"
  488. Return
  489. ${EndIf}
  490. ${EndIf}
  491. StrCmp $ZCodeCleanupBackup "" zcodeFinishOldUninstallDone
  492. ClearErrors
  493. RMDir /r "$ZCodeCleanupBackup"
  494. IfErrors zcodeFinishOldUninstallBackupDeleteFailed
  495. StrCpy $ZCodeCleanupBackup ""
  496. Goto zcodeFinishOldUninstallDone
  497. zcodeFinishOldUninstallBackupDeleteFailed:
  498. ; 修复原因:备份清理故障不影响旧卸载结果及后续新版本安装,只保留路径供排查。
  499. !insertmacro ZCodeReportInstallerStage "cleanup-backup-delete-failed path=$ZCodeCleanupBackup"
  500. zcodeFinishOldUninstallDone:
  501. FunctionEnd
  502. !macro customUnInstallCheck
  503. Call ZCodeFinishOldUninstall
  504. ; handleUninstallResult 会把旧卸载器的退出码放在 $R0;失败时显示清理诊断,
  505. ; 不再复用 appCannotBeClosed(该文案只适用于进程占用)。
  506. ${if} $R0 != 0
  507. ; 修复原因:静默自动更新无人值守,未设置 /SD 的模态框会一直等待用户点击,
  508. ; 使明确的退出码无法返回 electron-updater。静默时自动采用 IDOK,交互时仍显示提示。
  509. SetDetailsPrint listonly
  510. DetailPrint "ZCode: cleanup-failed exit-code=$R0"
  511. Call ZCodeShowUninstallerCleanupDetails
  512. ; 最终错误也沿用安装器语言,避免英文 Retry/Cancel 之后固定切回中文。
  513. !insertmacro ZCodeCleanupErrorMessage "旧版本清理失败(错误码 $R0)。可能是文件被占用、权限不足或磁盘空间不足。详细日志:${ZCODE_UNINSTALLER_LOG_PATH}" "Previous version cleanup failed (exit code $R0). Files may be in use, permissions may be insufficient, or disk space may be low. Log: ${ZCODE_UNINSTALLER_LOG_PATH}"
  514. SetErrorLevel 2
  515. Quit
  516. ${endif}
  517. !macroend
  518. !macro customUnInstallCheckCurrentUser
  519. ; per-machine 安装切换到 HKCU 旧版本时,electron-builder 会走另一条 hook;
  520. ; 复用同一诊断,避免同一个清理失败因注册表根键不同又退回默认文案。
  521. !insertmacro customUnInstallCheck
  522. !macroend
  523. !endif
  524. !define ZCODE_INSTALL_DIR_BACK_BUTTON_WIDTH 180
  525. !macro customHeader
  526. !ifndef BUILD_UNINSTALLER
  527. !insertmacro ZCodeDefineCleanupSnapshot
  528. ; 修复原因:异步生成的 header 可能先 include 本文件,再注册 UAC 插件目录。
  529. ; 在 customHeader 展开函数,确保插件已注册;preInit 仍调用同一函数和真实 UAC 判据。
  530. Function ZCodeInitializeInstallerLog
  531. Push $R0
  532. Push $R1
  533. Push $R2
  534. StrCpy $ZCodeInstallerLogUnavailable ""
  535. ${If} ${ZCODE_INSTALLER_IS_ELEVATED_INNER}
  536. StrCpy $ZCodeInstallerProcessRole "elevated-inner"
  537. StrCpy $ZCodeInstallerLogPath "${ZCODE_INSTALLER_ELEVATED_LOG_PATH}"
  538. ${Else}
  539. StrCpy $ZCodeInstallerProcessRole "outer"
  540. StrCpy $R0 $CMDLINE
  541. ClearErrors
  542. ${GetOptions} $R0 "/LOG=" $R1
  543. IfErrors zcodeInstallerLogUseDefault
  544. StrCmp $R1 "" zcodeInstallerLogUseDefault
  545. StrCpy $ZCodeInstallerLogPath $R1
  546. Goto zcodeInstallerLogPathReady
  547. zcodeInstallerLogUseDefault:
  548. StrCpy $ZCodeInstallerLogPath "${ZCODE_INSTALLER_DEFAULT_LOG_PATH}"
  549. zcodeInstallerLogPathReady:
  550. ${GetParent} $ZCodeInstallerLogPath $R2
  551. StrCmp $R2 "" zcodeInstallerLogInitialized
  552. CreateDirectory "$R2"
  553. ${EndIf}
  554. zcodeInstallerLogInitialized:
  555. !insertmacro ZCodeReportInstallerStage "installer-process-started role=$ZCodeInstallerProcessRole"
  556. Pop $R2
  557. Pop $R1
  558. Pop $R0
  559. FunctionEnd
  560. ; 修复原因:electron-builder 的 common.nsh 先设置 ShowInstDetails nevershow;
  561. ; hide 在该模板组合下仍可能留下空白列表且没有可展开入口,因此直接常显阶段详情。
  562. ShowInstDetails show
  563. !ifdef allowToChangeInstallationDirectory
  564. ; 修复原因:electron-builder 已在 assistedInstaller.nsh 中用该开关生成安装目录页面,
  565. ; 但 installUtil.nsh 随后还会用它禁止无 --updated 的手动覆盖保留快捷方式,导致旧卸载器
  566. ; 调用 UninstShortcut 注销开始菜单固定项。页面生成后撤掉开关,让自动更新和手动覆盖
  567. ; 在同一安装目录覆盖时都通过 KeepShortcuts 保留同一个 .lnk。
  568. !undef allowToChangeInstallationDirectory
  569. !endif
  570. !endif
  571. !macroend
  572. !ifndef BUILD_UNINSTALLER
  573. ; 修复原因:electron-builder 会先编译卸载器,但快捷方式目标读取只在安装更新流程中调用。
  574. ; 若把函数带入卸载器,NSIS 会产生 6010 未引用告警,并在 /WX 下直接中断 Windows CI。
  575. Function ZCodeReadShortcutTarget
  576. Exch $R9
  577. Push $R1
  578. Push $R2
  579. StrCpy $R2 ""
  580. System::Call 'Kernel32::SetEnvironmentVariableW(w "ZCODE_SHORTCUT_PATH", w "$R9") i.R1'
  581. StrCmp $R1 "0" zcodeReadShortcutTargetDone 0
  582. nsExec::ExecToStack /TIMEOUT=5000 `"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -NonInteractive -Command "[Console]::Out.Write(([Activator]::CreateInstance([type]::GetTypeFromProgID('WScript.Shell'))).CreateShortcut([Environment]::GetEnvironmentVariable('ZCODE_SHORTCUT_PATH')).TargetPath)"`
  583. Pop $R1
  584. Pop $R2
  585. StrCmp $R1 "0" zcodeReadShortcutTargetDone 0
  586. StrCpy $R2 ""
  587. zcodeReadShortcutTargetDone:
  588. System::Call 'Kernel32::SetEnvironmentVariableW(w "ZCODE_SHORTCUT_PATH", p 0) i.R1'
  589. StrCpy $R9 "$R2"
  590. Pop $R2
  591. Pop $R1
  592. Exch $R9
  593. FunctionEnd
  594. !endif
  595. !macro ZCodeRepairShortcutIfNeeded SHORTCUT_PATH LABEL_PREFIX
  596. ${if} ${FileExists} "${SHORTCUT_PATH}"
  597. Push "${SHORTCUT_PATH}"
  598. Call ZCodeReadShortcutTarget
  599. Pop $R0
  600. StrCmp $R0 "$appExe" ${LABEL_PREFIX}Done 0
  601. ; 修复原因:历史版本可能留下指向已移动 exe 的 .lnk,但无条件覆盖正确快捷方式会让
  602. ; 部分 Windows 11 丢失“所有应用”索引或用户固定关系,因此只修复目标不一致的项。
  603. ClearErrors
  604. CreateShortCut "${SHORTCUT_PATH}" "$appExe" "" "$appExe" 0 "" "" "${APP_DESCRIPTION}"
  605. IfErrors ${LABEL_PREFIX}Failed ${LABEL_PREFIX}Succeeded
  606. ${LABEL_PREFIX}Failed:
  607. DetailPrint "Unable to repair shortcut: ${SHORTCUT_PATH}"
  608. ClearErrors
  609. Goto ${LABEL_PREFIX}Done
  610. ${LABEL_PREFIX}Succeeded:
  611. WinShell::SetLnkAUMI "${SHORTCUT_PATH}" "${APP_ID}"
  612. ; 修复后的 .lnk 必须在最后一次写入后通知 Shell,避免开始菜单继续使用旧索引。
  613. System::Call 'Shell32::SHChangeNotify(i 0x00002000, i 0x0005, w "${SHORTCUT_PATH}", p 0)'
  614. ${LABEL_PREFIX}Done:
  615. ${endIf}
  616. !macroend
  617. !macro customInstall
  618. !ifndef BUILD_UNINSTALLER
  619. !insertmacro ZCodeReportInstallerStage "install-finalization-started"
  620. !endif
  621. ${if} ${isUpdated}
  622. ${orIf} $keepShortcuts == "true"
  623. !ifndef DO_NOT_CREATE_START_MENU_SHORTCUT
  624. !insertmacro ZCodeRepairShortcutIfNeeded "$newStartMenuLink" zcodeStartMenuShortcutRepair
  625. !endif
  626. !ifndef DO_NOT_CREATE_DESKTOP_SHORTCUT
  627. !insertmacro ZCodeRepairShortcutIfNeeded "$newDesktopLink" zcodeDesktopShortcutRepair
  628. !endif
  629. ${endIf}
  630. ; 修复原因:手动覆盖没有 --updated,继承旧快捷方式时仍需检查目标;首次安装没有旧项,
  631. ; 不应额外启动 PowerShell。用户已删除的快捷方式也不会重建。
  632. ; assisted installer 完成页始终直接运行本次安装落盘的 exe。
  633. ; 修复原因:安装信息键的 InstallLocation 用于旧卸载器路径解析;卸载注册表键也写入相同值,
  634. ; 避免 Windows 应用列表中的卸载项长期为空,并为后续迁移提供确定目录。
  635. WriteRegStr SHELL_CONTEXT "${UNINSTALL_REGISTRY_KEY}" InstallLocation "$INSTDIR"
  636. !ifdef UNINSTALL_REGISTRY_KEY_2
  637. WriteRegStr SHELL_CONTEXT "${UNINSTALL_REGISTRY_KEY_2}" InstallLocation "$INSTDIR"
  638. !endif
  639. StrCpy $launchLink "$appExe"
  640. !ifndef BUILD_UNINSTALLER
  641. !insertmacro ZCodeReportInstallerStage "install-completed"
  642. !endif
  643. !macroend
  644. !macro customPageAfterChangeDir
  645. Function ZCodeResizeInstallDirBackButton
  646. GetDlgItem $1 $HWNDPARENT 3
  647. StrCmp $1 0 zcodeResizeInstallDirBackButtonDone 0
  648. System::Call "*(i 0, i 0, i 0, i 0) p.r2"
  649. StrCmp $2 0 zcodeResizeInstallDirBackButtonDone 0
  650. System::Call "user32::GetWindowRect(p r1, p r2)"
  651. System::Call "user32::MapWindowPoints(p 0, p $HWNDPARENT, p r2, i 2)"
  652. System::Call "*$2(i.r3,i.r4,i.r5,i.r6)"
  653. System::Free $2
  654. IntOp $7 $5 - $3
  655. IntOp $8 $6 - $4
  656. IntCmp $7 ${ZCODE_INSTALL_DIR_BACK_BUTTON_WIDTH} zcodeResizeInstallDirBackButtonDone zcodeResizeInstallDirBackButtonResize zcodeResizeInstallDirBackButtonDone
  657. zcodeResizeInstallDirBackButtonResize:
  658. ; 修复原因:阻断页把“上一步”改成中文动作文案,NSIS 默认按钮宽度可能裁掉文字。
  659. ; 保持右边缘不动向左扩宽,避免和右侧“安装/取消”按钮重叠。
  660. IntOp $3 $5 - ${ZCODE_INSTALL_DIR_BACK_BUTTON_WIDTH}
  661. System::Call "user32::MoveWindow(p r1, i r3, i r4, i ${ZCODE_INSTALL_DIR_BACK_BUTTON_WIDTH}, i r8, i 1)"
  662. zcodeResizeInstallDirBackButtonDone:
  663. FunctionEnd
  664. Function ZCodeFindNestedDataDir
  665. Exch $R9
  666. Push $0
  667. Push $1
  668. StrCpy $R2 ""
  669. IfFileExists "$R9\.zcode\*.*" 0 +2
  670. StrCpy $R2 "$R9\.zcode"
  671. StrCmp $R2 "" 0 zcodeFindNestedDataDirDone
  672. IfFileExists "$R9\.zcode" 0 zcodeFindNestedDataDirListChildren
  673. StrCpy $R2 "$R9\.zcode"
  674. StrCmp $R2 "" 0 zcodeFindNestedDataDirDone
  675. zcodeFindNestedDataDirListChildren:
  676. FindFirst $0 $1 "$R9\*"
  677. IfErrors zcodeFindNestedDataDirDone
  678. zcodeFindNestedDataDirNext:
  679. StrCmp $1 "" zcodeFindNestedDataDirClose
  680. StrCmp $1 "." zcodeFindNestedDataDirContinue
  681. StrCmp $1 ".." zcodeFindNestedDataDirContinue
  682. IfFileExists "$R9\$1\*.*" 0 zcodeFindNestedDataDirContinue
  683. Push "$R9\$1"
  684. Call ZCodeFindNestedDataDir
  685. StrCmp $R2 "" zcodeFindNestedDataDirContinue zcodeFindNestedDataDirClose
  686. zcodeFindNestedDataDirContinue:
  687. FindNext $0 $1
  688. IfErrors zcodeFindNestedDataDirClose
  689. Goto zcodeFindNestedDataDirNext
  690. zcodeFindNestedDataDirClose:
  691. FindClose $0
  692. zcodeFindNestedDataDirDone:
  693. Pop $1
  694. Pop $0
  695. Pop $R9
  696. FunctionEnd
  697. Function ZCodeBlockInstallDirContainsData
  698. Call ZCodeDetectPreviousUninstallerCapabilities
  699. StrCmp $ZCodePreviousUninstallerSupportsManifest "1" zcodeInstallDirDataBlockSkip
  700. ; Bugfix: 用户可能把数据存储目录放进安装目录,Windows 更新覆盖安装目录时会清掉 .zcode。
  701. ; assisted installer 会把不含应用名的选择目录补成 "$INSTDIR\${APP_FILENAME}",所以这里按相同规则计算最终安装目录。
  702. ${StrContains} $R1 "${APP_FILENAME}" "$INSTDIR"
  703. StrCmp $R1 "" 0 zcodeInstallDirDataBlockUseSelectedDir
  704. StrCpy $R0 "$INSTDIR\${APP_FILENAME}"
  705. Goto zcodeInstallDirDataBlockCheckDir
  706. zcodeInstallDirDataBlockUseSelectedDir:
  707. StrCpy $R0 "$INSTDIR"
  708. zcodeInstallDirDataBlockCheckDir:
  709. ; 修复原因:旧阻断只检查最终安装目录直属的 .zcode,漏掉 data\.zcode 等子目录数据。
  710. ; 安装器覆盖安装时会管理整个安装目录树,递归命中任意 .zcode 都必须阻断。
  711. Push "$R0"
  712. Call ZCodeFindNestedDataDir
  713. StrCmp $R2 "" zcodeInstallDirDataBlockSkip zcodeInstallDirDataBlockFound
  714. zcodeInstallDirDataBlockFound:
  715. IfSilent zcodeInstallDirDataBlockSilent
  716. !insertmacro MUI_HEADER_TEXT "需要修改安装目录" "当前安装目录或其子目录包含 ZCode 数据目录"
  717. nsDialogs::Create 1018
  718. Pop $0
  719. StrCmp $0 error zcodeInstallDirDataBlockDialogFailed 0
  720. ${NSD_CreateLabel} 0u 0u 300u 44u "检测到该安装目录或其子目录中存在 .zcode 数据目录:$\r$\n$R2"
  721. Pop $1
  722. ${NSD_CreateLabel} 0u 54u 300u 70u "为避免历史会话和配置被安装器清理,请返回上一步选择其他安装目录。$\r$\n$\r$\n当前目录不能继续安装。"
  723. Pop $1
  724. GetDlgItem $1 $HWNDPARENT 1
  725. EnableWindow $1 0
  726. GetDlgItem $1 $HWNDPARENT 3
  727. EnableWindow $1 1
  728. SendMessage $1 ${WM_SETTEXT} 0 "STR:重选目录"
  729. Call ZCodeResizeInstallDirBackButton
  730. nsDialogs::Show
  731. Return
  732. zcodeInstallDirDataBlockDialogFailed:
  733. MessageBox MB_OK|MB_ICONSTOP "检测到安装目录或其子目录中存在 .zcode 数据目录,安装已停止。请重新运行安装器并选择其他安装目录。"
  734. SetErrorLevel 1
  735. Quit
  736. zcodeInstallDirDataBlockSilent:
  737. SetErrorLevel 1
  738. Quit
  739. zcodeInstallDirDataBlockSkip:
  740. Abort
  741. FunctionEnd
  742. Function ZCodeBlockInstallDirContainsDataLeave
  743. ; 修复原因:阻断页的下一步按钮已禁用,但自动化或系统快捷键仍可能触发下一页。
  744. ; leave 回调只处理继续前进的路径,这里强制留在当前页,确保用户只能返回修改安装目录。
  745. Abort
  746. FunctionEnd
  747. Page custom ZCodeBlockInstallDirContainsData ZCodeBlockInstallDirContainsDataLeave
  748. !macroend