Unistall only installed files
can anybody write an exmaple script for me 🙁
15 posts
You will need the TrimNewLines function to be present also.Var UninstLog
; Add file macro
!macro File FileName
File "${FileName}"
FileWrite $UninstLog "$OUTPATH\${FileName}$\r$\n"
!macroend
!define File "!insertmacro File"
Section -openlogfile
FileOpen $UninstLog "$INSTDIR\uninstall.log" w
SectionEnd
Section "Install Main"
SetOutPath $INSTDIR
${File} "file1.ext"
${File} "file2.ext"
${File} "file3.ext"
SectionEnd
Section "Install Other"
SetOutPath "$INSTDIR\Other"
${File} "file4.ext"
${File} "file5.ext"
${File} "file6.ext"
SectionEnd
Section -closelogfile
FileClose $UninstLog
SectionEnd
Section Uninstall
; Can't uninstall if uninstall.log is missing!
IfFileExists "$EXEDIR\uninstall.log" +3
MessageBox MB_OK|MB_ICONSTOP "uninstall.log not found!$\r$\nUninstallation cannot be done!"
Abort
Push $R0
FileOpen $UninstLog "$EXEDIR\uninstall.log" r
LoopRead:
ClearErrors
FileRead $UninstLog $R0
IfErrors LoopDone
Push $R0
Call TrimNewLines
Pop $R0
Delete $R0
Goto LoopRead
LoopDone:
FileClose $UninstLog
Pop $R0
SectionEnd
For example, insert it at the end of the code Afrow UK provided.Function TrimNewlines
Exch $R0
Push $R1
Push $R2
StrCpy $R1 0
loop:
IntOp $R1 $R1 - 1
StrCpy $R2 $R0 1 $R1
StrCmp $R2 "$\r" loop
StrCmp $R2 "$\n" loop
IntOp $R1 $R1 + 1
IntCmp $R1 0 no_trim_needed
StrCpy $R0 $R0 $R1
no_trim_needed:
Pop $R2
Pop $R1
Exch $R0
FunctionEnd
Call must be used with function names starting with "un." in the uninstall section.error at "Call TrimNewLines"
Usage: Call function_name | [:label_name]
Error in script "I:\Documents and Settings\Administrator\Desktop\unistallonlyinstalled\example.nsi" on line 52 -- aborting creation process
Another problem is that the "File" macro uses $OUTPATH instead of $OUTDIR (you should have got some warnings about this when you compiled the script, eg unknown variable/constant "OUTPATH\file1.ext" detected, ignoring (macro:File:2)).Section -openlogfile
SetOutPath $INSTDIR
FileOpen $UninstLog "$INSTDIR\uninstall.log" w
SectionEnd
FileWrite $UninstLog "$OUTDIR\${FileName}$\r$\n"These two changes will let your installer create the uninstsall.log file with the correct data.i've used this code, only problem with $OUTPATH
Var UninstLog
; Add file macro
!macro File FileName
File "${FileName}"
FileWrite $UninstLog "$OUTPATH\${FileName}$\r$\n"
!macroend
!define File "!insertmacro File"
Section -openlogfile
FileOpen $UninstLog "$INSTDIR\uninstall.log" w
SectionEnd
Section "Install Main"
SetOutPath $INSTDIR
${File} "file1.ext"
${File} "file2.ext"
${File} "file3.ext"
SectionEnd
Section "Install Other"
SetOutPath "$INSTDIR\Other"
${File} "file4.ext"
${File} "file5.ext"
${File} "file6.ext"
SectionEnd
Section -closelogfile
FileClose $UninstLog
SectionEnd
Section Uninstall
; Can't uninstall if uninstall.log is missing!
IfFileExists "$INSTDIR\uninstall.log" +3
MessageBox MB_OK|MB_ICONSTOP "uninstall.log not found!$\r$\nUninstallation cannot be done!"
Abort
Push $R0
FileOpen $UninstLog "$INSTDIR\uninstall.log" r
LoopRead:
ClearErrors
FileRead $UninstLog $R0
IfErrors LoopDone
Push $R0
Call un.TrimNewLines
Pop $R0
Delete $R0
Goto LoopRead
LoopDone:
FileClose $UninstLog
Pop $R0
SectionEnd
Function un.TrimNewlines
Exch $R0
Push $R1
Push $R2
StrCpy $R1 0
loop:
IntOp $R1 $R1 - 1
StrCpy $R2 $R0 1 $R1
StrCmp $R2 "$\r" loop
StrCmp $R2 "$\n" loop
IntOp $R1 $R1 + 1
IntCmp $R1 0 no_trim_needed
StrCpy $R0 $R0 $R1
no_trim_needed:
Pop $R2
Pop $R1
Exch $R0
FunctionEnd
$OUTPATH\file1.ext
$OUTPATH\file2.ext
$OUTPATH\file3.ext
$OUTPATH\file4.ext
$OUTPATH\file5.ext
$OUTPATH\file6.ext
Originally posted by pengyouok i've used $OUTDIR for $OUTPATH, so it works completely. Thanx for your helps 🙂
Sorry about the "un.TrimNewlines" problem - I did not look at the code to see where the TrimNewlines function was being used.
In your script the "FileOpen" command will fail to create the uninstall.log file if the $INSTDIR folder does not exist. One way to fix this is to change the -openlogfile section:Another problem is that the "File" macro uses $OUTPATH instead of $OUTDIR (you should have got some warnings about this when you compiled the script, eg unknown variable/constant "OUTPATH\file1.ext" detected, ignoring (macro:File:2)).Section -openlogfile
SetOutPath $INSTDIR
FileOpen $UninstLog "$INSTDIR\uninstall.log" w
SectionEnd
To fix this change the line toThese two changes will let your installer create the uninstsall.log file with the correct data.FileWrite $UninstLog "$OUTDIR\${FileName}$\r$\n"
You'll need to add some code to the uninstaller to make it delete the uninstall.log file, the uninstall.exe program, the empty folders and the registry data (have another look at the original Basic.nsi script to see how to do this).
[edit]
Another thing that might cause problems is that the "File" macro can store the wrong information if you include a path instead of just a filename, e.g.
${File} "path\file7.ext"
[/edit]