Files
ucvl-zonghengjia-open-source/windows/installer/VPNPlus.nsi
2026-10-11 23:23:20 +00:00

267 lines
9.4 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
SetCompressor /SOLID lzma
RequestExecutionLevel admin
!include "MUI2.nsh"
!include "x64.nsh"
!include "LogicLib.nsh"
!include "FileFunc.nsh"
!include "PayloadTransaction.nsh"
!include "RemovalPayload.nsh"
!include "RegistryCleanup.nsh"
!include "InstallationIntegration.nsh"
!include "GuardianGate.nsh"
!define PRODUCT_NAME "优创⁺纵横家"
!ifndef PRODUCT_VERSION
!define PRODUCT_VERSION "0.2.16"
!endif
!define PRODUCT_PUBLISHER "优创未来(UCVL)"
!ifndef PRODUCT_BUILD_SUFFIX
!define PRODUCT_BUILD_SUFFIX ""
!endif
!ifndef PRODUCT_DISPLAY_VERSION
!define PRODUCT_DISPLAY_VERSION "${PRODUCT_VERSION}${PRODUCT_BUILD_SUFFIX}"
!endif
!ifndef PRODUCT_REVISION
!define PRODUCT_REVISION "0"
!endif
!ifndef APP_SOURCE_DIR
!define APP_SOURCE_DIR "${__FILEDIR__}\..\dist\app"
!endif
!define PRODUCT_WEB "https://vpn.toplc.cn/"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\VPNPlus.exe"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\UCVL.VPNPlus"
Name "${PRODUCT_NAME}"
!ifdef INSTALLER_OUTPUT
OutFile "${INSTALLER_OUTPUT}"
!else
OutFile "${__FILEDIR__}\..\artifacts\UCVL-Zonghengjia-${PRODUCT_VERSION}${PRODUCT_BUILD_SUFFIX}-win-x64-setup.exe"
!endif
InstallDir "$LOCALAPPDATA\Programs\UCVL\VPNPlus"
InstallDirRegKey HKCU "${PRODUCT_DIR_REGKEY}" "Path"
BrandingText "优创未来 · 优创⁺纵横家"
Icon "${__FILEDIR__}\..\assets\zonghengjia-app-v1.ico"
UninstallIcon "${__FILEDIR__}\..\assets\zonghengjia-app-v1.ico"
VIProductVersion "${PRODUCT_VERSION}.${PRODUCT_REVISION}"
VIAddVersionKey /LANG=2052 "ProductName" "优创⁺纵横家"
VIAddVersionKey /LANG=2052 "CompanyName" "优创未来(UCVL)"
VIAddVersionKey /LANG=2052 "FileDescription" "优创⁺纵横家 Windows x64 安装程序"
VIAddVersionKey /LANG=2052 "FileVersion" "${PRODUCT_DISPLAY_VERSION}"
VIAddVersionKey /LANG=2052 "ProductVersion" "${PRODUCT_DISPLAY_VERSION}"
VIAddVersionKey /LANG=2052 "LegalCopyright" "© 2026 优创未来(UCVL)"
!define MUI_ICON "${__FILEDIR__}\..\assets\zonghengjia-app-v1.ico"
!define MUI_UNICON "${__FILEDIR__}\..\assets\zonghengjia-app-v1.ico"
Var Updating
!define MUI_CUSTOMFUNCTION_GUIINIT SetupUpdateControls
!define MUI_FINISHPAGE_TITLE "纵横家已更新完成"
!define MUI_FINISHPAGE_TEXT "已覆盖原安装目录,账号和用户配置已保留。点击下方按钮重启纵横家,无需重启电脑。"
!define MUI_FINISHPAGE_BUTTON "重启纵横家"
!define MUI_PAGE_CUSTOMFUNCTION_PRE SkipUpdatePage
!insertmacro MUI_PAGE_WELCOME
!define MUI_PAGE_CUSTOMFUNCTION_PRE SkipUpdatePage
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE RestartClient
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
!insertmacro MUI_LANGUAGE "SimpChinese"
Function .onInit
${GetParameters} $0
!insertmacro InitGuardianGate
${If} $GuardianControlled == "1"
; /D is preserved for the request-bound target. No upgrade UI/restart path.
Return
${EndIf}
ClearErrors
${GetOptions} $0 "/UPDATE" $1
${IfNot} ${Errors}
StrCpy $Updating "1"
; Old clients used /S /UPDATE: show progress and the final restart button too.
SetSilent normal
${EndIf}
; Double-clicking a new package on an installed machine is also an upgrade.
ReadRegStr $2 HKCU "${PRODUCT_DIR_REGKEY}" "Path"
${If} $2 != ""
${AndIf} ${FileExists} "$2\VPNPlus.exe"
StrCpy $INSTDIR $2
StrCpy $Updating "1"
SetSilent normal
${EndIf}
FunctionEnd
Function SkipUpdatePage
${If} $Updating == "1"
Abort
${EndIf}
FunctionEnd
Function RestartClient
${If} $GuardianControlled == "1"
Return
${EndIf}
; ExtractAndVerifyPayload leaves $OUTDIR in $PLUGINSDIR\payload.
; The installed app must not inherit that soon-to-be-removed directory.
SetOutPath "$INSTDIR"
${If} $Updating == "1"
Exec '"$INSTDIR\VPNPlus.exe" --auto-connect'
${Else}
Exec '"$INSTDIR\VPNPlus.exe"'
${EndIf}
FunctionEnd
Function SetupUpdateControls
${If} $Updating == "1"
GetDlgItem $0 $HWNDPARENT 2
EnableWindow $0 0
${EndIf}
FunctionEnd
Section "优创⁺纵横家主程序" SEC_MAIN
SetShellVarContext current
${IfNot} ${RunningX64}
StrCpy $0 33
Call GuardianExitOnFailure
MessageBox MB_ICONSTOP "优创⁺纵横家仅支持 64 位 Windows 10/11。"
Abort
${EndIf}
; Fully extract and hash-check the candidate BEFORE stopping the working app.
!insertmacro ExtractAndVerifyPayload
Call GuardianExitOnFailure
${If} $0 == 30
MessageBox MB_ICONSTOP "安装包解压失败,当前程序未被停止或修改。"
Abort
${EndIf}
${If} $0 != 0
MessageBox MB_ICONSTOP "安装包校验失败,当前程序未被停止或修改。请重新下载安装包。"
Abort
${EndIf}
!insertmacro PrepareInstallationIntegration
Call GuardianExitOnFailure
${If} $0 != 0
MessageBox MB_ICONSTOP "无法准备卸载组件或快捷方式,当前程序未被停止或修改。"
Abort
${EndIf}
${If} $GuardianControlled == "1"
!insertmacro RunGuardianPhase "--installer-guardian-gate"
Call GuardianExitOnFailure
${EndIf}
${If} $GuardianControlled != "1"
${AndIf} ${FileExists} "$INSTDIR\VPNPlus.exe"
StrCpy $0 20
ClearErrors
ExecWait '"$PLUGINSDIR\payload\VPNPlus.exe" --shutdown-installed "$INSTDIR"' $0
${If} ${Errors}
StrCpy $0 20
${EndIf}
${If} $0 != 0
MessageBox MB_ICONSTOP "原程序暂时无法安全退出,尚未覆盖安装。请退出纵横家后重试。"
Abort
${EndIf}
${EndIf}
; Each replacement is atomic, the main exe is replaced LAST, and a durable
; backup/journal permits recovery if copying fails or the installer is interrupted.
${If} $GuardianControlled == "1"
!insertmacro RunGuardianPhase "--installer-guardian-apply"
${Else}
!insertmacro ApplyVerifiedPayload "--installer-apply-integrated"
${EndIf}
; Controlled failures return directly: the independent guardian owns any
; rollback/restart; do not write last-error or execute the restored client.
Call GuardianExitOnFailure
${If} $0 != 0
CreateDirectory "$INSTDIR\.ucvl-installer"
CopyFiles /SILENT "$PLUGINSDIR\payload\install-error.txt" "$INSTDIR\.ucvl-installer\last-error.txt"
${If} $0 == 20
${AndIf} ${FileExists} "$INSTDIR\VPNPlus.exe"
SetOutPath "$INSTDIR"
Exec '"$INSTDIR\VPNPlus.exe"'
MessageBox MB_ICONSTOP "本次更新未完成,已保留或恢复旧版本并重新打开。账号和配置未删除。"
${Else}
MessageBox MB_ICONSTOP "本次更新未完成。恢复记录和旧文件备份已保留,请重新运行安装包进行恢复。不要卸载或删除安装目录。"
${EndIf}
Abort
${EndIf}
; The helper returns success only after payload, shell files and HKCU
; registration have all been verified and durably committed together.
${If} $GuardianControlled == "1"
SetErrorLevel 0
Quit
${EndIf}
SectionEnd
Section "Uninstall"
SetShellVarContext current
ReadRegStr $2 HKCU "${PRODUCT_DIR_REGKEY}" "Path"
${If} $2 == ""
MessageBox MB_ICONSTOP "没有找到当前安装登记,未删除文件。请先用当前安装包修复。"
Abort
${EndIf}
GetFullPathName $2 "$2"
GetFullPathName $4 "$INSTDIR"
${If} $2 != $4
MessageBox MB_ICONSTOP "此卸载器不属于当前登记的安装目录,未删除文件或修改其它安装。"
Abort
${EndIf}
; This independent embedded helper survives an interrupted removal of main.
!insertmacro PrepareRemovalHelper
${If} $0 != 0
MessageBox MB_ICONSTOP "无法准备卸载程序,未删除文件。"
Abort
${EndIf}
!insertmacro RunRemovalHelper "--uninstaller-check"
${If} $0 != 0
MessageBox MB_ICONSTOP "安装记录、版本或文件不一致,未停止客户端或删除文件。请先用当前安装包修复。"
Abort
${EndIf}
${If} ${FileExists} "$INSTDIR\VPNPlus.exe"
StrCpy $0 20
ClearErrors
ExecWait '"$PLUGINSDIR\remove\VPNPlus.exe" --shutdown-installed "$INSTDIR"' $0
${If} ${Errors}
StrCpy $0 20
${EndIf}
${If} $0 != 0
MessageBox MB_ICONSTOP "客户端未安全退出,尚未卸载。请断开并退出后重试。"
Abort
${EndIf}
${EndIf}
!insertmacro RunRemovalHelper "--uninstaller-remove"
${If} $0 != 0
MessageBox MB_ICONSTOP "卸载未完成。账号、配置和程序备份均保留;请重新运行本卸载器或安装包恢复。"
Abort
${EndIf}
Delete "$DESKTOP\优创⁺纵横家.lnk"
Delete "$DESKTOP\VPN+.lnk"
Delete "$SMPROGRAMS\优创未来\优创⁺纵横家.lnk"
Delete "$SMPROGRAMS\优创未来\VPN+.lnk"
RMDir "$SMPROGRAMS\优创未来"
!insertmacro RemoveOwnedUserRegistration "${PRODUCT_UNINST_KEY}"
${If} $0 != 0
MessageBox MB_ICONSTOP "程序文件已移除并保留备份,但系统登记未清理完成。请重新运行卸载器完成清理。"
Abort
${EndIf}
!insertmacro RemoveOwnedUserRegistration "${PRODUCT_DIR_REGKEY}"
${If} $0 != 0
MessageBox MB_ICONSTOP "程序文件已移除并保留备份,但启动登记未清理完成。请重新运行卸载器完成清理。"
Abort
${EndIf}
Delete "$INSTDIR\Uninstall.exe"
; No recursive deletion. User extras and .ucvl-installer recovery backups stay.
RMDir "$INSTDIR"
MessageBox MB_ICONINFORMATION "程序已卸载。账号、用户配置及安装目录中的恢复备份已保留,不会删除其它文件。"
SectionEnd