Fixed, Game configurations window: new test engine entry was still added when pressing "New Test Engine" button, then canceling the browse dialog.

Fixed, general interface: in some cases opening "Test Map" drop-down resulted in an exception when trying to access a disposed/non-existing test engine icon.
This commit is contained in:
MaxED 2016-04-26 22:28:03 +00:00 committed by spherallic
parent b7fbb443e2
commit 6982133004
2 changed files with 92 additions and 52 deletions

View File

@ -1,64 +1,105 @@
using System;
#region ================== Namespaces
using System;
using System.Drawing;
using System.IO;
#endregion
namespace CodeImp.DoomBuilder.GZBuilder.Data
{
public class EngineInfo : IDisposable
{
// Disposing
private bool isdisposed;
#region ================== Constants
public const string DEFAULT_ENGINE_NAME = "Engine with no name";
public const string DEFAULT_ENGINE_NAME = "Engine with no name";
#endregion
#region ================== Variables
// Settings
private string testprogramname;
public string TestProgramName { get { return testprogramname; } set { testprogramname = value; CheckProgramName(); } }
public string TestProgram;
private string testprogram;
private Bitmap icon;
public string TestParameters;
public bool CustomParameters;
public int TestSkill;
public string TestSkin;
public int TestGametype;
public bool TestShortPaths;
private Bitmap icon;
public Bitmap TestProgramIcon { get { return icon; } }
public EngineInfo()
// Disposing
private bool isdisposed;
#endregion
#region ================== Properties
public string TestProgramName { get { return testprogramname; } set { testprogramname = value; CheckProgramName(); } }
public string TestProgram { get { return testprogram; } set { testprogram = value; CheckProgramName(); } }
public Bitmap TestProgramIcon { get { if(icon == null) UpdateIcon(); return icon; } }
#endregion
#region ================== Constructors / Disposer
public EngineInfo()
{
testprogramname = DEFAULT_ENGINE_NAME;
}
public EngineInfo(EngineInfo other)
public EngineInfo(EngineInfo other)
{
testprogramname = other.TestProgramName;
TestProgram = other.TestProgram;
testprogram = other.testprogram;
TestParameters = other.TestParameters;
CustomParameters = other.CustomParameters;
TestSkill = other.TestSkill;
TestSkin = other.TestSkin;
TestGametype = other.TestGametype;
TestShortPaths = other.TestShortPaths;
icon = other.icon;
UpdateIcon();
}
public void Dispose()
{
// Not already disposed?
if(!isdisposed)
{
// Clean up
icon.Dispose();
// Done
isdisposed = true;
}
}
#endregion
#region ================== Methods
private void CheckProgramName()
{
if(testprogramname == DEFAULT_ENGINE_NAME && !String.IsNullOrEmpty(TestProgram))
if(testprogramname == DEFAULT_ENGINE_NAME && !String.IsNullOrEmpty(testprogram))
{
// Get engine name from path
testprogramname = Path.GetFileNameWithoutExtension(TestProgram);
testprogramname = Path.GetFileNameWithoutExtension(testprogram);
}
}
// Update icon
private void UpdateIcon()
{
if(icon != null)
{
icon.Dispose();
icon = null;
}
if(File.Exists(TestProgram))
if(File.Exists(testprogram))
{
Icon i = Icon.ExtractAssociatedIcon(TestProgram);
Icon i = Icon.ExtractAssociatedIcon(testprogram);
icon = (i != null ? i.ToBitmap() : new Bitmap(Properties.Resources.Question));
}
else
@ -67,17 +108,6 @@ namespace CodeImp.DoomBuilder.GZBuilder.Data
}
}
public void Dispose()
{
// Not already disposed?
if (!isdisposed)
{
// Clean up
icon.Dispose();
// Done
isdisposed = true;
}
}
}
#endregion
}
}

View File

@ -746,31 +746,41 @@ namespace CodeImp.DoomBuilder.Windows
//mxd
private void btnNewEngine_Click(object sender, EventArgs e)
{
preventchanges = true;
EngineInfo newInfo = new EngineInfo();
newInfo.TestSkill = (int)Math.Ceiling(gameconfig.Skills.Count / 2f); //set Medium skill level
newInfo.TestSkin = "Sonic";
newInfo.TestGametype = -1; //Single player
configinfo.TestEngines.Add(newInfo);
configinfo.Changed = true;
//store current engine name
if(!String.IsNullOrEmpty(cbEngineSelector.Text))
configinfo.TestProgramName = cbEngineSelector.Text;
// Set initial directory?
if(testapplication.Text.Length > 0)
{
try { testprogramdialog.InitialDirectory = Path.GetDirectoryName(testapplication.Text); }
catch(Exception) { }
}
//refresh engines list
cbEngineSelector.Items.Clear();
foreach(EngineInfo info in configinfo.TestEngines)
cbEngineSelector.Items.Add(info.TestProgramName);
// Browse for test program
if(testprogramdialog.ShowDialog() == DialogResult.OK)
{
preventchanges = true;
cbEngineSelector.SelectedIndex = configinfo.TestEngines.Count - 1;
btnRemoveEngine.Enabled = true;
// Add new EngineInfo
EngineInfo newInfo = new EngineInfo();
newInfo.TestSkill = (int)Math.Ceiling(gameconfig.Skills.Count / 2f); // Set Medium skill level
configinfo.TestEngines.Add(newInfo);
configinfo.Changed = true;
preventchanges = false;
// Store current engine name
if(!String.IsNullOrEmpty(cbEngineSelector.Text))
configinfo.TestProgramName = cbEngineSelector.Text;
// Open engine browser
browsetestprogram_Click(this, EventArgs.Empty);
// Refresh engines list
cbEngineSelector.Items.Clear();
foreach(EngineInfo info in configinfo.TestEngines)
cbEngineSelector.Items.Add(info.TestProgramName);
cbEngineSelector.SelectedIndex = configinfo.TestEngines.Count - 1;
btnRemoveEngine.Enabled = true;
preventchanges = false;
// Set engine path
testapplication.Text = testprogramdialog.FileName;
}
}
//mxd