!define PRODUCT_NAME "AAA"
!define PRODUCT_VERSION "3.0.1.1965"
!define PRODUCT_PUBLISHER "BBB"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
SetCompressor lzma
!include "MUI.nsh"
!include "StrFunc.nsh"
!include "Library.nsh"
!include "WordFunc.nsh"
!define MUI_ABORTWARING
!define MUI_ICON "Bin\System\icon\AAA.ico"
!define MUI_WELCOMEPAGE_TITLE "欢迎使用“AAA”安装向导"
!define MUI_WELCOMEPAGE_TEXT "\r\n这个安装向导将指引你完成“AAA”的升级安装过程。\r\n\r\n开始安装前,建议先关闭其他所有应用程序。这将允许“升级程序”更新指定的系统问件,而不需要重新启动计算机。\r\n\r\n$_CLICK"
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "License.rtf"
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE "SimpChinese"
Name "AAA"
OutFile "upgrade_x86.exe"
InstallDir "$PROGRAMFILES\AAA"
ShowInstDetails show
ShowUnInstDetails show
BrandingText "hahaha..."
BrandingText "NSIS"
Section -Post
SetRegView 32
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
SetRegView lastused
SectionEnd
Section -Upgrade
SetDetailsPrint textonly
DetailPrint "正在更新程序组件..."
;SetDetailsPrint none
SetAutoClose true
SetOutPath "$INSTDIR"
SetOverwrite on
File /r "update_x86\*.*"
SectionEnd
Function .onInit
;禁止多个安装程序同时运行
System::Call 'kernel32::CreateMutexA(i 0, i 0, t "VAUpdate") i .r1 ?e'
Pop $R0
StrCmp $R0 0 +3
MessageBox MB_OK|MB_ICONEXCLAMATION "升级程序已经在运行。"
Abort
;判断是否已安装过AAA
ClearErrors
StrCpy $R1 ""
ReadRegStr $R1 ${PRODUCT_UNINST_ROOT_KEY} ${PRODUCT_UNINST_KEY} "UninstallString"
StrLen $0 $R1
${if} $0 < 1
;没有安装了软件
MessageBox MB_OK|MB_ICONEXCLAMATION "您未安装本软件,不能使用此升级程序!"
;退出安装程序
Abort
${else}
!insertmacro VersionCompare
;读取已安装软件版本,放在$R2中
ReadRegStr $R2 ${PRODUCT_UNINST_ROOT_KEY} ${PRODUCT_UNINST_KEY} "DisplayVersion"
;比较已安装软件和待安装软件的版本,并把结果放在$1中,结果有三个,1,2,和0
${VersionCompare} "$R2" "${PRODUCT_VERSION}" $1
StrCmp $1 "1" 0 +3
MessageBox MB_OK "待安装版本比已安装版本低"
Abort
StrCmp $1 "0" 0 +3
MessageBox MB_OK "待安装版本和已安装版本一样"
Abort
${endif}
FunctionEnd