This repository has been archived on 2023-02-02. You can view files and clone it, but cannot push or open issues or pull requests.
mfgames-nitride-cil/src/MfGames.Nitride.IO/Paths/UPathExtensions.cs

46 lines
1.1 KiB
C#
Raw Normal View History

2021-09-07 05:15:45 +00:00
using Zio;
2022-09-06 05:53:22 +00:00
namespace MfGames.Nitride.IO.Paths;
/// <summary>
/// Extension methods for the UPath class.
/// </summary>
public static class UPathExtensions
2021-09-07 05:15:45 +00:00
{
/// <summary>
/// Gets the directory path, which excludes the directory at the end
/// of the path.
2021-09-07 05:15:45 +00:00
/// </summary>
/// <param name="path">The path to manipulate.</param>
/// <returns>A normalized path.</returns>
public static string GetDirectoryIndexPath(this UPath path)
2021-09-07 05:15:45 +00:00
{
if (path.GetNameWithoutExtension() == "index")
2021-09-07 05:15:45 +00:00
{
2022-07-09 04:52:10 +00:00
return path.GetDirectory()
.ToString()
.TrimEnd('/')
+ "/";
2021-09-07 05:15:45 +00:00
}
return path.ToString();
}
2021-09-07 05:15:45 +00:00
public static string GetParentDirectoryIndexPath(this UPath path)
{
UPath indexPath = path.GetDirectoryIndexPath();
UPath parent = indexPath.GetDirectory();
2021-09-07 05:15:45 +00:00
if (parent == null!)
{
parent = "/";
2021-09-07 05:15:45 +00:00
}
2022-07-09 04:52:10 +00:00
string parentPath = parent.ToString()
.TrimEnd('/')
+ "/";
return parentPath;
2021-09-07 05:15:45 +00:00
}
}