Files
xieyi-weixin-/installer.nsi
2026-09-29 15:51:28 +08:00

217 lines
8.5 KiB
NSIS
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
Unicode true
!include "MUI2.nsh"
!include "LogicLib.nsh"
!include "FileFunc.nsh"
!include "WinVer.nsh"
!include "x64.nsh"
; Without a Windows 10 manifest, GetVersion lies (reports 6.2) and WinVer checks misfire.
ManifestSupportedOS all
!ifndef APP_VERSION
!define APP_VERSION "1.0.0"
!endif
!ifndef APP_FILE_VERSION
!define APP_FILE_VERSION "1.0.0.0"
!endif
!ifndef SOURCE_DIR
!define SOURCE_DIR "dist\ZhenAI-WeCom-Assistant-v${APP_VERSION}"
!endif
!define APP_NAME "甄AI客服"
!define APP_PUBLISHER "甄养堂"
; Qt WebEngine/PyInstaller 程序不能在打包后改名,否则浏览器子进程启动会失败。
!define APP_EXE "ZhenAI-WeCom-Assistant-v${APP_VERSION}.exe"
!define APP_DIR_NAME "ZhenAIService"
!define UNINSTALL_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZhenAIService"
Name "${APP_NAME}"
Caption "${APP_NAME} 安装程序"
OutFile "dist\installer\甄AI客服-安装包-v${APP_VERSION}.exe"
InstallDir "$LOCALAPPDATA\Programs\${APP_DIR_NAME}"
InstallDirRegKey HKCU "${UNINSTALL_KEY}" "InstallLocation"
RequestExecutionLevel user
SetCompressor zlib
ShowInstDetails nevershow
ShowUninstDetails nevershow
BrandingText "${APP_PUBLISHER}"
VIProductVersion "${APP_FILE_VERSION}"
VIAddVersionKey /LANG=2052 "ProductName" "${APP_NAME}"
VIAddVersionKey /LANG=2052 "ProductVersion" "${APP_VERSION}"
VIAddVersionKey /LANG=2052 "CompanyName" "${APP_PUBLISHER}"
VIAddVersionKey /LANG=2052 "LegalCopyright" "Copyright (C) 2026 ${APP_PUBLISHER}"
VIAddVersionKey /LANG=2052 "FileDescription" "${APP_NAME} 安装程序"
VIAddVersionKey /LANG=2052 "FileVersion" "${APP_VERSION}"
Var InstallMutex
Var SkipRegistration
Var InstallResult
Function .onInit
; 程序内置 Python 3.12、Qt 6.10 和 Chromium,依赖 Windows 10 才有的系统接口
; (api-ms-win-core-path / synch-l1-2 / shcore-scaling 等)。在 Windows 7/8.1
; 上安装后只会弹出“丢失 api-ms-win-core-path-l1-1-0.dll”之类看不懂的错误,
; 所以在这里用中文说清楚并终止安装。
${IfNot} ${AtLeastWin10}
MessageBox MB_ICONSTOP|MB_OK "${APP_NAME} 需要 Windows 10(64 位)或更高版本。$\r$\n$\r$\n当前电脑的 Windows 版本过低(例如 Windows 7 / 8.1),程序内置的运行库无法在此系统上启动,安装已取消。请升级系统或更换电脑后重新安装。"
Abort
${EndIf}
${IfNot} ${RunningX64}
MessageBox MB_ICONSTOP|MB_OK "${APP_NAME} 只支持 64 位 Windows 10 及以上系统,当前系统为 32 位,安装已取消。"
Abort
${EndIf}
; Isolated installer verification can avoid changing the user's shortcuts/registry.
StrCpy $SkipRegistration 0
${GetParameters} $0
ClearErrors
${GetOptions} $0 "/NOREGISTRATION" $1
IfErrors +2
StrCpy $SkipRegistration 1
System::Call 'kernel32::CreateMutexW(p 0, i 0, w "Local\ZhenYangTangRPAInstaller") p .r0 ?e'
StrCpy $InstallMutex $0
Pop $1
${If} $1 == 183
IfSilent +2
MessageBox MB_OK|MB_ICONEXCLAMATION "另一个安装程序正在运行,请等待它完成后重试。"
SetErrorLevel 1618
Abort
${EndIf}
FunctionEnd
!define MUI_ABORTWARNING
!define MUI_ICON "assets\brand\zhenyangtang-icon.ico"
!define MUI_UNICON "assets\brand\zhenyangtang-icon.ico"
!define MUI_FINISHPAGE_RUN "$INSTDIR\${APP_EXE}"
!define MUI_FINISHPAGE_RUN_TEXT "启动甄AI客服"
!define MUI_FINISHPAGE_RUN_NOTCHECKED
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
!insertmacro MUI_LANGUAGE "SimpChinese"
; Run outside $INSTDIR so the helper never locks files being replaced.
; Complete this shared install/uninstall check before deleting any files.
!macro DefineCloseApplication PREFIX
Function ${PREFIX}CloseApplication
InitPluginsDir
File /oname=$PLUGINSDIR\close-installed-app.ps1 "installer_close_app.ps1"
; Native PowerShell can inspect 64-bit application process paths.
StrCpy $0 "$WINDIR\System32\WindowsPowerShell\v1.0\powershell.exe"
IfFileExists "$WINDIR\Sysnative\WindowsPowerShell\v1.0\powershell.exe" 0 +2
StrCpy $0 "$WINDIR\Sysnative\WindowsPowerShell\v1.0\powershell.exe"
close_app_retry:
DetailPrint "正在关闭甄AI客服并等待文件释放..."
nsExec::ExecToLog '"$0" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -File "$PLUGINSDIR\close-installed-app.ps1" -InstallDir "$INSTDIR"'
Pop $1
${If} $1 != 0
IfSilent close_app_failed
MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION "无法关闭正在运行的甄AI客服,或安装目录中的文件仍被占用。请从系统托盘退出甄AI客服后重试。安装文件尚未修改。" IDRETRY close_app_retry
close_app_failed:
SetErrorLevel 2
Abort
${EndIf}
FunctionEnd
!macroend
!insertmacro DefineCloseApplication ""
!insertmacro DefineCloseApplication "un."
Section "安装甄AI客服" MainSection
SetShellVarContext current
SetRegView 64
; Reserve enough room before extraction; no installed files are changed here.
${DriveSpace} "$TEMP" "/D=F /S=K" $0
IfErrors install_space_failed
IntCmp $0 ${PAYLOAD_KB} temp_space_ok install_space_failed temp_space_ok
temp_space_ok:
${GetRoot} "$INSTDIR" $1
${GetRoot} "$TEMP" $2
StrCmp $1 $2 install_space_ok
${DriveSpace} "$1" "/D=F /S=K" $0
IfErrors install_space_failed
IntCmp $0 ${PAYLOAD_KB} install_space_ok install_space_failed install_space_ok
install_space_failed:
IfSilent +2
MessageBox MB_OK|MB_ICONSTOP "磁盘空间不足,安装需要至少 ${PAYLOAD_KB} KB 的可用空间。旧版本未修改,请释放空间后重试。"
SetErrorLevel 112
Abort
install_space_ok:
; Extract and verify the entire new payload before touching the old install.
InitPluginsDir
SetOutPath "$PLUGINSDIR\payload"
ClearErrors
File /r "${SOURCE_DIR}\*.*"
IfErrors install_failed
File /oname=$PLUGINSDIR\close-installed-app.ps1 "installer_close_app.ps1"
File /oname=$PLUGINSDIR\ZhenAIUpdater.exe "${SOURCE_DIR}\ZhenAIUpdater.exe"
SetOutPath "$PLUGINSDIR"
StrCpy $InstallResult "$LOCALAPPDATA\ZhenYangTangRPA\updates\install-result.json"
${If} $SkipRegistration == 1
StrCpy $InstallResult "$INSTDIR.install-result.json"
${EndIf}
nsExec::ExecToLog '"$PLUGINSDIR\ZhenAIUpdater.exe" --apply-payload "$PLUGINSDIR\payload" --install-dir "$INSTDIR" --target-version "${APP_VERSION}" --close-script "$PLUGINSDIR\close-installed-app.ps1" --result-file "$InstallResult"'
Pop $0
${If} $0 != 0
Goto install_failed
${EndIf}
SetOutPath "$INSTDIR"
${If} $SkipRegistration != 1
WriteUninstaller "$INSTDIR\卸载甄AI客服.exe"
CreateShortCut "$DESKTOP\甄AI客服.lnk" "$INSTDIR\${APP_EXE}" "" "$INSTDIR\${APP_EXE}" 0
CreateDirectory "$SMPROGRAMS\甄AI客服"
CreateShortCut "$SMPROGRAMS\甄AI客服\甄AI客服.lnk" "$INSTDIR\${APP_EXE}" "" "$INSTDIR\${APP_EXE}" 0
CreateShortCut "$SMPROGRAMS\甄AI客服\卸载甄AI客服.lnk" "$INSTDIR\卸载甄AI客服.exe"
WriteRegStr HKCU "${UNINSTALL_KEY}" "DisplayName" "甄AI客服"
WriteRegStr HKCU "${UNINSTALL_KEY}" "DisplayVersion" "${APP_VERSION}"
WriteRegStr HKCU "${UNINSTALL_KEY}" "Publisher" "${APP_PUBLISHER}"
WriteRegStr HKCU "${UNINSTALL_KEY}" "DisplayIcon" "$INSTDIR\${APP_EXE}"
WriteRegStr HKCU "${UNINSTALL_KEY}" "InstallLocation" "$INSTDIR"
WriteRegStr HKCU "${UNINSTALL_KEY}" "UninstallString" '$\"$INSTDIR\卸载甄AI客服.exe$\"'
WriteRegStr HKCU "${UNINSTALL_KEY}" "QuietUninstallString" '$\"$INSTDIR\卸载甄AI客服.exe$\" /S'
WriteRegDWORD HKCU "${UNINSTALL_KEY}" "NoModify" 1
WriteRegDWORD HKCU "${UNINSTALL_KEY}" "NoRepair" 1
${EndIf}
Goto install_done
install_failed:
IfSilent +2
MessageBox MB_OK|MB_ICONSTOP "安装未完成,旧版本已保留。请关闭正在运行的安装程序后重试。详细原因保存在本机更新记录中。"
SetErrorLevel 2
Abort
install_done:
SectionEnd
Section "Uninstall"
SetShellVarContext current
SetRegView 64
Call un.CloseApplication
Delete "$DESKTOP\甄AI客服.lnk"
Delete "$SMPROGRAMS\甄AI客服\甄AI客服.lnk"
Delete "$SMPROGRAMS\甄AI客服\卸载甄AI客服.lnk"
RMDir "$SMPROGRAMS\甄AI客服"
Delete "$INSTDIR\ZhenAI-WeCom-Assistant-v*.exe"
Delete "$INSTDIR\甄AI客服.exe"
Delete "$INSTDIR\卸载甄AI客服.exe"
Delete "$INSTDIR\ZhenAIUpdater.exe"
Delete "$INSTDIR\installation-manifest.json"
RMDir /r "$INSTDIR\_internal"
RMDir "$INSTDIR"
DeleteRegKey HKCU "${UNINSTALL_KEY}"
; 用户配置和聊天资料位于 %LOCALAPPDATA%\ZhenYangTangRPA,卸载时有意保留。
SectionEnd