Archive: FileOpen interferes with program


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:


so here is the function i included in my setup script

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

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

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


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

!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

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.


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


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


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.


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