Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Useful common functions for MS and MF installers alike
- !include "Common\FDSMigrate.nsh"
- Var RecordSettings
- Function FDSInit
- # This bit of code checks for the option /WRITESETTINGS=1 and sets the $RecordSettings flag if it is
- ${GetParameters} $R0
- ClearErrors
- ${GetOptions} $R0 /WRITESETTINGS= $0
- ${If} $0 != ""
- IntOp $RecordSettings 0 + 1 # just set it to 1 - don't know how else to do this! :)
- DetailPrint "**** WriteSettings Activated! - Configuration file will be written out to ${INSTALLINI} ****"
- ${Else}
- IntOp $RecordSettings 0 + 0 # just set it to 0
- ${Endif}
- # Reads the default values from the ini file if they exist
- ReadIniStr $0 '${INSTALLINI}' '${APPNAME}' 'StartMenu'
- ${IfNot} $0 == ""
- StrCpy $StartMenuGroup $0
- ${EndIf}
- ReadIniStr $1 '${INSTALLINI}' '${APPNAME}' 'InstallDir'
- ${IfNot} $1 == ""
- StrCpy $INSTDIR $1
- ${EndIf}
- DetailPrint "*** Read Installation Settings '$StartMenuGroup' & '$INSTDIR'"
- FunctionEnd
- Section -FDSCommon
- ${If} $RecordSettings = 1
- DetailPrint "*** Written Installation Settings '$StartMenuGroup' & '$INSTDIR'"
- WriteIniStr '${INSTALLINI}' '${APPNAME}' 'StartMenu' '$StartMenuGroup'
- WriteIniStr '${INSTALLINI}' '${APPNAME}' 'InstallDir' '$INSTDIR'
- ${EndIf}
- # save the version number and location in the registry on installation
- WriteRegStr HKLM "SOFTWARE\Formation\${APPNAME}" "Version" "${VERSION}"
- WriteRegStr HKLM "SOFTWARE\Formation\${APPNAME}" "InstallDir" "$INSTDIR"
- SectionEnd
- # This function simply checks for Administrator rights and if not found then brings up a messagebox and quits the installer
- !ifndef NODONGLE
- Function CheckAdminRights
- UserInfo::GetAccountType
- pop $0
- ${If} $0 != "admin" ;Require admin rights on NT4+
- MessageBox mb_iconstop "Administrator rights required to run this installer!"
- SetErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
- Quit
- ${EndIf}
- FunctionEnd
- !endif
- !ifdef X64
- Function CheckX64System
- ${IfNot} ${RunningX64}
- MessageBox MB_OK "A 64-bit Windows system is required to install this software."
- Quit
- ${EndIf}
- FunctionEnd
- !endif
- Function CheckMinimumOS
- # Checks for at least XP SP3
- ${If} ${AtLeastWinXP}
- ${If} ${IsWinXP}
- ${AndIfNot} ${AtLeastServicePack} 3
- MessageBox MB_OK "Windows XP Service Pack 3 and above are required to install this software."
- Quit
- ${EndIf}
- ${EndIf}
- FunctionEnd
- # This macro takes three parameters - path and libraryname extension and will back it up to a
- # new libraryname.oldXX where XX is an unused number
- # N.B. Leave out the last / in the path and the . in the extension, and only use " around pathnames if they have spaces in them
- #
- # Eg "$DOCUMENTS\Multiframe\Multiframe ${MAJOR_VERSION}" LoadLibrary llb
- Var num
- !macro LibraryBackup Path LibraryName Extension
- IntOp $num 1 + 1
- ${DoWhile} ${FileExists} "${Path}\${LibraryName}.old$num"
- IntOp $num $num + 1
- ${LoopUntil} $num = 100
- DetailPrint "${Path}\${LibraryName}.${Extension} backed up and saved as ${Path}\${LibraryName}.old$num"
- CopyFiles /SILENT /FILESONLY '${Path}\${LibraryName}.${Extension}' '${Path}\${LibraryName}.old$num'
- !macroend
- ################################################################################################################
- # Macros to make reading and writing INI files easier
- # ReadSectionState should be called in .oninit once for each section that is present and 'selectable'
- # WriteSectionState should be called once in each section block when its installed
- # IMPORTANT: make sure the SectionName in both calls is the same!
- !macro ReadSectionState SectionName SectionID
- ReadIniStr $0 '${INSTALLINI}' '${APPNAME}' '${SectionName}'
- ${If} $0 = 1
- SectionGetFlags ${SectionID} $1
- IntOp $1 $1 | ${SF_SELECTED}
- SectionSetFlags ${SectionID} $1
- DetailPrint "*** Read Settings for '${INSTALLINI}' '${APPNAME}' '${SectionName}'"
- ${EndIf}
- !macroend
- !macro WriteSectionState SectionName
- ${If} $RecordSettings = 1
- WriteIniStr '${INSTALLINI}' '${APPNAME}' '${SectionName}' 1
- DetailPrint "*** Written Settings for '${INSTALLINI}' '${APPNAME}' '${SectionName}'"
- ${EndIf}
- !macroend
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement