Implement AddFileLogRaw
authorWuzzy <Wuzzy2@mail.ru>
Tue, 14 May 2019 21:49:01 +0200
changeset 14951 23fc5022bdea
parent 14950 00cf807b7faa
child 14952 414924c06704
Implement AddFileLogRaw
hedgewars/uPhysFSLayer.pas
hedgewars/uUtils.pas
--- a/hedgewars/uPhysFSLayer.pas	Tue May 14 20:58:39 2019 +0200
+++ b/hedgewars/uPhysFSLayer.pas	Tue May 14 21:49:01 2019 +0200
@@ -35,6 +35,7 @@
 procedure pfsReadLn(f: PFSFile; var s: shortstring);
 procedure pfsReadLnA(f: PFSFile; var s: ansistring);
 procedure pfsWriteLn(f: PFSFile; s: shortstring);
+procedure pfsWriteRaw(f: PFSFile; s: PChar; len: QWord);
 function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64;
 function pfsEOF(f: PFSFile): boolean;
 
@@ -179,6 +180,11 @@
     PHYSFS_writeBytes(f, @c, 1);
 end;
 
+procedure pfsWriteRaw(f: PFSFile; s: PChar; len: QWord);
+begin
+    PHYSFS_writeBytes(f, s, len);
+end;
+
 function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64;
 var r: Int64;
 begin
--- a/hedgewars/uUtils.pas	Tue May 14 20:58:39 2019 +0200
+++ b/hedgewars/uUtils.pas	Tue May 14 21:49:01 2019 +0200
@@ -526,6 +526,7 @@
 end;
 
 procedure AddFileLogRaw(s: pchar); cdecl;
+var tmp: shortstring;
 begin
 s:= s;
 {$IFNDEF PAS2C}
@@ -534,9 +535,17 @@
 if SDL_LockMutex(logMutex) <> 0 then
     OutError('Logging mutex could not be locked!', true);
 {$ENDIF}
-// TODO: uncomment next two lines
-// write(logFile, s);
-// flush(logFile);
+tmp:= IntToStr(GameTicks) + ': ';
+if (logFile <> nil) then
+    begin
+    pfsWriteRaw(logFile, Str2PChar(tmp), StrLen(Str2PChar(tmp)));
+    pfsWriteRaw(logFile, s, StrLen(s));
+    end
+else
+    begin
+    Write(stdout, Str2PChar(tmp));
+    Flush(stdout);
+    end;
 {$IFDEF USE_VIDEO_RECORDING}
 if SDL_UnlockMutex(logMutex) <> 0 then
     OutError('Logging mutex could not be unlocked!', true);