installer-nsh-smoke.nsi 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. Unicode true
  2. Name "ZCode installer.nsh smoke"
  3. OutFile "${OUTPUT_FILE}"
  4. InstallDir "$TEMP\zcode-installer-nsh-smoke"
  5. RequestExecutionLevel user
  6. SilentInstall silent
  7. !addincludedir "${NSIS_INCLUDE_DIR}"
  8. !addincludedir "${ELECTRON_BUILDER_NSIS_INCLUDE_DIR}"
  9. !include "LogicLib.nsh"
  10. !ifndef BUILD_UNINSTALLER
  11. !include "MUI2.nsh"
  12. !include "StrContains.nsh"
  13. !endif
  14. !define APP_DESCRIPTION "ZCode NSIS smoke fixture"
  15. !define APP_FILENAME "ZCode"
  16. !define APP_ID "dev.zcode.installer-nsh-smoke"
  17. !define UNINSTALL_REGISTRY_KEY "Software\\ZCodeInstallerSmoke\\{7C2A992D-72BB-4F8C-8DF0-0EA8A7B1F1C3}"
  18. ; This fixture invokes the cleanup macro from a normal section; electron-builder's real uninstaller uses un.*.
  19. !ifdef BUILD_UNINSTALLER
  20. !define ZCODE_UNINSTALLER_FUNCTION_PREFIX ""
  21. !endif
  22. ; Simulate a manually launched overwrite installer without --updated.
  23. !define isUpdated `1 == 0`
  24. !define allowToChangeInstallationDirectory
  25. !define ZCODE_INSTALLER_DEFAULT_LOG_PATH "${DEFAULT_LOG_PATH}"
  26. !define ZCODE_INSTALLER_ELEVATED_LOG_PATH "${ELEVATED_LOG_PATH}"
  27. !ifdef FORCE_ELEVATED_INNER
  28. !define ZCODE_INSTALLER_IS_ELEVATED_INNER `1 == 1`
  29. !endif
  30. Var appExe
  31. Var launchLink
  32. Var newStartMenuLink
  33. Var newDesktopLink
  34. Var keepShortcuts
  35. !include "${ZCODE_INSTALLER_NSH}"
  36. ; 与正式构建保持顺序:common.nsh 的常量在自定义 include 之后才可用。
  37. !define UNINSTALL_FILENAME "uninstaller.exe"
  38. ; 回归原因:electron-builder 异步生成 header 时,自定义 include 可能先于插件目录注册。
  39. ; 普通场景使用真实 UAC 判据,避免恒假替身掩盖插件尚未可用的编译错误。
  40. !addplugindir /x86-unicode "${NSIS_PLUGIN_DIR}"
  41. !ifndef BUILD_UNINSTALLER
  42. !insertmacro customHeader
  43. !ifdef allowToChangeInstallationDirectory
  44. !error "customHeader must enable shortcut preservation for manual overwrite"
  45. !endif
  46. !insertmacro customPageAfterChangeDir
  47. Function .onInit
  48. !insertmacro preInit
  49. FunctionEnd
  50. !endif
  51. Section
  52. SetOutPath "$INSTDIR"
  53. File /oname=ZCode.exe "${FIXTURE_EXE}"
  54. StrCpy $appExe "$INSTDIR\ZCode.exe"
  55. StrCpy $launchLink "$INSTDIR\stale-target.exe"
  56. StrCpy $newStartMenuLink "$INSTDIR\start-menu.lnk"
  57. StrCpy $newDesktopLink "$INSTDIR\desktop.lnk"
  58. StrCpy $keepShortcuts "true"
  59. !ifdef PRECREATE_SHORTCUTS
  60. !ifdef STALE_SHORTCUTS
  61. CreateShortCut "$newStartMenuLink" "$INSTDIR\stale-target.exe" "--stale"
  62. CreateShortCut "$newDesktopLink" "$INSTDIR\stale-target.exe" "--stale"
  63. !else
  64. CreateShortCut "$newStartMenuLink" "$appExe" "--preserved"
  65. CreateShortCut "$newDesktopLink" "$appExe" "--preserved"
  66. !endif
  67. !ifndef BUILD_UNINSTALLER
  68. Push "$newStartMenuLink"
  69. Call ZCodeReadShortcutTarget
  70. Pop $R8
  71. FileOpen $0 "$INSTDIR\read-shortcut-target.txt" w
  72. FileWrite $0 "$R8"
  73. FileClose $0
  74. !endif
  75. !endif
  76. !ifndef BUILD_UNINSTALLER
  77. SetDetailsPrint none
  78. !insertmacro customInit
  79. ; The real electron-builder template invokes these hooks at the same points.
  80. !insertmacro customInstallSectionStarted
  81. !insertmacro customInstallCleanupStarted
  82. !insertmacro customInstallCleanupCompleted
  83. !insertmacro customInstallExtractStarted
  84. !insertmacro customInstallExtractCompleted
  85. !insertmacro customInstallShortcutsStarted
  86. !insertmacro customInstallShortcutsCompleted
  87. !insertmacro customInstall
  88. !endif
  89. FileOpen $0 "$INSTDIR\launch-link.txt" w
  90. FileWrite $0 "$launchLink"
  91. FileClose $0
  92. ; Expand cleanup diagnostics in the uninstaller smoke fixture so /WX checks the reference.
  93. !ifdef BUILD_UNINSTALLER
  94. !insertmacro customRemoveFiles
  95. !endif
  96. ; customInstall 会向夹具专属注册表键写入 InstallLocation,运行后必须清理,
  97. ; 不能在测试机上留下残留(spec:夹具不得写入真实注册表)。
  98. DeleteRegKey HKCU "Software\ZCodeInstallerSmoke"
  99. SectionEnd