mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Add MountContent shims
This commit is contained in:
parent
c6a261eeee
commit
a6161e693c
5 changed files with 82 additions and 8 deletions
|
@ -63,7 +63,16 @@ namespace LibHac.Fs
|
|||
SdCard = 1
|
||||
}
|
||||
|
||||
public enum FileSystemType
|
||||
public enum ContentType
|
||||
{
|
||||
Meta = 0,
|
||||
Control = 1,
|
||||
Manual = 2,
|
||||
Logo = 3,
|
||||
Data = 4,
|
||||
}
|
||||
|
||||
public enum FileSystemProxyType
|
||||
{
|
||||
Code = 0,
|
||||
Data = 1,
|
||||
|
|
65
src/LibHac/Fs/Shim/Content.cs
Normal file
65
src/LibHac/Fs/Shim/Content.cs
Normal file
|
@ -0,0 +1,65 @@
|
|||
using System;
|
||||
using LibHac.Common;
|
||||
using LibHac.FsService;
|
||||
using LibHac.FsSystem;
|
||||
using LibHac.Ncm;
|
||||
|
||||
namespace LibHac.Fs.Shim
|
||||
{
|
||||
public static class Content
|
||||
{
|
||||
public static Result MountContent(this FileSystemClient fs, U8Span mountName, U8Span path, ContentType type)
|
||||
{
|
||||
if (type == ContentType.Meta)
|
||||
return ResultFs.InvalidArgument.Log();
|
||||
|
||||
return MountContent(fs, mountName, path, TitleId.Zero, type);
|
||||
}
|
||||
|
||||
public static Result MountContent(this FileSystemClient fs, U8Span mountName, TitleId programId, ContentType type)
|
||||
{
|
||||
Result rc = MountHelpers.CheckMountNameAcceptingReservedMountName(mountName);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
FileSystemProxyType fspType = ConvertToFileSystemProxyType(type);
|
||||
|
||||
IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject();
|
||||
|
||||
rc = fsProxy.OpenFileSystemWithPatch(out IFileSystem fileSystem, programId, fspType);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
return fs.Register(mountName, fileSystem);
|
||||
}
|
||||
|
||||
public static Result MountContent(this FileSystemClient fs, U8Span mountName, U8Span path, TitleId titleId, ContentType type)
|
||||
{
|
||||
Result rc = MountHelpers.CheckMountNameAcceptingReservedMountName(mountName);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
FileSystemProxyType fspType = ConvertToFileSystemProxyType(type);
|
||||
|
||||
return MountContentImpl(fs, mountName, path, titleId, fspType);
|
||||
}
|
||||
|
||||
private static Result MountContentImpl(FileSystemClient fs, U8Span mountName, U8Span path, TitleId titleId, FileSystemProxyType type)
|
||||
{
|
||||
FsPath.FromSpan(out FsPath fsPath, path);
|
||||
|
||||
IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject();
|
||||
|
||||
Result rc = fsProxy.OpenFileSystemWithId(out IFileSystem fileSystem, ref fsPath, titleId, type);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
return fs.Register(mountName, fileSystem);
|
||||
}
|
||||
|
||||
private static FileSystemProxyType ConvertToFileSystemProxyType(ContentType type) => type switch
|
||||
{
|
||||
ContentType.Meta => FileSystemProxyType.ContentMeta,
|
||||
ContentType.Control => FileSystemProxyType.ContentControl,
|
||||
ContentType.Manual => FileSystemProxyType.ContentManual,
|
||||
ContentType.Data => FileSystemProxyType.ContentData,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null),
|
||||
};
|
||||
}
|
||||
}
|
|
@ -38,12 +38,12 @@ namespace LibHac.FsService
|
|||
AutoCreateSaveData = true;
|
||||
}
|
||||
|
||||
public Result OpenFileSystemWithId(out IFileSystem fileSystem, ref FsPath path, TitleId titleId, FileSystemType type)
|
||||
public Result OpenFileSystemWithId(out IFileSystem fileSystem, ref FsPath path, TitleId titleId, FileSystemProxyType type)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Result OpenFileSystemWithPatch(out IFileSystem fileSystem, TitleId titleId, FileSystemType type)
|
||||
public Result OpenFileSystemWithPatch(out IFileSystem fileSystem, TitleId titleId, FileSystemProxyType type)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
|
|
@ -11,8 +11,8 @@ namespace LibHac.FsService
|
|||
{
|
||||
Result SetCurrentProcess(long processId);
|
||||
Result OpenDataFileSystemByCurrentProcess(out IFileSystem fileSystem);
|
||||
Result OpenFileSystemWithPatch(out IFileSystem fileSystem, TitleId titleId, FileSystemType type);
|
||||
Result OpenFileSystemWithId(out IFileSystem fileSystem, ref FsPath path, TitleId titleId, FileSystemType type);
|
||||
Result OpenFileSystemWithPatch(out IFileSystem fileSystem, TitleId titleId, FileSystemProxyType type);
|
||||
Result OpenFileSystemWithId(out IFileSystem fileSystem, ref FsPath path, TitleId titleId, FileSystemProxyType type);
|
||||
Result OpenDataFileSystemByProgramId(out IFileSystem fileSystem, TitleId titleId);
|
||||
Result OpenBisFileSystem(out IFileSystem fileSystem, ref FsPath rootPath, BisPartitionId partitionId);
|
||||
Result OpenBisStorage(out IStorage storage, BisPartitionId partitionId);
|
||||
|
|
|
@ -162,11 +162,11 @@ namespace LibHac
|
|||
|
||||
switch (content.Type)
|
||||
{
|
||||
case ContentType.Program:
|
||||
case ContentType.Data:
|
||||
case Ncm.ContentType.Program:
|
||||
case Ncm.ContentType.Data:
|
||||
title.MainNca = contentNca;
|
||||
break;
|
||||
case ContentType.Control:
|
||||
case Ncm.ContentType.Control:
|
||||
title.ControlNca = contentNca;
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue