Two installations in one installer: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
m (Updated author and download links, and changed format of some pages.) |
m (Updated by user: Afrow UK.) |
||
Line 1: | Line 1: | ||
== Description == | == Description == | ||
This | 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 == | == 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'... | 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'... | ||
<highlight-nsis>Name "Multiple InstFiles" | <highlight-nsis> | ||
Name "Multiple InstFiles" | |||
OutFile "multi-install.exe" | OutFile "multi-install.exe" | ||
Line 21: | Line 22: | ||
## This is the title on the first Directory page | ## This is the title on the first Directory page | ||
!define MUI_DIRECTORYPAGE_TEXT_TOP "Setup will install Program #1 in the \ | !define MUI_DIRECTORYPAGE_TEXT_TOP "Setup will install Program #1 in the \ | ||
following folder." | following folder..." | ||
!define MUI_PAGE_CUSTOMFUNCTION_PRE SelectFilesA | !define MUI_PAGE_CUSTOMFUNCTION_PRE SelectFilesA | ||
Line 29: | Line 30: | ||
## This is the title on the second Directory page | ## This is the title on the second Directory page | ||
!define MUI_DIRECTORYPAGE_TEXT_TOP "Setup will install Program #2 in the \ | !define MUI_DIRECTORYPAGE_TEXT_TOP "Setup will install Program #2 in the \ | ||
following folder." | following folder..." | ||
!define MUI_PAGE_CUSTOMFUNCTION_PRE SelectFilesB | !define MUI_PAGE_CUSTOMFUNCTION_PRE SelectFilesB | ||
Line 39: | Line 40: | ||
!insertmacro MUI_LANGUAGE "English" | !insertmacro MUI_LANGUAGE "English" | ||
##=========================================================================== | |||
## Install dir's | |||
##=========================================================================== | |||
!define PROG1_InstDir "C:\PROG1" | |||
!define PROG2_InstDir "C:\PROG2" | |||
##=========================================================================== | ##=========================================================================== | ||
Line 50: | Line 58: | ||
SectionIn RO | SectionIn RO | ||
## Main files to install here | ## Main files to install here | ||
messagebox mb_ok sec1 | |||
SectionEnd | SectionEnd | ||
Line 55: | Line 65: | ||
Section "Other" SEC2 | Section "Other" SEC2 | ||
## Other files to install here | ## Other files to install here | ||
messagebox mb_ok sec2 | |||
SectionEnd | SectionEnd | ||
Line 64: | Line 76: | ||
Section "Main" SEC3 | Section "Main" SEC3 | ||
## Main files to install here | ## Main files to install here | ||
messagebox mb_ok sec3 | |||
SectionEnd | SectionEnd | ||
Line 72: | Line 85: | ||
## Other files to install here | ## Other files to install here | ||
messagebox mb_ok sec4 | |||
SectionEnd | |||
## This must be the last section | |||
Section -dummy SEC_LAST | |||
SectionEnd | SectionEnd | ||
Line 80: | Line 99: | ||
## Please don't modify below here unless you're a NSIS 'wiz-kid' | ## 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 | ## If user goes back to this page from 1st Directory page | ||
Line 107: | Line 131: | ||
Loop: | Loop: | ||
IntOp $R0 $R0 + 1 | IntOp $R0 $R0 + 1 | ||
SectionGetFlags $R0 $R1 # Get section flags | SectionGetFlags $R0 $R1 # Get section flags | ||
WriteINIStr "$PLUGINSDIR\sections.ini" Sections $R0 $R1 # Save state | |||
WriteINIStr "$ | |||
!insertmacro UnselectSection $R0 # Then unselect it | !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 $R1 | ||
Line 139: | Line 163: | ||
Call ResetFilesB | 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 $R1 | ||
Line 154: | Line 195: | ||
StrCpy $R0 ${PROG2} # Group 2 starts at SEC3! | StrCpy $R0 ${PROG2} # Group 2 starts at SEC3! | ||
Loop: | |||
IntOp $R0 $R0 + 1 | IntOp $R0 $R0 + 1 | ||
ReadINIStr "$R1" "$PLUGINSDIR\sections.ini Sections $R0 # Get sec flags | |||
ReadINIStr "$R1" "$ | SectionSetFlags $R0 $R1 # Re-set flags for sec | ||
StrCmp $R0 ${Sec_LAST} 0 Loop | |||
SectionSetFlags $R0 $R1 # Re-set flags for | |||
Pop $R1 | Pop $R1 | ||
Line 169: | Line 207: | ||
## Here we are deleting the temp INI file at the end of installation | ## Here we are deleting the temp INI file at the end of installation | ||
Function DeleteSectionsINI | Function DeleteSectionsINI | ||
Delete "$ | Delete "$PLUGINSDIR\Sections.ini" | ||
FunctionEnd</highlight-nsis> | FlushINI "$PLUGINSDIR\Sections.ini" | ||
FunctionEnd | |||
</highlight-nsis> | |||
If you need some help, feel free to PM me (Afrow UK) via the NSIS forums. | If you need some help, feel free to PM me (Afrow UK) via the NSIS forums. |
Revision as of 06:40, 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