Old 10th May 2018, 09:18   #1
Gluck
Member
 
Join Date: Apr 2018
Posts: 85
What's wrong?

Hi,

I have found this link:

http://forums.winamp.com/newthread.p...newthread&f=65

I want remove an IP (everytime) from hosts file.

I have written (ehm, copied ) this sample:

WindowIcon Off
SilentInstall Silent
AutoCloseWindow True

OutFile Hosts(remove).exe


Section


!include "FileFunc.nsh"
!include "TextFunc.nsh"
!include "WordFunc.nsh"


!define STRING "127.0.0.1"
!define HOSTS "$EXEDIR\Test.txt"


FileOpen $0 "${HOSTS}" a
FileSeek $0 0 END
FileWrite $0 "$\r$\n"
FileWrite $0 "${STRING}"
FileClose $0



ExecWait "$EXEDIR\App\notepad.exe"


${LineFind} "$EXEDIR\Test.txt" "$EXEDIR\Test2.txt" "2:3 10:-5 -3:-2" "Example3"
IfErrors 0 +2
MessageBox MB_OK "Error"

SectionEnd

Function Example3
StrCpy $0 SkipWrite

Push $0
FunctionEnd

Sorry if it is not beautiful, but is a WIP...

In file Test.txt I have:

154.128.255.0
114.247.23.65
127.0.0.1
123.158.42.167
127.0.0.1
127.0.0.1

In file test2.txt I obtain:

154.128.255.0
123.158.42.167
127.0.0.1
127.0.0.1

I loose 114.247.23.65 WHY??? and only the firsrt 127.0.0.1

What have I to write to delete all 127.0.0.1 and NOT 114.247.23.65

Thanks
Gluck is offline   Reply With Quote
Old 10th May 2018, 09:48   #2
Gluck
Member
 
Join Date: Apr 2018
Posts: 85
Sorry, the right link is this:

http://nsis.sourceforge.net/LineFind

Tha code until execwait is OK, the trouble are only after execwait...
Gluck is offline   Reply With Quote
Old 10th May 2018, 11:43   #3
Gluck
Member
 
Join Date: Apr 2018
Posts: 85
I've changed approach... (this is more elegant, but the troubles persist).

After execwait:

ClearErrors
FileOpen $0 "${HOSTS}" "r"
GetTempFileName $R0
FileOpen $1 $R0 "w"
loop:
FileRead $0 $2
IfErrors done
StrCmp $2 "${STRING}$\r$\n" 0 +2

StrCmp $2 "${STRING}" 0 +2
StrCpy $2 ""


FileWrite $1 $2
Goto loop

done:
FileClose $0
FileClose $1
Delete "${HOSTS}"
CopyFiles /SILENT $R0 "${HOSTS}"
Delete $R0

This solution is even better...

Everything goes right until the last line.
If the IP is the the last line it is copied to the next versione of hosts.
(if it is in the middle of text, then disappear).

How can I delete the last entry?
Gluck is offline   Reply With Quote
Old 10th May 2018, 12:54   #4
Gluck
Member
 
Join Date: Apr 2018
Posts: 85
DONE!

I've removed the carriage symbol...

ClearErrors
FileOpen $0 "${HOSTS}" "r"
GetTempFileName $R0
FileOpen $1 $R0 "w"
loop:
FileRead $0 $2
IfErrors done reached{STRING}$\r$\n" 0 +2
StrCpy $2 ""
StrCmp $2 "${STRING}" 0 +2
StrCpy $2 ""

THANKS TO EVERYBODY!!!
Gluck is offline   Reply With Quote
Reply
Go Back   Winamp & SHOUTcast 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