Archive: Uninstall only installed files


Uninstall only installed files
Hello!
Im new to NSIS but i have made som installers.
But now im trying to make so only the installed files gets uninstalled. I found this
But then my uninstallers uninstalls I stops then i trys to delete the folder. For example: then the uninstaller trys to uninstall INSTDIR\direxample the uninstallers stop and does nothing.
whats wrong with the code? If I skip to install that section that dosent work an other one makes it stop :(

Here is the code for one section that dont work:

Section "FGDs" SEC02
${AddItem} "$INSTDIR\fgd"
${SetOutPath} "$INSTDIR\fgd\counter-strike"
${File} "C:\Documents and Settings\Jocke\Skrivbord\Baafens mapp\instaler\Mapping\instalfiler\FGD\fgd\counter-strike\" "cs_expert-tom793c.fgd"
${File} "C:\Documents and Settings\Jocke\Skrivbord\Baafens mapp\instaler\Mapping\instalfiler\FGD\fgd\counter-strike\" "halflife-cs_expert.fgd"
${SetOutPath} "$INSTDIR"
${File} "C:\Documents and Settings\Jocke\Skrivbord\Baafens mapp\instaler\Mapping\instalfiler\" "Readme Baafen VHETOOLS Pack.txt"
SectionEnd

and this is how the uninstall sections looks like:
Quote:

Section -closelogfile
FileClose $UninstLog
SetFileAttributes "$INSTDIR\${UninstLog}" READONLY|SYSTEM|HIDDEN
SectionEnd

Section Uninstall

; Can't uninstall if uninstall log is missing!
IfFileExists "$INSTDIR\${UninstLog}" +3
MessageBox MB_OK|MB_ICONSTOP "$(UninstLogMissing)"
Abort

Push $R0
Push $R1
Push $R2
SetFileAttributes "$INSTDIR\${UninstLog}" NORMAL
FileOpen $UninstLog "$INSTDIR\${UninstLog}" r
StrCpy $R1 0

GetLineCount:
ClearErrors
FileRead $UninstLog $R0
IntOp $R1 $R1 + 1
IfErrors 0 GetLineCount

LoopRead:
FileSeek $UninstLog 0 SET
StrCpy $R2 0
FindLine:
FileRead $UninstLog $R0
IntOp $R2 $R2 + 1
StrCmp $R1 $R2 0 FindLine

StrCpy $R0 $R0 -2
IfFileExists "$R0\*.*" 0 +3
RMDir $R0 #is dir
Goto +3
IfFileExists $R0 0 +2
Delete $R0 #is file

StrCmp $R1 0 LoopDone
IntOp $R1 $R1 - 1
Goto LoopRead
LoopDone:
FileClose $UninstLog
Delete "$INSTDIR\${UninstLog}"
Pop $R2
Pop $R1
Pop $R0

SectionEnd I have attached the script/code so you can take a look at the whole script and see if you can find anny wrong with it.

EDIT: Now I have another problem to. I have 4 things that can be installed with the installer. But I cant uninstall if the first of them is installed. Its says that it cant find the uninstal log. Again see the attached code.

EDIT Agian: Now I saw that then the uninstallers just stop The folder that it trys to remove is removed. Only 2 files is left and that is the uninstaller and the log that the uninstaller uses, How can I fix this?

// Sorry for my bad english I hope you understand

Sorry for dubble post but I cant edit anymore..
Well I have only one thing left.
The uninstaller dosent delete the uninstall.log thats why my uninstaller freeze.

This part is that will delete the uninstall.log but i dont

FileClose $UninstLog
Delete "$INSTDIR\${UninstLog}"
Pop $R2
Pop $R1
Pop $R0

It's a bit odd, but here's a couple things you might look at:
1. $INSTDIR during uninstall is the directory in which the Uninstaller is located, which means that it's NOT necessarily what $INSTIDR was set to during the install. So it could be that you are not even in the right directory (or at least not in the directory you think you are.)

2. The uninstaller by default copies itself to the TEMP folder and runs from there, which would also mean that $INSTDIR could be pointed to your temp directory and not where you intended.

My recommendation would be that during install, you write $INSTDIR either to the registry or save it to a known file location. Then, during uninstall read the value back to you know exactly where to look.

You can also specify $INSTDIR during uninstall by using the _? switch. Refer to the section 3.2.2 of the help files for more info.


_?= sets $INSTDIR. It also stops the uninstaller from copying itself to the temporary directory and running from there. It can be used along with ExecWait to wait for the uninstaller to finish. It must be the last parameter used in the command line and must not contain any quotes, even if the path contains spaces.
But the user who installs the files can choose were to install. So if I sett the $INSTDIR to C:Program/name and if the user installs the program at C:name. What will happen then?

My recommendation would be that during install, you write $INSTDIR either to the registry or save it to a known file location. Then, during uninstall read the value back to you know exactly where to look.
Like I said Im kind of new to NSIS so how can I make this
work?

I think I know what the problem is now. I think the prolem is that uninstall.log is still in use. Then I try to delete it my computer says that uninstall.log is in use.

So FileClose $UninstLog dosent do what i should do..
I hope someone can answear how to solve this.