balu.g12
12th October 2011 08:50 UTC
Skip deleting Modified/Added files and folders duirng Uninstall
Hi,
Presently i am deleting the Installed files/folders in uninstall section by using RMDIR /r $INSTDIR
But user may modify some installed files or he may add some directoires/files anywhere under $INSTDIR after installation.
I wanted to know,
During uninstallation, if there is any way to skip the deletion of some folder and its contents, if that folder has a modified files in it..
Can some body suggest me the solution with small example please?
Appreciate your help!
Regards,
Balaji.G
MSG
12th October 2011 12:05 UTC
You should never rmdir /r $instdir, exactly because of the reason you mention: The user might have added files of his/her own. (Also, the $INSTDIR variable in the uninstaller only contains the directory where uninstall.exe is stored. So if the user moves uninstall.exe, you'll end up deleting files not belonging to your app at all!)
The solution is however not to 'exclude' some files. The solution is to include only those files that you KNOW you want to delete. To do this, you must simply add a delete command for every single file that you install.
If you think that's ugly, keep in mind that the user will never see the code to begin with. They will however notice what you end up deleting from their system. And deleting the entire Program Files folder just because the user installed there instead of in a subdir, now THAT is ugly.
(Note: to circumvent the problem with $instdir in the uninstaller, you need to verify that the folder is the correct one: Load the install path from registry, and/or check for some marker files specific to your application.)
balu.g12
12th October 2011 13:21 UTC
Hi,
Just before posting my question, i read about consequences of using rmdir /r $instdir and i have planned to load the install path from registry instead of using rmdir /r $instdir.
Thanks for the suggestion.
##simply add a delete command for every single file that you install##
some of the problems, why i have left this idea is :
1) I have Thousands of files which i i will copy during installation.
2) I don't have any/proper idea on how to checkfor/getthelist of modified/New files.
{{My thinking is as follows:
while copying the files(File /r dir\*.*) during installation - redirect the each filename with path and time stamp to a file_timestamp.log file
while uninstallation - from the file_timestamp.log read every filename and verify if the time stamp is matching or not.
If the file timestamp is changed donot delete the parent folder and its contents.
Else Delete the file and empty directories.
?? but i am not sure how to get the file timestamp of a file and verify it??
}}
I am new to NSIS, Can you please suggest me how to proceed on this.
MSG
12th October 2011 14:16 UTC
To do that, you'll need to create an exe/vbs/bat file that creates a filelist at compiletime, and saves it as NSIS code such as "File dir\subdir\file1.ext", with the appropriate SetOutPath commands for the subdirs. Then !include that nsh code so that that the compiler can add them to the installer exe. You can create a textfile with timestamps at the same time, and parse that in the uninstaller (use File "dir\timestamps.txt" in the uninstaller section, and then some parsing functions from for example wordfunc.nsh). Tricky, but possible.