2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#region ================== Copyright (c) 2007 Pascal vd Heiden
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
|
|
|
* This program is released under GNU General Public License
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
using System;
|
2016-05-12 13:56:25 +00:00
|
|
|
using System.Collections.Generic;
|
2009-04-19 18:07:22 +00:00
|
|
|
using System.Diagnostics;
|
|
|
|
using System.IO;
|
|
|
|
using CodeImp.DoomBuilder.Config;
|
|
|
|
using System.Windows.Forms;
|
|
|
|
using System.Text.RegularExpressions;
|
2015-11-30 14:18:42 +00:00
|
|
|
using CodeImp.DoomBuilder.Data;
|
2016-05-12 13:56:25 +00:00
|
|
|
using CodeImp.DoomBuilder.ZDoom.Scripting;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Compilers
|
|
|
|
{
|
|
|
|
internal sealed class AccCompiler : Compiler
|
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
|
|
|
private const string ACS_ERROR_FILE = "acs.err";
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
2016-05-12 13:56:25 +00:00
|
|
|
|
|
|
|
private AcsParserSE parser; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
2016-05-12 13:56:25 +00:00
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
public bool SourceIsMapScriptsLump; //mxd
|
|
|
|
internal AcsParserSE Parser { get { return parser; } } //mxd
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
#region ================== Constructor
|
|
|
|
|
|
|
|
// Constructor
|
2015-12-17 10:07:28 +00:00
|
|
|
public AccCompiler(CompilerInfo info) : base(info, false)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disposer
|
|
|
|
public override void Dispose()
|
|
|
|
{
|
|
|
|
// Not already disposed?
|
|
|
|
if(!isdisposed)
|
|
|
|
{
|
|
|
|
// Clean up
|
|
|
|
|
|
|
|
// Done
|
|
|
|
base.Dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
|
|
|
// This runs the compiler
|
|
|
|
public override bool Run()
|
|
|
|
{
|
|
|
|
Process process;
|
|
|
|
int line = 0;
|
|
|
|
string sourcedir = Path.GetDirectoryName(sourcefile);
|
2013-03-29 11:24:30 +00:00
|
|
|
|
2016-05-12 13:56:25 +00:00
|
|
|
// Preprocess the file
|
|
|
|
parser = new AcsParserSE
|
|
|
|
{
|
2016-05-31 23:57:41 +00:00
|
|
|
IsMapScriptsLump = SourceIsMapScriptsLump,
|
2016-05-12 13:56:25 +00:00
|
|
|
OnInclude = delegate(AcsParserSE se, string includefile, AcsParserSE.IncludeType includetype)
|
|
|
|
{
|
|
|
|
TextResourceData data = General.Map.Data.GetTextResourceData(includefile);
|
|
|
|
if(data == null)
|
|
|
|
{
|
2016-05-31 23:57:41 +00:00
|
|
|
se.ReportError("Unable to find include file \"" + includefile + "\".");
|
2016-05-30 00:18:22 +00:00
|
|
|
return false; // Fial
|
2016-05-12 13:56:25 +00:00
|
|
|
}
|
2016-05-30 00:18:22 +00:00
|
|
|
|
|
|
|
return se.Parse(data, true, includetype, false);
|
2016-05-12 13:56:25 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
string inputfilepath = Path.Combine(this.tempdir.FullName, inputfile);
|
|
|
|
using(FileStream stream = File.OpenRead(inputfilepath))
|
|
|
|
{
|
2016-05-29 00:38:55 +00:00
|
|
|
// Map SCRIPTS lump is empty. Abort the process without generating any warnings or errors.
|
|
|
|
if(SourceIsMapScriptsLump && stream.Length == 0) return false;
|
2016-05-30 00:18:22 +00:00
|
|
|
|
2022-09-18 17:54:53 +00:00
|
|
|
DataLocation dl = new DataLocation(DataLocation.RESOURCE_DIRECTORY, Path.GetDirectoryName(inputfilepath), false, false, false, null);
|
2016-05-31 23:57:41 +00:00
|
|
|
//mxd. TextResourceData must point to temp path when compiling WAD lumps for lump to be recognized as map lump when reporting errors...
|
2016-11-24 21:09:24 +00:00
|
|
|
TextResourceData data = new TextResourceData(stream, dl, (SourceIsMapScriptsLump ? inputfile : sourcefile));
|
2016-05-12 13:56:25 +00:00
|
|
|
if(!parser.Parse(data, info.Files, true, AcsParserSE.IncludeType.NONE, false))
|
|
|
|
{
|
|
|
|
// Check for errors
|
|
|
|
if(parser.HasError) ReportError(new CompilerError(parser.ErrorDescription, parser.ErrorSource, parser.ErrorLine));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//mxd. External lumps should be libraries
|
|
|
|
if(!SourceIsMapScriptsLump && !parser.IsLibrary)
|
|
|
|
{
|
2016-05-31 23:57:41 +00:00
|
|
|
ReportError(new CompilerError("External ACS files can only be compiled as libraries.", sourcefile));
|
2016-05-12 13:56:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//mxd. Update script names if we are compiling the map SCRIPTS lump
|
|
|
|
if(SourceIsMapScriptsLump)
|
|
|
|
{
|
|
|
|
General.Map.UpdateScriptNames(parser);
|
|
|
|
}
|
|
|
|
|
2013-04-01 11:06:01 +00:00
|
|
|
//xabis
|
2013-03-29 11:24:30 +00:00
|
|
|
// Copy includes from the resources into the compiler's folder, preserving relative pathing and naming
|
2016-05-12 13:56:25 +00:00
|
|
|
HashSet<string> includes = parser.GetIncludes(); //mxd
|
|
|
|
foreach(string include in includes)
|
2014-12-03 23:15:26 +00:00
|
|
|
{
|
2016-05-12 13:56:25 +00:00
|
|
|
// Grab the script text from the resources
|
|
|
|
TextResourceData data = General.Map.Data.GetTextResourceData(include);
|
|
|
|
if(data != null && data.Stream != null)
|
2014-12-03 23:15:26 +00:00
|
|
|
{
|
2016-05-12 13:56:25 +00:00
|
|
|
// Pull the pk3 or directory sub folder out if applicable
|
|
|
|
FileInfo fi = new FileInfo(Path.Combine(this.tempdir.FullName, include));
|
2013-03-29 11:24:30 +00:00
|
|
|
|
2016-05-12 13:56:25 +00:00
|
|
|
// Do not allow files to be overwritten, either accidentally or maliciously
|
|
|
|
if(!fi.Exists)
|
|
|
|
{
|
|
|
|
General.WriteLogLine("Copying script include: " + include);
|
2015-11-30 14:18:42 +00:00
|
|
|
|
2016-05-12 13:56:25 +00:00
|
|
|
// Create the directory path as needed
|
|
|
|
if(!string.IsNullOrEmpty(fi.DirectoryName)) Directory.CreateDirectory(fi.DirectoryName);
|
2013-03-29 11:24:30 +00:00
|
|
|
|
2016-05-12 13:56:25 +00:00
|
|
|
// Dump the script into the target file
|
|
|
|
BinaryReader reader = new BinaryReader(data.Stream);
|
|
|
|
File.WriteAllBytes(fi.FullName, reader.ReadBytes((int)data.Stream.Length));
|
2013-03-29 11:24:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Create parameters
|
|
|
|
string args = this.parameters;
|
|
|
|
args = args.Replace("%FI", inputfile);
|
|
|
|
args = args.Replace("%FO", outputfile);
|
|
|
|
args = args.Replace("%FS", sourcefile);
|
|
|
|
args = args.Replace("%PT", this.tempdir.FullName);
|
|
|
|
args = args.Replace("%PS", sourcedir);
|
2013-08-23 13:28:55 +00:00
|
|
|
args = args.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); //mxd. This fixes include path when the map is in a root directory
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Setup process info
|
2015-11-13 21:42:41 +00:00
|
|
|
ProcessStartInfo processinfo = new ProcessStartInfo();
|
2009-04-19 18:07:22 +00:00
|
|
|
processinfo.Arguments = args;
|
2014-05-15 13:16:30 +00:00
|
|
|
processinfo.FileName = Path.Combine(info.Path, info.ProgramFile); //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
processinfo.CreateNoWindow = false;
|
|
|
|
processinfo.ErrorDialog = false;
|
|
|
|
processinfo.UseShellExecute = true;
|
|
|
|
processinfo.WindowStyle = ProcessWindowStyle.Hidden;
|
|
|
|
processinfo.WorkingDirectory = this.workingdir;
|
|
|
|
|
|
|
|
// Output info
|
|
|
|
General.WriteLogLine("Running compiler...");
|
|
|
|
General.WriteLogLine("Program: " + processinfo.FileName);
|
|
|
|
General.WriteLogLine("Arguments: " + processinfo.Arguments);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Start the compiler
|
|
|
|
process = Process.Start(processinfo);
|
|
|
|
}
|
|
|
|
catch(Exception e)
|
|
|
|
{
|
|
|
|
// Unable to start the compiler
|
|
|
|
General.ShowErrorMessage("Unable to start the compiler (" + info.Name + "). " + e.GetType().Name + ": " + e.Message, MessageBoxButtons.OK);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait for compiler to complete
|
|
|
|
process.WaitForExit();
|
2015-12-27 21:54:50 +00:00
|
|
|
TimeSpan deltatime = TimeSpan.FromTicks(process.ExitTime.Ticks - process.StartTime.Ticks);
|
2009-04-19 18:07:22 +00:00
|
|
|
General.WriteLogLine("Compiler process has finished.");
|
|
|
|
General.WriteLogLine("Compile time: " + deltatime.TotalSeconds.ToString("########0.00") + " seconds");
|
|
|
|
|
|
|
|
// Now find the error file
|
|
|
|
string errfile = Path.Combine(this.workingdir, ACS_ERROR_FILE);
|
|
|
|
if(File.Exists(errfile))
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Regex to find error lines
|
|
|
|
Regex errlinematcher = new Regex(":[0-9]+: ", RegexOptions.Compiled | RegexOptions.CultureInvariant);
|
|
|
|
|
|
|
|
// Read all lines
|
2015-11-24 10:46:49 +00:00
|
|
|
bool erroradded = false; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
string[] errlines = File.ReadAllLines(errfile);
|
2016-05-31 23:57:41 +00:00
|
|
|
string temppath = this.tempdir.FullName + Path.DirectorySeparatorChar.ToString(); //mxd. Need trailing slash..
|
2009-04-19 18:07:22 +00:00
|
|
|
while(line < errlines.Length)
|
|
|
|
{
|
|
|
|
// Check line
|
|
|
|
string linestr = errlines[line];
|
|
|
|
Match match = errlinematcher.Match(linestr);
|
|
|
|
if(match.Success && (match.Index > 0))
|
|
|
|
{
|
|
|
|
CompilerError err = new CompilerError();
|
|
|
|
|
|
|
|
// The match without spaces and semicolon is the line number
|
|
|
|
string linenr = match.Value.Replace(":", "").Trim();
|
|
|
|
if(!int.TryParse(linenr, out err.linenumber))
|
|
|
|
err.linenumber = CompilerError.NO_LINE_NUMBER;
|
|
|
|
else
|
|
|
|
err.linenumber--;
|
|
|
|
|
|
|
|
// Everything before the match is the filename
|
2015-11-30 14:18:42 +00:00
|
|
|
err.filename = linestr.Substring(0, match.Index).Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
|
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
|
|
|
|
|
|
|
//mxd. Get rid of temp directory path
|
2016-05-31 23:57:41 +00:00
|
|
|
if(err.filename.StartsWith(temppath)) err.filename = err.filename.Replace(temppath, string.Empty);
|
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
if(!Path.IsPathRooted(err.filename))
|
|
|
|
{
|
2015-11-30 14:18:42 +00:00
|
|
|
//mxd. If the error is in an include file, try to find it in loaded resources
|
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
|
|
|
if(includes.Contains(err.filename))
|
2015-11-30 14:18:42 +00:00
|
|
|
{
|
|
|
|
foreach(DataReader dr in General.Map.Data.Containers)
|
|
|
|
{
|
|
|
|
if(dr is DirectoryReader && dr.FileExists(err.filename))
|
|
|
|
{
|
|
|
|
err.filename = Path.Combine(dr.Location.location, err.filename);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Add working directory to filename, so it could be recognized as map namespace lump in MapManager.CompileLump()
|
|
|
|
err.filename = Path.Combine(processinfo.WorkingDirectory, err.filename);
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Everything after the match is the description
|
|
|
|
err.description = linestr.Substring(match.Index + match.Length).Trim();
|
|
|
|
|
|
|
|
// Report the error
|
|
|
|
ReportError(err);
|
2015-11-24 10:46:49 +00:00
|
|
|
erroradded = true; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Next line
|
|
|
|
line++;
|
|
|
|
}
|
2015-11-24 10:46:49 +00:00
|
|
|
|
|
|
|
//mxd. Some ACC errors are not properly formatted. If that's the case, threat the whole acs.err as an error...
|
|
|
|
if(!erroradded && errlines.Length > 0)
|
|
|
|
{
|
|
|
|
ReportError(new CompilerError(string.Join(Environment.NewLine, errlines)));
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
catch(Exception e)
|
|
|
|
{
|
|
|
|
// Error reading errors (ironic, isn't it)
|
|
|
|
ReportError(new CompilerError("Failed to retrieve compiler error report. " + e.GetType().Name + ": " + e.Message));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
2016-05-12 13:56:25 +00:00
|
|
|
}
|