Get diff of two rom sets

This commit is contained in:
Matt Nadareski
2016-04-19 15:41:06 -07:00
parent 45a1fc37a0
commit b02e7bbce1

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Xml; using System.Xml;
@@ -8,6 +9,25 @@ namespace SabreTools.Helper
{ {
public class RomManipulation public class RomManipulation
{ {
/// <summary>
/// Return if the file is XML or not
/// </summary>
/// <param name="filename">Name of the file to be parsed</param>
/// <returns>True if the file is XML, false otherwise</returns>
public static bool IsXmlDat(string filename)
{
XmlDocument doc = new XmlDocument();
try
{
doc.LoadXml(File.ReadAllText(filename));
}
catch (XmlException)
{
return false;
}
return true;
}
/// <summary> /// <summary>
/// Parse a DAT and return all found games and roms within /// Parse a DAT and return all found games and roms within
/// </summary> /// </summary>
@@ -304,18 +324,16 @@ namespace SabreTools.Helper
}); });
} }
public static bool IsXmlDat(string filename) /// <summary>
/// Get differences between two lists of RomData objects
/// </summary>
/// <param name="A">First RomData list</param>
/// <param name="B">Second RomData list</param>
/// <returns>Any rom that's not in both lists</returns>
/// <remarks>Adapted from http://stackoverflow.com/questions/5620266/the-opposite-of-intersect</remarks>
public static List<RomData> Diff(List<RomData> A, List<RomData> B)
{ {
XmlDocument doc = new XmlDocument(); return A.Except(B).Union(B.Except(A)).ToList();
try
{
doc.LoadXml(File.ReadAllText(filename));
}
catch (XmlException)
{
return false;
}
return true;
} }
} }
} }