Add MountContent shims

This commit is contained in:
Alex Barney 2019-11-01 12:47:55 -05:00
parent c6a261eeee
commit a6161e693c
5 changed files with 82 additions and 8 deletions

View file

@ -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,

View 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),
};
}
}

View file

@ -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();
}

View file

@ -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);

View file

@ -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;
}