mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DatFile] File ordering should use Natural comparisons
This commit is contained in:
@@ -47,13 +47,7 @@ namespace SabreTools.Library.Dats
|
||||
if (merge || (diff != 0 && (diff & DiffMode.Against) == 0))
|
||||
{
|
||||
// Make sure there are no folders in inputs
|
||||
List<string> newInputFileNames = FileTools.GetOnlyFilesFromInputs(inputPaths, appendparent: true);
|
||||
|
||||
// If we're in inverse cascade, reverse the list
|
||||
if ((diff & DiffMode.ReverseCascade) != 0)
|
||||
{
|
||||
newInputFileNames.Reverse();
|
||||
}
|
||||
List<string> newInputFileNames = FileTools.GetOnlyFilesFromInputs(inputPaths, appendparent: true, reverse: (diff & DiffMode.ReverseCascade) != 0);
|
||||
|
||||
// Create a dictionary of all ROMs from the input DATs
|
||||
List<DatFile> datHeaders = PopulateUserData(newInputFileNames, inplace, clean,
|
||||
|
||||
@@ -407,9 +407,10 @@ namespace SabreTools.Library.Tools
|
||||
/// Retrieve a list of just files from inputs
|
||||
/// </summary>
|
||||
/// <param name="inputs">List of strings representing directories and files</param>
|
||||
/// <param name="appendparent">True if the parent name should be appended after the special character "¬", false otherwise</param>
|
||||
/// <param name="appendparent">True if the parent name should be appended after the special character "¬", false otherwise (default)</param>
|
||||
/// <param name="reverse">True if the order output should be reversed, false otherwise (default)</param>
|
||||
/// <returns>List of strings representing just files from the inputs</returns>
|
||||
public static List<string> GetOnlyFilesFromInputs(List<string> inputs, bool appendparent = false)
|
||||
public static List<string> GetOnlyFilesFromInputs(List<string> inputs, bool appendparent = false, bool reverse = false)
|
||||
{
|
||||
List<string> outputs = new List<string>();
|
||||
foreach (string input in inputs)
|
||||
@@ -417,9 +418,6 @@ namespace SabreTools.Library.Tools
|
||||
if (Directory.Exists(input))
|
||||
{
|
||||
List<string> files = FileTools.RetrieveFiles(input, new List<string>());
|
||||
|
||||
// Make sure the files in the directory are ordered correctly
|
||||
files = Style.OrderByAlphaNumeric(files, s => s).ToList();
|
||||
foreach (string file in files)
|
||||
{
|
||||
try
|
||||
@@ -453,6 +451,16 @@ namespace SabreTools.Library.Tools
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure the outputs are ordered correctly
|
||||
if (reverse)
|
||||
{
|
||||
outputs.Sort(new NaturalReversedComparer());
|
||||
}
|
||||
else
|
||||
{
|
||||
outputs.Sort(new NaturalComparer());
|
||||
}
|
||||
|
||||
return outputs;
|
||||
}
|
||||
|
||||
|
||||
@@ -954,18 +954,6 @@ namespace SabreTools.Library.Tools
|
||||
return localTime;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// http://stackoverflow.com/questions/248603/natural-sort-order-in-c-sharp
|
||||
/// </summary>
|
||||
public static IEnumerable<T> OrderByAlphaNumeric<T>(this IEnumerable<T> source, Func<T, string> selector)
|
||||
{
|
||||
int max = source
|
||||
.SelectMany(i => Regex.Matches(selector(i), @"\d+").Cast<Match>().Select(m => (int?)m.Value.Length))
|
||||
.Max() ?? 0;
|
||||
|
||||
return source.OrderBy(i => Regex.Replace(selector(i), @"\d+", m => m.Value.PadLeft(max, '0')));
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user