[RomTools] Try to make sort more safe

This commit is contained in:
Matt Nadareski
2016-09-11 17:40:46 -07:00
parent 9d3019dfaa
commit a595a54f7b
2 changed files with 32 additions and 13 deletions

View File

@@ -225,6 +225,8 @@ namespace SabreTools.Helper
/// <param name="norename">True if files are not renamed, false otherwise</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>
public static bool Sort(List<Rom> roms, bool norename) public static bool Sort(List<Rom> roms, bool norename)
{
try
{ {
roms.Sort(delegate (Rom x, Rom y) roms.Sort(delegate (Rom x, Rom y)
{ {
@@ -248,6 +250,12 @@ namespace SabreTools.Helper
}); });
return true; return true;
} }
catch (Exception ex)
{
Console.WriteLine(ex);
return false;
}
}
#endregion #endregion
} }

View File

@@ -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
} }
} }