Uses the file system path service for music and book path parsing

This commit is contained in:
BinaryAlley committed 2026-10-10 15:48:41 +03:00
1 parent 15d27adc1f
commit 09c31a4fe6
15 files changed
+303 -87

No files matched your search

@@ -53,6 +53,20 @@ public interface IPathService
/// <returns>An <see cref="Result{TValue}"/> containing the path segments of the path up one level from <paramref name="path"/>, or an error.</returns>
Result<IEnumerable<PathSegment>> GoUpOneLevel(string path);
/// <summary>
/// Gets the name of the file or directory stored at <paramref name="path"/>, using the path separator of the current platform.
/// </summary>
/// <param name="path">The path whose name is retrieved.</param>
/// <returns>The name of the file or directory stored at <paramref name="path"/>.</returns>
string GetFileName(string path);
/// <summary>
/// Gets the name of the file stored at <paramref name="path"/> without its extension, using the path separator of the current platform.
/// </summary>
/// <param name="path">The path whose file name is retrieved.</param>
/// <returns>The name of the file stored at <paramref name="path"/> without its extension.</returns>
string GetFileNameWithoutExtension(string path);
/// <summary>
/// Returns a collection of characters that are invalid for paths.
/// </summary>
@@ -105,6 +105,32 @@ public class PathService : IPathService
return _platformContext.PathStrategy.GoUpOneLevel(newPathResult.Value);
}
/// <summary>
/// Gets the name of the file or directory stored at <paramref name="path"/>, using the path separator of the current platform.
/// </summary>
/// <param name="path">The path whose name is retrieved.</param>
/// <returns>The name of the file or directory stored at <paramref name="path"/>.</returns>
public string GetFileName(string path)
{
if (string.IsNullOrEmpty(path))
return path;
string trimmedPath = path.TrimEnd(PathSeparator);
int lastSeparatorIndex = trimmedPath.LastIndexOf(PathSeparator);
return lastSeparatorIndex < 0 ? trimmedPath : trimmedPath[(lastSeparatorIndex + 1)..];
}
/// <summary>
/// Gets the name of the file stored at <paramref name="path"/> without its extension, using the path separator of the current platform.
/// </summary>
/// <param name="path">The path whose file name is retrieved.</param>
/// <returns>The name of the file stored at <paramref name="path"/> without its extension.</returns>
public string GetFileNameWithoutExtension(string path)
{
string fileName = GetFileName(path);
int lastDotIndex = fileName.LastIndexOf('.');
return lastDotIndex <= 0 ? fileName : fileName[..lastDotIndex];
}
/// <summary>
/// Returns a collection of characters that are invalid for paths.
/// </summary>