Name "FreeSpace Open" # Defines !define REGKEY "SOFTWARE\$(^Name)" !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 ;Used to record mod dependencies. !define optionallist "'$\"${VPSADV}$\" $\"${VPSCORE}$\" $\"NEXT$\" $\"${DERELICTVOICE}$\" $\"${DERELICTCORE}$\" $\"NEXT$\" $\"${AWAKEVOICE}$\" $\"${AWAKECORE}$\" $\"NEXT$\" $\"${AWAKECORE}$\" $\"${FSPORTCORE}$\" $\"NEXT$\" $\"${FSPORTEXTRA}$\" $\"${FSPORTCORE}$\" $\"NEXT$\"'" # MUI defines !define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico" !define MUI_FINISHPAGE_NOAUTOCLOSE !define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico" !define MUI_UNFINISHPAGE_NOAUTOCLOSE !define MUI_COMPONENTSPAGE_SMALLDESC # Included files !include Sections.nsh !include MUI.nsh !include NSISArray.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 ${Array} optional 15 15 ${ArrayFunc} WriteList ${ArrayFunc} ReadToStack # Installer pages ;these define the pages in the installer and the order in which they are shown. !insertmacro MUI_PAGE_WELCOME !insertmacro MUI_PAGE_LICENSE license.txt !insertmacro MUI_PAGE_COMPONENTS !insertmacro MUI_PAGE_DIRECTORY !insertmacro MUI_PAGE_INSTFILES !insertmacro MUI_PAGE_FINISH !insertmacro MUI_UNPAGE_CONFIRM !insertmacro MUI_UNPAGE_COMPONENTS !insertmacro MUI_UNPAGE_INSTFILES # Installer languages !insertmacro MUI_LANGUAGE English # Installer attributes OutFile FreeSpaceOpensetup.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 "!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 Rename "$INSTDIR\FreeSpace Open Launcher.lnk" "$DESKTOP\FreeSpace Open Launcher.lnk" CopyFiles /silent "$DESKTOP\FreeSpace Open Launcher.lnk" "$SMPROGRAMS\Games\FreeSpace 2" 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" CreateShortcut "$SMPROGRAMS\Games\FreeSpace 2\Revert to Retail.lnk" $INSTDIR\RevertToRetail.exe ;Tells the Uninstaller that this section was installed. WriteRegStr HKLM "${REGKEY}\Components" "Core Files" 1 SectionEnd Section /o "!OpenAL Sound Drivers" OPENAL AddSize 348 SetOutPath $TEMP SetOverwrite on ;Downloads OpenAL NSISdl::download http://fs2source.warpcore.org/exes/latest/OpenALwEAX.exe $TEMP\OpenALwEAX.exe ;Runs the OpenAL Installer and waits for it to finish. execwait $TEMP\OpenALwEAX.exe Delete /REBOOTOK $TEMP\OpenALwEAX.exe SectionEnd SectionGroup /e "!Media VPs" MEDIAVPS Section /o "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 $INSTDIR\Installer\mv.txt Push $INSTDIR\Installer\mv.txt Call 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 SectionEnd Section /o "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 $INSTDIR\Installer\mv_adv.txt Push $INSTDIR\Installer\mv_adv.txt Call Moddl WriteRegStr HKLM "${REGKEY}\Components" "Advanced VPs" 1 SectionEnd SectionGroupEnd Section /o "!.MVE Cutscenes" CUTSCENE AddSize 693564 ;Downloads the mod text file and passes it to the Moddl function. NSISdl::download_quiet $CUTSCENEMODTXT $INSTDIR\Installer\cutscene.txt Push $INSTDIR\Installer\cutscene.txt Call Moddl WriteRegStr HKLM "${REGKEY}\Components" ".MVE Cutscenes" 1 SectionEnd ;This is where all the mods will go when they are submitted. SectionGroup "!Mods" MODS ;Derelict Group - Contact is RazorsKiss SectionGroup "Derelict" DERELICT ;The required files for Derelict Section /o "Derelict Core Files" DERELICTCORE ;Downloads the mod text file and passes it to the Moddl function. NSISdl::download_quiet $DERELICTMODTXT $INSTDIR\Installer\derelict.txt Push $INSTDIR\Installer\derelict.txt Call Moddl WriteRegStr HKLM "${REGKEY}\Components" "Derelict Core Files" 1 SectionEnd ; Section /o "Derelict Voice Pack" DERELICTVOICE ;Downloads the mod text file and passes it to the Moddl function. NSISdl::download_quiet $DERELICTVOICEMODTXT $INSTDIR\Installer\derelictvoice.txt Push $INSTDIR\Installer\derelictvoice.txt Call Moddl WriteRegStr HKLM "${REGKEY}\Components" "Derelict Voice Pack" 1 SectionEnd SectionGroupEnd ;JAD 1&2 - Contact is Axem Section /o "Just Another Day" JAD1 ;Downloads the mod text file and passes it to the Moddl function. NSISdl::download_quiet $JAD1MODTXT $INSTDIR\Installer\JAD1.txt Push $INSTDIR\Installer\JAD1.txt Call Moddl WriteRegStr HKLM "${REGKEY}\Components" "Just Another Day" 1 SectionEnd Section /o "Just Another Day 2" JAD2 ;Downloads the mod text file and passes it to the Moddl function. NSISdl::download_quiet $JAD2MODTXT $INSTDIR\Installer\JAD2.txt Push $INSTDIR\Installer\JAD2.txt Call Moddl WriteRegStr HKLM "${REGKEY}\Components" "Just Another Day 2" 1 SectionEnd ;Port and Awakenings - Contact is Goober5000 SectionGroup "FreeSpace Port" FSPORT Section /o "FSPort Core Files" FSPORTCORE ;Downloads the mod text file and passes it to the Moddl function. NSISdl::download_quiet $FSPORTMODTXT $INSTDIR\Installer\fsport.txt Push $INSTDIR\Installer\fsport.txt Call Moddl WriteRegStr HKLM "${REGKEY}\Components" "FSPort Core Files" 1 SectionEnd Section /o "FSPort Extras" FSPORTEXTRA ;Downloads the mod text file and passes it to the Moddl function. NSISdl::download_quiet $FSPORTEXTRAMODTXT $INSTDIR\Installer\fsportextra.txt Push $INSTDIR\Installer\fsportextra.txt Call Moddl WriteRegStr HKLM "${REGKEY}\Components" "FSPort Extras" 1 SectionEnd SectionGroup "Awakenings" AWAKE Section /o "Awakenings Core Files" AWAKECORE ;Downloads the mod text file and passes it to the Moddl function. NSISdl::download_quiet $AWAKEMODTXT $INSTDIR\Installer\awake.txt Push $INSTDIR\Installer\awake.txt Call Moddl WriteRegStr HKLM "${REGKEY}\Components" "Awakenings Core Files" 1 SectionEnd Section /o "Awakenings Voice Pack" AWAKEVOICE ;Downloads the mod text file and passes it to the Moddl function. NSISdl::download_quiet $AWAKEVOICEMODTXT $INSTDIR\Installer\awakevoice.txt Push $INSTDIR\Installer\awakevoice.txt Call Moddl WriteRegStr HKLM "${REGKEY}\Components" "Awakenings Voice Pack" 1 SectionEnd SectionGroupEnd SectionGroupEnd Section /o "Homesick" HOMESICK ;Downloads the mod text file and passes it to the Moddl function. NSISdl::download_quiet $HOMESICKMODTXT $INSTDIR\Installer\homesick.txt Push $INSTDIR\Installer\homesick.txt Call Moddl WriteRegStr HKLM "${REGKEY}\Components" "Homesick" 1 SectionEnd Section /o "Transcend" TRANSCEND ;Downloads the mod text file and passes it to the Moddl function. NSISdl::download_quiet $TRANSCENDMODTXT $INSTDIR\Installer\transcend.txt Push $INSTDIR\Installer\transcend.txt Call Moddl WriteRegStr HKLM "${REGKEY}\Components" "Transcend" 1 SectionEnd Section /o "Sync" SYNC ;Downloads the mod text file and passes it to the Moddl function. NSISdl::download_quiet $SYNCMODTXT $INSTDIR\Installer\sync.txt Push $INSTDIR\Installer\sync.txt Call Moddl WriteRegStr HKLM "${REGKEY}\Components" "Sync" 1 SectionEnd SectionGroupEnd ;this runs after everything else. Section -post SECPOST WriteRegStr HKLM "${REGKEY}" Path $INSTDIR WriteUninstaller $INSTDIR\RevertToRetail.exe WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" DisplayName "$(^Name)" WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" DisplayVersion "${VERSION}" WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" Publisher "${COMPANY}" WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" URLInfoAbout "${URL}" WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" DisplayIcon $INSTDIR\RevertToRetail.exe WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" UninstallString $INSTDIR\RevertToRetail.exe WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" NoModify 1 WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" NoRepair 1 NSISdl::download http://www.fsoinstaller.com/files/installer/UpdateFreeSpaceOpen.exe $INSTDIR\UpdateFreeSpaceOpen.exe CreateShortcut "$SMPROGRAMS\Games\FreeSpace 2\Update FreeSpace Open.lnk" $INSTDIR\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 # Uninstaller sections Section /o "un.Advanced VPs" UNVPSADV Delete /REBOOTOK $INSTDIR\mediavps\mp*adveffects.vp Delete /REBOOTOK $INSTDIR\mediavps\mv_adveffects.vp DeleteRegValue HKLM "${REGKEY}\Components" "Advanced VPs" SectionEnd Section /o "un.Core VPs" UNVPSCORE Delete /REBOOTOK $INSTDIR\mediavps\mv*.vp Delete /REBOOTOK $INSTDIR\mediavps\mp*.vp DeleteRegValue HKLM "${REGKEY}\Components" "Core VPs" SectionEnd Section /o "un.Derelict Voice Pack" UNDERELICTVOICE ;Gets the folder that the mod was installed to and removes everything from it. FileOpen $0 $INSTDIR\Installer\derelictvoice.txt r FileRead $0 $foldername FileRead $0 $foldername Delete /REBOOTOK $INSTDIR\$foldername\*1.vp Delete /REBOOTOK $INSTDIR\$foldername\*2.vp Delete /REBOOTOK $INSTDIR\$foldername\*3.vp Delete /REBOOTOK $INSTDIR\$foldername\*4.vp DeleteRegValue HKLM "${REGKEY}\Components" "Derelict Voice Pack" SectionEnd Section /o "un.Derelict Core Files" UNDERELICTCORE ;Gets the folder that the mod was installed to and removes everything from it. FileOpen $0 $INSTDIR\Installer\derelict.txt r FileRead $0 $foldername FileRead $0 $foldername Delete /REBOOTOK $INSTDIR\$foldername\* DeleteRegValue HKLM "${REGKEY}\Components" "Derelict Core Files" SectionEnd Section /o "un.Just Another Day" UNJAD1 ;Gets the folder that the mod was installed to and removes everything from it. FileOpen $0 $INSTDIR\Installer\JAD1.txt r FileRead $0 $foldername FileRead $0 $foldername Delete /REBOOTOK $INSTDIR\$foldername\* DeleteRegValue HKLM "${REGKEY}\Components" "Just Another Day" SectionEnd Section /o "un.Just Another Day 2" UNJAD2 ;Gets the folder that the mod was installed to and removes everything from it. FileOpen $0 $INSTDIR\Installer\JAD2.txt r FileRead $0 $foldername FileRead $0 $foldername Delete /REBOOTOK $INSTDIR\$foldername\* DeleteRegValue HKLM "${REGKEY}\Components" "Just Another Day 2" SectionEnd Section /o "un.FSPort" UNFSPORTCORE ;Gets the folder that the mod was installed to and removes everything from it. FileOpen $0 $INSTDIR\Installer\fsport.txt r FileRead $0 $foldername FileRead $0 $foldername Delete /REBOOTOK $INSTDIR\$foldername\* DeleteRegValue HKLM "${REGKEY}\Components" "FSPort Core Files" DeleteRegValue HKLM "${REGKEY}\Components" "FSPort Extras" SectionEnd Section /o "un.Awakenings" UNAWAKECORE ;Gets the folder that the mod was installed to and removes everything from it. FileOpen $0 $INSTDIR\Installer\awake.txt r FileRead $0 $foldername FileRead $0 $foldername Delete /REBOOTOK $INSTDIR\$foldername\* DeleteRegValue HKLM "${REGKEY}\Components" "Awakenings Core Files" DeleteRegValue HKLM "${REGKEY}\Components" "Awakenings Voice Pack" SectionEnd Section /o "un..MVE Cutscenes" UNCUTSCENE ;Gets the folder that the mod was installed to and removes everything from it. FileOpen $0 $INSTDIR\Installer\cutscene.txt r FileRead $0 $foldername FileRead $0 $foldername Delete /REBOOTOK $INSTDIR\$foldername\* DeleteRegValue HKLM "${REGKEY}\Components" ".MVE Cutscenes" SectionEnd Section /o "un.Homesick" UNHOMESICK ;Gets the folder that the mod was installed to and removes everything from it. FileOpen $0 $INSTDIR\Installer\homesick.txt r FileRead $0 $foldername FileRead $0 $foldername Delete /REBOOTOK $INSTDIR\$foldername\* DeleteRegValue HKLM "${REGKEY}\Components" "Homesick" SectionEnd Section /o "un.Transcend" UNTRANSCEND ;Gets the folder that the mod was installed to and removes everything from it. FileOpen $0 $INSTDIR\Installer\transcend.txt r FileRead $0 $foldername FileRead $0 $foldername Delete /REBOOTOK $INSTDIR\$foldername\* DeleteRegValue HKLM "${REGKEY}\Components" "Transcend" SectionEnd Section /o "un.Sync" UNSYNC ;Gets the folder that the mod was installed to and removes everything from it. FileOpen $0 $INSTDIR\Installer\sync.txt r FileRead $0 $foldername FileRead $0 $foldername Delete /REBOOTOK $INSTDIR\$foldername\* DeleteRegValue HKLM "${REGKEY}\Components" "Sync" SectionEnd Section /o "un.Core Files" UNCORE Delete /REBOOTOK "$SMPROGRAMS\Games\FreeSpace 2\*.lnk" Delete /REBOOTOK $INSTDIR\$EXENAME Delete /REBOOTOK $INSTDIR\$EXEDEBUGNAME Delete /REBOOTOK $INSTDIR\$FREDNAME Delete /REBOOTOK $INSTDIR\$FREDDEBUGNAME Delete /REBOOTOK $INSTDIR\Launcher.exe Delete /REBOOTOK $INSTDIR\launcher6.ini Delete /REBOOTOK $INSTDIR\data\fs2open_pxo.cfg DeleteRegValue HKLM "${REGKEY}\Components" "Core Files" SectionEnd Section -un.post UNSECPOST DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" Delete /REBOOTOK $INSTDIR\UpdateFreeSpaceOpen.exe Delete /REBOOTOK $INSTDIR\reverttoretail.exe DeleteRegValue HKLM "${REGKEY}" Path DeleteRegKey /IfEmpty HKLM "${REGKEY}\Components" DeleteRegKey /IfEmpty HKLM "${REGKEY}" 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 ;Gets the latest VERSION string. CreateDirectory $INSTDIR\Installer NSISdl::download_quiet http://www.fsoinstaller.com/files/installer/version.txt $INSTDIR\Installer\version.txt FileOpen $0 $INSTDIR\Installer\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 installer 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/FreeSpaceOpensetup.exe" Quit current: NSISdl::download_quiet http://www.fsoinstaller.com/files/installer/filenames.txt $INSTDIR\Installer\filenames.txt Call getFileNames ;Creates an array that holds the dependent mods and their dependencies. ${optional->Init} ${optional->WriteList} ${optionallist} FunctionEnd # Uninstaller functions Function un.onInit ReadRegStr $INSTDIR HKLM "${REGKEY}" Path Call un.getFileNames FunctionEnd Function getFileNames Push $0 Push $1 FileOpen $0 $INSTDIR\Installer\filenames.txt r FileRead $0 $1 Push $1 Call TrimNewlines Pop $EXENAME FileRead $0 $1 Push $1 Call TrimNewlines Pop $EXEDEBUGNAME FileRead $0 $1 Push $1 Call TrimNewlines Pop $FREDNAME FileRead $0 $1 Push $1 Call TrimNewlines Pop $FREDDEBUGNAME FileRead $0 $1 Push $1 Call TrimNewlines Pop $EXESHORTCUT FileRead $0 $1 Push $1 Call TrimNewlines Pop $EXEDEBUGSHORTCUT FileRead $0 $1 Push $1 Call TrimNewlines Pop $FREDSHORTCUT FileRead $0 $1 Push $1 Call TrimNewlines Pop $FREDDEBUGSHORTCUT ;locations of mod text files. FileRead $0 $1 Push $1 Call TrimNewlines Pop $DERELICTMODTXT FileRead $0 $1 Push $1 Call TrimNewlines Pop $DERELICTVOICEMODTXT FileRead $0 $1 Push $1 Call TrimNewlines Pop $JAD1MODTXT FileRead $0 $1 Push $1 Call TrimNewlines Pop $JAD2MODTXT FileRead $0 $1 Push $1 Call TrimNewlines Pop $FSPORTMODTXT FileRead $0 $1 Push $1 Call TrimNewlines Pop $FSPORTEXTRAMODTXT FileRead $0 $1 Push $1 Call TrimNewlines Pop $AWAKEMODTXT FileRead $0 $1 Push $1 Call TrimNewlines Pop $AWAKEVOICEMODTXT FileRead $0 $1 Push $1 Call TrimNewlines Pop $CUTSCENEMODTXT FileRead $0 $1 Push $1 Call TrimNewlines Pop $HOMESICKMODTXT FileRead $0 $1 Push $1 Call TrimNewlines Pop $TRANSCENDMODTXT FileRead $0 $1 Push $1 Call TrimNewlines Pop $SYNCMODTXT Pop $1 Pop $0 FunctionEnd Function un.getFileNames Push $0 Push $1 FileOpen $0 $INSTDIR\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 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 ;Probably the most important part of the script. This does most of the real work. Function 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 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 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 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 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 ;This is called whenever a box is checked or unchecked on the Components page. ;This is probably the hardest part of the script to understand. Just warning you. Function .onSelChange ;Preserve variable values. Push $R0 Push $R1 Push $0 Push $1 ;Make sure we know where to stop. Push "END" ;Pushes all the Strings in the Array onto the stack. ${optional->ReadToStack} 0 -1 ;Go through the strings one at a time. loop: ;get the next dependent section and see if we're done. Pop $0 StrCmp $0 "END" End ;get the next dependency for the current dependent section. Pop $1 ;Find out if the dependent section is selected. SectionGetFlags $0 $R0 ;Apply a bitmask to the flags, eliminated the flags we don't care about. IntOp $R0 $R0 & ${SF_SELECTED} ;If the dependent section is selected, goto changesomething StrCmp $R0 ${SF_SELECTED} changesomething ;Otherwise, keep popping values until we find "NEXT" startpop: Pop $1 StrCmp $1 "NEXT" loop Goto startpop ;We need to see if all the dependencies are checked. changesomething: ;See if we're done with this section. StrCmp $1 "NEXT" loop ;Get the flags for this section SectionGetFlags $1 $R0 ;sets the "selected" flag to 1, without touching the others. IntOp $R0 $R0 | ${SF_SELECTED} SectionSetFlags $1 $R0 ;get the next dependency. Pop $1 ;loop. Goto changesomething ;Done checking all the dependent sections. End: ;restore variable values. Pop $1 Pop $0 Pop $R1 Pop $R0 FunctionEnd ; TrimNewlines ; input, top of stack (e.g. whatever$\r$\n) ; output, top of stack (replaces, with e.g. whatever) ; modifies no other variables. Function 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 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