Archive: Conditional nsisconf.nsh script settings


Conditional nsisconf.nsh script settings
Hey guys and gals, New to the forum but have been using NSIS for some time but have a new requirement that has me pulling my hair out (what little I have left).

I have about 50 install scripts that I need to change the default install path in. Now all of them use a define in the nsisconf.nsh file to set the default root install path for all applications.

!Define DEFAULT_APP_PATH "C:\Program Files\Company\....."

The company was sold to a new parent company and now the default root isntall path would be.

!Define DEFAULT_APP_PATH "C:\Program Files\NewCompany\....."

The problem is that when new installs are ran they want the Old Default path used if the location had previous versions installed and the new path when the application was never installed. So what I am attempting to do is set a conditional check in the nsisconf.nsh file to check for the default root path. However, all my efforts have resulted in a compile error that the check is not valid outside of a section. How can I do something similar to the following within the nsisconf.nsh file


${DirState} "D:\Program Files\Company\....." $0
StrCmp $0 "-1" NoAppsInstalled 0
!define DEFAULT_APP_PATH "C:\Program Files\Company\....."
Goto DefaultPathSet
NoAppsInstalled:
!define DEFAULT_APP_PATH "C:\Program Files\NewCompany\....."
DefaultPathSet:

Any Ideas?
I have tried using functions and macros as well but still get the same error with a function the Call Function name generates the error.

You're confusing run time with compile time. !define is compile time. StrCmp/Goto is run time.

If your old installers saved the install directory in the registry you can get it using InstallDirRegKey. If not then you will have to add code to set $INSTDIR accordingly at run time.

Also is nsisconf.nsh the root file you are talking about? You shouldn't really use that and create your own nsh instead and !include it when necessary.

Edit: And why use DirState to check if a directory exists? Use IfFileExists [path]\*.* (or ${If} ${FileExists} [path]\*.*). Note *.* is valid because . and .. are valid children.

Stu


The code block (in the Inital post) was just to indicate what I am trying to accomlish in an easy to understand form.

And Yes, nsisconf.nsh is the root file, The company I work for modified it as a base for all installer setting company !defines thus creating my problem. They did this to ensure that all of the installers created would use specific settings.

But part of the issue is that I need to set the !Define Default_App_Path value which is compile time in some manner that would allow it to be dynamic at run time.
As I did not write all of the installers that I need to recompile I was hoping (probably in vain) that I could find a solution that would prevent my having to edit over 50 install scripts and only make one change.
If that is not possible then I may have to just write a Macro and include it in all of the installers. But thought I would try here to see if someone had a better approach that will keep me from needing to edit 50+ files.


Originally posted by Roger_wgnr
I need to set the !Define Default_App_Path value which is compile time in some manner that would allow it to be dynamic at run time.
This is not possible, unless you !define it to a $variable. In any case you'll need to edit all 50 scripts to do a registry search in either .onInit or a pre-Directory function.

I was afraid of that. Well I will see what I can cook up.
I was wondering if it is possible to use a Relative Path in a Define and if so is it related to the NSIS directory of the directory of the nsi script?
For example I have the following structure

Program
Source
Installer
Resouces

In the installer directory is the nsi and nsh scripts for the program but I need to load say an icon and some text files that are in the resources directory.

could I do something like this
!Define Resources '\..\Resources\'

This is because the installers are part of the SVN repositorys and when developers pull the code and installers each one tends to use a different local path for the root of the repostiory structure. like for my example
developer 1 uses C:\SVN\Program
Developer 2 uses C:\SVN_Repository\Program
Developer 3 uses D:\MYSVN\Program
and so on.

Originally posted by Roger_wgnr
I was wondering if it is possible to use a Relative Path in a Define and if so is it related to the NSIS directory of the directory of the nsi script?
Yes, this is possible, and No, it is related to NOTHING. A define is simply a way to replace "a long sentence that you don't want to type ten times" with ${AShortVersion}. During compilation, every ${define} is replaced, word for word, with what it was defined as. Therefore there is NO interpretation of its contents, at all. It's just replacing text (or script code, to be exact).

Compile time paths are relative to the script being compiled.

Stu