Go Back   Winamp Forums > Developer Center > NSIS Discussion

Reply
Thread Tools Search this Thread Display Modes
Old 20th November 2004, 17:03   #1
Rookie12
Guest
 
Posts: n/a
Unistall only installed files

can anybody write an exmaple script for me
  Reply With Quote
Old 20th November 2004, 17:35   #2
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Birmingham, England
Posts: 8,202
This has already been asked before. You can only do this by creating a list of files on installation (write to a file using FileOpen, FileWrite) and then read from this file on uninstallation and delete each file.

e.g.
code:
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



You will need the TrimNewLines function to be present also.

-Stu

Need an installer? http://www.afrowsoft.co.uk
Afrow UK is offline   Reply With Quote
Old 20th November 2004, 19:37   #3
Rookie12
Guest
 
Posts: n/a
how can i present TrimNewLines function ?
  Reply With Quote
Old 20th November 2004, 19:56   #4
pengyou
Major Dude
 
Join Date: Mar 2003
Posts: 569
TrimNewlines is in the NSIS Users Manual

http://nsis.sourceforge.net/Docs/AppendixC.html#C.2
pengyou is offline   Reply With Quote
Old 20th November 2004, 20:04   #5
Rookie12
Guest
 
Posts: n/a
how can i use this in script?

sorry i'm just 12
  Reply With Quote
Old 20th November 2004, 20:25   #6
pengyou
Major Dude
 
Join Date: Mar 2003
Posts: 569
To use TrimNewlines, just insert the code into your script.
code:
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

For example, insert it at the end of the code Afrow UK provided.
pengyou is offline   Reply With Quote
Old 20th November 2004, 20:41   #7
Rookie12
Guest
 
Posts: n/a
Quote:
Call must be used with function names starting with "un." in the uninstall section.
Usage: Call function_name | [:label_name]
Error in script "I:\Documents and Settings\Administrator\Desktop\unistallonlyinstalled\example.nsi" on line 52 -- aborting creation process
error at "Call TrimNewLines"
  Reply With Quote
Old 20th November 2004, 21:09   #8
Rookie12
Guest
 
Posts: n/a
i've used un.TrimNewLines and FileWrite $INSTDIR "$OUTPATH\${FileName}$\r$\n" so no more problem about making setup but now uninstall.log is empty
  Reply With Quote
Old 20th November 2004, 21:52   #9
Rookie12
Guest
 
Posts: n/a
Script on Basic.nsi, but unistaller doesnt work.
Attached Files
File Type: rar unistallonlyinstalled.rar (1.4 KB, 130 views)
  Reply With Quote
Old 20th November 2004, 22:13   #10
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Birmingham, England
Posts: 8,202
Sorry I updated my code above after you must have copied it. I have made some alterations so you'll have to copy and paste it again.

-Stu

Need an installer? http://www.afrowsoft.co.uk
Afrow UK is offline   Reply With Quote
Old 20th November 2004, 22:38   #11
pengyou
Major Dude
 
Join Date: Mar 2003
Posts: 569
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:
code:
Section -openlogfile
SetOutPath $INSTDIR
FileOpen $UninstLog "$INSTDIR\uninstall.log" w
SectionEnd

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)).

To fix this change the line to
code:
FileWrite $UninstLog "$OUTDIR\${FileName}$\r$\n"
These two changes will let your installer create the uninstsall.log file with the correct data.

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]
pengyou is offline   Reply With Quote
Old 20th November 2004, 22:52   #12
Rookie12
Guest
 
Posts: n/a
code:

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



i've used this code, only problem with $OUTPATH

this is contents of uninstall.log

Quote:
$OUTPATH\file1.ext
$OUTPATH\file2.ext
$OUTPATH\file3.ext
$OUTPATH\file4.ext
$OUTPATH\file5.ext
$OUTPATH\file6.ext
  Reply With Quote
Old 20th November 2004, 22:57   #13
Rookie12
Guest
 
Posts: n/a
Quote:
Originally posted by pengyou
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:
code:
Section -openlogfile
SetOutPath $INSTDIR
FileOpen $UninstLog "$INSTDIR\uninstall.log" w
SectionEnd

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)).

To fix this change the line to
code:
FileWrite $UninstLog "$OUTDIR\${FileName}$\r$\n"
These two changes will let your installer create the uninstsall.log file with the correct data.

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]
ok i've used $OUTDIR for $OUTPATH, so it works completely. Thanx for your helps
Attached Files
File Type: nsi unistall.only.installed.files.based.on.basic.nsi (3.1 KB, 115 views)
  Reply With Quote
Old 21st November 2004, 11:26   #14
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Birmingham, England
Posts: 8,202
Ah yes sorry about that. I meant to put $OUTDIR but I put $OUTPATH instead sorry

I never actually tested the code (although I should have). It was written here and then.

-Stu

Need an installer? http://www.afrowsoft.co.uk
Afrow UK is offline   Reply With Quote
Old 25th November 2004, 22:14   #15
Rookie12
Guest
 
Posts: n/a
is this possible for registry strings too?
  Reply With Quote
Reply
Go Back   Winamp Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump