mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Fix ordering issue by source
This commit is contained in:
@@ -1123,12 +1123,13 @@ namespace SabreTools.DatFiles
|
|||||||
/// <returns>True if it sorted correctly, false otherwise</returns>
|
/// <returns>True if it sorted correctly, false otherwise</returns>
|
||||||
private static bool Sort(ref List<DatItem> items, bool norename)
|
private static bool Sort(ref List<DatItem> items, bool norename)
|
||||||
{
|
{
|
||||||
|
// Create the comparer extenal to the delegate
|
||||||
|
var nc = new NaturalComparer();
|
||||||
|
|
||||||
items.Sort(delegate (DatItem x, DatItem y)
|
items.Sort(delegate (DatItem x, DatItem y)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var nc = new NaturalComparer();
|
|
||||||
|
|
||||||
// If machine names don't match
|
// If machine names don't match
|
||||||
string? xMachineName = x.GetMachine()?.GetName();
|
string? xMachineName = x.GetMachine()?.GetName();
|
||||||
string? yMachineName = y.GetMachine()?.GetName();
|
string? yMachineName = y.GetMachine()?.GetName();
|
||||||
@@ -1176,12 +1177,13 @@ namespace SabreTools.DatFiles
|
|||||||
/// <returns>True if it sorted correctly, false otherwise</returns>
|
/// <returns>True if it sorted correctly, false otherwise</returns>
|
||||||
private static bool SortDB(ref List<KeyValuePair<long, DatItem>> mappings, bool norename)
|
private static bool SortDB(ref List<KeyValuePair<long, DatItem>> mappings, bool norename)
|
||||||
{
|
{
|
||||||
|
// Create the comparer extenal to the delegate
|
||||||
|
var nc = new NaturalComparer();
|
||||||
|
|
||||||
mappings.Sort(delegate (KeyValuePair<long, DatItem> x, KeyValuePair<long, DatItem> y)
|
mappings.Sort(delegate (KeyValuePair<long, DatItem> x, KeyValuePair<long, DatItem> y)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var nc = new NaturalComparer();
|
|
||||||
|
|
||||||
// TODO: Fix this since DB uses an external map for machines
|
// TODO: Fix this since DB uses an external map for machines
|
||||||
|
|
||||||
// If machine names don't match
|
// If machine names don't match
|
||||||
|
|||||||
@@ -398,7 +398,7 @@ namespace SabreTools.DatFiles
|
|||||||
List<DatItem> sortedList = GetItemsForBucket(key);
|
List<DatItem> sortedList = GetItemsForBucket(key);
|
||||||
|
|
||||||
// Sort and merge the list
|
// Sort and merge the list
|
||||||
Sort(ref sortedList, false);
|
Sort(ref sortedList);
|
||||||
sortedList = Merge(sortedList);
|
sortedList = Merge(sortedList);
|
||||||
|
|
||||||
// Add the list back to the dictionary
|
// Add the list back to the dictionary
|
||||||
@@ -798,7 +798,7 @@ namespace SabreTools.DatFiles
|
|||||||
List<DatItem> sortedList = GetItemsForBucket(key);
|
List<DatItem> sortedList = GetItemsForBucket(key);
|
||||||
|
|
||||||
// Sort the list of items to be consistent
|
// Sort the list of items to be consistent
|
||||||
Sort(ref sortedList, false);
|
Sort(ref sortedList);
|
||||||
|
|
||||||
// Add the list back to the dictionary
|
// Add the list back to the dictionary
|
||||||
RemoveBucket(key);
|
RemoveBucket(key);
|
||||||
@@ -814,15 +814,22 @@ namespace SabreTools.DatFiles
|
|||||||
/// Sort a list of DatItem objects by SourceID, Game, and Name (in order)
|
/// Sort a list of DatItem objects by SourceID, Game, and Name (in order)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="items">List of DatItem objects representing the items to be sorted</param>
|
/// <param name="items">List of DatItem objects representing the items to be sorted</param>
|
||||||
/// <param name="norename">True if files are not renamed, false otherwise</param>
|
|
||||||
/// <returns>True if it sorted correctly, false otherwise</returns>
|
/// <returns>True if it sorted correctly, false otherwise</returns>
|
||||||
private bool Sort(ref List<DatItem> items, bool norename)
|
private bool Sort(ref List<DatItem> items)
|
||||||
{
|
{
|
||||||
|
// Create the comparer extenal to the delegate
|
||||||
|
var nc = new NaturalComparer();
|
||||||
|
|
||||||
|
// Sort by machine, type, item name, and source
|
||||||
items.Sort(delegate (DatItem x, DatItem y)
|
items.Sort(delegate (DatItem x, DatItem y)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var nc = new NaturalComparer();
|
// Compare on source
|
||||||
|
int xSourceIndex = x.GetFieldValue<Source?>(DatItem.SourceKey)?.Index ?? 0;
|
||||||
|
int ySourceIndex = y.GetFieldValue<Source?>(DatItem.SourceKey)?.Index ?? 0;
|
||||||
|
if (xSourceIndex != ySourceIndex)
|
||||||
|
return xSourceIndex - ySourceIndex;
|
||||||
|
|
||||||
// Get the machines
|
// Get the machines
|
||||||
Machine? xMachine = x.GetMachine();
|
Machine? xMachine = x.GetMachine();
|
||||||
@@ -849,13 +856,7 @@ namespace SabreTools.DatFiles
|
|||||||
// If item names don't match
|
// If item names don't match
|
||||||
string? xName = Path.GetFileName(TextHelper.RemovePathUnsafeCharacters(x.GetName() ?? string.Empty));
|
string? xName = Path.GetFileName(TextHelper.RemovePathUnsafeCharacters(x.GetName() ?? string.Empty));
|
||||||
string? yName = Path.GetFileName(TextHelper.RemovePathUnsafeCharacters(y.GetName() ?? string.Empty));
|
string? yName = Path.GetFileName(TextHelper.RemovePathUnsafeCharacters(y.GetName() ?? string.Empty));
|
||||||
if (xName != yName)
|
return nc.Compare(xName, yName);
|
||||||
return nc.Compare(xName, yName);
|
|
||||||
|
|
||||||
// Otherwise, compare on machine or source, depending on the flag
|
|
||||||
int? xSourceIndex = x.GetFieldValue<Source?>(DatItem.SourceKey)?.Index;
|
|
||||||
int? ySourceIndex = y.GetFieldValue<Source?>(DatItem.SourceKey)?.Index;
|
|
||||||
return (norename ? nc.Compare(xMachineName, yMachineName) : (xSourceIndex - ySourceIndex) ?? 0);
|
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1153,12 +1153,13 @@ namespace SabreTools.DatFiles
|
|||||||
/// <returns>True if it sorted correctly, false otherwise</returns>
|
/// <returns>True if it sorted correctly, false otherwise</returns>
|
||||||
private bool Sort(ref List<KeyValuePair<long, DatItem>> itemMappings, bool norename)
|
private bool Sort(ref List<KeyValuePair<long, DatItem>> itemMappings, bool norename)
|
||||||
{
|
{
|
||||||
|
// Create the comparer extenal to the delegate
|
||||||
|
var nc = new NaturalComparer();
|
||||||
|
|
||||||
itemMappings.Sort(delegate (KeyValuePair<long, DatItem> x, KeyValuePair<long, DatItem> y)
|
itemMappings.Sort(delegate (KeyValuePair<long, DatItem> x, KeyValuePair<long, DatItem> y)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var nc = new NaturalComparer();
|
|
||||||
|
|
||||||
// Get the machines
|
// Get the machines
|
||||||
Machine? xMachine = _machines[_itemToMachineMapping[x.Key]];
|
Machine? xMachine = _machines[_itemToMachineMapping[x.Key]];
|
||||||
Machine? yMachine = _machines[_itemToMachineMapping[y.Key]];
|
Machine? yMachine = _machines[_itemToMachineMapping[y.Key]];
|
||||||
|
|||||||
@@ -256,7 +256,8 @@ namespace SabreTools.DatTools
|
|||||||
List<DatFile> outDats = [];
|
List<DatFile> outDats = [];
|
||||||
|
|
||||||
// Ensure the current DatFile is sorted optimally
|
// Ensure the current DatFile is sorted optimally
|
||||||
datFile.BucketBy(ItemKey.CRC);
|
datFile.BucketBy(ItemKey.CRC, norename: false);
|
||||||
|
datFile.Deduplicate();
|
||||||
|
|
||||||
// Loop through each of the inputs and get or create a new DatData object
|
// Loop through each of the inputs and get or create a new DatData object
|
||||||
InternalStopwatch watch = new("Initializing and filling all output DATs");
|
InternalStopwatch watch = new("Initializing and filling all output DATs");
|
||||||
@@ -306,7 +307,7 @@ namespace SabreTools.DatTools
|
|||||||
foreach (var key in datFile.Items.SortedKeys)
|
foreach (var key in datFile.Items.SortedKeys)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
List<DatItem> items = ItemDictionary.Merge(datFile.GetItemsForBucket(key));
|
List<DatItem> items = datFile.GetItemsForBucket(key);
|
||||||
|
|
||||||
// If the rom list is empty or null, just skip it
|
// If the rom list is empty or null, just skip it
|
||||||
if (items == null || items.Count == 0)
|
if (items == null || items.Count == 0)
|
||||||
|
|||||||
@@ -552,7 +552,7 @@ namespace SabreTools.DatTools
|
|||||||
/// <returns>-1 for a coming before b, 0 for a == b, 1 for a coming after b</returns>
|
/// <returns>-1 for a coming before b, 0 for a == b, 1 for a coming after b</returns>
|
||||||
private static int SplitByLevelSort(string a, string b)
|
private static int SplitByLevelSort(string a, string b)
|
||||||
{
|
{
|
||||||
NaturalComparer nc = new();
|
var nc = new NaturalComparer();
|
||||||
int adeep = a.Count(c => c == '/' || c == '\\');
|
int adeep = a.Count(c => c == '/' || c == '\\');
|
||||||
int bdeep = b.Count(c => c == '/' || c == '\\');
|
int bdeep = b.Count(c => c == '/' || c == '\\');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user