Old 26th November 2004, 16:42   #1
Llynix
Guest
 
Posts: n/a
Leave a directory behind on uninstall

So far these forums have been very useful, special thanks to all who have posted.

I tried searching for the answer to this one but couldn't quite find the perfect solution.

I want the user to have an option to save a certain directory called cache upon uninstall.

The Directory struction of the program is:

Cache
Configuration
Data
src
Utils
and then numerous dll's and other files in the default install directory.

Any ideas how I can preserve the cache directory if the user wants to?
  Reply With Quote
Old 26th November 2004, 17:11   #2
scrose
Junior Member
 
scrose's Avatar
 
Join Date: Nov 2004
Posts: 36
For similar circumstances I have used something like this.
code:
Var keepCache

Function un.onInit
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to uninstall ${PRODUCT_NAME}?" IDYES +2
Abort
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON1 "Do you want to keep your cache folder?" IDNO +2
StrCpy $keepCache "Yes"
FunctionEnd

Section Uninstall
StrCmp $keepCache "Yes" +2
Delete "$INSTDIR\Cache\*.*"
Delete "$INSTDIR\Configuration\*.*"
Delete "$INSTDIR\Data\*.*"
Delete "$INSTDIR\src\*.*"
Delete "$INSTDIR\Utils\*.*"

StrCmp $keepCache "Yes" +2
RMDir "$INSTDIR\Cache"
RMDir "$INSTDIR\Configuration"
RMDir "$INSTDIR\Data"
RMDir "$INSTDIR\src"
RMDir "$INSTDIR\Utils"
SectionEnd

Have the StrCmp jump over the Deletes and RMDirs that should skipped.
scrose is offline   Reply With Quote
Old 26th November 2004, 17:25   #3
Llynix
Junior Member
 
Join Date: Nov 2004
Posts: 32
Send a message via AIM to Llynix
Quote:
Originally posted by scrose
For similar circumstances I have used something like this.

(snip)

Have the StrCmp jump over the Deletes and RMDirs that should skipped.
Thank you, one additional question. How would I remove all the loose files, "DELETE $INSTDIR\*" ?
Llynix is offline   Reply With Quote
Old 26th November 2004, 17:33   #4
scrose
Junior Member
 
scrose's Avatar
 
Join Date: Nov 2004
Posts: 36
Yes, something like this.
code:
Delete "$INSTDIR\*.*"
RMDir "$INSTDIR"

But be careful when using *.* with Delete; you might erase something you didn't instead to. If possible, it's much safer to have a separate Delete command for each file you want to uninstall. Same is true for RMDir.
scrose is offline   Reply With Quote
Old 26th November 2004, 20:07   #5
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Be careful with this:
code:
StrCmp $keepCache "Yes" +2
Delete "$INSTDIR\Cache\*.*"
Delete "$INSTDIR\Configuration\*.*"
Delete "$INSTDIR\Data\*.*"
Delete "$INSTDIR\src\*.*"
Delete "$INSTDIR\Utils\*.*"

StrCmp $keepCache "Yes" +2
RMDir "$INSTDIR\Cache"
RMDir "$INSTDIR\Configuration"
RMDir "$INSTDIR\Data"
RMDir "$INSTDIR\src"
RMDir "$INSTDIR\Utils"



Firstly you only need one StrCmp for the whole lot and secondly you're using +2 (only jumping over the first command!)
code:
StrCmp $keepCache "Yes" keepCache
Delete "$INSTDIR\Cache\*.*"
Delete "$INSTDIR\Configuration\*.*"
Delete "$INSTDIR\Data\*.*"
Delete "$INSTDIR\src\*.*"
Delete "$INSTDIR\Utils\*.*"

RMDir "$INSTDIR\Cache"
RMDir "$INSTDIR\Configuration"
RMDir "$INSTDIR\Data"
RMDir "$INSTDIR\src"
RMDir "$INSTDIR\Utils"
keepCache:



-Stu
Afrow UK is offline   Reply With Quote
Old 26th November 2004, 20:12   #6
scrose
Junior Member
 
scrose's Avatar
 
Join Date: Nov 2004
Posts: 36
Llynix only wanted to keep the Cache directory. That's why each StrCmp only jumped over one line.
scrose is offline   Reply With Quote
Old 26th November 2004, 20:48   #7
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Ah my mistake.

-Stu
Afrow UK is offline   Reply With Quote
Old 26th November 2004, 21:14   #8
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,153
the RMDir skip is not really needed (unless you want to keep the folder even if it's empty)

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump