added support for loading maps with command line arguments

This commit is contained in:
codeimp 2008-09-07 17:55:20 +00:00
parent 354a2248ee
commit e77a91eec4
3 changed files with 174 additions and 52 deletions

View file

@ -37,6 +37,7 @@ using SlimDX.Direct3D9;
using System.Drawing;
using CodeImp.DoomBuilder.Plugins;
using CodeImp.DoomBuilder.Types;
using System.Collections.ObjectModel;
#endregion
@ -129,7 +130,13 @@ namespace CodeImp.DoomBuilder
// Tools
private static Triangulator earclipper;
// Command line arguments
private static string[] cmdargs;
private static string autoloadfile = null;
private static string autoloadmap = null;
private static string autoloadconfig = null;
#endregion
#region ================== Properties
@ -140,6 +147,7 @@ namespace CodeImp.DoomBuilder
public static string ConfigsPath { get { return configspath; } }
public static string CompilersPath { get { return compilerspath; } }
public static string PluginsPath { get { return pluginspath; } }
public static ICollection<string> CommandArgs { get { return Array.AsReadOnly<string>(cmdargs); } }
internal static MainForm MainWindow { get { return mainwindow; } }
public static IMainForm Interface { get { return mainwindow; } }
public static ProgramConfiguration Settings { get { return settings; } }
@ -154,6 +162,9 @@ namespace CodeImp.DoomBuilder
public static bool DebugBuild { get { return debugbuild; } }
internal static Triangulator EarClipper { get { return earclipper; } }
internal static TypesManager Types { get { return types; } }
internal static string AutoLoadFile { get { return autoloadfile; } }
internal static string AutoLoadMap { get { return autoloadmap; } }
internal static string AutoLoadConfig { get { return autoloadconfig; } }
#endregion
@ -432,7 +443,7 @@ namespace CodeImp.DoomBuilder
{
Uri localpath;
Version thisversion;
// Determine states
#if DEBUG
debugbuild = true;
@ -470,12 +481,18 @@ namespace CodeImp.DoomBuilder
// Remove the previous log file and start logging
if(File.Exists(logfile)) File.Delete(logfile);
General.WriteLogLine("Doom Builder " + thisversion.Major + "." + thisversion.Minor + " startup");
General.WriteLogLine("Application path: " + apppath);
General.WriteLogLine("Temporary path: " + temppath);
General.WriteLogLine("Local settings path: " + settingspath);
General.WriteLogLine("Configurations path: " + configspath);
General.WriteLogLine("Compilers path: " + compilerspath);
General.WriteLogLine("Plugins path: " + pluginspath);
General.WriteLogLine("Application path: " + apppath);
General.WriteLogLine("Temporary path: " + temppath);
General.WriteLogLine("Local settings path: " + settingspath);
General.WriteLogLine("Configurations path: " + configspath);
General.WriteLogLine("Compilers path: " + compilerspath);
General.WriteLogLine("Plugins path: " + pluginspath);
General.WriteLogLine("Command-line arguments: " + args.Length);
for(int i = 0; i < args.Length; i++)
General.WriteLogLine("Argument " + i + ": \"" + args[i] + "\"");
// Parse command-line arguments
ParseCommandLineArgs(args);
// Load configuration
General.WriteLogLine("Loading program configuration...");
@ -575,6 +592,56 @@ namespace CodeImp.DoomBuilder
// End program here
Terminate(false);
}
// This parses the command line arguments
private static void ParseCommandLineArgs(string[] args)
{
// Keep a copy
cmdargs = args;
// Make a queue so we can parse the values from left to right
Queue<string> argslist = new Queue<string>(args);
// Parse list
while(argslist.Count > 0)
{
// Get next arg
string curarg = argslist.Dequeue();
// Map name info?
if(string.Compare(curarg, "-MAP", true) == 0)
{
// Store next arg as map name information
autoloadmap = argslist.Dequeue();
}
// Config name info?
else if((string.Compare(curarg, "-CFG", true) == 0) ||
(string.Compare(curarg, "-CONFIG", true) == 0))
{
// Store next arg as config filename information
autoloadconfig = argslist.Dequeue();
}
// Every other arg
else
{
// No command to load file yet?
if(autoloadfile == null)
{
// Check if this is a file we can load
if(File.Exists(curarg))
{
// Load this file!
autoloadfile = curarg.Trim();
}
else
{
// Note in the log that we cannot find this file
General.WriteLogLine("WARNING: Cannot find the specified file \"" + curarg + "\"");
}
}
}
}
}
#endregion
@ -769,44 +836,48 @@ namespace CodeImp.DoomBuilder
// Open map options dialog
openmapwindow = new OpenMapOptionsForm(filename);
if(openmapwindow.ShowDialog(mainwindow) == DialogResult.OK)
{
// Display status
mainwindow.DisplayStatus("Opening map file...");
Cursor.Current = Cursors.WaitCursor;
// Clear the display
mainwindow.ClearDisplay();
// Trash the current map, if any
if(map != null) map.Dispose();
// Create map manager with given options
map = new MapManager();
if(map.InitializeOpenMap(filename, openmapwindow.Options))
{
// Add recent file
mainwindow.AddRecentFile(filename);
}
else
{
// Unable to create map manager
map.Dispose();
map = null;
// Show splash logo on display
mainwindow.ShowSplashDisplay();
}
// All done
mainwindow.RedrawDisplay();
mainwindow.UpdateInterface();
mainwindow.HideInfo();
mainwindow.DisplayReady();
Cursor.Current = Cursors.Default;
}
OpenMapFileWithOptions(filename, openmapwindow.Options);
}
}
// This opens the specified file without dialog
internal static void OpenMapFileWithOptions(string filename, MapOptions options)
{
// Display status
mainwindow.DisplayStatus("Opening map file...");
Cursor.Current = Cursors.WaitCursor;
// Clear the display
mainwindow.ClearDisplay();
// Trash the current map, if any
if(map != null) map.Dispose();
// Create map manager with given options
map = new MapManager();
if(map.InitializeOpenMap(filename, options))
{
// Add recent file
mainwindow.AddRecentFile(filename);
}
else
{
// Unable to create map manager
map.Dispose();
map = null;
// Show splash logo on display
mainwindow.ShowSplashDisplay();
}
// All done
mainwindow.RedrawDisplay();
mainwindow.UpdateInterface();
mainwindow.HideInfo();
mainwindow.DisplayReady();
Cursor.Current = Cursors.Default;
}
// This saves the current map
// Returns tre when saved, false when cancelled or failed
[BeginAction("savemap")]

View file

@ -608,8 +608,8 @@ namespace CodeImp.DoomBuilder.Windows
this.thingfilters.Name = "thingfilters";
this.thingfilters.Size = new System.Drawing.Size(130, 25);
this.thingfilters.ToolTipText = "Things Filter";
this.thingfilters.SelectedIndexChanged += new System.EventHandler(this.thingfilters_SelectedIndexChanged);
this.thingfilters.DropDownClosed += new System.EventHandler(this.LoseFocus);
this.thingfilters.SelectedIndexChanged += new System.EventHandler(this.thingfilters_SelectedIndexChanged);
//
// toolStripSeparator8
//
@ -996,14 +996,14 @@ namespace CodeImp.DoomBuilder.Windows
this.display.Size = new System.Drawing.Size(823, 367);
this.display.TabIndex = 5;
this.display.MouseLeave += new System.EventHandler(this.display_MouseLeave);
this.display.Paint += new System.Windows.Forms.PaintEventHandler(this.display_Paint);
this.display.MouseMove += new System.Windows.Forms.MouseEventHandler(this.display_MouseMove);
this.display.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.display_MouseDoubleClick);
this.display.MouseClick += new System.Windows.Forms.MouseEventHandler(this.display_MouseClick);
this.display.MouseDown += new System.Windows.Forms.MouseEventHandler(this.display_MouseDown);
this.display.MouseMove += new System.Windows.Forms.MouseEventHandler(this.display_MouseMove);
this.display.MouseClick += new System.Windows.Forms.MouseEventHandler(this.display_MouseClick);
this.display.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.display_MouseDoubleClick);
this.display.Resize += new System.EventHandler(this.display_Resize);
this.display.MouseUp += new System.Windows.Forms.MouseEventHandler(this.display_MouseUp);
this.display.MouseEnter += new System.EventHandler(this.display_MouseEnter);
this.display.Paint += new System.Windows.Forms.PaintEventHandler(this.display_Paint);
this.display.MouseUp += new System.Windows.Forms.MouseEventHandler(this.display_MouseUp);
//
// processor
//
@ -1027,14 +1027,15 @@ namespace CodeImp.DoomBuilder.Windows
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "Doom Builder";
this.Deactivate += new System.EventHandler(this.MainForm_Deactivate);
this.Load += new System.EventHandler(this.MainForm_Load);
this.Resize += new System.EventHandler(this.MainForm_Resize);
this.Shown += new System.EventHandler(this.MainForm_Shown);
this.Activated += new System.EventHandler(this.MainForm_Activated);
this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.MainForm_KeyUp);
this.Move += new System.EventHandler(this.MainForm_Move);
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_FormClosing);
this.Resize += new System.EventHandler(this.MainForm_Resize);
this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.MainForm_KeyUp);
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.MainForm_KeyDown);
this.ResizeEnd += new System.EventHandler(this.MainForm_ResizeEnd);
this.Load += new System.EventHandler(this.MainForm_Load);
this.menumain.ResumeLayout(false);
this.menumain.PerformLayout();
this.toolbar.ResumeLayout(false);

View file

@ -33,6 +33,7 @@ using CodeImp.DoomBuilder.Map;
using System.Reflection;
using CodeImp.DoomBuilder.Plugins;
using CodeImp.DoomBuilder.Controls;
using CodeImp.DoomBuilder.IO;
#endregion
@ -174,6 +175,55 @@ namespace CodeImp.DoomBuilder.Windows
#endregion
#region ================== Window
// Window is first shown
private void MainForm_Shown(object sender, EventArgs e)
{
// Check if the command line arguments tell us to load something
if(General.AutoLoadFile != null)
{
bool showdialog = false;
MapOptions options = new MapOptions();
Configuration mapsettings;
// Any of the options already given?
if(General.AutoLoadMap != null)
{
// Try to find existing options in the settings file
string dbsfile = General.AutoLoadFile.Substring(0, General.AutoLoadFile.Length - 4) + ".dbs";
if(File.Exists(dbsfile))
try { mapsettings = new Configuration(dbsfile, true); }
catch(Exception) { mapsettings = new Configuration(true); }
else
mapsettings = new Configuration(true);
// Set map name and other options
options = new MapOptions(mapsettings, General.AutoLoadMap);
// Set configuration file (constructor already does this, but we want this info from the cmd args if possible)
options.ConfigFile = General.AutoLoadConfig;
if(options.ConfigFile == null) options.ConfigFile = mapsettings.ReadSetting("gameconfig", "");
if(options.ConfigFile.Trim().Length == 0) showdialog = true;
}
else
{
// No options given
showdialog = true;
}
// Show open map dialog?
if(showdialog)
{
// Show open dialog
General.OpenMapFile(General.AutoLoadFile);
}
else
{
// Open with options
General.OpenMapFileWithOptions(General.AutoLoadFile, options);
}
}
}
// Window is loaded
private void MainForm_Load(object sender, EventArgs e)