Uninstall only installed files: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Updated author and download links, and changed format of some pages.)
m (Updated author links.)
Line 1: Line 1:
{|align=right
|<small>Author: [[{{ns:2}}:Afrow UK|Afrow UK]] ([[{{ns:3}}:Afrow UK|talk]], [[{{ns:-1}}:Contributions/Afrow UK|contrib]])</small>
|}
<br style="clear:both;">
== Description ==
== Description ==
This a code written in the NSIS forums for [[user:Rookie12|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.
This a code written in the NSIS forums for [[user:Rookie12|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.
Line 68: Line 72:
</highlight-nsis>
</highlight-nsis>
-Stu
-Stu
Page author: [[User:Afrow UK|Afrow UK]]

Revision as of 03:05, 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