BSOD2600
24th October 2009 09:24 UTC
File Append broken
I'm using the following code while in Silent mode (via /S). It's overwriting the log file instead of appending the data to it. My buggy code or something buggy with NSIS 2.45?
Function WriteErrorCode
    Exch $0   ; message
    Exch
    Exch $1   ; error code
    !define /date DATESTAMP "%Y-%m-%d %H:%M:%S"
    
    SetOutPath $EXEDIR
    FileOpen $9 $EXEDIR\Install_Errors.log a        
    FileWrite $9 "${DATESTAMP} - ErrorCode:$1 - $0$\r$\n"    
    FileClose $9 
    SetErrorLevel $1
    Abort
FunctionEnd
    
      820815
      24th October 2009 10:54 UTC
      ;FileOpen
      FileSeek $9 0 END
      ;FileWrite
     
    
      BSOD2600
      24th October 2009 17:48 UTC
      I agree FileSeek should accomplish what I want. Isn't the point of the FileOpen append option to save the existing content and write the new at its end?
     
    
      pengyou
      24th October 2009 17:55 UTC
      
      
        Isn't the point of the FileOpen append option to save the existing content and write the new at its end?
      
The manual says FileOpen's "a" mode means "append, meaning opened for both read and write, contents preserved". It then says
      
        In all open modes, the file pointer is placed at the beginning of the file
      
See 
http://nsis.sourceforge.net/Docs/Chapter4.html#4.9.5.2
     
    
      BSOD2600
      24th October 2009 18:02 UTC
      Ah, assumed it would do that for me automatically. With the FileSeek, all works as expected after all. Thanks for the clarification and another round of RTFM ;)
     
    
      pengyou
      24th October 2009 18:53 UTC
      I have lost count of how many times I have re-read the manual!