mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Add MountApplicationPackage
This commit is contained in:
parent
31563ad108
commit
89d70757a3
11 changed files with 203 additions and 11 deletions
|
@ -47,17 +47,29 @@ namespace LibHac.Common
|
|||
|
||||
public static int Compare(ReadOnlySpan<byte> s1, ReadOnlySpan<byte> s2)
|
||||
{
|
||||
int maxLen = Math.Min(s1.Length, s2.Length);
|
||||
int i = 0;
|
||||
|
||||
return Compare(s1, s2, maxLen);
|
||||
while (true)
|
||||
{
|
||||
int c1 = ((uint)i < (uint)s1.Length ? s1[i] : 0);
|
||||
int c2 = ((uint)i < (uint)s2.Length ? s2[i] : 0);
|
||||
|
||||
if (c1 != c2)
|
||||
return c1 - c2;
|
||||
|
||||
if (c1 == 0)
|
||||
return 0;
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public static int Compare(ReadOnlySpan<byte> s1, ReadOnlySpan<byte> s2, int maxLen)
|
||||
{
|
||||
for (int i = 0; i < maxLen; i++)
|
||||
{
|
||||
byte c1 = s1[i];
|
||||
byte c2 = s2[i];
|
||||
int c1 = ((uint)i < (uint)s1.Length ? s1[i] : 0);
|
||||
int c2 = ((uint)i < (uint)s2.Length ? s2[i] : 0);
|
||||
|
||||
if (c1 != c2)
|
||||
return c1 - c2;
|
||||
|
@ -69,6 +81,51 @@ namespace LibHac.Common
|
|||
return 0;
|
||||
}
|
||||
|
||||
public static int CompareCaseInsensitive(ReadOnlySpan<byte> s1, ReadOnlySpan<byte> s2)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
while (true)
|
||||
{
|
||||
int c1 = ((uint)i < (uint)s1.Length ? ToLowerAsciiInvariant(s1[i]) : 0);
|
||||
int c2 = ((uint)i < (uint)s2.Length ? ToLowerAsciiInvariant(s2[i]) : 0);
|
||||
|
||||
if (c1 != c2)
|
||||
return c1 - c2;
|
||||
|
||||
if (c1 == 0)
|
||||
return 0;
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public static int CompareCaseInsensitive(ReadOnlySpan<byte> s1, ReadOnlySpan<byte> s2, int maxLen)
|
||||
{
|
||||
for (int i = 0; i < maxLen; i++)
|
||||
{
|
||||
int c1 = ((uint)i < (uint)s1.Length ? ToLowerAsciiInvariant(s1[i]) : 0);
|
||||
int c2 = ((uint)i < (uint)s2.Length ? ToLowerAsciiInvariant(s2[i]) : 0);
|
||||
|
||||
if (c1 != c2)
|
||||
return c1 - c2;
|
||||
|
||||
if (c1 == 0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static byte ToLowerAsciiInvariant(byte c)
|
||||
{
|
||||
if ((uint)(c - 'A') <= 'Z' - 'A')
|
||||
{
|
||||
c = (byte)(c | 0x20);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Concatenates 2 byte strings.
|
||||
/// </summary>
|
||||
|
|
|
@ -44,7 +44,7 @@ namespace LibHac.Common
|
|||
|
||||
public override string ToString()
|
||||
{
|
||||
return StringUtils.Utf8ToString(_buffer);
|
||||
return StringUtils.Utf8ZToString(_buffer);
|
||||
}
|
||||
|
||||
public bool IsNull() => _buffer == default;
|
||||
|
|
|
@ -43,7 +43,7 @@ namespace LibHac.Common
|
|||
|
||||
public override string ToString()
|
||||
{
|
||||
return StringUtils.Utf8ToString(_buffer);
|
||||
return StringUtils.Utf8ZToString(_buffer);
|
||||
}
|
||||
|
||||
public bool IsNull() => _buffer == null;
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
namespace LibHac.Fs
|
||||
using LibHac.Common;
|
||||
|
||||
namespace LibHac.Fs
|
||||
{
|
||||
public class FileStorageBasedFileSystem : FileStorage2
|
||||
{
|
||||
// ReSharper disable once UnusedAutoPropertyAccessor.Local
|
||||
// FS keeps a shared pointer to the base filesystem
|
||||
private IFileSystem BaseFileSystem { get; set; }
|
||||
private IFile BaseFile { get; set; }
|
||||
|
||||
private FileStorageBasedFileSystem() : base() { }
|
||||
private FileStorageBasedFileSystem() { }
|
||||
|
||||
public static Result CreateNew(out FileStorageBasedFileSystem created, IFileSystem baseFileSystem, string path,
|
||||
public static Result CreateNew(out FileStorageBasedFileSystem created, IFileSystem baseFileSystem, U8Span path,
|
||||
OpenMode mode)
|
||||
{
|
||||
var obj = new FileStorageBasedFileSystem();
|
||||
|
@ -24,9 +28,9 @@
|
|||
return rc;
|
||||
}
|
||||
|
||||
private Result Initialize(IFileSystem baseFileSystem, string path, OpenMode mode)
|
||||
private Result Initialize(IFileSystem baseFileSystem, U8Span path, OpenMode mode)
|
||||
{
|
||||
Result rc = baseFileSystem.OpenFile(out IFile file, path, mode);
|
||||
Result rc = baseFileSystem.OpenFile(out IFile file, path.ToString(), mode);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
SetFile(file);
|
||||
|
|
|
@ -79,6 +79,8 @@
|
|||
public static Result UnexpectedErrorInHostFileGetSize => new Result(ModuleFs, 5308);
|
||||
public static Result UnknownHostFileSystemError => new Result(ModuleFs, 5309);
|
||||
|
||||
public static Result InvalidNcaMountPoint => new Result(ModuleFs, 5320);
|
||||
|
||||
public static Result PreconditionViolation => new Result(ModuleFs, 6000);
|
||||
public static Result InvalidArgument => new Result(ModuleFs, 6001);
|
||||
public static Result InvalidPath => new Result(ModuleFs, 6002);
|
||||
|
|
52
src/LibHac/Fs/Shim/Application.cs
Normal file
52
src/LibHac/Fs/Shim/Application.cs
Normal file
|
@ -0,0 +1,52 @@
|
|||
using System;
|
||||
using LibHac.Common;
|
||||
using LibHac.FsService;
|
||||
using LibHac.FsSystem;
|
||||
|
||||
namespace LibHac.Fs.Shim
|
||||
{
|
||||
public static class Application
|
||||
{
|
||||
public static Result MountApplicationPackage(this FileSystemClient fs, U8Span mountName, U8Span path)
|
||||
{
|
||||
Result rc;
|
||||
|
||||
if (fs.IsEnabledAccessLog(AccessLogTarget.System))
|
||||
{
|
||||
TimeSpan startTime = fs.Time.GetCurrent();
|
||||
rc = Run(fs, mountName, path);
|
||||
TimeSpan endTime = fs.Time.GetCurrent();
|
||||
|
||||
fs.OutputAccessLog(rc, startTime, endTime, "");
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = Run(fs, mountName, path);
|
||||
}
|
||||
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
if (fs.IsEnabledAccessLog(AccessLogTarget.System))
|
||||
{
|
||||
fs.EnableFileSystemAccessorAccessLog(mountName);
|
||||
}
|
||||
|
||||
return Result.Success;
|
||||
|
||||
static Result Run(FileSystemClient fs, U8Span mountName, U8Span path)
|
||||
{
|
||||
Result rc = MountHelpers.CheckMountName(mountName);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
FsPath.FromSpan(out FsPath fsPath, path);
|
||||
|
||||
IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject();
|
||||
|
||||
rc = fsProxy.OpenFileSystemWithId(out IFileSystem fileSystem, ref fsPath, default, FileSystemProxyType.ApplicationPackage);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
return fs.Register(mountName, fileSystem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
13
src/LibHac/FsService/Creators/PartitionFileSystemCreator.cs
Normal file
13
src/LibHac/FsService/Creators/PartitionFileSystemCreator.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
using System;
|
||||
using LibHac.Fs;
|
||||
|
||||
namespace LibHac.FsService.Creators
|
||||
{
|
||||
public class PartitionFileSystemCreator : IPartitionFileSystemCreator
|
||||
{
|
||||
public Result Create(out IFileSystem fileSystem, IStorage pFsStorage)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
13
src/LibHac/FsService/Creators/RomFileSystemCreator.cs
Normal file
13
src/LibHac/FsService/Creators/RomFileSystemCreator.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
using System;
|
||||
using LibHac.Fs;
|
||||
|
||||
namespace LibHac.FsService.Creators
|
||||
{
|
||||
public class RomFileSystemCreator : IRomFileSystemCreator
|
||||
{
|
||||
public Result Create(out IFileSystem fileSystem, IStorage romFsStorage)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
29
src/LibHac/FsService/Creators/StorageOnNcaCreator.cs
Normal file
29
src/LibHac/FsService/Creators/StorageOnNcaCreator.cs
Normal file
|
@ -0,0 +1,29 @@
|
|||
using System;
|
||||
using LibHac.Fs;
|
||||
using LibHac.FsSystem.NcaUtils;
|
||||
|
||||
namespace LibHac.FsService.Creators
|
||||
{
|
||||
public class StorageOnNcaCreator : IStorageOnNcaCreator
|
||||
{
|
||||
public Result Create(out IStorage storage, out NcaFsHeader fsHeader, Nca nca, int fsIndex, bool isCodeFs)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Result CreateWithPatch(out IStorage storage, out NcaFsHeader fsHeader, Nca baseNca, Nca patchNca, int fsIndex, bool isCodeFs)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Result OpenNca(out Nca nca, IStorage ncaStorage)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Result VerifyAcidSignature(IFileSystem codeFileSystem, Nca nca)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
using System;
|
||||
using LibHac.Fs;
|
||||
|
||||
namespace LibHac.FsService.Creators
|
||||
{
|
||||
public class TargetManagerFileSystemCreator : ITargetManagerFileSystemCreator
|
||||
{
|
||||
public Result Create(out IFileSystem fileSystem, bool openCaseSensitive)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Result GetCaseSensitivePath(out bool isSuccess, ref string path)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,6 +16,10 @@ namespace LibHac.FsService
|
|||
|
||||
var gcStorageCreator = new EmulatedGameCardStorageCreator(gameCard);
|
||||
|
||||
creators.RomFileSystemCreator = new RomFileSystemCreator();
|
||||
creators.PartitionFileSystemCreator = new PartitionFileSystemCreator();
|
||||
creators.StorageOnNcaCreator = new StorageOnNcaCreator();
|
||||
creators.TargetManagerFileSystemCreator = new TargetManagerFileSystemCreator();
|
||||
creators.SubDirectoryFileSystemCreator = new SubDirectoryFileSystemCreator();
|
||||
creators.SaveDataFileSystemCreator = new SaveDataFileSystemCreator(keyset);
|
||||
creators.GameCardStorageCreator = gcStorageCreator;
|
||||
|
|
Loading…
Reference in a new issue