mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[Style] Add custom replacements for some System.IO.Path methods
This commit is contained in:
@@ -5260,7 +5260,7 @@ namespace SabreTools.Helper.Dats
|
|||||||
foreach (string key in keys)
|
foreach (string key in keys)
|
||||||
{
|
{
|
||||||
// Here, the key is the name of the game to be used for comparison
|
// 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
|
// Get the path that the file will be written out to
|
||||||
string path = HttpUtility.HtmlDecode(String.IsNullOrEmpty(tempDat.Name)
|
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
|
// 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
|
// Then we write the last DAT out since it would be skipped otherwise
|
||||||
|
|||||||
@@ -398,6 +398,74 @@ namespace SabreTools.Helper.Tools
|
|||||||
|
|
||||||
#endregion
|
#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
|
#region WoD-based String Cleaning
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user