mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[RomTools] Try to make sort more safe
This commit is contained in:
@@ -226,27 +226,35 @@ namespace SabreTools.Helper
|
|||||||
/// <returns>True if it sorted correctly, false otherwise</returns>
|
/// <returns>True if it sorted correctly, false otherwise</returns>
|
||||||
public static bool Sort(List<Rom> roms, bool norename)
|
public static bool Sort(List<Rom> roms, bool norename)
|
||||||
{
|
{
|
||||||
roms.Sort(delegate (Rom x, Rom y)
|
try
|
||||||
{
|
{
|
||||||
if (x.Metadata.SystemID == y.Metadata.SystemID)
|
roms.Sort(delegate (Rom x, Rom y)
|
||||||
{
|
{
|
||||||
if (x.Metadata.SourceID == y.Metadata.SourceID)
|
if (x.Metadata.SystemID == y.Metadata.SystemID)
|
||||||
{
|
{
|
||||||
if (x.Machine.Name == y.Machine.Name)
|
if (x.Metadata.SourceID == y.Metadata.SourceID)
|
||||||
{
|
{
|
||||||
if (Path.GetDirectoryName(x.Name) == Path.GetDirectoryName(y.Name))
|
if (x.Machine.Name == y.Machine.Name)
|
||||||
{
|
{
|
||||||
return Style.CompareNumeric(Path.GetFileName(x.Name), Path.GetFileName(y.Name));
|
if (Path.GetDirectoryName(x.Name) == Path.GetDirectoryName(y.Name))
|
||||||
|
{
|
||||||
|
return Style.CompareNumeric(Path.GetFileName(x.Name), Path.GetFileName(y.Name));
|
||||||
|
}
|
||||||
|
return Style.CompareNumeric(Path.GetDirectoryName(x.Name), Path.GetDirectoryName(y.Name));
|
||||||
}
|
}
|
||||||
return Style.CompareNumeric(Path.GetDirectoryName(x.Name), Path.GetDirectoryName(y.Name));
|
return Style.CompareNumeric(x.Machine.Name, y.Machine.Name);
|
||||||
}
|
}
|
||||||
return Style.CompareNumeric(x.Machine.Name, y.Machine.Name);
|
return (norename ? String.Compare(x.Machine.Name, y.Machine.Name) : x.Metadata.SourceID - y.Metadata.SourceID);
|
||||||
}
|
}
|
||||||
return (norename ? String.Compare(x.Machine.Name, y.Machine.Name) : x.Metadata.SourceID - y.Metadata.SourceID);
|
return (norename ? String.Compare(x.Machine.Name, y.Machine.Name) : x.Metadata.SystemID - y.Metadata.SystemID);
|
||||||
}
|
});
|
||||||
return (norename ? String.Compare(x.Machine.Name, y.Machine.Name) : x.Metadata.SystemID - y.Metadata.SystemID);
|
return true;
|
||||||
});
|
}
|
||||||
return true;
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -514,6 +514,17 @@ namespace SabreTools.Helper
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// http://stackoverflow.com/questions/146134/how-to-remove-illegal-characters-from-path-and-filenames
|
||||||
|
/// </summary>
|
||||||
|
public static string StripInvalidPathChars(string s)
|
||||||
|
{
|
||||||
|
string regexSearch = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());
|
||||||
|
Regex r = new Regex(string.Format("[{0}]", Regex.Escape(regexSearch)));
|
||||||
|
s = r.Replace(s, "");
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user