hedgewars/uUtils.pas
changeset 8095 df61e150eb70
parent 7896 67217e6108fd
child 8204 9a6030d96273
--- 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}