Archive: Alternate install directories


Alternate install directories
I've been trying this for a few days now with no success.
Basically I want a install directory page that gives an option to install in one of two directories. I have the page display fine using Installoptions. However I have no idea on how to write the script that will determine which of the directories has been selected and which directory to therefore install to. Any help would be appreciated.


I'd have two radio buttons, one by each directory box.

Use ReadINIStr to find the State of the radio buttons. If radio button #1 State is 0, then radio button #2 must be selected, else its State will be 1.

-Stu


Afrow UK could you please provide more detail regarding ReadINIStr and how then to use the the state of the radio buttons to install in the chosen directory. I do have two radio buttons for the directories but the main problem is how to write the script. A brief example would definately help.


If you use Modern UI, instead of using ReadINIStr you should use !insertmacro MUI_INSTALLOPTIONS_READ.

An example of reading an INI file:

ReadINIStr $0 "MyINIFile.ini" "Field 3" "State"

Thanks Afrow UK and deguix. I'm now further along but still uncertain about the next part. Now that I can read the 'state' what do I then add in the script that basically says ok if that's what has been selected now install these files to the selected directory ? I hope I'm being clear about what I'm asking.


I still can't figure it out. Can anyone please help with a brief example ?


I have a similar question, so I'll post it in this thread instead of starting a new one:


Instead of using radio buttons/chechboxes, I use a droplist in my custom MUI page.

The listbox looks like this in the .ini:


[Settings]
NumFields=1

[Field 1]
Type=Droplist
ListItems=U.S.(english)|UK(english)|French|German|Italian|Spanish
State=U.S.(english)
Left=40
Right=-40
Top=50
Bottom=70


Now - in the NSIS script, I have successfully made my custom page with the droplist appear before the Welcome page. So when I open the compiled installer now, the language select listbox comes up first.

In the NSIS script, I have this so far:


Function InstallLanguage ;"InstallLanguage" defined with Page command
!insertmacro MUI_HEADER_TEXT "$(TEXT_IO_TITLE)" "$(TEXT_IO_SUBTITLE)"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "ioDX-IW.ini"
!insertmacro MUI_INSTALLOPTIONS_READ $R0 "ioDX-IW.ini" "Field 1" "U.S.(english)"
!insertmacro MUI_INSTALLOPTIONS_READ $R1 "ioDX-IW.ini" "Field 1" "UK(english)"
!insertmacro MUI_INSTALLOPTIONS_READ $R2 "ioDX-IW.ini" "Field 1" "French"
!insertmacro MUI_INSTALLOPTIONS_READ $R3 "ioDX-IW.ini" "Field 1" "German"
!insertmacro MUI_INSTALLOPTIONS_READ $R4 "ioDX-IW.ini" "Field 1" "Italian"
!insertmacro MUI_INSTALLOPTIONS_READ $R5 "ioDX-IW.ini" "Field 1" "Spanish"
FunctionEnd


Now, I want to continue that function with code that will let me change the install directory according to what the user selected.

To do that, I would like to put the user-selection into a common variable, so that ${USER_SELECTION} for instance is the installdir for the language the user selected.

It's the same install dir in my case, but in the install dir path there is one folder for each language, and I'm supposed to extract files to the proper language folder based on the language the user chose.

Is that possible, and if so how do I do it?

Would this code do what I want(mentioned above)?


Function InstallLanguage ;"InstallLanguage" defined with Page command
!insertmacro MUI_HEADER_TEXT "$(TEXT_IO_TITLE)" "$(TEXT_IO_SUBTITLE)"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "ioDX-IW.ini"
!insertmacro MUI_INSTALLOPTIONS_READ $R0 "ioDX-IW.ini" "Field 1" "U.S.(english)"
!insertmacro MUI_INSTALLOPTIONS_READ $R0 "ioDX-IW.ini" "Field 1" "UK(english)"
!insertmacro MUI_INSTALLOPTIONS_READ $R0 "ioDX-IW.ini" "Field 1" "French"
!insertmacro MUI_INSTALLOPTIONS_READ $R0 "ioDX-IW.ini" "Field 1" "German"
!insertmacro MUI_INSTALLOPTIONS_READ $R0 "ioDX-IW.ini" "Field 1" "Italian"
!insertmacro MUI_INSTALLOPTIONS_READ $R0 "ioDX-IW.ini" "Field 1" "Spanish"

${if} $R0 == 1
StrCpy $INST_DIR "content\examples\files\"
${endif}

${if} $R0 == 1
StrCpy $INST_DIR "content\examples\files\english"
${endif}

${if} $R0 == 1
StrCpy $INST_DIR "content\examples\files\french"
${endif}

${if} $R0 == 1
StrCpy $INST_DIR "content\examples\files\german"
${endif}

${if} $R0 == 1
StrCpy $INST_DIR "content\examples\files\italian"
${endif}

${if} $R0 == 1
StrCpy $INST_DIR "content\examples\files\spanish"
${endif}
FunctionEnd


-I would then put $INST_DIR in the file commands, like so:

"$INSTDIR\$INST_DIR\example.bmp"

(or how ever I'm supposed to write the variable into the path).

Would that work?



-Or, in the function above, would I have to write

${if} $R0 == U.S.(english)
StrCpy $INST_DIR "content\examples\files\"
${endif}

and so on?

In other words, the listbox state name instead of 1?

Well - that didn't work.

Tried the last thing there, with putting the listbox names instead of 1.

The script compiles without errors or warnings, but if I for instance choose French in the listbox, the installer just puts everything into $INSTDIR, instead of "$INSTDIR\$INST_DIR\".

Can someone please help me out here?
I really need to get this working. :(

Again - I need to get the User input from the listbox and use it to make a variable I can use as part of the install path, so that each language can have it's own path.

Thanks in advance.


You're reading the states of all of the radio buttons into the same variable. Each time, you override the value before you check it. You should either read them into different variables or check right after you read.


Thanks for the reply. :)

But should I use
${if} $R0 == 1

, or

${if} $R0 == U.S.(english)


(in other words '1' instead of the droplist name)?


[EDIT]-and it's a droplist, not radiobuttons.[/EDIT]


Oh, sorry. You're using a droplist, not radio buttons. The code should look something like this:

!insertmacro MUI_INSTALLOPTIONS_READ $R0 "ioDX-IW.ini" "Field 1" "STATE"
${if} $R0 == "U.S.(english)"
${elseif} $R0 == "French"
${elseif} $R0 == "German"
${endif}
The selected item will be the value of STATE.

Oh - thanks. :)

I'll try to work from that. :)


Haven't tested what you gave me yet, but I have another question:

How do I skip a Custom Page?

-My installer can be re-opened, and when the User re-opens it, it will skip past the Welcome page, License page, and Directory page.

This all works already.

But when I try to use the same function for the Custom Page, it doesn't affect it. Even though the mentioned pages are skipped, the Custom Page still appears first.

Here's how it looks now:


!define MUI_PAGE_CUSTOMFUNCTION_PRE SkipPages
Page custom InstallLanguage ;Custom page
!insertmacro MUI_PAGE_WELCOME
!define MUI_PAGE_CUSTOMFUNCTION_PRE SkipPages
!insertmacro MUI_PAGE_LICENSE "InternalReadme.rtf"
!define MUI_PAGE_CUSTOMFUNCTION_PRE SkipPages
!insertmacro MUI_PAGE_DIRECTORY
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE checksections
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH


This does not give any errors or warnings when compiling, and it works as intended with the "normal" pages, but doesn't do anything to the Custom Page.

If I put another !define MUI_PAGE_CUSTOMFUNCTION_PRE SkipPages above the !insertmacro MUI_PAGE_WELCOME, then I do get an error; that it's already defined.


So how do I skip a Custom Page?

MUI_PAGE_CUSTOMFUNCTION_PRE only works for MUI pages. Since you create the page yourself, you should skip it yourself. You can skip it by simply not calling InstallOptions in the page creation function (InstallLanguage).


OK, thanks - I think I know how.

Oh, and the code you gave me above worked exactly as I wanted(with some adaptations), so thank you again. :)