94 lines
2.7 KiB
C#
94 lines
2.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Xml.Linq;
|
|
using UAF;
|
|
using UAF.WPF.Models;
|
|
|
|
namespace DataFileAnalyzer
|
|
{
|
|
/// <summary>
|
|
/// A dependency to a data file.
|
|
/// </summary>
|
|
public class DataFileDependency : ListViewItemData
|
|
{
|
|
/// <summary>
|
|
/// Normalized path of the target file
|
|
/// </summary>
|
|
public string Path { get; set; }
|
|
|
|
/// <summary>
|
|
/// Key of the target file if it exists
|
|
/// </summary>
|
|
public DataFileKey Key { get; set; }
|
|
|
|
/// <summary>
|
|
/// On which platform this dependency exists
|
|
/// </summary>
|
|
public HashSet<Platform> Platforms { get; set; }
|
|
|
|
/// <summary>
|
|
/// Constructor
|
|
/// </summary>
|
|
public DataFileDependency()
|
|
{
|
|
Key = DataFileKey.Invalid;
|
|
Platforms = new HashSet<Platform>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Save in an XML element
|
|
/// </summary>
|
|
public bool Save(XElement _element)
|
|
{
|
|
_element.SetAttributeValue("Path", Path);
|
|
DataFileKey.Save(Key, _element);
|
|
_element.SetAttributeValue("Missing", Missing);
|
|
|
|
if (Platforms.Count != 0)
|
|
{
|
|
string platformListString = string.Join(",",
|
|
Enum.GetValues(typeof (PlatformId)).Cast<PlatformId>().Select(x => new Platform(x).Name));
|
|
_element.SetAttributeValue("Platforms", platformListString);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Load from an XML element
|
|
/// </summary>
|
|
public bool Load(XElement _element)
|
|
{
|
|
bool result = true;
|
|
|
|
Path = _element.Attribute("Path").Value;
|
|
Key = DataFileKey.Load(_element);
|
|
Missing = Convert.ToBoolean(_element.Attribute("Missing").Value);
|
|
|
|
XAttribute attr = _element.Attribute("Platforms");
|
|
if (attr != null && !string.IsNullOrEmpty(attr.Value))
|
|
{
|
|
string listString = attr.Value;
|
|
foreach(string platformName in listString.Split(','))
|
|
{
|
|
Platform platform = new Platform(platformName);
|
|
result &= (platform.Id != PlatformId.UNDEFINED);
|
|
Platforms.Add(platform);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Is the dependency valid
|
|
/// </summary>
|
|
public bool IsValid { get { return !Key.IsInvalid() && !Missing; } }
|
|
|
|
/// <summary>
|
|
/// Is the dependency missing
|
|
/// </summary>
|
|
public bool Missing { get; set; }
|
|
}
|
|
}
|