Better sort, fix naming collisions

This commit is contained in:
Matt Nadareski
2020-08-31 16:46:04 -07:00
parent e98039ae38
commit 0c10eaa52f
3 changed files with 18 additions and 10 deletions

View File

@@ -1415,7 +1415,7 @@ namespace SabreTools.Library.DatFiles
DatItem datItem = (DatItem)item.Clone(); DatItem datItem = (DatItem)item.Clone();
newdevs.AddRange((datItem.Machine.DeviceReferences ?? new List<ListXmlDeviceReference>()).Select(d => d.Name).ToList()); newdevs.AddRange((datItem.Machine.DeviceReferences ?? new List<ListXmlDeviceReference>()).Select(d => d.Name).ToList());
datItem.CopyMachineInformation(copyFrom); datItem.CopyMachineInformation(copyFrom);
if (Items[game].Where(i => i.Name.ToLowerInvariant() == datItem.Name.ToLowerInvariant()).Count() == 0) if (!Items[game].Contains(datItem))
{ {
foundnew = true; foundnew = true;
Items.Add(game, datItem); Items.Add(game, datItem);
@@ -1473,7 +1473,7 @@ namespace SabreTools.Library.DatFiles
newSlotOptions.AddRange(machineSlotOptions); newSlotOptions.AddRange(machineSlotOptions);
datItem.CopyMachineInformation(copyFrom); datItem.CopyMachineInformation(copyFrom);
if (Items[game].Where(i => i.Name.ToLowerInvariant() == datItem.Name.ToLowerInvariant()).Count() == 0) if (!Items[game].Contains(datItem))
{ {
foundnew = true; foundnew = true;
Items.Add(game, datItem); Items.Add(game, datItem);

View File

@@ -1226,10 +1226,15 @@ namespace SabreTools.Library.DatItems
{ {
if (x.Machine.Name == y.Machine.Name) if (x.Machine.Name == y.Machine.Name)
{ {
if (Path.GetDirectoryName(Sanitizer.RemovePathUnsafeCharacters(x.Name)) == Path.GetDirectoryName(Sanitizer.RemovePathUnsafeCharacters(y.Name))) if (x.ItemType == y.ItemType)
return nc.Compare(Path.GetFileName(Sanitizer.RemovePathUnsafeCharacters(x.Name)), Path.GetFileName(Sanitizer.RemovePathUnsafeCharacters(y.Name))); {
if (Path.GetDirectoryName(Sanitizer.RemovePathUnsafeCharacters(x.Name)) == Path.GetDirectoryName(Sanitizer.RemovePathUnsafeCharacters(y.Name)))
return nc.Compare(Path.GetFileName(Sanitizer.RemovePathUnsafeCharacters(x.Name)), Path.GetFileName(Sanitizer.RemovePathUnsafeCharacters(y.Name)));
return nc.Compare(Path.GetDirectoryName(Sanitizer.RemovePathUnsafeCharacters(x.Name)), Path.GetDirectoryName(Sanitizer.RemovePathUnsafeCharacters(y.Name))); return nc.Compare(Path.GetDirectoryName(Sanitizer.RemovePathUnsafeCharacters(x.Name)), Path.GetDirectoryName(Sanitizer.RemovePathUnsafeCharacters(y.Name)));
}
return x.ItemType - y.ItemType;
} }
return nc.Compare(x.Machine.Name, y.Machine.Name); return nc.Compare(x.Machine.Name, y.Machine.Name);

View File

@@ -453,14 +453,17 @@ namespace SabreTools.Library.DatItems
/// </summary> /// </summary>
public enum ItemType public enum ItemType
{ {
// "Actionable" item types
Rom = 0, Rom = 0,
Disk = 1, Disk = 1,
Sample = 2, Media = 2,
Release = 3,
// "Auxiliary" item types
Archive = 3,
BiosSet = 4, BiosSet = 4,
Archive = 5, Chip = 5,
Chip = 6, Release = 6,
Media = 7, Sample = 7,
Blank = 99, // This is not a real type, only used internally Blank = 99, // This is not a real type, only used internally
} }