- NSIS Discussion
- RMDir Bug?
Archive: RMDir Bug?
hungryOrb
10th April 2008 17:04 UTC
RMDir Bug?
hi,
erm when using:
RMDir /r "$INSTDIR"
the uninstaller starts deleting the Program Files folder, even if the app is not installed there. My small experience suggests to me that $INSTDIR does not carry the correct path to the uninstaller. It was suggested to me to put the $INSTDIR path into the registry at install time, and then extract it later. I'll post some results ;]
Edit1: Oh two things to note:
1) My uninstaller is placed inside ProgramFiles.
2) and the default install is Program Files
Anders
10th April 2008 17:25 UTC
$INSTDIR=the folder the uninstaller is started from
Afrow UK
10th April 2008 17:27 UTC
First you need to save the value of $INSTDIR in the registry, preferably with your Add/Remove registry (InstallLocation). Uninstalling that way is dangerous anyway but have a look at this page:
http://nsis.sourceforge.net/Validating_$INSTDIR_before_uninstall
Stu
hungryOrb
11th April 2008 11:00 UTC
Thanks Stu :D That's extremely helpful :O
I have no choice but to use 'RMDIR /r' on account of the update (new) files being missed in the uninstaller. I know personally, I like to see absolutely no trace of things that have been chosen for uninstall as well :]
'RMDIR /r' seems safe, as long as the INSTDIR can be located accurately ;] Half of my adobe folder has taken a hit, but I never liked Adobe Reader much anyways xD
<3@Stu
hungryOrb
11th April 2008 12:01 UTC
Stu, having looked at the page a lot, I've picked up on the type of validation being used, but when trying to use a similar setup, I find myself lost in placing the macro :/ It doesn't like to sit outside a section or function, but it doesn't seem to want to sit inside my onInit function either :/
I guess I'm just clueless on how to attach the macro to the Directory Page. I've been looking in the manual, and will continue to, but if there is some magic words that could be said, I'd be happy to include them in a sharing of my experience as a whole when the installer finishes- that is, to help other beginners ;]
Afrow UK
11th April 2008 12:19 UTC
It goes at the top of your uninstall section after getting the value of $INSTDIR. You can miss most of it off except the bit that checks if your application folder is appended to the end if you like (the !define ...)
Stu
hungryOrb
11th April 2008 12:42 UTC
Oh thanks!
With this lot:
----------------------------
Function un.onInit
ReadRegStr $R0 HKLM "Software\VB and VBA Program Settings\${PRODUCT_NAME}\Main" "InstPathHere"
!define CHECK_PATH "\${PRODUCT_NAME}"
StrLen $R1 "${CHECK_PATH}"
StrCpy $R2 $INSTDIR "" -$R1
StrCmp $R2 "${CHECK_PATH}" +3
MessageBox MB_YESNO|MB_ICONQUESTION "Unrecognised uninstall path. Continue anyway?" IDYES +2
Abort
;MessageBox MB_OK "Registry: InstPathHere = $R0"
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to completely remove $(^Name)? Connectors will not be removed." IDYES +2
Abort
FunctionEnd
----------------------------
--= I cant extract the name of the chosen folder of install right? because I don't know how many characters its going to be? So the validation will mostly just check the default folder name right? And at this point, the INSTDIR, is where the uninst.exe is sitting, so simply replace with $R0?
And ehm. Although I've seen countless examples, at the end of a string comparison (?) the +2/+3 jump to certain points right? I'm just confused on where they jump to.. :|
Thanks for helping so much Stu, you probably would prefer to spend time doing better stuff than spoon-feeding but I appreciate it muchly :]
Afrow UK
11th April 2008 15:07 UTC
No, replace $R0 with $INSTDIR on your ReadRegStr line.
Assuming you always append your default install folder to the end of your install path on install, this code will work fine.
Yes you can use this to validate the path on install as well.
There is a section in the manual regarding relative jumps.
Stu
hungryOrb
14th April 2008 10:29 UTC
Thanks Stu :] Although I cannot use $INSTDIR, because I put the uninstaller in a different directory to the main app. I think the installer is as complete as it can get for now :)
There are holes, but, they are only dangerous if a user decides to rename an important folder to the name of the INSTDIR or messes with registry. If it was totally safe, there'd be no excitement though right? ^.^