!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