Two installations in one installer: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
m (Wikipedia python library) |
m (Updated author and download links, and changed format of some pages.) |
||
Line 176: | Line 176: | ||
-Stu | -Stu | ||
Page author: Afrow UK | Page author: [[User:Afrow UK|Afrow UK]] |
Revision as of 12:45, 23 April 2005
Description
This script shows how we can install two programs with one installer, where each program has its own Directory and InstFiles pages. Obviously we still have the single Components page though, as if we chose to have two then we'd might as well make two bloody installer exe's!
The Script
Here's the code. You can compile this script straight off. You should put some files in the Sections first though, otherwise you can't really see it 'working'...
Name "Multiple InstFiles" OutFile "multi-install.exe" !include MUI.nsh !include Sections.nsh ##=========================================================================== ## Modern UI Pages ##=========================================================================== !insertmacro MUI_PAGE_WELCOME !define MUI_PAGE_CUSTOMFUNCTION_PRE SelectFilesBCheck !insertmacro MUI_PAGE_COMPONENTS ## This is the title on the first Directory page !define MUI_DIRECTORYPAGE_TEXT_TOP "Setup will install Program #1 in the \ following folder." !define MUI_PAGE_CUSTOMFUNCTION_PRE SelectFilesA !insertmacro MUI_PAGE_DIRECTORY !insertmacro MUI_PAGE_INSTFILES ## This is the title on the second Directory page !define MUI_DIRECTORYPAGE_TEXT_TOP "Setup will install Program #2 in the \ following folder." !define MUI_PAGE_CUSTOMFUNCTION_PRE SelectFilesB !insertmacro MUI_PAGE_DIRECTORY !define MUI_PAGE_CUSTOMFUNCTION_LEAVE DeleteSectionsINI !insertmacro MUI_PAGE_INSTFILES !insertmacro MUI_PAGE_FINISH !insertmacro MUI_LANGUAGE "English" ##=========================================================================== ## Start sections ##=========================================================================== ## Sections Group 1 SectionGroup "Program #1" PROG1 Section "Main" SEC1 SectionIn RO ## Main files to install here SectionEnd Section "Other" SEC2 ## Other files to install here SectionEnd SectionGroupEnd ## Sections Group 2 SectionGroup "Program #2" PROG2 Section "Main" SEC3 SectionIn RO ## Main files to install here SectionEnd Section "Other" SEC4 ## Other files to install here SectionEnd SectionGroupEnd ##=========================================================================== ## Please don't modify below here unless you're a NSIS 'wiz-kid' ##=========================================================================== ## If user goes back to this page from 1st Directory page ## we need to put the sections back to how they were before Var IfBack Function SelectFilesBCheck StrCmp $IfBack 1 0 NoCheck Call ResetFilesB NoCheck: FunctionEnd ## Here we are selecting first sections to install ## by unselecting all the others! Function SelectFilesA # If user clicks Back now, we will know to reselect Group 2's sections for # Components page StrCpy $IfBack 1 # We need to save the state of the Group 2 Sections # for the next InstFiles page Push $R0 Push $R1 StrCpy $R0 ${PROG2} # Group 2 start Loop: IntOp $R0 $R0 + 1 ClearErrors SectionGetFlags $R0 $R1 # Get section flags IfErrors Done WriteINIStr "$TEMP\sections.ini" "Sections" "$R0" "$R1" # Save state !insertmacro UnselectSection $R0 # Then unselect it Goto Loop # Go to next section(s) Done: Pop $R1 Pop $R0 FunctionEnd ## Here we need to unselect all Group 1 sections ## and then re-select those in Group 2 (that the user had selected on ## Components page) Function SelectFilesB Push $R0 Push $R1 StrCpy $R0 1 # Group 1 start StrCpy $R1 ${PROG2} # Group 1 finish Loop1: !insertmacro UnselectSection $R0 # Unselect section StrCmp $R0 $R1 Done1 IntOp $R0 $R0 + 1 Goto Loop1 # Go to next section(s) Done1: Call ResetFilesB Pop $R1 Pop $R0 FunctionEnd ## This will set all sections to how they were on the components page ## originally Function ResetFilesB Push $R0 Push $R1 StrCpy $R0 ${PROG2} # Group 2 starts at SEC3! Loop2: IntOp $R0 $R0 + 1 ClearErrors ReadINIStr "$R1" "$TEMP\sections.ini" "Sections" "$R0" # Get section flags (from INI) IfErrors Done2 SectionSetFlags $R0 $R1 # Re-set flags for this section Goto Loop2 # Go to next section(s) Done2: Pop $R1 Pop $R0 FunctionEnd ## Here we are deleting the temp INI file at the end of installation Function DeleteSectionsINI Delete "$TEMP\Sections.ini" FunctionEnd
If you need some help, feel free to PM me (Afrow UK) via the NSIS forums.
-Stu
Page author: Afrow UK