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?
Leave a directory behind on uninstall
8 posts
For similar circumstances I have used something like this.
Have the StrCmp jump over the Deletes and RMDirs that should skipped.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
Originally posted by scroseThank you, one additional question. How would I remove all the loose files, "DELETE $INSTDIR\*" ?
For similar circumstances I have used something like this.
(snip)
Have the StrCmp jump over the Deletes and RMDirs that should skipped.
Yes, something like this.
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.Delete "$INSTDIR\*.*"
RMDir "$INSTDIR"
Be careful with this:
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" +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"
-StuStrCmp $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:
Llynix only wanted to keep the Cache directory. That's why each StrCmp only jumped over one line.
Ah my mistake.
-Stu
-Stu
the RMDir skip is not really needed (unless you want to keep the folder even if it's empty)