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;
|
2014-12-22 21:36:49 +00:00
|
|
|
using System.IO;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Data
|
|
|
|
{
|
2011-07-26 20:06:38 +00:00
|
|
|
public struct DataLocation : IComparable<DataLocation>, IComparable, IEquatable<DataLocation>
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Constants
|
|
|
|
public const int RESOURCE_WAD = 0;
|
|
|
|
public const int RESOURCE_DIRECTORY = 1;
|
|
|
|
public const int RESOURCE_PK3 = 2;
|
|
|
|
|
|
|
|
// Members
|
|
|
|
public int type;
|
|
|
|
public string location;
|
2016-02-06 23:54:58 +00:00
|
|
|
private string name; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
public bool option1;
|
|
|
|
public bool option2;
|
2009-07-02 14:15:47 +00:00
|
|
|
public bool notfortesting;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Constructor
|
2009-07-02 14:15:47 +00:00
|
|
|
public DataLocation(int type, string location, bool option1, bool option2, bool notfortesting)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Initialize
|
|
|
|
this.type = type;
|
|
|
|
this.location = location;
|
|
|
|
this.option1 = option1;
|
|
|
|
this.option2 = option2;
|
2009-07-02 14:15:47 +00:00
|
|
|
this.notfortesting = notfortesting;
|
2016-02-06 23:54:58 +00:00
|
|
|
this.name = string.Empty; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This displays the struct as string
|
|
|
|
public override string ToString()
|
|
|
|
{
|
|
|
|
// Simply show location
|
|
|
|
return location;
|
|
|
|
}
|
|
|
|
|
2016-02-06 23:54:58 +00:00
|
|
|
//mxd. This returns short location name
|
|
|
|
public string GetShortName()
|
|
|
|
{
|
|
|
|
if(string.IsNullOrEmpty(name))
|
|
|
|
{
|
|
|
|
// Make shorter name for display purposes
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case RESOURCE_DIRECTORY:
|
|
|
|
name = location.Substring(location.LastIndexOf(Path.DirectorySeparatorChar) + 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RESOURCE_WAD:
|
|
|
|
case RESOURCE_PK3:
|
|
|
|
name = Path.GetFileName(location);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw new NotImplementedException("Unknown location type: " + type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-22 08:04:06 +00:00
|
|
|
return (name ?? string.Empty);
|
2016-02-06 23:54:58 +00:00
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// This compares two locations
|
|
|
|
public int CompareTo(DataLocation other)
|
|
|
|
{
|
|
|
|
return string.Compare(this.location, other.location, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This compares two locations
|
|
|
|
public int CompareTo(object obj)
|
|
|
|
{
|
|
|
|
return string.Compare(this.location, ((DataLocation)obj).location, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This compares two locations
|
|
|
|
public bool Equals(DataLocation other)
|
|
|
|
{
|
|
|
|
return (this.CompareTo(other) == 0);
|
|
|
|
}
|
2014-12-22 21:36:49 +00:00
|
|
|
|
|
|
|
//mxd
|
|
|
|
public bool IsValid()
|
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case RESOURCE_DIRECTORY:
|
|
|
|
if(!Directory.Exists(location)) return false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RESOURCE_WAD:
|
|
|
|
case RESOURCE_PK3:
|
|
|
|
if(!File.Exists(location)) return false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2016-02-06 23:54:58 +00:00
|
|
|
throw new NotImplementedException("Unknown location type: " + type);
|
2014-12-22 21:36:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|