Go Back   Winamp Forums > Developer Center > NSIS Discussion

Reply
Thread Tools Search this Thread Display Modes
Old 1st September 2003, 19:52   #1
DOCa Cola
Senior Member
 
DOCa Cola's Avatar
 
Join Date: Feb 2003
Location: Germany
Posts: 223
Send a message via ICQ to DOCa Cola Send a message via AIM to DOCa Cola Send a message via Yahoo to DOCa Cola
FileOpen interferes with program

i have written a small function for my setup that constantly checks for a failure in a log file a started program gives out

the error line i am looking for looks like this (it always ends with 'i_am_the_federation' <- that is important) and is one of many lines the program attaches to that log:

Quote:
[ Warning::ST3D_GraphicsEngine:: 118@ 8699] Storm3D Warning: Sprites\gui_federation.spr: Couldn't find particle sprite node definition 'i_am_the_federation'

so here is the function i included in my setup script
code:

start:
ClearErrors
FileOpen $0 "log.txt" "r"
loop:
sleep 250
FileRead $0 $2
StrLen $R0 $2
IntOp $R1 $R0 - 23
StrCpy $2 $2 1000 $R1
IfErrors start
StrCmp $2 "'i_am_the_federation'$\r$\n" 0 loop
FileClose $0
MessageBox MB_OK "error message placeholder"
;Clear the log
FileOpen $R3 "log.txt" "w"
FileClose $R3



Ok, the problem is not with the function itself,
but with the fileopen command.
the program cannot write to the file
during the reading time of my setup,
so the error cannot appear in the log.
so do you have a suggestion what i could change that the setup
doesn't block the program to write to the log file?

DOCa Cola
DOCa Cola is offline   Reply With Quote
Old 2nd September 2003, 07:40   #2
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,338
NSIS opens files only with read sharing so that weird results won't come out when reading the file. If you want to open it with write sharing too you'd have to use System.dll:

!define GENERIC_READ 0x80000000
!define GENERIC_WRITE 0x40000000
!define FILE_SHARE_READ 1
!define FILE_SHARE_WRITE 2

!define CREATE_NEW 1
!define CREATE_ALWAYS 2
!define OPEN_EXISTING 3
!define OPEN_ALWAYS 4

System::Call "Kernel32::CreateFileA(t 'log.txt', i ${GENERIC_READ}, i ${FILE_SHARE_READ} | ${FILE_SHARE_WRITE}, i 0, i ${OPEN_EXISTING}, i 0, i 0)"

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 2nd September 2003, 11:41   #3
DOCa Cola
Senior Member
 
DOCa Cola's Avatar
 
Join Date: Feb 2003
Location: Germany
Posts: 223
Send a message via ICQ to DOCa Cola Send a message via AIM to DOCa Cola Send a message via Yahoo to DOCa Cola
thx for the quick answer
no, i don't want to write to the file, just read it...so you say it shouldn't interfere with the program anyway when using FileOpen $0 "log.txt" "r" only?
i tried you system.dll call but i couldn't find a command list for FILE_SHARE_READ, so i just tried

code:
!define GENERIC_READ 0x80000000
!define GENERIC_WRITE 0x40000000
!define FILE_SHARE_READ 1
!define FILE_SHARE_WRITE 2

!define CREATE_NEW 1
!define CREATE_ALWAYS 2
!define OPEN_EXISTING 3
!define OPEN_ALWAYS 4

Section Test
start:
ClearErrors
System::Call "Kernel32::CreateFileA(t 'log.txt', i ${GENERIC_READ}, \
i ${FILE_SHARE_READ} | ${FILE_SHARE_WRITE}, i 0, i ${OPEN_EXISTING}, \
i 0, i 0)"
loop:
sleep 250
FileRead $0 $2
StrLen $R0 $2
IntOp $R1 $R0 - 23
StrCpy $2 $2 1000 $R1
IfErrors start
StrCmp $2 "'i_am_the_federation'$\r$\n" 0 loop
FileClose $0
MessageBox MB_OK "error message placeholder"
;Clear the log
FileOpen $R3 "log.txt" "w"
FileClose $R3
SectionEnd



DOCa Cola
DOCa Cola is offline   Reply With Quote
Old 2nd September 2003, 11:56   #4
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,338
Write sharing means other programs can write to the file while you're reading it. It doesn't mean you want to write to it.

FILE_SHARE_READ is a constant. What do you mean by command list?

I have forgot to mention that the handle to the file is the return value of the system call. Add i .r0 to the end of the system call and the handle will be inserted into $0. Use IntCmp $0 -1 to make sure the file open hasn't failed. After that you can use the file handle just as a file handle FileOpen would have returned.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 2nd September 2003, 12:38   #5
DOCa Cola
Senior Member
 
DOCa Cola's Avatar
 
Join Date: Feb 2003
Location: Germany
Posts: 223
Send a message via ICQ to DOCa Cola Send a message via AIM to DOCa Cola Send a message via Yahoo to DOCa Cola
ok, i have done that now with the system call, but the problem that it cannot write to the log file during my setup reads it presists, i try to prepare you a ready to use sample...
DOCa Cola is offline   Reply With Quote
Old 2nd September 2003, 13:26   #6
DOCa Cola
Senior Member
 
DOCa Cola's Avatar
 
Join Date: Feb 2003
Location: Germany
Posts: 223
Send a message via ICQ to DOCa Cola Send a message via AIM to DOCa Cola Send a message via Yahoo to DOCa Cola
ok, here it is, size is 1.6 mb (self extracting 7zip archive)
http://www.borgcore.de/outerspace/nsis/a2testfiles.exe
some instructions and info are inside the logfiletest.nsi

DOCa Cola
DOCa Cola is offline   Reply With Quote
Old 2nd September 2003, 14:04   #7
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,338
Remove the spaces between ${FILE_SHARE_READ}, | and ${FILE_SHARE_WRITE} and you should be able to write to the file even between CreateFile and FileClose. I hope that's what you meant, I really couldn't understand where the problem was in your program so I've just created my own example.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 2nd September 2003, 14:09   #8
DOCa Cola
Senior Member
 
DOCa Cola's Avatar
 
Join Date: Feb 2003
Location: Germany
Posts: 223
Send a message via ICQ to DOCa Cola Send a message via AIM to DOCa Cola Send a message via Yahoo to DOCa Cola
thank you! yes, that was what i meant! simply love that installer! i hope installshield/inno/wise setup users realize how much better nsis is

DOCa Cola
DOCa Cola is offline   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