Archive: How to correctly uninstall a PATH variable and value?


How to correctly uninstall a PATH variable and value?
Hello,

I am trying to apply the path manipulation function but am only partially successful at getting it right.
Path Manipulation
http://nsis.sourceforge.net/archive/....php?pageid=91

I can write a single path or several without a problem. Here's the kicker. I noticed upon updating a test installer, the function would *not* check to see if the path already exist. It will simply append the path and it will keep doing it. e.g. If the following paths are defined during first installation...

PATH: C:\alpha;C:\beta
These will simply get appended with the same path if I install again or update the installer...
PATH: C:\alpha;C:\beta;C:\alpha;C:\beta
Writing paths work like a charm but there is no check for duplicate paths. Is this how it is supposed to work?

Another kicker is this. I believe I have the uninstall call correct. First I'll show my install path manipulation call, then my uninstall...

Installation
Section "alpha"
Push "$INSTDIR\alpha"
Call AddToPath
SectionEnd

Deinstallation
Section "Uninstall"
Push "$INSTDIR\alpha"
Call un.RemoveFromPath
SectionEnd


Here's the catch with the above code. If a path variable does not exist on my system it is created "sweet". Upon Deinstallation the path value is removed but the path variable stays. In other words I have a variable "path" with no value. Is this ok?

Remember I mentioned how an update will append the same value even though it might already exist? If e.g. C:\alpha;C:\alpha;C:\alpha; already exist but during uninstall I only call one instance of remove alpha then only one instance of the path is removed. Here is a scenario. If a user applies 3 updates, the paths keep getting appended. If the user decides to uninstall, 2 paths are left behind.

The really big quirks with the function as a whole is...
1. It doesn't check to see if a path already exist. It will append the path/s regardless.
2. If the path variable doesn't already exist it will be created along with it's value *but* deinstallation will not remove the blank path variable.
3. Uninstallation will only remove one instance and not all instances of the same path.

I would really like to apply this function but would like to learn a little more about what's going on. Can someone help me apply this function correctly?

I am WinXP.

You have to check for the existence of your directory in the path variable yourself:

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

If you want to delete the key if it's empty, read its value, compare to "" and delete if it is "".


Hello Kichik,

Will you update the main script with the bit of a script you've given me here? Also, if the script in the archive is going to stay as is, would you mind if I ask why? I only ask because it seems it might already do as intended and without further modification to it.

I thank you very much for your help and feedback whenever you have the time. I am curious if the script at the archive is going to stay as is or if it will be enhanced with the bit you've provided here.


Thank you again Kichik


I have added a note about manual checking but the script itself is going to stay as is. I had a reason for not putting the check in it back when I wrote it, but I can't remember it now... :(

You're welcome.


Thank you Kichik, you're always much help and it is always appreciated.


Hello Kichik,

Sorry for the late breaking news. I am having trouble applying the loop to check if the path already exist. The compiler argued about "StrStr" so I've searched the archives, found the nsh and included it. Now it's choking over "addpath"...

I cannot find the label "addpath" anywhere within nearly 1500 lines of code. I've searched both the forums and the archives since the last date I posted on this thread and since, I've put it to side. I am back hacking at the script and am stumped with addpath. Scarier is, right after addpath is dontAdd... Another label no where to be found.

I found this thread which mentions something about an example but I cannot find one. On the NSIS archive page I find just the script but no example. Where does the loop check go? Where do I add the labels?

Thank you for your time. It is greatly appreciated.


You should use the StrStr function that comes with the path functions, it's not the same as the one in the documentation or the one in the archive. addPath and dontAdd are two labels you should define on your own. In addPath you should call AddPath and in dontPath you shouldn't. addPath will be jumped to if the directory is not already in the path and dontAdd will be called if it is.

I'll update it to be a bit more specific...


Hello Kichik,

I've did exactly as you said and started adding labels before I made the post. Trouble is I am failing at getting it just right. I added "addpath:" to the very top of the little snippet and the compiler complained about dontadd. When I tried placing dontAdd at the very bottom of the snippet hoping it would exit, it took the installation into a loop. I had to kill it.

I've downloaded and have included StrStr from the archives page. Do I need this include or not? Is this the StrStr the little snippet is referring too? I've included it but am still faced with the problem of not being able to get it to loop and see if the path already exist.

I think to be honest, it would help many if you simply added such functionality direct into your script. I only say this because what good is the same path found twice. It only needs to be found once.

Thank you Kichik, I am a little lost with this but hope you can help. Thank you again.


I have made AddToPath check for the existence of the directory in the path variable before adding and made both functions set the reboot flag when needed. I haven't got to test it too much so please let me know if there are any problems with the new changes.


Hello Kichik,

So far so good, this is a worthy script right out of beta :) I've tested it with one install path so far (4 installs) and it works perfect.

I will let you know of any odd behavior if adding any more paths to the script happen to make a conflict. This is truly appreciated and I am sure others will immediately find it as invaluable.

Thank you very much Kichik


Hello Kichik,

Quick update, I added several paths and tested re-installation several times. Everything is working great. Thank you again!

I am on XP, latest CVS build.


Great, thanks for helping me test.


Hello Kichik,

Just a side note, in order for a path to be registered, it must already exist. If the path does not exist it will not be added.

During testing I noticed some paths were not being registered. Took me a while but that's the culprit. So dev's should know not to register a path before it is actually created on the target system.

Just a side note :)


Path removal didn't work on NT. Updated.


Hello Kichik,

Thanks for the update, I appreciate it!