Archive: Path Manipulation


Path Manipulation
I'm using these functions for path manipulation
(thanks, KiCHiK :-)):

I would like to add a function that will first check if a specific
string is already defined in PATH, so it wouldn't add it again
(the string I add is always: "%FOO%\bin").

Can anyone help me on how to do that?


And when I use un.RemoveFromPath to remove a string from PATH, it
leaves the semi-colon that it added in front of it in the PATH string.
Is that done on purpose and is it not such a good idea to remove
that one?

Thanks!


The function checks if the directory is already there and doesn't add it if it is. If you want to check yourself anyway, simply read %PATH% using ReadEnvStr and only call the function if it's not there.

The semicolon is not on purpose, but it doesn't really hurt. It's just an empty path that will be ignored. There is also this issue which I should finally fix sometime...


Fixed.


Thanks for your fix!


One more question regarding the path manipulation:

I add my path to PATH like so:

Push "$INSTDIR\bin"
Call AddToPath


And I remove it in the uninstaller like so:


Push "$INSTDIR\bin"
Call un.RemoveFromPath


If I run the installer twice (with the same INSTDIR) it will add
the same path to PATH twice.
From how I understood your answer it shouldn't do that, should it?


I was wrong, it doesn't check if the path is already there. You should check for it yourself using ReadEnvStr and the StrStr function.


How do I get the PATH string for Windows 9x?


Use ReadEnvStr.


Hi,

I'm having problems with checking PATH for a string.
I just can't find the mistake, maybe someone can
help me?

The problem is when adding the string to PATH (AddToPath),
I first would like to check if the string is already there.
But the string is never found (StrStr always returns
-1), although in there.

I have attached my modified PathManipulation script.


Thanks,

Barbara


There is an example of checking on the archive page now. Try it and let me know if it works for you.


Thanks for the example, with your code I got it to work!

I had another problem then which was that I'm writing and testing
the installer without the actually data (those commands are added
through scripts that I don't have access to yet) and thus
$INSTDIR\bin was not created through my test installation.

If you then call:
GetFullPathName /SHORT $1 $1

(where $1 is "$INSTDIR\bin" and the path doesn't exist, the error
flag is set and $1 is empty.

For completenes, this is the code that works for me now:




ReadEnvStr $0 path
Push "$0;"
Push "$INSTDIR\bin;"
Call StrStr
Pop $2
IntCmp $2 -1 addPath addPath
StrCpy $1 "$INSTDIR\bin"
GetFullPathName /SHORT $1 $1
MessageBox MB_OK $1
ReadEnvStr $0 path
Push "$0;"
Push "$1;"
Call StrStr
Pop $2
IntCmp $2 -1 addPath addPath dontAdd


I have one remaining problem:

I'm testing for a string in PATH as posted abough.

If INSTDIR consists of spaces (such as "MyApp 2"), the
string is not detected and added to PATH again.

What can I do to solve this?


Use the updated functions, they check it for, spaces or no spaces.


I have now updated the functions (from your archive page).

If the installdir has spaces it works OK now.


On uninstallation it messes up the PATH string though:

The first entry on my box was:
C:\Program Files\Microsoft Visual ...
and after I uninstalled my SW my path was still in there but
the start of the string was shortened to:
\Microsoft Visual ...


Fixed, thanks.


Where is the archive page? I would like to download the functions to manipulate the path variable.


The archive has been replaced by the wiki:

http://nsis.sourceforge.net/Developer_Center

Here are some links that might answer your question:

http://nsis.sourceforge.net/Path_Manipulation

http://nsis.sourceforge.net/Path_man...on_in_run-time