diff --git a/sourcepawn/batchtool/compile.dpr b/sourcepawn/batchtool/compile.dpr index 8b2ba7d4..a395c37f 100644 --- a/sourcepawn/batchtool/compile.dpr +++ b/sourcepawn/batchtool/compile.dpr @@ -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 diff --git a/sourcepawn/batchtool/compile.exe b/sourcepawn/batchtool/compile.exe index fd210b68..55dbad21 100644 Binary files a/sourcepawn/batchtool/compile.exe and b/sourcepawn/batchtool/compile.exe differ diff --git a/sourcepawn/batchtool/icon.rc b/sourcepawn/batchtool/icon.rc new file mode 100644 index 00000000..983fcb2a --- /dev/null +++ b/sourcepawn/batchtool/icon.rc @@ -0,0 +1 @@ +SM ICON "pawn.ico" \ No newline at end of file diff --git a/sourcepawn/batchtool/icon.res b/sourcepawn/batchtool/icon.res new file mode 100644 index 00000000..a17f0d0e Binary files /dev/null and b/sourcepawn/batchtool/icon.res differ diff --git a/sourcepawn/batchtool/pawn.ico b/sourcepawn/batchtool/pawn.ico new file mode 100644 index 00000000..7a6ab60b Binary files /dev/null and b/sourcepawn/batchtool/pawn.ico differ diff --git a/sourcepawn/batchtool/uFunc.pas b/sourcepawn/batchtool/uFunc.pas index 13d216ed..2c98d61a 100644 --- a/sourcepawn/batchtool/uFunc.pas +++ b/sourcepawn/batchtool/uFunc.pas @@ -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. diff --git a/sourcepawn/batchtool/version.rc b/sourcepawn/batchtool/version.rc index e3d50087..fe31c692 100644 --- a/sourcepawn/batchtool/version.rc +++ b/sourcepawn/batchtool/version.rc @@ -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 diff --git a/sourcepawn/batchtool/version.res b/sourcepawn/batchtool/version.res index f4beb148..f9dcebeb 100644 Binary files a/sourcepawn/batchtool/version.res and b/sourcepawn/batchtool/version.res differ