2016-04-26 22:28:03 +00:00
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
|
|
using System;
|
2015-12-29 11:44:32 +00:00
|
|
|
|
using System.Drawing;
|
2012-11-02 23:11:38 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
2016-04-26 22:28:03 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
namespace CodeImp.DoomBuilder.GZBuilder.Data
|
|
|
|
|
{
|
2016-02-01 22:04:00 +00:00
|
|
|
|
public class EngineInfo : IDisposable
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2016-04-26 22:28:03 +00:00
|
|
|
|
#region ================== Constants
|
|
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
|
public const string DEFAULT_ENGINE_NAME = "Engine with no name";
|
2016-04-26 22:28:03 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
|
|
// Settings
|
2015-03-24 14:21:38 +00:00
|
|
|
|
private string testprogramname;
|
2016-04-26 22:28:03 +00:00
|
|
|
|
private string testprogram;
|
|
|
|
|
private Bitmap icon;
|
2013-09-11 09:47:53 +00:00
|
|
|
|
public string TestParameters;
|
|
|
|
|
public bool CustomParameters;
|
|
|
|
|
public int TestSkill;
|
|
|
|
|
public bool TestShortPaths;
|
2012-11-02 23:11:38 +00:00
|
|
|
|
|
2016-04-26 22:28:03 +00:00
|
|
|
|
// 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()
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2015-03-24 14:21:38 +00:00
|
|
|
|
testprogramname = DEFAULT_ENGINE_NAME;
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
2012-11-02 23:11:38 +00:00
|
|
|
|
|
2016-04-26 22:28:03 +00:00
|
|
|
|
public EngineInfo(EngineInfo other)
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2015-03-24 14:21:38 +00:00
|
|
|
|
testprogramname = other.TestProgramName;
|
2016-04-26 22:28:03 +00:00
|
|
|
|
testprogram = other.testprogram;
|
2013-09-11 09:47:53 +00:00
|
|
|
|
TestParameters = other.TestParameters;
|
|
|
|
|
CustomParameters = other.CustomParameters;
|
|
|
|
|
TestSkill = other.TestSkill;
|
|
|
|
|
TestShortPaths = other.TestShortPaths;
|
2016-04-26 22:28:03 +00:00
|
|
|
|
|
|
|
|
|
UpdateIcon();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
// Not already disposed?
|
|
|
|
|
if(!isdisposed)
|
|
|
|
|
{
|
|
|
|
|
// Clean up
|
|
|
|
|
icon.Dispose();
|
|
|
|
|
|
|
|
|
|
// Done
|
|
|
|
|
isdisposed = true;
|
|
|
|
|
}
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
2012-11-02 23:11:38 +00:00
|
|
|
|
|
2016-04-26 22:28:03 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
|
2015-03-24 14:21:38 +00:00
|
|
|
|
private void CheckProgramName()
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2016-04-26 22:28:03 +00:00
|
|
|
|
if(testprogramname == DEFAULT_ENGINE_NAME && !String.IsNullOrEmpty(testprogram))
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2016-03-04 21:21:41 +00:00
|
|
|
|
// Get engine name from path
|
2016-04-26 22:28:03 +00:00
|
|
|
|
testprogramname = Path.GetFileNameWithoutExtension(testprogram);
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
2016-04-26 22:28:03 +00:00
|
|
|
|
}
|
2015-12-29 11:44:32 +00:00
|
|
|
|
|
2016-04-26 22:28:03 +00:00
|
|
|
|
private void UpdateIcon()
|
|
|
|
|
{
|
2015-12-29 11:44:32 +00:00
|
|
|
|
if(icon != null)
|
|
|
|
|
{
|
|
|
|
|
icon.Dispose();
|
|
|
|
|
icon = null;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-26 22:28:03 +00:00
|
|
|
|
if(File.Exists(testprogram))
|
2015-12-29 11:44:32 +00:00
|
|
|
|
{
|
2016-04-26 22:28:03 +00:00
|
|
|
|
Icon i = Icon.ExtractAssociatedIcon(testprogram);
|
2016-06-19 00:09:53 +00:00
|
|
|
|
icon = new Bitmap(i != null ? i.ToBitmap() : Properties.Resources.Question);
|
2015-12-29 11:44:32 +00:00
|
|
|
|
}
|
2016-03-04 21:21:41 +00:00
|
|
|
|
else
|
2015-12-29 11:44:32 +00:00
|
|
|
|
{
|
2016-03-04 21:21:41 +00:00
|
|
|
|
icon = new Bitmap(Properties.Resources.Warning);
|
2015-12-29 11:44:32 +00:00
|
|
|
|
}
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
2016-02-01 22:04:00 +00:00
|
|
|
|
|
2016-04-26 22:28:03 +00:00
|
|
|
|
#endregion
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
2012-11-02 23:11:38 +00:00
|
|
|
|
}
|