|
@@ -57,6 +57,7 @@ type
|
|
|
|
|
|
var
|
|
|
StdOutHandle, StdErrHandle: THandle;
|
|
|
+ StdOutHandleIsConsole, StdErrHandleIsConsole: Boolean;
|
|
|
ScriptFilename: String;
|
|
|
Definitions, IncludePath, IncludeFiles, Output, OutputPath, OutputFilename: String;
|
|
|
SignTools: TStringList;
|
|
@@ -69,12 +70,19 @@ var
|
|
|
IsppOptions: TIsppOptions;
|
|
|
IsppMode: Boolean;
|
|
|
|
|
|
-procedure WriteToStdHandle(const H: THandle; S: String);
|
|
|
+procedure WriteToStdHandle(const Handle: THandle; const HandleIsConsole: Boolean; S: String);
|
|
|
begin
|
|
|
- var Utf8S := Utf8Encode(S);
|
|
|
- if Copy(Utf8S, 1, 1) <> #13 then Utf8S := Utf8S + #13#10;
|
|
|
- var BytesWritten: DWORD;
|
|
|
- WriteFile(H, Utf8S[1], Length(Utf8S), BytesWritten, nil);
|
|
|
+ if Copy(S, 1, 1) <> #13 then
|
|
|
+ S := S + #13#10;
|
|
|
+
|
|
|
+ if HandleIsConsole then begin
|
|
|
+ var CharsWritten: DWORD;
|
|
|
+ WriteConsole(Handle, @S[1], Length(S), CharsWritten, nil);
|
|
|
+ end else begin
|
|
|
+ var Utf8S := Utf8Encode(S);
|
|
|
+ var BytesWritten: DWORD;
|
|
|
+ WriteFile(Handle, Utf8S[1], Length(Utf8S), BytesWritten, nil);
|
|
|
+ end;
|
|
|
end;
|
|
|
|
|
|
procedure WriteStdOut(const S: String; const Warning: Boolean = False);
|
|
@@ -82,10 +90,10 @@ var
|
|
|
CSBI: TConsoleScreenBufferInfo;
|
|
|
DidSetColor: Boolean;
|
|
|
begin
|
|
|
- DidSetColor := Warning and GetConsoleScreenBufferInfo(StdOutHandle, CSBI) and
|
|
|
+ DidSetColor := Warning and StdOutHandleIsConsole and GetConsoleScreenBufferInfo(StdOutHandle, CSBI) and
|
|
|
SetConsoleTextAttribute(StdOutHandle, FOREGROUND_INTENSITY or FOREGROUND_RED or FOREGROUND_GREEN);
|
|
|
try
|
|
|
- WriteToStdHandle(StdOutHandle, S);
|
|
|
+ WriteToStdHandle(StdOutHandle, StdOutHandleIsConsole, S);
|
|
|
finally
|
|
|
if DidSetColor then
|
|
|
SetConsoleTextAttribute(StdOutHandle, CSBI.wAttributes);
|
|
@@ -97,10 +105,10 @@ var
|
|
|
CSBI: TConsoleScreenBufferInfo;
|
|
|
DidSetColor: Boolean;
|
|
|
begin
|
|
|
- DidSetColor := Error and GetConsoleScreenBufferInfo(StdErrHandle, CSBI) and
|
|
|
+ DidSetColor := Error and StdErrHandleIsConsole and GetConsoleScreenBufferInfo(StdErrHandle, CSBI) and
|
|
|
SetConsoleTextAttribute(StdErrHandle, FOREGROUND_INTENSITY or FOREGROUND_RED);
|
|
|
try
|
|
|
- WriteToStdHandle(StdErrHandle, S);
|
|
|
+ WriteToStdHandle(StdErrHandle, StdErrHandleIsConsole, S);
|
|
|
finally
|
|
|
if DidSetColor then
|
|
|
SetConsoleTextAttribute(StdErrHandle, CSBI.wAttributes);
|
|
@@ -111,7 +119,7 @@ function GetCursorPos: TPoint;
|
|
|
var
|
|
|
CSBI: TConsoleScreenBufferInfo;
|
|
|
begin
|
|
|
- if not GetConsoleScreenBufferInfo(StdOutHandle, CSBI) then
|
|
|
+ if not StdOutHandleIsConsole or not GetConsoleScreenBufferInfo(StdOutHandle, CSBI) then
|
|
|
Exit;
|
|
|
Result.X := CSBI.dwCursorPosition.X;
|
|
|
Result.Y := CSBI.dwCursorPosition.Y;
|
|
@@ -122,7 +130,7 @@ var
|
|
|
Coords: TCoord;
|
|
|
CSBI: TConsoleScreenBufferInfo;
|
|
|
begin
|
|
|
- if not GetConsoleScreenBufferInfo(StdOutHandle, CSBI) then
|
|
|
+ if not StdOutHandleIsConsole or not GetConsoleScreenBufferInfo(StdOutHandle, CSBI) then
|
|
|
Exit;
|
|
|
if P.X < 0 then Exit;
|
|
|
if P.Y < 0 then Exit;
|
|
@@ -138,17 +146,15 @@ var
|
|
|
CSBI: TConsoleScreenBufferInfo;
|
|
|
Str: String;
|
|
|
begin
|
|
|
- if GetConsoleScreenBufferInfo(StdOutHandle, CSBI) then
|
|
|
- begin
|
|
|
+ if StdOutHandleIsConsole and GetConsoleScreenBufferInfo(StdOutHandle, CSBI) then begin
|
|
|
if Length(S) > CSBI.dwSize.X then
|
|
|
Str := Copy(S, 1, CSBI.dwSize.X)
|
|
|
else
|
|
|
Str := Format('%-' + IntToStr(CSBI.dwSize.X) + 's', [S]);
|
|
|
- end
|
|
|
- else
|
|
|
+ end else
|
|
|
Str := S;
|
|
|
|
|
|
- WriteToStdHandle(StdOutHandle, Str);
|
|
|
+ WriteToStdHandle(StdOutHandle, StdOutHandleIsConsole, Str);
|
|
|
end;
|
|
|
|
|
|
function ConsoleCtrlHandler(dwCtrlType: DWORD): BOOL; stdcall;
|
|
@@ -637,8 +643,10 @@ begin
|
|
|
try
|
|
|
StdOutHandle := GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
StdErrHandle := GetStdHandle(STD_ERROR_HANDLE);
|
|
|
+ var Mode: DWORD;
|
|
|
+ StdOutHandleIsConsole := GetConsoleMode(StdOutHandle, Mode);
|
|
|
+ StdErrHandleIsConsole := GetConsoleMode(StdErrHandle, Mode);
|
|
|
SetConsoleCtrlHandler(@ConsoleCtrlHandler, True);
|
|
|
- SetConsoleOutputCP(CP_UTF8);
|
|
|
try
|
|
|
IsppMode := FileExists(ExtractFilePath(NewParamStr(0)) + 'ispp.dll');
|
|
|
ProcessCommandLine;
|