Tested first run
This commit is contained in:
@ -3,9 +3,25 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
internal abstract class XPath
|
||||
{
|
||||
|
||||
internal static string GetRelativePath(string path, int length)
|
||||
internal static string GetRelativePath(string path, int length, bool forceExtensionToLower)
|
||||
{
|
||||
string result = path[length..].Replace(@"\", "/");
|
||||
string result;
|
||||
if (forceExtensionToLower)
|
||||
{
|
||||
string extension = Path.GetExtension(path);
|
||||
string extensionLowered = Path.GetExtension(path).ToLower();
|
||||
if (extension != extensionLowered)
|
||||
{
|
||||
string? directoryName = Path.GetDirectoryName(path);
|
||||
if (string.IsNullOrEmpty(directoryName))
|
||||
throw new NullReferenceException(directoryName);
|
||||
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path);
|
||||
if (string.IsNullOrEmpty(fileNameWithoutExtension))
|
||||
throw new NullReferenceException(fileNameWithoutExtension);
|
||||
path = Path.Combine(directoryName, $"{fileNameWithoutExtension}{extensionLowered}");
|
||||
}
|
||||
}
|
||||
result = path[length..].Replace(@"\", "/");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user