mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Update DirectoryPathParser, PathUtility and WindowsPath for 13.1.0
This commit is contained in:
parent
61b29e57a3
commit
1f8277202f
5 changed files with 41 additions and 25 deletions
|
@ -3,8 +3,13 @@ using LibHac.Common;
|
||||||
using LibHac.Diag;
|
using LibHac.Diag;
|
||||||
using static LibHac.Fs.StringTraits;
|
using static LibHac.Fs.StringTraits;
|
||||||
|
|
||||||
namespace LibHac.Fs.Common;
|
// ReSharper disable once CheckNamespace
|
||||||
|
namespace LibHac.Fs;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Iterates through each directory in a path beginning with the root directory.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>Based on FS 13.1.0 (nnSdk 13.4.0)</remarks>
|
||||||
[NonCopyableDisposable]
|
[NonCopyableDisposable]
|
||||||
public ref struct DirectoryPathParser
|
public ref struct DirectoryPathParser
|
||||||
{
|
{
|
||||||
|
@ -15,11 +20,26 @@ public ref struct DirectoryPathParser
|
||||||
// Todo: Make private so we can use the GetCurrentPath method once lifetime tracking is better
|
// Todo: Make private so we can use the GetCurrentPath method once lifetime tracking is better
|
||||||
public Path CurrentPath;
|
public Path CurrentPath;
|
||||||
|
|
||||||
|
public DirectoryPathParser()
|
||||||
|
{
|
||||||
|
_buffer = Span<byte>.Empty;
|
||||||
|
_replacedChar = 0;
|
||||||
|
_position = 0;
|
||||||
|
CurrentPath = new Path();
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
CurrentPath.Dispose();
|
CurrentPath.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes this <see cref="DirectoryPathParser"/> with a new <see cref="Path"/>. The <see cref="Path"/>
|
||||||
|
/// should not be a fixed path that was just initialized with <see cref="PathFunctions.SetUpFixedPath"/>
|
||||||
|
/// because we need it to have an allocated write buffer.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The <see cref="Path"/> to iterate. Must have an allocated write buffer.</param>
|
||||||
|
/// <returns>The <see cref="Result"/> of the operation.</returns>
|
||||||
public Result Initialize(ref Path path)
|
public Result Initialize(ref Path path)
|
||||||
{
|
{
|
||||||
Span<byte> pathBuffer = path.GetWriteBufferLength() != 0 ? path.GetWriteBuffer() : Span<byte>.Empty;
|
Span<byte> pathBuffer = path.GetWriteBufferLength() != 0 ? path.GetWriteBuffer() : Span<byte>.Empty;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using LibHac.Common;
|
using LibHac.Common;
|
||||||
using LibHac.Diag;
|
using LibHac.Diag;
|
||||||
|
using LibHac.Fs.Impl;
|
||||||
using LibHac.FsSrv.Sf;
|
using LibHac.FsSrv.Sf;
|
||||||
using LibHac.Util;
|
using LibHac.Util;
|
||||||
using static LibHac.Fs.StringTraits;
|
using static LibHac.Fs.StringTraits;
|
||||||
|
@ -11,7 +12,7 @@ namespace LibHac.Fs;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Contains various utility functions for working with paths.
|
/// Contains various utility functions for working with paths.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>Based on FS 12.1.0 (nnSdk 12.3.1)</remarks>
|
/// <remarks>Based on FS 13.1.0 (nnSdk 13.4.0)</remarks>
|
||||||
public static class PathUtility
|
public static class PathUtility
|
||||||
{
|
{
|
||||||
public static void Replace(Span<byte> buffer, byte currentChar, byte newChar)
|
public static void Replace(Span<byte> buffer, byte currentChar, byte newChar)
|
||||||
|
@ -46,16 +47,6 @@ public static class PathUtility
|
||||||
(path.Length < 3 || path[2] == NullTerminator || path[2] == DirectorySeparator);
|
(path.Length < 3 || path[2] == NullTerminator || path[2] == DirectorySeparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsSeparator(byte c)
|
|
||||||
{
|
|
||||||
return c == DirectorySeparator;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool IsNul(byte c)
|
|
||||||
{
|
|
||||||
return c == NullTerminator;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Result ConvertToFspPath(out FspPath fspPath, ReadOnlySpan<byte> path)
|
public static Result ConvertToFspPath(out FspPath fspPath, ReadOnlySpan<byte> path)
|
||||||
{
|
{
|
||||||
UnsafeHelpers.SkipParamInit(out fspPath);
|
UnsafeHelpers.SkipParamInit(out fspPath);
|
||||||
|
@ -65,7 +56,7 @@ public static class PathUtility
|
||||||
if (length >= PathTool.EntryNameLengthMax + 1)
|
if (length >= PathTool.EntryNameLengthMax + 1)
|
||||||
return ResultFs.TooLongPath.Log();
|
return ResultFs.TooLongPath.Log();
|
||||||
|
|
||||||
Result rc = PathFormatter.SkipMountName(out ReadOnlySpan<byte> pathWithoutMountName, out _,
|
Result rc = PathFormatter.SkipMountName(out ReadOnlySpan<byte> pathWithoutMountName, out int skipLength,
|
||||||
new U8Span(path));
|
new U8Span(path));
|
||||||
if (rc.IsFailure()) return rc;
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
|
@ -73,10 +64,16 @@ public static class PathUtility
|
||||||
{
|
{
|
||||||
Replace(SpanHelpers.AsByteSpan(ref fspPath).Slice(0, 0x300), AltDirectorySeparator, DirectorySeparator);
|
Replace(SpanHelpers.AsByteSpan(ref fspPath).Slice(0, 0x300), AltDirectorySeparator, DirectorySeparator);
|
||||||
}
|
}
|
||||||
else if (fspPath.Str[0] == DirectorySeparator && fspPath.Str[1] == DirectorySeparator)
|
else
|
||||||
{
|
{
|
||||||
SpanHelpers.AsByteSpan(ref fspPath)[0] = AltDirectorySeparator;
|
bool isHostOrNoMountName = skipLength == 0 || StringUtils.Compare(path, CommonMountNames.HostRootFileSystemMountName,
|
||||||
SpanHelpers.AsByteSpan(ref fspPath)[1] = AltDirectorySeparator;
|
CommonMountNames.HostRootFileSystemMountName.Length) == 0;
|
||||||
|
|
||||||
|
if (isHostOrNoMountName && WindowsPath.IsUncPath(path.Slice(skipLength), true, false))
|
||||||
|
{
|
||||||
|
SpanHelpers.AsByteSpan(ref fspPath)[skipLength] = AltDirectorySeparator;
|
||||||
|
SpanHelpers.AsByteSpan(ref fspPath)[skipLength + 1] = AltDirectorySeparator;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
|
|
|
@ -10,7 +10,7 @@ namespace LibHac.Fs;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Contains functions for working with Windows paths.
|
/// Contains functions for working with Windows paths.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>Based on FS 12.1.0 (nnSdk 12.3.1)</remarks>
|
/// <remarks>Based on FS 13.1.0 (nnSdk 13.4.0)</remarks>
|
||||||
public static class WindowsPath
|
public static class WindowsPath
|
||||||
{
|
{
|
||||||
private const int WindowsDriveLength = 2;
|
private const int WindowsDriveLength = 2;
|
||||||
|
|
|
@ -22,7 +22,7 @@ public static class MountUtility
|
||||||
if (WindowsPath.IsWindowsDrive(path) || WindowsPath.IsUncPath(path))
|
if (WindowsPath.IsWindowsDrive(path) || WindowsPath.IsUncPath(path))
|
||||||
{
|
{
|
||||||
StringUtils.Copy(mountName.Name, CommonPaths.HostRootFileSystemMountName);
|
StringUtils.Copy(mountName.Name, CommonPaths.HostRootFileSystemMountName);
|
||||||
mountName.Name[PathTool.MountNameLengthMax] = StringTraits.NullTerminator;
|
mountName.Name[PathTool.MountNameLengthMax] = NullTerminator;
|
||||||
|
|
||||||
subPath = path;
|
subPath = path;
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
|
@ -30,7 +30,7 @@ public static class MountUtility
|
||||||
|
|
||||||
for (int i = 0; i <= maxMountLen; i++)
|
for (int i = 0; i <= maxMountLen; i++)
|
||||||
{
|
{
|
||||||
if (path[i] == StringTraits.DriveSeparator)
|
if (path[i] == DriveSeparator)
|
||||||
{
|
{
|
||||||
mountLen = i;
|
mountLen = i;
|
||||||
break;
|
break;
|
||||||
|
@ -53,7 +53,7 @@ public static class MountUtility
|
||||||
return ResultFs.InvalidPathFormat.Log();
|
return ResultFs.InvalidPathFormat.Log();
|
||||||
|
|
||||||
path.Value.Slice(0, mountLen).CopyTo(mountName.Name);
|
path.Value.Slice(0, mountLen).CopyTo(mountName.Name);
|
||||||
mountName.Name[mountLen] = StringTraits.NullTerminator;
|
mountName.Name[mountLen] = NullTerminator;
|
||||||
subPath = subPathTemp;
|
subPath = subPathTemp;
|
||||||
|
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using LibHac.Common;
|
using LibHac.Common;
|
||||||
using LibHac.Fs;
|
using LibHac.Fs;
|
||||||
using LibHac.Fs.Common;
|
|
||||||
using LibHac.Fs.Fsa;
|
using LibHac.Fs.Fsa;
|
||||||
using LibHac.Os;
|
using LibHac.Os;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue