[Style] Add custom replacements for some System.IO.Path methods

This commit is contained in:
Matt Nadareski
2016-10-30 21:12:41 -07:00
parent 2304fc8e73
commit 29fa610b22
2 changed files with 70 additions and 2 deletions

View File

@@ -5260,7 +5260,7 @@ namespace SabreTools.Helper.Dats
foreach (string key in keys)
{
// Here, the key is the name of the game to be used for comparison
if (tempDat.Name != null && tempDat.Name != Path.GetDirectoryName(key))
if (tempDat.Name != null && tempDat.Name != Style.GetDirectoryName(key))
{
// Get the path that the file will be written out to
string path = HttpUtility.HtmlDecode(String.IsNullOrEmpty(tempDat.Name)
@@ -5303,7 +5303,7 @@ namespace SabreTools.Helper.Dats
}
// Then set the DAT name to be the parent directory name
tempDat.Name = Path.GetDirectoryName(key);
tempDat.Name = Style.GetDirectoryName(key);
}
// Then we write the last DAT out since it would be skipped otherwise

View File

@@ -398,6 +398,74 @@ namespace SabreTools.Helper.Tools
#endregion
#region System.IO.Path Replacements
/// <summary>
/// Replacement for System.IO.Path.GetDirectoryName
/// </summary>
/// <param name="s">Path to get directory name out of</param>
/// <returns>Directory name from path</returns>
public static string GetDirectoryName(string s)
{
if (s == null)
{
return "";
}
if (s.Contains(Path.AltDirectorySeparatorChar.ToString()))
{
string[] tempkey = s.Split(Path.AltDirectorySeparatorChar);
return String.Join(Path.AltDirectorySeparatorChar.ToString(), tempkey.Take(tempkey.Length - 1));
}
else if (s.Contains(Path.DirectorySeparatorChar.ToString()))
{
string[] tempkey = s.Split(Path.DirectorySeparatorChar);
return String.Join(Path.DirectorySeparatorChar.ToString(), tempkey.Take(tempkey.Length - 1));
}
return "";
}
/// <summary>
/// Replacement for System.IO.Path.GetFileName
/// </summary>
/// <param name="s">Path to get file name out of</param>
/// <returns>File name from path</returns>
public static string GetFileName(string s)
{
if (s == null)
{
return "";
}
if (s.Contains(Path.AltDirectorySeparatorChar.ToString()))
{
string[] tempkey = s.Split(Path.AltDirectorySeparatorChar);
return tempkey.Last();
}
else if (s.Contains(Path.DirectorySeparatorChar.ToString()))
{
string[] tempkey = s.Split(Path.DirectorySeparatorChar);
return tempkey.Last();
}
return s;
}
/// <summary>
/// Replacement for System.IO.Path.GetFileNameWithoutExtension
/// </summary>
/// <param name="s">Path to get file name out of</param>
/// <returns>File name without extension from path</returns>
public static string GetFileNameWithoutExtension(string s)
{
s = GetFileName(s);
string[] tempkey = s.Split('.');
return String.Join(".", tempkey.Take(tempkey.Length - 1));
}
#endregion
#region WoD-based String Cleaning
/// <summary>