Remove use of PathTools constants

This commit is contained in:
Alex Barney 2021-12-19 00:37:24 -07:00
parent 865f271fe7
commit 00a5b07da0
12 changed files with 29 additions and 40 deletions

View file

@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using LibHac;
using LibHac.Common;
using LibHac.Common.Keys;
using LibHac.Crypto;
@ -388,4 +387,4 @@ public static class KeysCodeGen
0xE7, 0x86, 0x3B, 0x4F, 0x8E, 0x13, 0x09, 0x47, 0x32, 0x0E, 0x04, 0xB8, 0x4D, 0x5B, 0xB0, 0x46,
0x71, 0xB0, 0x5C, 0xF4, 0xAD, 0x63, 0x4F, 0xC5, 0xE2, 0xAC, 0x1E, 0xC4, 0x33, 0x96, 0x09, 0x7B
};
}
}

View file

@ -1,6 +1,5 @@
using System;
using System.IO;
using Octokit;
namespace LibHacBuild.CodeGen.Stage2;
@ -22,4 +21,4 @@ public static class RunStage2
return 0;
}
}
}

View file

@ -4,7 +4,6 @@ using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using LibHac.Common;
using LibHac.Diag;
using LibHac.FsSystem;
using LibHac.Util;
using static LibHac.Fs.StringTraits;
@ -58,8 +57,8 @@ public static class PathFormatter
newPath = default;
int maxMountLength = outMountNameBuffer.Length == 0
? PathTools.MountNameLengthMax + 1
: Math.Min(outMountNameBuffer.Length, PathTools.MountNameLengthMax + 1);
? PathTool.MountNameLengthMax + 1
: Math.Min(outMountNameBuffer.Length, PathTool.MountNameLengthMax + 1);
int mountLength;
for (mountLength = 0; mountLength < maxMountLength && path.At(mountLength) != 0; mountLength++)
@ -631,4 +630,4 @@ public static class PathFormatter
{
return Result.Success;
}
}
}

View file

@ -1,7 +1,6 @@
using System;
using LibHac.Common;
using LibHac.Diag;
using LibHac.FsSystem;
using static LibHac.Fs.PathUtility;
using static LibHac.Fs.StringTraits;
@ -48,7 +47,7 @@ public static class PathNormalizer
if (IsParentDirectoryPathReplacementNeeded(currentPath))
{
// Allocate a buffer to hold the replacement path.
convertedPath = new RentedArray<byte>(PathTools.MaxPathLength + 1);
convertedPath = new RentedArray<byte>(PathTool.EntryNameLengthMax + 1);
// Replace the path.
ReplaceParentDirectoryPath(convertedPath.Span, currentPath);
@ -368,4 +367,4 @@ public static class PathNormalizer
dest[i] = NullTerminator;
}
}
}

View file

@ -30,7 +30,7 @@ public struct DirectoryEntry
[FieldOffset(0x304)] public DirectoryEntryType Type;
[FieldOffset(0x308)] public long Size;
public Span<byte> Name => SpanHelpers.CreateSpan(ref _name, PathTools.MaxPathLength + 1);
public Span<byte> Name => SpanHelpers.CreateSpan(ref _name, PathTool.EntryNameLengthMax + 1);
}
public enum DirectoryEntryType : byte
@ -45,4 +45,4 @@ public enum NxFileAttributes : byte
None = 0,
Directory = 1 << 0,
Archive = 1 << 1
}
}

View file

@ -2,7 +2,6 @@
using LibHac.Common;
using LibHac.Diag;
using LibHac.Fs.Impl;
using LibHac.FsSystem;
using LibHac.Os;
using LibHac.Util;
using static LibHac.Fs.StringTraits;
@ -18,12 +17,12 @@ public static class MountUtility
subPath = default;
int mountLen = 0;
int maxMountLen = Math.Min(path.Length, PathTools.MountNameLengthMax);
int maxMountLen = Math.Min(path.Length, PathTool.MountNameLengthMax);
if (WindowsPath.IsWindowsDrive(path) || WindowsPath.IsUncPath(path))
{
StringUtils.Copy(mountName.Name, CommonPaths.HostRootFileSystemMountName);
mountName.Name[PathTools.MountNameLengthMax] = StringTraits.NullTerminator;
mountName.Name[PathTool.MountNameLengthMax] = StringTraits.NullTerminator;
subPath = path;
return Result.Success;
@ -31,7 +30,7 @@ public static class MountUtility
for (int i = 0; i <= maxMountLen; i++)
{
if (path[i] == PathTools.MountSeparator)
if (path[i] == StringTraits.DriveSeparator)
{
mountLen = i;
break;
@ -79,7 +78,7 @@ public static class MountUtility
if (name[i] == DriveSeparator || name[i] == DirectorySeparator)
return false;
if (++length > PathTools.MountNameLengthMax)
if (++length > PathTool.MountNameLengthMax)
return false;
}
@ -254,4 +253,4 @@ public static class MountUtility
StringUtils.Copy(commonPathBuffer.Slice(commonPathLength), subPath);
return Result.Success;
}
}
}

View file

@ -251,7 +251,7 @@ public class InMemoryFileSystem : IAttributeFileSystem
ref DirectoryEntry entry = ref entryBuffer[i];
StringUtils.Copy(entry.Name, CurrentDir.Name);
entry.Name[PathTools.MaxPathLength] = 0;
entry.Name[PathTool.EntryNameLengthMax] = 0;
entry.Type = DirectoryEntryType.Directory;
entry.Attributes = CurrentDir.Attributes;
@ -269,7 +269,7 @@ public class InMemoryFileSystem : IAttributeFileSystem
ref DirectoryEntry entry = ref entryBuffer[i];
StringUtils.Copy(entry.Name, CurrentFile.Name);
entry.Name[PathTools.MaxPathLength] = 0;
entry.Name[PathTool.EntryNameLengthMax] = 0;
entry.Type = DirectoryEntryType.File;
entry.Attributes = CurrentFile.Attributes;
@ -793,4 +793,4 @@ public class InMemoryFileSystem : IAttributeFileSystem
return false;
}
}
}
}

View file

@ -6,7 +6,6 @@ using LibHac.Fs.Fsa;
using LibHac.Fs.Impl;
using LibHac.FsSrv.Sf;
using LibHac.Os;
using LibHac.FsSystem;
using LibHac.Util;
using static LibHac.Fs.Impl.CommonMountNames;
using static LibHac.Fs.Impl.AccessLogStrings;
@ -40,7 +39,7 @@ public static class Bis
ReadOnlySpan<byte> mountName = GetBisMountName(_partitionId);
// Add 2 for the mount name separator and null terminator
int requiredNameBufferSize = StringUtils.GetLength(mountName, PathTools.MountNameLengthMax) + 2;
int requiredNameBufferSize = StringUtils.GetLength(mountName, PathTool.MountNameLengthMax) + 2;
Assert.SdkRequiresGreaterEqual(nameBuffer.Length, requiredNameBufferSize);
@ -194,4 +193,4 @@ public static class Bis
return Result.Success;
}
}
}

View file

@ -41,7 +41,7 @@ public class LocalDirectory : IDirectory
long length = isDir ? 0 : ((FileInfo)localEntry).Length;
StringUtils.Copy(entryBuffer[i].Name, name);
entryBuffer[i].Name[PathTools.MaxPathLength] = 0;
entryBuffer[i].Name[PathTool.EntryNameLengthMax] = 0;
entryBuffer[i].Attributes = localEntry.Attributes.ToNxAttributes();
entryBuffer[i].Type = type;

View file

@ -47,7 +47,7 @@ public class PartitionDirectory : IDirectory
entry.Size = fileEntry.Size;
StringUtils.Copy(entry.Name, nameUtf8);
entry.Name[PathTools.MaxPathLength] = 0;
entry.Name[PathTool.EntryNameLengthMax] = 0;
CurrentIndex++;
}
@ -68,4 +68,4 @@ public class PartitionDirectory : IDirectory
entryCount = count;
return Result.Success;
}
}
}

View file

@ -12,12 +12,8 @@ namespace LibHac.FsSystem;
public static class PathTools
{
// todo: Consolidate these
internal const char DirectorySeparator = '/';
internal const char MountSeparator = ':';
internal const int MountNameLengthMax = 0xF;
// Todo: Remove
internal const int MaxPathLength = 0x300;
private const char DirectorySeparator = '/';
private const char MountSeparator = ':';
public static string Normalize(string inPath)
{
@ -27,7 +23,7 @@ public static class PathTools
var sb = new ValueStringBuilder(initialBuffer);
int rootLen = 0;
int maxMountLen = Math.Min(inPath.Length, MountNameLengthMax);
int maxMountLen = Math.Min(inPath.Length, PathTool.MountNameLengthMax);
for (int i = 0; i < maxMountLen; i++)
{
@ -480,7 +476,7 @@ public static class PathTools
{
UnsafeHelpers.SkipParamInit(out length);
int maxLen = Math.Min(path.Length, MountNameLengthMax);
int maxLen = Math.Min(path.Length, PathTool.MountNameLengthMax);
for (int i = 0; i < maxLen; i++)
{
@ -518,4 +514,4 @@ public static class PathTools
MountName,
MountDelimiter
}
}
}

View file

@ -2,7 +2,6 @@
using System.Text;
using LibHac.Fs;
using LibHac.Fs.Fsa;
using LibHac.FsSystem;
using LibHac.Util;
namespace LibHac.Tools.FsSystem.RomFs;
@ -52,7 +51,7 @@ public class RomFsDirectory : IDirectory
Span<byte> nameUtf8 = Encoding.UTF8.GetBytes(name);
StringUtils.Copy(entry.Name, nameUtf8);
entry.Name[PathTools.MaxPathLength] = 0;
entry.Name[PathTool.EntryNameLengthMax] = 0;
entry.Type = DirectoryEntryType.Directory;
entry.Size = 0;
@ -72,7 +71,7 @@ public class RomFsDirectory : IDirectory
Span<byte> nameUtf8 = Encoding.UTF8.GetBytes(name);
StringUtils.Copy(entry.Name, nameUtf8);
entry.Name[PathTools.MaxPathLength] = 0;
entry.Name[PathTool.EntryNameLengthMax] = 0;
entry.Type = DirectoryEntryType.File;
entry.Size = info.Length;