Archive: User variables in file paths during file extraction


User variables in file paths during file extraction
Hello all,
OK, I searched everywhere but could not find any answers to my question below (perhaps wrong keywords?).
I am trying to have my installer modify file paths during the file extraction based on the user input. Very likely I am doing something wrong because NSIS badly complains at me.
Here is an example:

Say, I would like different files to be extracted depending on the language that the user chooses from a dropdown list. I store their choice in a user variable $MyLang, like so

var $MyLang

In the "install" section, I would like to do this:
IfFileExists "..\SomePath\$MyLang\SomeFile" 0 +3
file "..\SomePath\$MyLang\SomeFile"
goto SomewhereElse
MessageBox MB_OK "No supporting files for your particular language found ,defaulting to English."
file "..\SomePath\SomeFileInEnglish"

It seems that both IFFileExists and File commands ignore my $MyLang variable. In the case of File instruction NSIS complains that "..\SomePath\$MyLang\SomeFile" cannot be found.

Any ideas on how I can solve this problem?
I am suspecting that NSIS doesn't like my variables because they are filled in at runtime, but there has to be some way around this.

Thanks for any help.
Regards,
Vic


You may be right about NSIS not liking the variables because they are filled at runtime. Have you considered writing a macro or function to extract the files for each language you are supporting? You can still take the input from the user and then put the MyLang variable into a switch or a series of if else if, and then NSIS only extract the files according to the selected language. It may make your installer bigger than you wanted, and there is probably a better solution out there, but it should work.


I guess that may work, but seems a bit inefficient
Thanks for your suggestion. I guess, this would my last choice as I wanted all the matching happen automatically. In my installer tree I have folders that are named according to the language abbreviations and it would be easier if the extraction was dependant on one variable rather than on the set of if-else statements. This means that I would not have to modify the installer every time a new language (think folder) is added.
Any more cool ideas out there? :)
Thanks.


I'm not sure why the IfFileExisits would ignore your variable.

But I was under the impression that File was used to add files in at compile time and then extract them during installation.
So it makes sense that a variable cannot be used here.

How about, adding the extra files you want to distribute along with the installation.exe, not compiled into the exe but in a seperate folder, then use something like:
CopyFiles "$EXEDIR\SomePath\$MyLang\" "$INSTDIR"
(This will copy all the files in the $MyLang directory to the installation directory.)
CopyFiles "$EXEDIR\SomePath\$MyLang\SomeFile" "$INSTDIR"
(or this will only copy one file)


OK thanks, I will give this a thought and a shot! :)