Uninstall only installed files: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Updated author links.)
m (Added category links.)
Line 72: Line 72:
</highlight-nsis>
</highlight-nsis>
-Stu
-Stu
[[{{ns:14}}:Code Examples]]

Revision as of 22:19, 30 April 2005

Author: Afrow UK (talk, contrib)


Description

This a code written in the NSIS forums for Rookie12 a long while back. So many people have asked the same question since, so I thought that it was a good idea to put it up on here. You need the TrimNewLines function present in your script also. Make sure you rename the TrimNewLines function name to un.TrimNewLines (as the function is used in the uninstaller, ala "un.").

The Script

Var UninstLog
 
; Add file macro
!macro File FileName
 File "${FileName}"
 FileWrite $UninstLog "$OUTDIR\${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$\n \
  Uninstallation cannot proceed!"
   Abort
 
 Push $R0
 FileOpen $UninstLog "$EXEDIR\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

-Stu