Преглед изворни кода

improved console detection

Unknown пре 6 година
родитељ
комит
8eca1fb8ee
1 измењених фајлова са 18 додато и 2 уклоњено
  1. 18 2
      Quick.Commons.pas

+ 18 - 2
Quick.Commons.pas

@@ -7,7 +7,7 @@
   Author      : Kike Pérez
   Author      : Kike Pérez
   Version     : 1.7
   Version     : 1.7
   Created     : 14/07/2017
   Created     : 14/07/2017
-  Modified    : 27/02/2019
+  Modified    : 28/03/2019
 
 
   This file is part of QuickLib: https://github.com/exilon/QuickLib
   This file is part of QuickLib: https://github.com/exilon/QuickLib
 
 
@@ -191,6 +191,7 @@ type
   function Is64bitOS : Boolean;
   function Is64bitOS : Boolean;
   //checks if is a console app
   //checks if is a console app
   function IsConsole : Boolean;
   function IsConsole : Boolean;
+  function HasConsoleOutput : Boolean;
   //checks if compiled in debug mode
   //checks if compiled in debug mode
   {$ENDIF}
   {$ENDIF}
   function IsDebug : Boolean;
   function IsDebug : Boolean;
@@ -501,6 +502,21 @@ begin
 end;
 end;
 {$ENDIF}
 {$ENDIF}
 
 
+function HasConsoleOutput : Boolean;
+{$IFDEF MSWINDOWS}
+  var
+    stout : THandle;
+  begin
+    stout := GetStdHandle(Std_Output_Handle);
+    Win32Check(stout <> Invalid_Handle_Value);
+    Result := stout <> 0;
+  end;
+{$ELSE}
+  begin
+    Result := False;
+  end;
+{$ENDIF}
+
 function IsDebug: Boolean;
 function IsDebug: Boolean;
 begin
 begin
   {$IFDEF DEBUG}
   {$IFDEF DEBUG}
@@ -1320,7 +1336,7 @@ initialization
     begin
     begin
       if not IsService then
       if not IsService then
       begin
       begin
-        if IsConsole then Writeln(Format('[WARN] GetEnvironmentPaths: %s',[E.Message]))
+        if HasConsoleOutput then Writeln(Format('[WARN] GetEnvironmentPaths: %s',[E.Message]))
           else raise EEnvironmentPath.Create(Format('Get environment path error: %s',[E.Message]));
           else raise EEnvironmentPath.Create(Format('Get environment path error: %s',[E.Message]));
       end;
       end;
     end;
     end;