Llynix
26th November 2004 17:42 UTC
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?
scrose
26th November 2004 18:11 UTC
For similar circumstances I have used something like this.
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.
Llynix
26th November 2004 18:25 UTC
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\*" ?
scrose
26th November 2004 18:33 UTC
Yes, something like this.
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.
Afrow UK
26th November 2004 21:07 UTC
Be careful with this:
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!)
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
scrose
26th November 2004 21:12 UTC
Llynix only wanted to keep the Cache directory. That's why each StrCmp only jumped over one line.
Afrow UK
26th November 2004 21:48 UTC
Ah my mistake.
-Stu
Anders
26th November 2004 22:14 UTC
the RMDir skip is not really needed (unless you want to keep the folder even if it's empty)