srinke
11th December 2008 14:53 UTC
Uninstall files copied with CopyFiles *.*
Hello.
How can I uninstall files which have been copied during installation with following command:
CopyFiles /SILENT "$EXEDIR\User-Plugins\*.*" "$INSTDIR\User-Plugins"
Only the copied files should be deleted, NOT the files previously existed in the directory.
Thanks for help, Stefan.
Animaether
12th December 2008 06:29 UTC
Keep a log of the files you copied, read that log when it is time to uninstall.
I *think* CopyFiles ends up in the install details window, so you could grab from there.. otherwise, use FindFirst, FindNext, FindClose to get the files matching your file spec one-by-one so you can log them.
srinke
12th December 2008 07:08 UTC
Thank you.
That's what I have already thought about.
Has anybody a sample how to do this?
Instructor
12th December 2008 14:29 UTC
You can try: unList
srinke
13th January 2009 15:48 UTC
Thank you. I've tried unlist, but it imports the files which I tried to copy dynamically.
I wrote following which does what I need:
Name "UnCopy"
OutFile "UnCopy.exe"
InstallDir "$PROGRAMFILES\UnCopy"
!include "FileFunc.nsh"
!insertmacro un.GetFileAttributes
!include "TextFunc.nsh"
!insertmacro FileJoin
!insertmacro un.FileReadFromEnd
!insertmacro un.TrimNewLines
Section
InitPluginsDir
ExpandEnvStrings $R0 %COMSPEC%
SetOutPath "$INSTDIR\User-Plugins"
CopyFiles /SILENT "$EXEDIR\User-Plug-ins\*.*" "$INSTDIR\User-Plugins"
nsExec::Exec '"$R0" /C DIR "$INSTDIR\User-Plugins\*.*" /A-D /B /S /ON>"$INSTDIR\AdditionalPlugins.log"'
nsExec::Exec '"$R0" /C DIR "$INSTDIR\User-Plugins\*.*" /AD /B /S /ON>"$INSTDIR\Directories.log"'
${FileJoin} "$INSTDIR\Directories.log" "$INSTDIR\AdditionalPlugins.log" "$INSTDIR\AdditionalPlugins.log"
Delete "$INSTDIR\Directories.log"
SectionEnd
Function .onInstSuccess
WriteUninstaller $INSTDIR\uninstall.exe
FunctionEnd
Section Uninstall
${un.FileReadFromEnd} "$INSTDIR\AdditionalPlugins.log" un.FilesCallback
Delete "$INSTDIR\AdditionalPlugins.log"
RMDir "$INSTDIR\User-PlugIns"
Delete "$INSTDIR\uninstall.exe"
RMDir "$INSTDIR"
SectionEnd
Function un.FilesCallback
System::Call 'user32::OemToChar(t r9, t .r9)'
${un.TrimNewLines} '$9' $9
${un.GetFileAttributes} '$9' "DIRECTORY" $R0
IntCmp $R0 0 0 DeleteAsDir DeleteAsDir
Delete '$9'
goto FilesCallbackEnd
DeleteAsDir:
RMDir '$9'
FilesCallbackEnd:
Push 0
FunctionEnd
It copies files and directories recursivly from the installers subdirectory "User-Plug-ins" to the destination paths subdirectory "User-Plugins". The uninstaller will remove exactly this files and directories and nothing else!