Fixed bug where error messages weren't displayed; changed icon; added optional compiler.ini to set default output directory (Section "Main", Key "Output")

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401308
This commit is contained in:
Christian Hammacher 2007-08-10 20:00:08 +00:00
parent ac03126022
commit c2e2c5bfda
8 changed files with 63 additions and 32 deletions

View File

@ -1,7 +1,7 @@
(* AMX Mod X
(* SourceMod
* compile.exe
*
* by the AMX Mod X Development Team
* by the SourceMod Development Team (adapted from AMX Mod X's compiler tool)
*
*
* This program is free software; you can redistribute it and/or modify it
@ -33,17 +33,19 @@ program compile;
{$APPTYPE CONSOLE}
{$R version.res}
{$R icon.res}
uses
SysUtils, Classes,
SysUtils, Classes, IniFiles,
uFunc in 'uFunc.pas';
var
sr: TSearchRec;
i: Word;
var sr: TSearchRec;
i: Word;
cfg: TIniFile;
outdir: String;
begin
WriteLn('//SourceMod compile.exe');
WriteLn('// by the AMX Mod X Dev Team');
WriteLn('//SourceMod Batch Compiler');
WriteLn('// by the SourceMod Dev Team');
WriteLn;
if not FileExists(ExtractFilePath(ParamStr(0))+COMPILER_EXE) then
@ -52,7 +54,15 @@ begin
AppExit;
end;
if not DirectoryExists(ExtractFilePath(ParamStr(0))+'compiled') then
cfg := TIniFile.Create(ExtractFilePath(ParamStr(0)) + 'compiler.ini');
outdir := cfg.ReadString('Main', 'Output', '');
if (outdir <> '') and (DirectoryExists(outdir)) then
outdir := IncludeTrailingPathDelimiter(outdir)
else
outdir := '';
cfg.Free;
if (outdir = '') and (not DirectoryExists(ExtractFilePath(ParamStr(0))+'compiled')) then
CreateDir(ExtractFilePath(ParamStr(0))+'compiled');
if ( ParamCount > 0 ) then
@ -60,7 +70,7 @@ begin
for i := 1 to ParamCount do
begin
if FileExists(ParamStr(i)) then
CompilePlugin(ParamStr(i))
CompilePlugin(ParamStr(i), outdir)
else
begin
WriteLn;
@ -73,7 +83,7 @@ begin
if ( FindFirst('*.sp',faAnyFile,sr) = 0 ) then
begin
repeat
CompilePlugin(sr.Name);
CompilePlugin(sr.Name, outdir);
until ( FindNext(sr) <> 0 );
end
else

Binary file not shown.

View File

@ -0,0 +1 @@
SM ICON "pawn.ico"

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

View File

@ -40,7 +40,7 @@ resourcestring
COMPILER_EXE = 'spcomp.exe';
procedure AppExit;
procedure CompilePlugin(const Name: String);
procedure CompilePlugin(const Name, OutputDir: String);
function GetAgeFromDat(const FileName: String): Integer;
procedure SetAgeToDat(const FileName: String; const Age: Integer);
function GetConsoleOutput(const Command: String; var Output: TStringList): Boolean;
@ -55,7 +55,7 @@ begin
Halt;
end;
procedure CompilePlugin(const Name: String);
procedure CompilePlugin(const Name, OutputDir: String);
var
Output: TStringList;
i: Word;
@ -64,14 +64,18 @@ var
begin
FileName := ExtractFileName(Name);
FilePath := ExtractFilePath(Name);
Compiled := FilePath+'compiled\'+ChangeFileExt(Filename,'.smx');
if (OutputDir = '') then
Compiled := FilePath+'compiled\'+ChangeFileExt(Filename,'.smx')
else
Compiled := OutputDir+ChangeFileExt(Filename,'.smx');
if (FilePath='') then
FilePath := ExtractFilePath(ParamStr(0));
WriteLn;
WriteLn('//// '+ExtractFileName(FileName));
if FileExists(Compiled) and ( GetAgeFromDat(FileName)=FileAge(Name) ) then
if FileExists(Compiled) and ( GetAgeFromDat(Name)=FileAge(Name) ) then
begin
WriteLn('// Already compiled.');
WriteLn('// ----------------------------------------');
@ -82,7 +86,7 @@ begin
try
cStart := GetTickCount;
if not GetConsoleOutput(ExtractFilePath(ParamStr(0))+COMPILER_EXE+' "'+FilePath+FileName+'" "-o'+Compiled+'"',Output) then
if not GetConsoleOutput(ExtractFilePath(ParamStr(0))+COMPILER_EXE+' "'+FileName+'" "-o'+Compiled+'"',Output) then
begin
WriteLn('// Internal error.');
AppExit;
@ -103,7 +107,7 @@ begin
AppExit;
end;
SetAgeToDat(FileName,FileAge(Name));
SetAgeToDat(Name,FileAge(Name));
end;
function GetAgeFromDat(const FileName: String): Integer;
@ -123,6 +127,7 @@ begin
Ini.WriteInteger(FileName,'Age',Age);
Ini.UpdateFile;
Ini.Free;
SetFileAttributes(PChar(ExtractFilePath(ParamStr(0))+'compile.dat'), faHidden);
end;
function GetConsoleOutput(const Command: String; var Output: TStringList): Boolean;
@ -138,10 +143,11 @@ var
Buffer: array [0..255] of Char;
NumberOfBytesRead: DWORD;
Stream: TMemoryStream;
Errors: String;
begin
FillChar(ProcessInfo, SizeOf(TProcessInformation), 0);
FillChar(SecurityAttr, SizeOf(TSecurityAttributes), 0);
SecurityAttr.nLength := SizeOf(SecurityAttr);
SecurityAttr.bInheritHandle := True;
SecurityAttr.lpSecurityDescriptor := nil;
@ -157,9 +163,7 @@ begin
StartupInfo.wShowWindow := SW_HIDE;
StartupInfo.dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
if CreateProcess(nil, PChar(command), nil, nil, true,
CREATE_DEFAULT_ERROR_MODE or CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, nil, nil,
StartupInfo, ProcessInfo) then begin
if CreateProcess(nil, PChar(command), nil, nil, true, CREATE_DEFAULT_ERROR_MODE or CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo) then begin
Result := True;
CloseHandle(PipeOutputWrite);
CloseHandle(PipeErrorsWrite);
@ -171,20 +175,24 @@ begin
if not Succeed then Break;
Stream.Write(Buffer, NumberOfBytesRead);
end;
Stream.Position := 0;
Output.LoadFromStream(Stream);
finally
Stream.Free;
// nothing
end;
Stream.Position := 0;
Output.LoadFromStream(Stream);
Stream.Free;
CloseHandle(PipeOutputRead);
Errors := '';
try
while True do
begin
Succeed := ReadFile(PipeErrorsRead, Buffer, 255, NumberOfBytesRead, nil);
if not Succeed then Break;
Errors := Errors + Copy(Buffer, 1, NumberOfBytesRead);
end;
finally
// nothing
end;
CloseHandle(PipeErrorsRead);
@ -199,6 +207,18 @@ begin
CloseHandle(PipeErrorsRead);
CloseHandle(PipeErrorsWrite);
end;
end;
// error management
if (Errors <> '') then begin
if (Output.Count > 1) then begin
if (Trim(Output[Output.Count -2]) = '') then
Output.Strings[Output.Count -2] := TrimRight(Errors)
else
Output.Insert(Output.Count -1, TrimRight(Errors));
end
else
Output.Add(Errors);
Output.Text := Output.Text; // pseudo-rearrangement
end;
end;
end.

View File

@ -12,17 +12,17 @@ BEGIN
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "Comments", "AMXXPC compile.exe\0"
VALUE "Comments", "SPCOMP compile.exe\0"
//VALUE "CompanyName", "AMXX Development Team\0"
VALUE "FileDescription", "AMXXPC compile.exe\0"
VALUE "FileVersion", "1.5\0"
VALUE "InternalName", "AMXXPC compile.exe\0"
VALUE "LegalCopyright", "(c) 2004-2005, AMXX Development Team\0"
VALUE "FileDescription", "SPCOMP compile.exe\0"
VALUE "FileVersion", "1.0\0"
VALUE "InternalName", "SPCOMP compile.exe\0"
VALUE "LegalCopyright", "(c) 2007, SourceMod Development Team\0"
//VALUE "LegalTrademarks", "\0"
VALUE "OriginalFilename", "compile.exe\0"
//VALUE "PrivateBuild", "\0"
VALUE "ProductName", "AMXXPC compile.exe\0"
VALUE "ProductVersion", "1.5\0"
VALUE "ProductName", "SPCOMP compile.exe\0"
VALUE "ProductVersion", "1.0\0"
//VALUE "SpecialBuild", "\0"
END
END

Binary file not shown.