Name "FreeSpace Open Updater" # Defines !define REGKEY "SOFTWARE\FreeSpace Open" !define VERSION "3.6.9 - RC 7.9x Mk. 6" ;!define VERSION "3.6.9 Release" !define COMPANY "The FreeSpace 2 Source Code Project" !define URL http://www.hard-light.net/forums/index.php/topic,42854.0.html # MUI defines !define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico" !define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico" !define MUI_UNFINISHPAGE_NOAUTOCLOSE !define MUI_COMPONENTSPAGE_SMALLDESC # Included files !include Sections.nsh !include MUI.nsh !include ZipDLL.nsh # Reserved Files ReserveFile "${NSISDIR}\Plugins\AdvSplash.dll" # Variables Var foldername ;Names of the exes Var EXENAME Var EXEDEBUGNAME Var FREDNAME Var FREDDEBUGNAME Var EXESHORTCUT Var EXEDEBUGSHORTCUT Var FREDSHORTCUT Var FREDDEBUGSHORTCUT ;locations of mod text files. Var DERELICTMODTXT Var DERELICTVOICEMODTXT Var JAD1MODTXT Var JAD2MODTXT Var FSPORTMODTXT Var FSPORTEXTRAMODTXT Var AWAKEMODTXT Var AWAKEVOICEMODTXT Var CUTSCENEMODTXT Var HOMESICKMODTXT Var TRANSCENDMODTXT Var SYNCMODTXT # Installer pages ;these define the pages in the installer and the order in which they are shown. !insertmacro MUI_PAGE_INSTFILES !insertmacro MUI_UNPAGE_COMPONENTS !insertmacro MUI_UNPAGE_INSTFILES # Installer languages !insertmacro MUI_LANGUAGE English # Installer attributes OutFile FreeSpaceOpenupdatemaker.exe InstallDir C:\Games\FreeSpace2 CRCCheck on XPStyle on ShowInstDetails show VIProductVersion 3.6.9.0 VIAddVersionKey ProductName "FreeSpace Open" VIAddVersionKey ProductVersion "${VERSION}" VIAddVersionKey CompanyName "${COMPANY}" VIAddVersionKey CompanyWebsite "${URL}" VIAddVersionKey FileVersion "" VIAddVersionKey FileDescription "" VIAddVersionKey LegalCopyright "" InstallDirRegKey HKLM "${REGKEY}" Path ShowUninstDetails show # Installer sections Section "!un.Core Files" CORE AddSize 28509 SetOutPath $INSTDIR SetOverwrite on ;get the URL for the files. NSISdl::download_quiet http://www.fsoinstaller.com/files/installer/core_files.txt $INSTDIR\Installer\core_files.txt FileOpen $0 $INSTDIR\Installer\core_files.txt r FileRead $0 $1 ;Download the files. NSISdl::download $1 $TEMP\core_files.zip ;Unzip the files. !insertmacro ZIPDLL_EXTRACT $TEMP\core_files.zip $INSTDIR Delete /REBOOTOK $TEMP\core_files.zip NSISdl::download_quiet http://www.game-warden.com/fs2open_pxo.cfg $INSTDIR\data\fs2open_pxo.cfg ;The shortcut has to be created in the FreeSpace2 folder and then moved, otherwise it doesn't seem to work right. CreateShortcut "$INSTDIR\FreeSpace Open Launcher.lnk" $INSTDIR\Launcher.exe CopyFiles /silent "$INSTDIR\FreeSpace Open Launcher.lnk" "$SMPROGRAMS\Games\FreeSpace 2" CopyFiles /silent "$INSTDIR\FreeSpace Open Launcher.lnk" "$DESKTOP" Delete /REBOOTOK "$INSTDIR\FreeSpace Open Launcher.lnk" SetOutPath "$SMPROGRAMS\Games\FreeSpace 2" CreateShortcut "$SMPROGRAMS\Games\FreeSpace 2\$EXESHORTCUT.lnk" $INSTDIR\$EXENAME CopyFiles /silent "$SMPROGRAMS\Games\FreeSpace 2\$EXESHORTCUT.lnk" "$DESKTOP" ;Tells the Uninstaller that this section was installed. WriteRegStr HKLM "${REGKEY}\Components" "Core Files" 1 SectionEnd SectionGroup /e "!un.Media VPs" MEDIAVPS Section /o "un.Core VPs" VPSCORE AddSize 489632 ;Downloads the mod text file and passes it to the Moddl function. NSISdl::download_quiet http://www.fsoinstaller.com/files/installer/mv.txt $TEMP\mv.txt Push $TEMP\mv.txt Push $INSTDIR\Installer\mv.txt Call un.checkver Pop $1 StrCmp "$1" "NO" done Push $TEMP\mv.txt Call un.Moddl ;replaces a regular launcher6.ini with one that has the mediavps folder as the mod. Delete /REBOOTOK $INSTDIR\launcher6.ini Rename $INSTDIR\$foldername\mvlauncher6.ini $INSTDIR\launcher6.ini WriteRegStr HKLM "${REGKEY}\Components" "Core VPs" 1 Delete $INSTDIR\Installer\mv.txt Rename $TEMP\mv.txt $INSTDIR\Installer\mv.txt done: SectionEnd Section /o "un.Advanced VPs" VPSADV AddSize 334996 ;Downloads the mod text file and passes it to the Moddl function. NSISdl::download_quiet http://www.fsoinstaller.com/files/installer/mv_adv.txt $TEMP\mv_adv.txt Push $TEMP\mv_adv.txt Push $INSTDIR\Installer\mv_adv.txt Call un.checkver Pop $1 StrCmp "$1" "NO" done Push $TEMP\mv_adv.txt Call un.Moddl WriteRegStr HKLM "${REGKEY}\Components" "Advanced VPs" 1 Delete $INSTDIR\Installer\mv_adv.txt Rename $TEMP\mv_adv.txt $INSTDIR\Installer\mv_adv.txt done: SectionEnd SectionGroupEnd SectionGroup "!un.Mods" MODS ;Derelict Group - Contact is RazorsKiss SectionGroup "un.Derelict" DERELICT ;The required files for Derelict Section /o "un.Derelict Core Files" DERELICTCORE ;Downloads the mod text file and passes it to the Moddl function. NSISdl::download_quiet $DERELICTMODTXT $TEMP\derelict.txt Push $TEMP\derelict.txt Push $INSTDIR\Installer\derelict.txt Call un.checkver Pop $1 StrCmp "$1" "NO" done Push $TEMP\derelict.txt Call un.Moddl WriteRegStr HKLM "${REGKEY}\Components" "Derelict Core Files" 1 Delete $INSTDIR\Installer\derelict.txt Rename $TEMP\derelict.txt $INSTDIR\Installer\derelict.txt done: SectionEnd ; Section /o "un.Derelict Voice Pack" DERELICTVOICE ;Downloads the mod text file and passes it to the Moddl function. NSISdl::download_quiet $DERELICTVOICEMODTXT $TEMP\derelictvoice.txt Push $TEMP\derelictvoice.txt Push $INSTDIR\Installer\derelictvoice.txt Call un.checkver Pop $1 StrCmp "$1" "NO" done Push $TEMP\derelictvoice.txt Call un.Moddl WriteRegStr HKLM "${REGKEY}\Components" "Derelict Voice Pack" 1 Delete $INSTDIR\Installer\derelictvoice.txt Rename $TEMP\derelictvoice.txt $INSTDIR\Installer\derelictvoice.txt done: SectionEnd SectionGroupEnd ;JAD 1&2 - Contact is Axem Section /o "un.Just Another Day" JAD1 ;Downloads the mod text file and passes it to the Moddl function. NSISdl::download_quiet $JAD1MODTXT $TEMP\JAD1.txt Push $TEMP\JAD1.txt Push $INSTDIR\Installer\JAD1.txt Call un.checkver Pop $1 StrCmp "$1" "NO" done Push $TEMP\JAD1.txt Call un.Moddl WriteRegStr HKLM "${REGKEY}\Components" "Just Another Day" 1 Delete $INSTDIR\Installer\JAD1.txt Rename $TEMP\JAD1.txt $INSTDIR\Installer\JAD1.txt done: SectionEnd Section /o "un.Just Another Day 2" JAD2 ;Downloads the mod text file and passes it to the Moddl function. NSISdl::download_quiet $JAD2MODTXT $TEMP\JAD2.txt Push $TEMP\JAD2.txt Push $INSTDIR\Installer\JAD2.txt Call un.checkver Pop $1 StrCmp "$1" "NO" done Push $TEMP\JAD2.txt Call un.Moddl WriteRegStr HKLM "${REGKEY}\Components" "Just Another Day 2" 1 Delete $INSTDIR\Installer\JAD2.txt Rename $TEMP\JAD2.txt $INSTDIR\Installer\JAD2.txt done: SectionEnd ;Port and Awakenings - Contact is Goober5000 SectionGroup "un.FreeSpace Port" FSPORT Section /o "un.FSPort Core Files" FSPORTCORE ;Downloads the mod text file and passes it to the Moddl function. NSISdl::download_quiet $FSPORTMODTXT $TEMP\fsport.txt Push $TEMP\fsport.txt Push $INSTDIR\Installer\fsport.txt Call un.checkver Pop $1 StrCmp "$1" "NO" done Push $TEMP\fsport.txt Call un.Moddl WriteRegStr HKLM "${REGKEY}\Components" "FSPort Core Files" 1 Delete $INSTDIR\Installer\fsport.txt Rename $TEMP\fsport.txt $INSTDIR\Installer\fsport.txt done: SectionEnd Section /o "un.FSPort Extras" FSPORTEXTRA ;Downloads the mod text file and passes it to the Moddl function. NSISdl::download_quiet $FSPORTEXTRAMODTXT $TEMP\fsportextra.txt Push $TEMP\fsportextra.txt Push $INSTDIR\Installer\fsportextra.txt Call un.checkver Pop $1 StrCmp "$1" "NO" done Push $TEMP\fsportextra.txt Call un.Moddl WriteRegStr HKLM "${REGKEY}\Components" "FSPort Extras" 1 Delete $INSTDIR\Installer\fsportextra.txt Rename $TEMP\fsportextra.txt $INSTDIR\Installer\fsportextra.txt done: SectionEnd SectionGroup "un.Awakenings" AWAKE Section /o "un.Awakenings Core Files" AWAKECORE ;Downloads the mod text file and passes it to the Moddl function. NSISdl::download_quiet $AWAKEMODTXT $TEMP\awake.txt Push $TEMP\awake.txt Push $INSTDIR\Installer\awake.txt Call un.checkver Pop $1 StrCmp "$1" "NO" done Push $TEMP\awake.txt Call un.Moddl WriteRegStr HKLM "${REGKEY}\Components" "Awakenings Core Files" 1 Delete $INSTDIR\Installer\awake.txt Rename $TEMP\awake.txt $INSTDIR\Installer\awake.txt done: SectionEnd Section /o "un.Awakenings Voice Pack" AWAKEVOICE ;Downloads the mod text file and passes it to the Moddl function. NSISdl::download_quiet $AWAKEVOICEMODTXT $TEMP\awakevoice.txt Push $TEMP\awakevoice.txt Push $INSTDIR\Installer\awakevoice.txt Call un.checkver Pop $1 StrCmp "$1" "NO" done Push $TEMP\awakevoice.txt Call un.Moddl WriteRegStr HKLM "${REGKEY}\Components" "Awakenings Voice Pack" 1 Delete $INSTDIR\Installer\awakevoice.txt Rename $TEMP\awakevoice.txt $INSTDIR\Installer\awakevoice.txt done: SectionEnd SectionGroupEnd SectionGroupEnd Section /o "un.Homesick" HOMESICK ;Downloads the mod text file and passes it to the Moddl function. NSISdl::download_quiet $HOMESICKMODTXT $TEMP\homesick.txt Push $TEMP\homesick.txt Push $INSTDIR\Installer\homesick.txt Call un.checkver Pop $1 StrCmp "$1" "NO" done Push $TEMP\homesick.txt Call un.Moddl WriteRegStr HKLM "${REGKEY}\Components" "Homesick" 1 Delete $INSTDIR\Installer\homesick.txt Rename $TEMP\homesick.txt $INSTDIR\Installer\homesick.txt done: SectionEnd Section /o "un.Transcend" TRANSCEND ;Downloads the mod text file and passes it to the Moddl function. NSISdl::download_quiet $TRANSCENDMODTXT $TEMP\transcend.txt Push $TEMP\transcend.txt Push $INSTDIR\Installer\transcend.txt Call un.checkver Pop $1 StrCmp "$1" "NO" done Push $TEMP\transcend.txt Call un.Moddl WriteRegStr HKLM "${REGKEY}\Components" "Transcend" 1 Delete $INSTDIR\Installer\transcend.txt Rename $TEMP\transcend.txt $INSTDIR\Installer\transcend.txt done: SectionEnd Section /o "un.Sync" SYNC ;Downloads the mod text file and passes it to the Moddl function. NSISdl::download_quiet $SYNCMODTXT $TEMP\sync.txt Push $TEMP\sync.txt Push $INSTDIR\Installer\sync.txt Call un.checkver Pop $1 StrCmp "$1" "NO" done Push $TEMP\sync.txt Call un.Moddl WriteRegStr HKLM "${REGKEY}\Components" "Sync" 1 Delete $INSTDIR\Installer\sync.txt Rename $TEMP\sync.txt $INSTDIR\Installer\sync.txt done: SectionEnd SectionGroupEnd ;this runs after everything else. Section -post SECPOST WriteUninstaller $EXEDIR\UpdateFreeSpaceOpen.exe SectionEnd # Macro for selecting uninstaller sections !macro SELECT_UNSECTION SECTION_NAME UNSECTION_ID Push $R0 ReadRegStr $R0 HKLM "${REGKEY}\Components" "${SECTION_NAME}" StrCmp $R0 1 0 next${UNSECTION_ID} !insertmacro SelectSection "${UNSECTION_ID}" GoTo done${UNSECTION_ID} next${UNSECTION_ID}: !insertmacro UnselectSection "${UNSECTION_ID}" done${UNSECTION_ID}: Pop $R0 !macroend Section -un.post UNSECPOST SectionEnd # Installer functions ;This is the first thing to run when the installer starts. Function .onInit InitPluginsDir Push $R1 ;Puts up the pretty picture at the beginning. File /oname=$PLUGINSDIR\spltmp.bmp logo.bmp advsplash::show 1000 1000 1000 -1 $PLUGINSDIR\spltmp Pop $R1 Pop $R1 FunctionEnd # Uninstaller functions Function un.onInit InitPluginsDir Push $R1 ;Puts up the pretty picture at the beginning. File /oname=$PLUGINSDIR\spltmp.bmp logo.bmp advsplash::show 1000 1000 1000 -1 $PLUGINSDIR\spltmp Pop $R1 Pop $R1 ReadRegStr $INSTDIR HKLM "${REGKEY}" Path ;Gets the latest VERSION string. NSISdl::download_quiet http://www.fsoinstaller.com/files/installer/update_version.txt $TEMP\update_version.txt FileOpen $0 $TEMP\update_version.txt r FileRead $0 $1 ;Compares the VERSION strings and opens the download page if this version is outdated. StrCmp "$1" "${VERSION}" current 0 MessageBox MB_OK|MB_ICONSTOP|MB_TOPMOST "This updater is outdated.$\nNow bringing up the download page for the most recent version.$\n(Note: If you do not have a working internet connection, it will cause this box to show.)" ExecShell "" "http://www.fsoinstaller.com/files/installer/UpdateFreeSpaceOpen.exe" Quit current: Call un.getFileNames FunctionEnd Function un.getFileNames Push $0 Push $1 FileOpen $0 $INSTDIR\Installer\filenames.txt r FileRead $0 $1 Push $1 Call un.TrimNewlines Pop $EXENAME FileRead $0 $1 Push $1 Call un.TrimNewlines Pop $EXEDEBUGNAME FileRead $0 $1 Push $1 Call un.TrimNewlines Pop $FREDNAME FileRead $0 $1 Push $1 Call un.TrimNewlines Pop $FREDDEBUGNAME FileRead $0 $1 Push $1 Call un.TrimNewlines Pop $EXESHORTCUT FileRead $0 $1 Push $1 Call un.TrimNewlines Pop $EXEDEBUGSHORTCUT FileRead $0 $1 Push $1 Call un.TrimNewlines Pop $FREDSHORTCUT FileRead $0 $1 Push $1 Call un.TrimNewlines Pop $FREDDEBUGSHORTCUT ;locations of mod text files. FileRead $0 $1 Push $1 Call un.TrimNewlines Pop $DERELICTMODTXT FileRead $0 $1 Push $1 Call un.TrimNewlines Pop $DERELICTVOICEMODTXT FileRead $0 $1 Push $1 Call un.TrimNewlines Pop $JAD1MODTXT FileRead $0 $1 Push $1 Call un.TrimNewlines Pop $JAD2MODTXT FileRead $0 $1 Push $1 Call un.TrimNewlines Pop $FSPORTMODTXT FileRead $0 $1 Push $1 Call un.TrimNewlines Pop $FSPORTEXTRAMODTXT FileRead $0 $1 Push $1 Call un.TrimNewlines Pop $AWAKEMODTXT FileRead $0 $1 Push $1 Call un.TrimNewlines Pop $AWAKEVOICEMODTXT FileRead $0 $1 Push $1 Call un.TrimNewlines Pop $CUTSCENEMODTXT FileRead $0 $1 Push $1 Call un.TrimNewlines Pop $HOMESICKMODTXT FileRead $0 $1 Push $1 Call un.TrimNewlines Pop $TRANSCENDMODTXT FileRead $0 $1 Push $1 Call un.TrimNewlines Pop $SYNCMODTXT Pop $1 Pop $0 FunctionEnd Function un.checkver Exch $R0 Exch Exch $R1 Exch Push $0 Push $1 Push $2 Push $3 FileOpen $0 "$R0" r loop1: FileRead $0 $2 DetailPrint "$2" Push "$2" Call un.TrimNewlines Pop "$2" StrCmp "$2" "END" 0 loop1 StrCmp "$2" "" noupdate FileRead $0 "$2" Push "$2" Call un.TrimNewlines Pop "$2" FileOpen $1 $R1 r loop2: FileRead $1 $3 DetailPrint "$3" Push $3 Call un.TrimNewlines Pop $3 StrCmp "$3" "END" 0 loop2 StrCmp "$3" "" noupdate FileRead $1 $3 Push $3 Call un.TrimNewlines Pop $3 DetailPrint "$2 | $3" StrCmp $2 $3 noupdate update noupdate: StrCpy $R0 "NO" Goto end update: StrCpy $R0 "YES" end: Pop $3 Pop $2 Pop $1 Pop $0 Pop $R1 DetailPrint $R0 Exch $R0 FunctionEnd ;Probably the most important part of the script. This does most of the real work. Function un.Moddl ;preserves whatever values were in these variables before. Exch $R0 Push $R1 Push $0 Push $1 Push $2 Push $3 ;Opens the mod text file for this mod. FileOpen $0 $R0 r loop2: FileRead $0 $R1 Push $R1 Call un.TrimNewlines Pop $R1 StrCmp "$R1" "FOLDER" cd StrCmp "$R1" "URL" new StrCmp "$R1" "FILES" loop Goto done ;IF the command URL is put in the mod text file, we come here. new: ;gets the URL to download from and trims extra formating off of it. FileRead $0 $1 Push $1 Call un.TrimNewlines Pop $1 ;Let's start downloading files! goto loop2 ;if the command FOLDER is put in the mod text file, we come here. cd: ;gets a new folder to put the remaining files in. FileRead $0 $foldername Push $foldername Call un.TrimNewlines Pop $foldername SetOutPath $INSTDIR\$foldername Goto loop2 ;now we start downloading files. loop: ;Get the filename and trim formatting. FileRead $0 $2 Push $2 Call un.TrimNewlines Pop $2 ;Are we done yet? StrCmp "$2" "END" done ;Has the NEW command been encountered? StrCmp "$2" "URL" new ;Has the CD command been encountered? StrCmp "$2" "FOLDER" cd ;This should only be true if the text file didn't download. StrCmp "$2" "" fail ;get the file extention. StrCpy $3 "$2" 3 -3 ;See if it's a zip file. StrCmp "$3" "zip" 0 notzip ;Download the zip file to a temp location. NSISdl::download $1$2 $TEMP\$2 ;Unzip the file to the correct location. !insertmacro ZIPDLL_EXTRACT "$TEMP\$2" $OUTDIR ;Delete the zip file (Not needed any more) Delete /REBOOTOK $TEMP\$2 ;get the next file. Goto loop ;It's not a zip file. notzip: ;Download it straight to the correct folder. NSISdl::download $1$2 "$OUTDIR\$2" ;get the next file. Goto loop ;got a blank line. fail: MessageBox MB_OK|MB_ICONSTOP|MB_TOPMOST "For some reason, your internet connection did not allow a mod text file to download correctly.$\nSome files may not have been downloaded.$\n$R0" ;We've done all the files now. done: ;restore the variables to what they were before the function was called. Pop $3 Pop $2 Pop $1 Pop $0 Pop $R1 Pop $R0 FunctionEnd Function un.TrimNewlines ;Preserve Variable values and get input Exch $R0 Push $R1 Push $R2 ;Put the number 0 in $R1 StrCpy $R1 0 ;Start the loop loop: ;Get the last character in the string in $R0 IntOp $R1 $R1 - 1 StrCpy $R2 $R0 1 $R1 ;Is $R0 a return or newline character? ;If so, remove it from $R0 by subtracting 1 from $R1 StrCmp $R2 "$\r" loop StrCmp $R2 "$\n" loop ;Otherwise, add 1 to $R1 IntOp $R1 $R1 + 1 ;If we're back at zero, we've search $R0 from the back ;until we hit a non-return or newline character. IntCmp $R1 0 no_trim_needed ;Chops $R1 characters off of the end of $R0. StrCpy $R0 $R0 $R1 no_trim_needed: ;Restore variable values Pop $R2 Pop $R1 ;Put the Return value on the top of the stack. Exch $R0 FunctionEnd