From 123fc0655dfe6d8986a01fe17044acdf662dc153 Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Wed, 5 Jan 2022 12:04:09 -0700 Subject: [PATCH] Update Fs.Path for 13.1.0 --- src/LibHac/Fs/Common/Path.cs | 73 +++++++++++++++++++++++++++++++----- 1 file changed, 63 insertions(+), 10 deletions(-) diff --git a/src/LibHac/Fs/Common/Path.cs b/src/LibHac/Fs/Common/Path.cs index 49af516f..89dd8230 100644 --- a/src/LibHac/Fs/Common/Path.cs +++ b/src/LibHac/Fs/Common/Path.cs @@ -4,8 +4,8 @@ using System.Diagnostics; using LibHac.Common; using LibHac.Diag; using LibHac.Util; -using static LibHac.Fs.StringTraits; using static InlineIL.IL.Emit; +using static LibHac.Fs.StringTraits; // ReSharper disable once CheckNamespace namespace LibHac.Fs; @@ -21,12 +21,12 @@ public struct PathFlags public void AllowBackslash() => _value |= 1 << 4; public void AllowAllCharacters() => _value |= 1 << 5; - public bool IsWindowsPathAllowed() => (_value & (1 << 0)) != 0; - public bool IsRelativePathAllowed() => (_value & (1 << 1)) != 0; - public bool IsEmptyPathAllowed() => (_value & (1 << 2)) != 0; - public bool IsMountNameAllowed() => (_value & (1 << 3)) != 0; - public bool IsBackslashAllowed() => (_value & (1 << 4)) != 0; - public bool AreAllCharactersAllowed() => (_value & (1 << 5)) != 0; + public readonly bool IsWindowsPathAllowed() => (_value & (1 << 0)) != 0; + public readonly bool IsRelativePathAllowed() => (_value & (1 << 1)) != 0; + public readonly bool IsEmptyPathAllowed() => (_value & (1 << 2)) != 0; + public readonly bool IsMountNameAllowed() => (_value & (1 << 3)) != 0; + public readonly bool IsBackslashAllowed() => (_value & (1 << 4)) != 0; + public readonly bool AreAllCharactersAllowed() => (_value & (1 << 5)) != 0; } /// @@ -83,7 +83,7 @@ public static class PathExtensions /// ensure a write buffer is allocated and copy the input path to it. will /// directly use the input buffer without copying. If this method is used, the caller must ensure the path /// is normalized before passing it to . -/// Based on FS 12.1.0 (nnSdk 12.3.1) +/// Based on FS 13.1.0 (nnSdk 13.4.0) [DebuggerDisplay("{" + nameof(ToString) + "(),nq}")] [NonCopyableDisposable] public ref struct Path @@ -225,9 +225,9 @@ public ref struct Path } /// - /// Returns if + /// Returns if the has no buffer or has an empty string. /// - /// + /// if the current path is empty; otherwise . public readonly bool IsEmpty() { return _string.At(0) == 0; @@ -957,6 +957,59 @@ public ref struct Path return Result.Success; } + /// + /// Combines a and a path string into a single path. + /// + /// If is not empty, this 's IsNormalized flag will + /// be set to the value of 's flag. + /// Otherwise the flag will be set to . + /// The first path to combine. + /// The second path to combine. + /// : The operation was successful.
+ /// : The IsNormalized flag of + /// is not .
+ public Result Combine(in Path path1, ReadOnlySpan path2) + { + int path1Length = path1.GetLength(); + int path2Length = StringUtils.GetLength(path2); + + Result rc = Preallocate(path1Length + SeparatorLength + path2Length + NullTerminatorLength); + if (rc.IsFailure()) return rc; + + rc = Initialize(in path1); + if (rc.IsFailure()) return rc; + + rc = AppendChild(path2); + if (rc.IsFailure()) return rc; + + return Result.Success; + } + + /// + /// Combines a path string and a into a single path. + /// + /// This 's IsNormalized flag will + /// always be set to . + /// The first path to combine. + /// The second path to combine. + /// : The operation was successful. + public Result Combine(ReadOnlySpan path1, in Path path2) + { + int path1Length = StringUtils.GetLength(path1); + int path2Length = path2.GetLength(); + + Result rc = Preallocate(path1Length + SeparatorLength + path2Length + NullTerminatorLength); + if (rc.IsFailure()) return rc; + + rc = Initialize(path1); + if (rc.IsFailure()) return rc; + + rc = AppendChild(in path2); + if (rc.IsFailure()) return rc; + + return Result.Success; + } + /// /// Removes the last entry from this . ///