Advertisement
Guest User

Untitled

a guest
Jun 21st, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Useful common functions for MS and MF installers alike
  2.  
  3. !include "Common\FDSMigrate.nsh"
  4.  
  5. Var RecordSettings
  6.  
  7. Function FDSInit
  8.  
  9.     # This bit of code checks for the option /WRITESETTINGS=1 and sets the $RecordSettings flag if it is
  10.     ${GetParameters} $R0
  11.     ClearErrors
  12.     ${GetOptions} $R0 /WRITESETTINGS= $0
  13.     ${If} $0 != ""
  14.         IntOp $RecordSettings 0 + 1 # just set it to 1 - don't know how else to do this! :)
  15.         DetailPrint "**** WriteSettings Activated! - Configuration file will be written out to ${INSTALLINI} ****"
  16.     ${Else}
  17.         IntOp $RecordSettings 0 + 0 # just set it to 0
  18.     ${Endif}
  19.  
  20.     # Reads the default values from the ini file if they exist    
  21.     ReadIniStr $0 '${INSTALLINI}' '${APPNAME}' 'StartMenu'
  22.     ${IfNot} $0 == ""
  23.       StrCpy $StartMenuGroup $0
  24.     ${EndIf}    
  25.     ReadIniStr $1 '${INSTALLINI}' '${APPNAME}' 'InstallDir'
  26.     ${IfNot} $1 == ""
  27.       StrCpy $INSTDIR $1
  28.     ${EndIf}    
  29.     DetailPrint "*** Read Installation Settings '$StartMenuGroup' & '$INSTDIR'"
  30.        
  31. FunctionEnd
  32.  
  33. Section -FDSCommon
  34.     ${If} $RecordSettings = 1
  35.         DetailPrint "*** Written Installation Settings '$StartMenuGroup' & '$INSTDIR'"
  36.         WriteIniStr '${INSTALLINI}' '${APPNAME}' 'StartMenu' '$StartMenuGroup'
  37.         WriteIniStr '${INSTALLINI}' '${APPNAME}' 'InstallDir' '$INSTDIR'
  38.     ${EndIf}
  39.    
  40.     # save the version number and location in the registry on installation
  41.     WriteRegStr HKLM "SOFTWARE\Formation\${APPNAME}" "Version" "${VERSION}"
  42.     WriteRegStr HKLM "SOFTWARE\Formation\${APPNAME}" "InstallDir" "$INSTDIR"
  43.    
  44. SectionEnd
  45.  
  46. # This function simply checks for Administrator rights and if not found then brings up a messagebox and quits the installer
  47. !ifndef NODONGLE
  48. Function CheckAdminRights
  49.     UserInfo::GetAccountType
  50.    pop $0
  51.     ${If} $0 != "admin" ;Require admin rights on NT4+
  52.         MessageBox mb_iconstop "Administrator rights required to run this installer!"
  53.         SetErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
  54.         Quit
  55.     ${EndIf}
  56. FunctionEnd
  57. !endif
  58.  
  59. !ifdef X64
  60. Function CheckX64System
  61.     ${IfNot} ${RunningX64}
  62.         MessageBox MB_OK "A 64-bit Windows system is required to install this software."
  63.         Quit
  64.     ${EndIf}
  65. FunctionEnd
  66. !endif
  67.  
  68. Function CheckMinimumOS
  69.     # Checks for at least XP SP3
  70.     ${If} ${AtLeastWinXP}
  71.         ${If} ${IsWinXP}
  72.         ${AndIfNot} ${AtLeastServicePack} 3
  73.             MessageBox MB_OK "Windows XP Service Pack 3 and above are required to install this software."
  74.             Quit
  75.         ${EndIf}
  76.     ${EndIf}
  77. FunctionEnd
  78.    
  79. # This macro takes three parameters - path and libraryname extension and will back it up to a
  80. # new libraryname.oldXX where XX is an unused number
  81. # 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
  82. #
  83. # Eg "$DOCUMENTS\Multiframe\Multiframe ${MAJOR_VERSION}" LoadLibrary llb  
  84. Var num
  85. !macro LibraryBackup Path LibraryName Extension
  86.   IntOp $num 1 + 1
  87.   ${DoWhile} ${FileExists} "${Path}\${LibraryName}.old$num"
  88.     IntOp $num $num + 1
  89.   ${LoopUntil} $num = 100
  90.   DetailPrint "${Path}\${LibraryName}.${Extension} backed up and saved as ${Path}\${LibraryName}.old$num"
  91.   CopyFiles /SILENT /FILESONLY '${Path}\${LibraryName}.${Extension}' '${Path}\${LibraryName}.old$num'      
  92. !macroend
  93.  
  94. ################################################################################################################
  95. # Macros to make reading and writing INI files easier
  96. # ReadSectionState should be called in .oninit once for each section that is present and 'selectable'
  97. # WriteSectionState should be called once in each section block when its installed
  98. # IMPORTANT: make sure the SectionName in both calls is the same!
  99.  
  100. !macro ReadSectionState SectionName SectionID
  101.     ReadIniStr $0 '${INSTALLINI}' '${APPNAME}' '${SectionName}'
  102.     ${If} $0 = 1
  103.         SectionGetFlags ${SectionID} $1
  104.         IntOp $1 $1 | ${SF_SELECTED}
  105.         SectionSetFlags ${SectionID} $1        
  106.         DetailPrint "*** Read Settings for '${INSTALLINI}' '${APPNAME}' '${SectionName}'"
  107.     ${EndIf}
  108. !macroend    
  109.  
  110. !macro WriteSectionState SectionName
  111.     ${If} $RecordSettings = 1
  112.         WriteIniStr '${INSTALLINI}' '${APPNAME}' '${SectionName}' 1
  113.         DetailPrint "*** Written Settings for '${INSTALLINI}' '${APPNAME}' '${SectionName}'"
  114.     ${EndIf}
  115. !macroend
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement