Two installations in one installer: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
m (Updated by user: Afrow UK.) |
m (Updated by user: Afrow UK.) |
||
Line 197: | Line 197: | ||
Loop: | Loop: | ||
IntOp $R0 $R0 + 1 | IntOp $R0 $R0 + 1 | ||
ReadINIStr "$R1" "$PLUGINSDIR\sections.ini Sections $R0 # Get sec flags | ReadINIStr "$R1" "$PLUGINSDIR\sections.ini" Sections $R0 # Get sec flags | ||
SectionSetFlags $R0 $R1 # Re-set flags for sec | SectionSetFlags $R0 $R1 # Re-set flags for sec | ||
StrCmp $R0 ${Sec_LAST} 0 Loop | StrCmp $R0 ${Sec_LAST} 0 Loop |
Revision as of 06:42, 27 April 2005
Description
This scripts shows how we can install two programs with one installer, where each program has its own Directory and InstFiles page. 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" ##=========================================================================== ## Install dir's ##=========================================================================== !define PROG1_InstDir "C:\PROG1" !define PROG2_InstDir "C:\PROG2" ##=========================================================================== ## Start sections ##=========================================================================== ## Sections Group 1 SectionGroup "Program #1" PROG1 Section "Main" SEC1 SectionIn RO ## Main files to install here messagebox mb_ok sec1 SectionEnd Section "Other" SEC2 ## Other files to install here messagebox mb_ok sec2 SectionEnd SectionGroupEnd ## Sections Group 2 SectionGroup "Program #2" PROG2 Section "Main" SEC3 ## Main files to install here messagebox mb_ok sec3 SectionEnd Section "Other" SEC4 ## Other files to install here messagebox mb_ok sec4 SectionEnd ## This must be the last section Section -dummy SEC_LAST SectionEnd SectionGroupEnd ##=========================================================================== ## Please don't modify below here unless you're a NSIS 'wiz-kid' ##=========================================================================== ## Create $PLUGINSDIR Function .onInit InitPluginsDir FunctionEnd ## 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 SectionGetFlags $R0 $R1 # Get section flags WriteINIStr "$PLUGINSDIR\sections.ini" Sections $R0 $R1 # Save state !insertmacro UnselectSection $R0 # Then unselect it StrCmp $R0 ${Sec_LAST} 0 Loop # Set current $INSTDIR to PROG1_InstDir define StrCpy $INSTDIR "${PROG1_InstDir}" 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 StrCpy $R1 ${PROG2} # Group 2 start Loop2: IntOp $R1 $R1 + 1 SectionGetFlags $R1 $R0 IntOp $R0 $R0 & ${SF_SELECTED} StrCmp $R0 ${SF_SELECTED} NoSkip StrCmp $R1 ${Sec_LAST} 0 Loop2 Pop $R1 Pop $R0 Abort NoSkip: # Set current $INSTDIR to PROG2_InstDir define StrCpy $INSTDIR "${PROG2_InstDir}" 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! Loop: IntOp $R0 $R0 + 1 ReadINIStr "$R1" "$PLUGINSDIR\sections.ini" Sections $R0 # Get sec flags SectionSetFlags $R0 $R1 # Re-set flags for sec StrCmp $R0 ${Sec_LAST} 0 Loop Pop $R1 Pop $R0 FunctionEnd ## Here we are deleting the temp INI file at the end of installation Function DeleteSectionsINI Delete "$PLUGINSDIR\Sections.ini" FlushINI "$PLUGINSDIR\Sections.ini" FunctionEnd
If you need some help, feel free to PM me (Afrow UK) via the NSIS forums.
-Stu
Page author: Afrow UK