revisit the debugfile section
authorkoda
Thu, 22 Nov 2012 02:15:23 +0100
changeset 8095 df61e150eb70
parent 8093 2286a39140da
child 8098 4efee370e2de
revisit the debugfile section
hedgewars/uUtils.pas
--- a/hedgewars/uUtils.pas	Wed Nov 21 23:34:54 2012 +0100
+++ b/hedgewars/uUtils.pas	Thu Nov 22 02:15:23 2012 +0100
@@ -404,7 +404,7 @@
 procedure initModule(isNotPreview: boolean);
 {$IFDEF DEBUGFILE}
 var logfileBase: shortstring;
-{$IFNDEF MOBILE}var i: LongInt;{$ENDIF}
+    i: LongInt;
 {$ENDIF}
 begin
 {$IFDEF DEBUGFILE}
@@ -423,26 +423,25 @@
 {$I-}
 {$IFDEF MOBILE}
     {$IFDEF IPHONEOS} Assign(f, UserPathPrefix + '/hw-' + logfileBase + '.log'); {$ENDIF}
-    {$IFDEF ANDROID} Assign(f,pathPrefix + '/' + logfileBase + '.log'); {$ENDIF}
-    Rewrite(f);
+    {$IFDEF ANDROID} Assign(f, pathPrefix + '/' + logfileBase + '.log'); {$ENDIF}
+    i:= i; // avoid hint
 {$ELSE}
+    f:= stdout; // if everything fails, write to stderr
     if (UserPathPrefix <> '') then
         begin
-            i:= 0;
-            while(i < 7) do
+        if not FileExists(UserPathPrefix + '/Logs/') then
+            CreateDir(UserPathPrefix + '/Logs/');
+        i:= 0;
+        while(i < 7) do
             begin
-                assign(f, UserPathPrefix + '/Logs/' + logfileBase + inttostr(i) + '.log');
-                rewrite(f);
-                if IOResult = 0 then
-                    break;
-                inc(i)
+            assign(f, UserPathPrefix + '/Logs/' + logfileBase + inttostr(i) + '.log');
+            if IOResult = 0 then
+                break;
+            inc(i)
             end;
-            if i = 7 then
-                f:= stderr; // if everything fails, write to stderr
-        end
-    else
-        f:= stderr;
+        end;
 {$ENDIF}
+    Rewrite(f);
 {$I+}
 {$ENDIF}