Skip to content
⌘ NSIS Forum Archive

What's wrong?

4 posts

Gluck#

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#
Sorry, the right link is this:



Tha code until execwait is OK, the trouble are only after execwait...
Gluck#
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#
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!!! 🙂