Rewrite the NSIS installer logic to use LogicLib
This commit is contained in:
@@ -24,6 +24,10 @@ Var UQMUSERDATA
|
|||||||
; MUI 1.67 compatible ------
|
; MUI 1.67 compatible ------
|
||||||
!include "MUI.nsh"
|
!include "MUI.nsh"
|
||||||
|
|
||||||
|
; Start using macros for block structure
|
||||||
|
!include "LogicLib.nsh"
|
||||||
|
|
||||||
|
|
||||||
; MUI Settings
|
; MUI Settings
|
||||||
!define MUI_ABORTWARNING
|
!define MUI_ABORTWARNING
|
||||||
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\win-install.ico"
|
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\win-install.ico"
|
||||||
@@ -104,17 +108,16 @@ Function .onInit
|
|||||||
StrCpy $UQMARGS ""
|
StrCpy $UQMARGS ""
|
||||||
StrCpy $MAKEICON 0
|
StrCpy $MAKEICON 0
|
||||||
ReadEnvStr $0 APPDATA
|
ReadEnvStr $0 APPDATA
|
||||||
StrCmp $0 "" NoAppData
|
${If} $0 == ""
|
||||||
ExpandEnvStrings $UQMUSERDATA "%APPDATA%\uqm"
|
|
||||||
Goto GotAppData
|
|
||||||
NoAppData:
|
|
||||||
ReadEnvStr $0 USERPROFILE
|
ReadEnvStr $0 USERPROFILE
|
||||||
StrCmp $0 "" NoProfile
|
${If} $0 == ""
|
||||||
ExpandEnvStrings $UQMUSERDATA "%USERPROFILE%\Application Data\uqm"
|
|
||||||
Goto GotAppData
|
|
||||||
NoProfile:
|
|
||||||
StrCpy $UQMUSERDATA "$INSTDIR\userdata\uqm"
|
StrCpy $UQMUSERDATA "$INSTDIR\userdata\uqm"
|
||||||
GotAppData:
|
${Else}
|
||||||
|
ExpandEnvStrings $UQMUSERDATA "%USERPROFILE%\Application Data\uqm"
|
||||||
|
${EndIf}
|
||||||
|
${Else}
|
||||||
|
ExpandEnvStrings $UQMUSERDATA "%APPDATA%\uqm"
|
||||||
|
${EndIf}
|
||||||
FunctionEnd
|
FunctionEnd
|
||||||
|
|
||||||
# To use:
|
# To use:
|
||||||
@@ -134,67 +137,73 @@ Function HandlePackage
|
|||||||
Push $3
|
Push $3
|
||||||
StrCpy $R9 0 # failure count
|
StrCpy $R9 0 # failure count
|
||||||
# Check to make sure the file wasn't already installed
|
# Check to make sure the file wasn't already installed
|
||||||
IfFileExists "$0\$1" 0 NotThere
|
${If} ${FileExists} "$0\$1"
|
||||||
md5dll::GetFileMD5 "$0\$1"
|
md5dll::GetFileMD5 "$0\$1"
|
||||||
Pop $3
|
Pop $3
|
||||||
StrCmp $MD5SUM $3 0 NotThere
|
${If} $MD5SUM == $3
|
||||||
MessageBox MB_ICONINFORMATION|MB_OK "The package $1 has already been installed."
|
MessageBox MB_ICONINFORMATION|MB_OK "The package $1 has already been installed."
|
||||||
Goto PackageDone
|
Goto PackageDone
|
||||||
NotThere:
|
${EndIf}
|
||||||
|
${EndIf}
|
||||||
|
# It's not installed, so check if it's in the package dir.
|
||||||
SetOutPath "$0"
|
SetOutPath "$0"
|
||||||
SetOverwrite ifdiff
|
SetOverwrite ifdiff
|
||||||
IfFileExists "$PACKAGEDIR\$1" 0 CheckForZip
|
${If} ${FileExists} "$PACKAGEDIR\$1"
|
||||||
md5dll::GetFileMD5 "$PACKAGEDIR\$1"
|
md5dll::GetFileMD5 "$PACKAGEDIR\$1"
|
||||||
Pop $3
|
Pop $3
|
||||||
StrCmp $MD5SUM $3 PackageOK
|
${If} $MD5SUM != $3
|
||||||
MessageBox MB_ICONINFORMATION|MB_OKCANCEL "The file $PACKAGEDIR\$1 appears to be corrupt. The expected MD5 sum was '$MD5SUM', but the actual MD5 sum was '$3'. Press OK to attempt to download a fresh copy from the distribution site, or Cancel to skip the package." IDOK AttemptDownload IDCANCEL PackageDone
|
MessageBox MB_ICONINFORMATION|MB_OKCANCEL "The file $PACKAGEDIR\$1 appears to be corrupt. The expected MD5 sum was '$MD5SUM', but the actual MD5 sum was '$3'. Press OK to attempt to download a fresh copy from the distribution site, or Cancel to skip the package." IDOK AttemptDownload IDCANCEL PackageDone
|
||||||
PackageOK:
|
${EndIf}
|
||||||
CopyFiles "$PACKAGEDIR\$1" "$0\$1"
|
CopyFiles "$PACKAGEDIR\$1" "$0\$1"
|
||||||
Goto PackageDone
|
Goto PackageDone
|
||||||
CheckForZip:
|
${EndIf}
|
||||||
IfFileExists "$PACKAGEDIR\$1.zip" 0 AttemptDownload
|
# It's not in the package dir, but check if it's there but an over-helpful
|
||||||
|
# browser stuck a .zip at the end
|
||||||
|
${If} ${FileExists} "$PACKAGEDIR\$1.zip"
|
||||||
md5dll::GetFileMD5 "$PACKAGEDIR\$1.zip"
|
md5dll::GetFileMD5 "$PACKAGEDIR\$1.zip"
|
||||||
Pop $3
|
Pop $3
|
||||||
StrCmp $MD5SUM $3 ZipPackageOK
|
${If} $MD5SUM != $3
|
||||||
MessageBox MB_ICONINFORMATION|MB_OKCANCEL "The file $PACKAGEDIR\$1.zip appears to be corrupt. The expected MD5 sum was '$MD5SUM', but the actual MD5 sum was '$3'. Press OK to attempt to download a fresh copy from the distribution site, or Cancel to skip the package." IDOK AttemptDownload IDCANCEL PackageDone
|
MessageBox MB_ICONINFORMATION|MB_OKCANCEL "The file $PACKAGEDIR\$1.zip appears to be corrupt. The expected MD5 sum was '$MD5SUM', but the actual MD5 sum was '$3'. Press OK to attempt to download a fresh copy from the distribution site, or Cancel to skip the package." IDOK AttemptDownload IDCANCEL PackageDone
|
||||||
ZipPackageOK:
|
${EndIf}
|
||||||
CopyFiles "$PACKAGEDIR\$1.zip" "$0\$1"
|
CopyFiles "$PACKAGEDIR\$1.zip" "$0\$1"
|
||||||
Goto PackageDone
|
Goto PackageDone
|
||||||
|
${EndIf}
|
||||||
|
|
||||||
|
# We're now in a loop of trying to download the file until the user gives
|
||||||
|
# up. Since the only way to iterate through the loop more than once is to
|
||||||
|
# have the user reply to a message box, this loop is still marked by a
|
||||||
|
# label instead of being part of a Do/Loop macro.
|
||||||
AttemptDownload:
|
AttemptDownload:
|
||||||
GetTempFileName $DOWNLOADTARGET
|
GetTempFileName $DOWNLOADTARGET
|
||||||
Delete $DOWNLOADTARGET
|
Delete $DOWNLOADTARGET
|
||||||
CreateDirectory $DOWNLOADTARGET
|
CreateDirectory $DOWNLOADTARGET
|
||||||
inetc::get "https://downloads.sourceforge.net/project/sc2/$DOWNLOADPATH$1" "$DOWNLOADTARGET/$1" /END
|
inetc::get "https://downloads.sourceforge.net/project/sc2/$DOWNLOADPATH$1" "$DOWNLOADTARGET/$1" /END
|
||||||
Pop $2
|
Pop $2
|
||||||
StrCmp $2 "OK" DownloadSuccessful
|
${If} $2 != "OK"
|
||||||
StrCmp $2 "Cancelled" DownloadCanceled
|
${If} $2 == "Cancelled"
|
||||||
StrCpy $2 "Could not install the package $1 due to the following error: $\"$2$\"."
|
|
||||||
Goto CheckMandatory
|
|
||||||
DownloadCanceled:
|
|
||||||
StrCpy $2 "Download was canceled by user."
|
StrCpy $2 "Download was canceled by user."
|
||||||
CheckMandatory:
|
${Else}
|
||||||
IntCmp $MANDATORY 0 NotMandatory
|
StrCpy $2 "Could not install the package $1 due to the following error: $\"$2$\"."
|
||||||
|
${EndIf}
|
||||||
|
${If} $MANDATORY != 0
|
||||||
StrCpy $3 "THIS IS A MANDATORY PACKAGE. Without this package, $(^Name) will NOT run."
|
StrCpy $3 "THIS IS A MANDATORY PACKAGE. Without this package, $(^Name) will NOT run."
|
||||||
Goto DisplayError
|
${Else}
|
||||||
NotMandatory:
|
|
||||||
StrCpy $3 "This is an optional package. $(^Name) will still run, but some content will not be available."
|
StrCpy $3 "This is an optional package. $(^Name) will still run, but some content will not be available."
|
||||||
DisplayError:
|
${EndIf}
|
||||||
MessageBox MB_ICONEXCLAMATION|MB_YESNO "$2 $3 Do you want to retry from a different mirror?" IDYES AttemptDownload
|
MessageBox MB_ICONEXCLAMATION|MB_YESNO "$2 $3 Do you want to retry from a different mirror?" IDYES AttemptDownload
|
||||||
Goto DoneWithTempFile
|
${Else}
|
||||||
DownloadSuccessful:
|
|
||||||
md5dll::GetFileMD5 "$DOWNLOADTARGET\$1"
|
md5dll::GetFileMD5 "$DOWNLOADTARGET\$1"
|
||||||
Pop $3
|
Pop $3
|
||||||
StrCmp $MD5SUM $3 DownloadedPackageOK
|
${If} $MD5SUM != $3
|
||||||
IntCmp $MANDATORY 0 NotMandatory2
|
${If} $MANDATORY != 0
|
||||||
StrCpy $3 "THIS IS A MANDATORY PACKAGE. Without this package, $(^Name) will NOT run."
|
StrCpy $3 "THIS IS A MANDATORY PACKAGE. Without this package, $(^Name) will NOT run."
|
||||||
Goto DisplayError2
|
${Else}
|
||||||
NotMandatory2:
|
|
||||||
StrCpy $3 "This is an optional package. $(^Name) will still run, but some content will not be available."
|
StrCpy $3 "This is an optional package. $(^Name) will still run, but some content will not be available."
|
||||||
DisplayError2:
|
${EndIf}
|
||||||
MessageBox MB_ICONEXCLAMATION|MB_YESNO "The downloaded file $1 doesn't match the internal MD5 sum. This probably means the download was corrupt. $3 Do you want to retry from a different mirror? (Select NO to install the downloaded package anyway - for instance, if you know that the content pack was upgraded or modified since.)" IDYES AttemptDownload
|
MessageBox MB_ICONEXCLAMATION|MB_YESNO "The downloaded file $1 doesn't match the internal MD5 sum. This probably means the download was corrupt. $3 Do you want to retry from a different mirror? (Select NO to install the downloaded package anyway - for instance, if you know that the content pack was upgraded or modified since.)" IDYES AttemptDownload
|
||||||
DownloadedPackageOK:
|
${EndIf}
|
||||||
CopyFiles "$DOWNLOADTARGET\$1" "$0\$1"
|
CopyFiles "$DOWNLOADTARGET\$1" "$0\$1"
|
||||||
DoneWithTempFile:
|
${EndIf}
|
||||||
RmDir /r $DOWNLOADTARGET
|
RmDir /r $DOWNLOADTARGET
|
||||||
PackageDone:
|
PackageDone:
|
||||||
Pop $3
|
Pop $3
|
||||||
@@ -213,11 +222,11 @@ Function AppendToFile
|
|||||||
Exch $1 # File name
|
Exch $1 # File name
|
||||||
Push $2 # using $2 for file handle
|
Push $2 # using $2 for file handle
|
||||||
FileOpen $2 $1 a
|
FileOpen $2 $1 a
|
||||||
IfErrors done
|
${Unless} ${Errors}
|
||||||
FileSeek $2 0 END # seek to end
|
FileSeek $2 0 END # seek to end
|
||||||
FileWrite $2 $0
|
FileWrite $2 $0
|
||||||
FileClose $2
|
FileClose $2
|
||||||
done:
|
${EndUnless}
|
||||||
Pop $2
|
Pop $2
|
||||||
Pop $1
|
Pop $1
|
||||||
Pop $0
|
Pop $0
|
||||||
@@ -408,9 +417,9 @@ Section -ShortcutsAndIcons
|
|||||||
CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Documentation\WhatsNew.lnk" "$INSTDIR\WhatsNew.txt"
|
CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Documentation\WhatsNew.lnk" "$INSTDIR\WhatsNew.txt"
|
||||||
CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Keyboard Test.lnk" "$INSTDIR\keyjam.exe"
|
CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Keyboard Test.lnk" "$INSTDIR\keyjam.exe"
|
||||||
CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Saved Games.lnk" "$UQMUSERDATA\save"
|
CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Saved Games.lnk" "$UQMUSERDATA\save"
|
||||||
IntCmp $MAKEICON 1 0 NoIcon NoIcon
|
${If} $MAKEICON = 1
|
||||||
CreateShortCut "$DESKTOP\The Ur-Quan Masters.lnk" "$INSTDIR\uqm.exe" $UQMARGS
|
CreateShortCut "$DESKTOP\The Ur-Quan Masters.lnk" "$INSTDIR\uqm.exe" $UQMARGS
|
||||||
NoIcon:
|
${EndIf}
|
||||||
CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Uninstall.lnk" "$INSTDIR\uninst.exe"
|
CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Uninstall.lnk" "$INSTDIR\uninst.exe"
|
||||||
!insertmacro MUI_STARTMENU_WRITE_END
|
!insertmacro MUI_STARTMENU_WRITE_END
|
||||||
SectionEnd
|
SectionEnd
|
||||||
|
|||||||
Reference in New Issue
Block a user