mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Remove use of PathTools constants
This commit is contained in:
parent
865f271fe7
commit
00a5b07da0
12 changed files with 29 additions and 40 deletions
|
@ -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;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using Octokit;
|
||||
|
||||
namespace LibHacBuild.CodeGen.Stage2;
|
||||
|
||||
|
|
|
@ -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++)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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++;
|
||||
}
|
||||
|
|
|
@ -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++)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue