From 04d21101cfaf610ce59c60e2ef72f12a09dbd9be Mon Sep 17 00:00:00 2001 From: codeimp Date: Fri, 28 Sep 2007 08:56:18 +0000 Subject: [PATCH] miauw. --- Build/Compilers/glBSP.cfg | 28 ++++++ Source/Builder.csproj | 1 + Source/General/General.cs | 65 ++++++++++++-- Source/General/NodebuilderInfo.cs | 113 ++++++++++++++++++++++++ Source/Interface/ConfigForm.Designer.cs | 1 + Source/Interface/ConfigForm.cs | 13 +++ 6 files changed, 216 insertions(+), 5 deletions(-) create mode 100644 Build/Compilers/glBSP.cfg create mode 100644 Source/General/NodebuilderInfo.cs diff --git a/Build/Compilers/glBSP.cfg b/Build/Compilers/glBSP.cfg new file mode 100644 index 00000000..75838686 --- /dev/null +++ b/Build/Compilers/glBSP.cfg @@ -0,0 +1,28 @@ + +// How to display the nodebuilder name +title = "glBSP"; + +// Parameter placeholders: +// %F is the WAD file where the nodebuilder must read from +// %T is the WAD file to which the nodebuilde writes its output (optional) + +// Settings used when saving a map +savemap +{ + compiler = "glBSP.exe"; + parameters = "%F -o %T"; +} + +// Settings used when testing a map +testmap +{ + compiler = "glBSP.exe"; + parameters = "%F -o %T"; +} + +// Settings used when using 3D mode +mode3dbuild +{ + compiler = "glBSP.exe"; + parameters = "-normal -noreject -v5 -factor 1 %F -o %T"; +} diff --git a/Source/Builder.csproj b/Source/Builder.csproj index 78c52e0d..c68f5b7b 100644 --- a/Source/Builder.csproj +++ b/Source/Builder.csproj @@ -54,6 +54,7 @@ + diff --git a/Source/General/General.cs b/Source/General/General.cs index 5fabba6f..49e213ae 100644 --- a/Source/General/General.cs +++ b/Source/General/General.cs @@ -82,6 +82,7 @@ namespace CodeImp.DoomBuilder // Files and Folders private const string SETTINGS_CONFIG_FILE = "Builder.cfg"; private const string GAME_CONFIGS_DIR = "Configurations"; + private const string COMPILERS_DIR = "Compilers"; #endregion @@ -91,6 +92,7 @@ namespace CodeImp.DoomBuilder private static string apppath; private static string temppath; private static string configspath; + private static string compilerspath; // Main objects private static Assembly thisasm; @@ -101,6 +103,7 @@ namespace CodeImp.DoomBuilder // Configurations private static List configs; + private static List nodebuilders; #endregion @@ -110,9 +113,11 @@ namespace CodeImp.DoomBuilder public static string AppPath { get { return apppath; } } public static string TempPath { get { return temppath; } } public static string ConfigsPath { get { return configspath; } } + public static string CompilersPath { get { return compilerspath; } } public static MainForm MainWindow { get { return mainwindow; } } public static Configuration Settings { get { return settings; } } public static List Configs { get { return configs; } } + public static List Nodebuilders { get { return nodebuilders; } } public static MapManager Map { get { return map; } } public static ActionManager Actions { get { return actions; } } @@ -198,8 +203,8 @@ namespace CodeImp.DoomBuilder // Make array configs = new List(); - - // Go for all files in the configurations directory + + // Go for all cfg files in the configurations directory filenames = Directory.GetFiles(configspath, "*.cfg", SearchOption.TopDirectoryOnly); foreach(string filepath in filenames) { @@ -220,6 +225,53 @@ namespace CodeImp.DoomBuilder configs.Sort(); } + // This finds all nodebuilder configurations + private static void FindNodebuilderConfigurations() + { + Configuration cfg; + string[] filenames; + + // Display status + mainwindow.DisplayStatus("Loading nodebuilder configurations..."); + + // Make array + nodebuilders = new List(); + + // Go for all cfg files in the compilers directory + filenames = Directory.GetFiles(compilerspath, "*.cfg", SearchOption.TopDirectoryOnly); + foreach(string filepath in filenames) + { + try + { + // Try loading the configuration + cfg = new Configuration(filepath, true); + + // Check for erors + if(cfg.ErrorResult != 0) + { + // Error in configuration + MessageBox.Show(mainwindow, "Unable to load the nodebuilder configuration file \"" + filepath + "\".\n" + + "Error near line " + cfg.ErrorLine + ": " + cfg.ErrorDescription, + Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); + } + else + { + // Make nodebuilder info + nodebuilders.Add(new NodebuilderInfo(cfg)); + } + } + catch(Exception) + { + // Unable to load configuration + MessageBox.Show(mainwindow, "Unable to load the nodebuilder configuration file \"" + filepath + "\".", + Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + // Sort the configurations list + configs.Sort(); + } + #endregion #region ================== Startup @@ -237,11 +289,10 @@ namespace CodeImp.DoomBuilder localpath = new Uri(Path.GetDirectoryName(thisasm.GetName().CodeBase)); apppath = Uri.UnescapeDataString(localpath.AbsolutePath); - // Temporary directory + // Setup directories temppath = Path.GetTempPath(); - - // Configurations directory configspath = Path.Combine(apppath, GAME_CONFIGS_DIR); + compilerspath = Path.Combine(apppath, COMPILERS_DIR); // Load configuration if(!File.Exists(Path.Combine(apppath, SETTINGS_CONFIG_FILE))) throw (new FileNotFoundException("Unable to find the program configuration \"" + SETTINGS_CONFIG_FILE + "\".")); @@ -263,6 +314,9 @@ namespace CodeImp.DoomBuilder // Load game configurations FindGameConfigurations(); + + // Load nodebuilder configurations + FindNodebuilderConfigurations(); // Run application from the main window mainwindow.DisplayReady(); @@ -482,3 +536,4 @@ namespace CodeImp.DoomBuilder #endregion } } + diff --git a/Source/General/NodebuilderInfo.cs b/Source/General/NodebuilderInfo.cs new file mode 100644 index 00000000..429f3bce --- /dev/null +++ b/Source/General/NodebuilderInfo.cs @@ -0,0 +1,113 @@ + +#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; +using System.Collections; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using CodeImp.DoomBuilder.IO; +using CodeImp.DoomBuilder.Images; +using System.IO; +using System.Diagnostics; + +#endregion + +namespace CodeImp.DoomBuilder +{ + internal class NodebuilderInfo : IComparable + { + #region ================== Constants + + #endregion + + #region ================== Variables + + private string name; + private ProcessStartInfo savemapprocess; + private ProcessStartInfo testmapprocess; + private ProcessStartInfo mode3dbuildprocess; + + #endregion + + #region ================== Properties + + public string Name { get { return name; } } + public ProcessStartInfo SaveMapProcess { get { return savemapprocess; } } + public ProcessStartInfo TestMapProcess { get { return testmapprocess; } } + public ProcessStartInfo Mode3DBuildProcess { get { return mode3dbuildprocess; } } + + #endregion + + #region ================== Constructor / Disposer + + // Constructor + public NodebuilderInfo(Configuration cfg) + { + // Initialize + this.name = cfg.ReadSetting("title", ""); + + // Setup save map process + SetupProcess(out savemapprocess, + cfg.ReadSetting("savemap.compiler", ""), + cfg.ReadSetting("savemap.parameters", "")); + + // Setup test map process + SetupProcess(out testmapprocess, + cfg.ReadSetting("testmap.compiler", ""), + cfg.ReadSetting("testmap.parameters", "")); + + // Setup 3d build process + SetupProcess(out mode3dbuildprocess, + cfg.ReadSetting("mode3dbuild.compiler", ""), + cfg.ReadSetting("mode3dbuild.parameters", "")); + } + + // This sets up a process + private void SetupProcess(out ProcessStartInfo processinfo, string compiler, string parameters) + { + processinfo = new ProcessStartInfo(); + processinfo.Arguments = parameters; + processinfo.FileName = Path.Combine(General.CompilersPath, compiler); + processinfo.CreateNoWindow = false; + processinfo.ErrorDialog = false; + processinfo.UseShellExecute = true; + processinfo.WindowStyle = ProcessWindowStyle.Hidden; + processinfo.WorkingDirectory = General.TempPath; + } + + #endregion + + #region ================== Methods + + // This compares it to other ConfigurationInfo objects + public int CompareTo(NodebuilderInfo other) + { + // Compare + return name.CompareTo(other.name); + } + + // String representation + public override string ToString() + { + return name; + } + + #endregion + } +} diff --git a/Source/Interface/ConfigForm.Designer.cs b/Source/Interface/ConfigForm.Designer.cs index fee3cb9c..eba9df65 100644 --- a/Source/Interface/ConfigForm.Designer.cs +++ b/Source/Interface/ConfigForm.Designer.cs @@ -205,6 +205,7 @@ namespace CodeImp.DoomBuilder.Interface this.listconfigs.Size = new System.Drawing.Size(215, 300); this.listconfigs.Sorted = true; this.listconfigs.TabIndex = 0; + this.listconfigs.SelectedIndexChanged += new System.EventHandler(this.listconfigs_SelectedIndexChanged); // // cancel // diff --git a/Source/Interface/ConfigForm.cs b/Source/Interface/ConfigForm.cs index 0478e75c..ffc1b0b7 100644 --- a/Source/Interface/ConfigForm.cs +++ b/Source/Interface/ConfigForm.cs @@ -43,6 +43,19 @@ namespace CodeImp.DoomBuilder.Interface // Add a copy listconfigs.Items.Add(ci.Clone()); } + + // Fill list of nodebuilders + confignodebuilder.Items.AddRange(General.Nodebuilders.ToArray()); } + + #region ================== Configuration Panel + + // Configuration item selected + private void listconfigs_SelectedIndexChanged(object sender, EventArgs e) + { + + } + + #endregion } } \ No newline at end of file