Update to LibHac v0.14.3 (#2925)

* Update to LibHac v0.14.3

* Fix loading NCAs that don't have a data partition
This commit is contained in:
Alex Barney 2021-12-23 09:55:50 -07:00 committed by GitHub
parent cb43cc7e32
commit aa932a6df1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
33 changed files with 554 additions and 406 deletions

View File

@ -14,6 +14,7 @@ using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using Path = System.IO.Path;
namespace Ryujinx.HLE.FileSystem.Content
{
@ -203,10 +204,10 @@ namespace Ryujinx.HLE.FileSystem.Content
foreach (var ncaPath in fs.EnumerateEntries("*.cnmt.nca", SearchOptions.Default))
{
fs.OpenFile(out IFile ncaFile, ncaPath.FullPath.ToU8Span(), OpenMode.Read);
using (ncaFile)
{
var nca = new Nca(_virtualFileSystem.KeySet, ncaFile.AsStorage());
using var ncaFile = new UniqueRef<IFile>();
fs.OpenFile(ref ncaFile.Ref(), ncaPath.FullPath.ToU8Span(), OpenMode.Read);
var nca = new Nca(_virtualFileSystem.KeySet, ncaFile.Get.AsStorage());
if (nca.Header.ContentType != NcaContentType.Meta)
{
Logger.Warning?.Print(LogClass.Application, $"{ncaPath} is not a valid metadata file");
@ -215,12 +216,11 @@ namespace Ryujinx.HLE.FileSystem.Content
}
using var pfs0 = nca.OpenFileSystem(0, integrityCheckLevel);
using var cnmtFile = new UniqueRef<IFile>();
pfs0.OpenFile(out IFile cnmtFile, pfs0.EnumerateEntries().Single().FullPath.ToU8Span(), OpenMode.Read);
pfs0.OpenFile(ref cnmtFile.Ref(), pfs0.EnumerateEntries().Single().FullPath.ToU8Span(), OpenMode.Read);
using (cnmtFile)
{
var cnmt = new Cnmt(cnmtFile.AsStream());
var cnmt = new Cnmt(cnmtFile.Get.AsStream());
if (cnmt.Type != ContentMetaType.AddOnContent || (cnmt.TitleId & 0xFFFFFFFFFFFFE000) != aocBaseId)
{
@ -238,8 +238,6 @@ namespace Ryujinx.HLE.FileSystem.Content
}
}
}
}
}
public void AddAocItem(ulong titleId, string containerPath, string ncaPath, bool enabled)
{
@ -272,24 +270,24 @@ namespace Ryujinx.HLE.FileSystem.Content
if (_aocData.TryGetValue(aocTitleId, out AocItem aoc) && aoc.Enabled)
{
var file = new FileStream(aoc.ContainerPath, FileMode.Open, FileAccess.Read);
using var ncaFile = new UniqueRef<IFile>();
PartitionFileSystem pfs;
IFile ncaFile;
switch (Path.GetExtension(aoc.ContainerPath))
{
case ".xci":
pfs = new Xci(_virtualFileSystem.KeySet, file.AsStorage()).OpenPartition(XciPartitionType.Secure);
pfs.OpenFile(out ncaFile, aoc.NcaPath.ToU8Span(), OpenMode.Read);
pfs.OpenFile(ref ncaFile.Ref(), aoc.NcaPath.ToU8Span(), OpenMode.Read);
break;
case ".nsp":
pfs = new PartitionFileSystem(file.AsStorage());
pfs.OpenFile(out ncaFile, aoc.NcaPath.ToU8Span(), OpenMode.Read);
pfs.OpenFile(ref ncaFile.Ref(), aoc.NcaPath.ToU8Span(), OpenMode.Read);
break;
default:
return false; // Print error?
}
aocStorage = new Nca(_virtualFileSystem.KeySet, ncaFile.AsStorage()).OpenStorage(NcaSectionType.Data, integrityCheckLevel);
aocStorage = new Nca(_virtualFileSystem.KeySet, ncaFile.Get.AsStorage()).OpenStorage(NcaSectionType.Data, integrityCheckLevel);
return true;
}
@ -625,18 +623,18 @@ namespace Ryujinx.HLE.FileSystem.Content
private IFile OpenPossibleFragmentedFile(IFileSystem filesystem, string path, OpenMode mode)
{
IFile file;
using var file = new UniqueRef<IFile>();
if (filesystem.FileExists($"{path}/00"))
{
filesystem.OpenFile(out file, $"{path}/00".ToU8Span(), mode);
filesystem.OpenFile(ref file.Ref(), $"{path}/00".ToU8Span(), mode);
}
else
{
filesystem.OpenFile(out file, path.ToU8Span(), mode);
filesystem.OpenFile(ref file.Ref(), path.ToU8Span(), mode);
}
return file;
return file.Release();
}
private Stream GetZipStream(ZipArchiveEntry entry)
@ -753,9 +751,11 @@ namespace Ryujinx.HLE.FileSystem.Content
string cnmtPath = fs.EnumerateEntries("/", "*.cnmt").Single().FullPath;
if (fs.OpenFile(out IFile metaFile, cnmtPath.ToU8Span(), OpenMode.Read).IsSuccess())
using var metaFile = new UniqueRef<IFile>();
if (fs.OpenFile(ref metaFile.Ref(), cnmtPath.ToU8Span(), OpenMode.Read).IsSuccess())
{
var meta = new Cnmt(metaFile.AsStream());
var meta = new Cnmt(metaFile.Get.AsStream());
if (meta.Type == ContentMetaType.SystemUpdate)
{
@ -781,9 +781,11 @@ namespace Ryujinx.HLE.FileSystem.Content
var romfs = nca.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.ErrorOnInvalid);
if (romfs.OpenFile(out IFile systemVersionFile, "/file".ToU8Span(), OpenMode.Read).IsSuccess())
using var systemVersionFile = new UniqueRef<IFile>();
if (romfs.OpenFile(ref systemVersionFile.Ref(), "/file".ToU8Span(), OpenMode.Read).IsSuccess())
{
systemVersion = new SystemVersion(systemVersionFile.AsStream());
systemVersion = new SystemVersion(systemVersionFile.Get.AsStream());
}
}
}
@ -818,9 +820,11 @@ namespace Ryujinx.HLE.FileSystem.Content
string cnmtPath = fs.EnumerateEntries("/", "*.cnmt").Single().FullPath;
if (fs.OpenFile(out IFile metaFile, cnmtPath.ToU8Span(), OpenMode.Read).IsSuccess())
using var metaFile = new UniqueRef<IFile>();
if (fs.OpenFile(ref metaFile.Ref(), cnmtPath.ToU8Span(), OpenMode.Read).IsSuccess())
{
var meta = new Cnmt(metaFile.AsStream());
var meta = new Cnmt(metaFile.Get.AsStream());
IStorage contentStorage = contentNcaStream.AsStorage();
if (contentStorage.GetSize(out long size).IsSuccess())
@ -887,9 +891,11 @@ namespace Ryujinx.HLE.FileSystem.Content
string cnmtPath = fs.EnumerateEntries("/", "*.cnmt").Single().FullPath;
if (fs.OpenFile(out IFile metaFile, cnmtPath.ToU8Span(), OpenMode.Read).IsSuccess())
using var metaFile = new UniqueRef<IFile>();
if (fs.OpenFile(ref metaFile.Ref(), cnmtPath.ToU8Span(), OpenMode.Read).IsSuccess())
{
var meta = new Cnmt(metaFile.AsStream());
var meta = new Cnmt(metaFile.Get.AsStream());
if (meta.Type == ContentMetaType.SystemUpdate)
{
@ -903,9 +909,11 @@ namespace Ryujinx.HLE.FileSystem.Content
{
var romfs = nca.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.ErrorOnInvalid);
if (romfs.OpenFile(out IFile systemVersionFile, "/file".ToU8Span(), OpenMode.Read).IsSuccess())
using var systemVersionFile = new UniqueRef<IFile>();
if (romfs.OpenFile(ref systemVersionFile.Ref(), "/file".ToU8Span(), OpenMode.Read).IsSuccess())
{
systemVersion = new SystemVersion(systemVersionFile.AsStream());
systemVersion = new SystemVersion(systemVersionFile.Get.AsStream());
}
}
@ -952,9 +960,11 @@ namespace Ryujinx.HLE.FileSystem.Content
string cnmtPath = fs.EnumerateEntries("/", "*.cnmt").Single().FullPath;
if (fs.OpenFile(out IFile metaFile, cnmtPath.ToU8Span(), OpenMode.Read).IsSuccess())
using var metaFile = new UniqueRef<IFile>();
if (fs.OpenFile(ref metaFile.Ref(), cnmtPath.ToU8Span(), OpenMode.Read).IsSuccess())
{
var meta = new Cnmt(metaFile.AsStream());
var meta = new Cnmt(metaFile.Get.AsStream());
if (contentStorage.GetSize(out long size).IsSuccess())
{
@ -1020,9 +1030,11 @@ namespace Ryujinx.HLE.FileSystem.Content
{
var romfs = nca.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.ErrorOnInvalid);
if (romfs.OpenFile(out IFile systemVersionFile, "/file".ToU8Span(), OpenMode.Read).IsSuccess())
using var systemVersionFile = new UniqueRef<IFile>();
if (romfs.OpenFile(ref systemVersionFile.Ref(), "/file".ToU8Span(), OpenMode.Read).IsSuccess())
{
return new SystemVersion(systemVersionFile.AsStream());
return new SystemVersion(systemVersionFile.Get.AsStream());
}
}

View File

@ -3,25 +3,23 @@ using LibHac.Common;
using LibHac.Fs;
using LibHac.Fs.Fsa;
using LibHac.FsSrv.FsCreator;
using LibHac.FsSystem;
namespace Ryujinx.HLE.FileSystem
{
public class EncryptedFileSystemCreator : IEncryptedFileSystemCreator
{
public Result Create(out ReferenceCountedDisposable<IFileSystem> encryptedFileSystem, ReferenceCountedDisposable<IFileSystem> baseFileSystem,
EncryptedFsKeyId keyId, in EncryptionSeed encryptionSeed)
{
UnsafeHelpers.SkipParamInit(out encryptedFileSystem);
if (keyId < EncryptedFsKeyId.Save || keyId > EncryptedFsKeyId.CustomStorage)
public Result Create(ref SharedRef<IFileSystem> outEncryptedFileSystem,
ref SharedRef<IFileSystem> baseFileSystem, IEncryptedFileSystemCreator.KeyId idIndex,
in EncryptionSeed encryptionSeed)
{
if (idIndex < IEncryptedFileSystemCreator.KeyId.Save || idIndex > IEncryptedFileSystemCreator.KeyId.CustomStorage)
{
return ResultFs.InvalidArgument.Log();
}
// Force all-zero keys for now since people can open the emulator with different keys or sd seeds sometimes
var fs = new AesXtsFileSystem(baseFileSystem, new byte[0x32], 0x4000);
encryptedFileSystem = new ReferenceCountedDisposable<IFileSystem>(fs);
// Todo: Reenable when AesXtsFileSystem is fixed
outEncryptedFileSystem = SharedRef<IFileSystem>.CreateMove(ref baseFileSystem);
return Result.Success;
}

View File

@ -17,6 +17,8 @@ using System.Buffers.Text;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
using Path = System.IO.Path;
using RightsId = LibHac.Fs.RightsId;
namespace Ryujinx.HLE.FileSystem
@ -240,11 +242,13 @@ namespace Ryujinx.HLE.FileSystem
{
foreach (DirectoryEntryEx ticketEntry in fs.EnumerateEntries("/", "*.tik"))
{
Result result = fs.OpenFile(out IFile ticketFile, ticketEntry.FullPath.ToU8Span(), OpenMode.Read);
using var ticketFile = new UniqueRef<IFile>();
Result result = fs.OpenFile(ref ticketFile.Ref(), ticketEntry.FullPath.ToU8Span(), OpenMode.Read);
if (result.IsSuccess())
{
Ticket ticket = new Ticket(ticketFile.AsStream());
Ticket ticket = new Ticket(ticketFile.Get.AsStream());
if (ticket.TitleKeyType == TitleKeyType.Common)
{
@ -280,12 +284,14 @@ namespace Ryujinx.HLE.FileSystem
{
Span<SaveDataInfo> info = stackalloc SaveDataInfo[8];
Result rc = hos.Fs.OpenSaveDataIterator(out var iterator, spaceId);
using var iterator = new UniqueRef<SaveDataIterator>();
Result rc = hos.Fs.OpenSaveDataIterator(ref iterator.Ref(), spaceId);
if (rc.IsFailure()) return rc;
while (true)
{
rc = iterator.ReadSaveDataInfo(out long count, info);
rc = iterator.Get.ReadSaveDataInfo(out long count, info);
if (rc.IsFailure()) return rc;
if (count == 0)

View File

@ -116,8 +116,10 @@ namespace Ryujinx.HLE.HOS.Applets.Error
if (romfs.FileExists(filePath))
{
romfs.OpenFile(out IFile binaryFile, filePath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
StreamReader reader = new StreamReader(binaryFile.AsStream(), Encoding.Unicode);
using var binaryFile = new UniqueRef<IFile>();
romfs.OpenFile(ref binaryFile.Ref(), filePath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
StreamReader reader = new StreamReader(binaryFile.Get.AsStream(), Encoding.Unicode);
return CleanText(reader.ReadToEnd());
}

View File

@ -25,6 +25,7 @@ using System.Reflection;
using static LibHac.Fs.ApplicationSaveDataManagement;
using static Ryujinx.HLE.HOS.ModLoader;
using ApplicationId = LibHac.Ncm.ApplicationId;
using Path = System.IO.Path;
namespace Ryujinx.HLE.HOS
{
@ -101,9 +102,11 @@ namespace Ryujinx.HLE.HOS
foreach (DirectoryEntryEx fileEntry in pfs.EnumerateEntries("/", "*.nca"))
{
pfs.OpenFile(out IFile ncaFile, fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
using var ncaFile = new UniqueRef<IFile>();
Nca nca = new Nca(fileSystem.KeySet, ncaFile.AsStorage());
pfs.OpenFile(ref ncaFile.Ref(), fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
Nca nca = new Nca(fileSystem.KeySet, ncaFile.Release().AsStorage());
int ncaProgramIndex = (int)(nca.Header.TitleId & 0xF);
@ -116,7 +119,7 @@ namespace Ryujinx.HLE.HOS
{
int dataIndex = Nca.GetSectionIndexFromType(NcaSectionType.Data, NcaContentType.Program);
if (nca.Header.GetFsHeader(dataIndex).IsPatchSection())
if (nca.SectionExists(NcaSectionType.Data) && nca.Header.GetFsHeader(dataIndex).IsPatchSection())
{
patchNca = nca;
}
@ -143,9 +146,11 @@ namespace Ryujinx.HLE.HOS
foreach (DirectoryEntryEx fileEntry in pfs.EnumerateEntries("/", "*.nca"))
{
pfs.OpenFile(out IFile ncaFile, fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
using var ncaFile = new UniqueRef<IFile>();
Nca nca = new Nca(fileSystem.KeySet, ncaFile.AsStorage());
pfs.OpenFile(ref ncaFile.Ref(), fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
Nca nca = new Nca(fileSystem.KeySet, ncaFile.Release().AsStorage());
int ncaProgramIndex = (int)(nca.Header.TitleId & 0xF);
@ -429,7 +434,9 @@ namespace Ryujinx.HLE.HOS
// Sets TitleId, so be sure to call before using it
private MetaLoader ReadNpdm(IFileSystem fs)
{
Result result = fs.OpenFile(out IFile npdmFile, "/main.npdm".ToU8Span(), OpenMode.Read);
using var npdmFile = new UniqueRef<IFile>();
Result result = fs.OpenFile(ref npdmFile.Ref(), "/main.npdm".ToU8Span(), OpenMode.Read);
MetaLoader metaData;
@ -441,10 +448,10 @@ namespace Ryujinx.HLE.HOS
}
else
{
npdmFile.GetSize(out long fileSize).ThrowIfFailure();
npdmFile.Get.GetSize(out long fileSize).ThrowIfFailure();
var npdmBuffer = new byte[fileSize];
npdmFile.Read(out _, 0, npdmBuffer).ThrowIfFailure();
npdmFile.Get.Read(out _, 0, npdmBuffer).ThrowIfFailure();
metaData = new MetaLoader();
metaData.Load(npdmBuffer).ThrowIfFailure();
@ -461,12 +468,14 @@ namespace Ryujinx.HLE.HOS
private static void ReadControlData(Switch device, Nca controlNca, ref BlitStruct<ApplicationControlProperty> controlData, ref string titleName, ref string displayVersion)
{
using var controlFile = new UniqueRef<IFile>();
IFileSystem controlFs = controlNca.OpenFileSystem(NcaSectionType.Data, device.System.FsIntegrityCheckLevel);
Result result = controlFs.OpenFile(out IFile controlFile, "/control.nacp".ToU8Span(), OpenMode.Read);
Result result = controlFs.OpenFile(ref controlFile.Ref(), "/control.nacp".ToU8Span(), OpenMode.Read);
if (result.IsSuccess())
{
result = controlFile.Read(out long bytesRead, 0, controlData.ByteSpan, ReadOption.None);
result = controlFile.Get.Read(out long bytesRead, 0, controlData.ByteSpan, ReadOption.None);
if (result.IsSuccess() && bytesRead == controlData.ByteSpan.Length)
{
@ -508,9 +517,11 @@ namespace Ryujinx.HLE.HOS
Logger.Info?.Print(LogClass.Loader, $"Loading {name}...");
codeFs.OpenFile(out IFile nsoFile, $"/{name}".ToU8Span(), OpenMode.Read).ThrowIfFailure();
using var nsoFile = new UniqueRef<IFile>();
nsos[i] = new NsoExecutable(nsoFile.AsStorage(), name);
codeFs.OpenFile(ref nsoFile.Ref(), $"/{name}".ToU8Span(), OpenMode.Read).ThrowIfFailure();
nsos[i] = new NsoExecutable(nsoFile.Release().AsStorage(), name);
}
// ExeFs file replacements
@ -680,9 +691,11 @@ namespace Ryujinx.HLE.HOS
foreach (DirectoryEntryEx fileEntry in pfs.EnumerateEntries("/", "*.nca"))
{
pfs.OpenFile(out IFile ncaFile, fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
using var ncaFile = new UniqueRef<IFile>();
Nca nca = new Nca(fileSystem.KeySet, ncaFile.AsStorage());
pfs.OpenFile(ref ncaFile.Ref(), fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
Nca nca = new Nca(fileSystem.KeySet, ncaFile.Release().AsStorage());
if (nca.Header.ContentType != NcaContentType.Program)
{
@ -691,7 +704,7 @@ namespace Ryujinx.HLE.HOS
int dataIndex = Nca.GetSectionIndexFromType(NcaSectionType.Data, NcaContentType.Program);
if (nca.Header.GetFsHeader(dataIndex).IsPatchSection())
if (nca.SectionExists(NcaSectionType.Data) && nca.Header.GetFsHeader(dataIndex).IsPatchSection())
{
continue;
}

View File

@ -1,3 +1,4 @@
using LibHac.Common;
using LibHac.Common.Keys;
using LibHac.Fs;
using LibHac.Fs.Shim;
@ -306,9 +307,9 @@ namespace Ryujinx.HLE.HOS
public void LoadKip(string kipPath)
{
using IStorage kipFile = new LocalStorage(kipPath, FileAccess.Read);
using var kipFile = new SharedRef<IStorage>(new LocalStorage(kipPath, FileAccess.Read));
ProgramLoader.LoadKip(KernelContext, new KipExecutable(kipFile));
ProgramLoader.LoadKip(KernelContext, new KipExecutable(in kipFile));
}
public void ChangeDockedModeState(bool newState)

View File

@ -26,7 +26,8 @@ namespace Ryujinx.HLE.HOS
public HorizonClient NsClient { get; private set; }
public HorizonClient SdbClient { get; private set; }
internal LibHacIReader ArpIReader { get; private set; }
private SharedRef<LibHacIReader> _arpIReader;
internal LibHacIReader ArpIReader => _arpIReader.Get;
public LibHacHorizonManager()
{
@ -42,8 +43,8 @@ namespace Ryujinx.HLE.HOS
public void InitializeArpServer()
{
ArpIReader = new LibHacIReader();
RyujinxClient.Sm.RegisterService(new LibHacArpServiceObject(ArpIReader), "arp:r").ThrowIfFailure();
_arpIReader.Reset(new LibHacIReader());
RyujinxClient.Sm.RegisterService(new LibHacArpServiceObject(ref _arpIReader), "arp:r").ThrowIfFailure();
}
public void InitializeBcatServer()

View File

@ -15,6 +15,7 @@ using System.Linq;
using System.IO;
using Ryujinx.HLE.HOS.Kernel.Process;
using System.Globalization;
using Path = System.IO.Path;
namespace Ryujinx.HLE.HOS
{
@ -470,8 +471,10 @@ namespace Ryujinx.HLE.HOS
.Where(f => f.Type == DirectoryEntryType.File && !fileSet.Contains(f.FullPath))
.OrderBy(f => f.FullPath, StringComparer.Ordinal))
{
baseRom.OpenFile(out IFile file, entry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
builder.AddFile(entry.FullPath, file);
using var file = new UniqueRef<IFile>();
baseRom.OpenFile(ref file.Ref(), entry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
builder.AddFile(entry.FullPath, file.Release());
}
Logger.Info?.Print(LogClass.ModLoader, "Building new RomFS...");
@ -487,10 +490,12 @@ namespace Ryujinx.HLE.HOS
.Where(f => f.Type == DirectoryEntryType.File)
.OrderBy(f => f.FullPath, StringComparer.Ordinal))
{
fs.OpenFile(out IFile file, entry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
using var file = new UniqueRef<IFile>();
fs.OpenFile(ref file.Ref(), entry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
if (fileSet.Add(entry.FullPath))
{
builder.AddFile(entry.FullPath, file);
builder.AddFile(entry.FullPath, file.Release());
}
else
{

View File

@ -1,4 +1,5 @@
using LibHac;
using LibHac.Common;
using LibHac.Fs;
using LibHac.Fs.Shim;
using Ryujinx.Common;
@ -170,13 +171,15 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc
SaveDataFilter saveDataFilter = new SaveDataFilter();
saveDataFilter.SetUserId(new LibHac.Fs.UserId((ulong)userId.High, (ulong)userId.Low));
_horizonClient.Fs.OpenSaveDataIterator(out SaveDataIterator saveDataIterator, SaveDataSpaceId.User, in saveDataFilter).ThrowIfFailure();
using var saveDataIterator = new UniqueRef<SaveDataIterator>();
_horizonClient.Fs.OpenSaveDataIterator(ref saveDataIterator.Ref(), SaveDataSpaceId.User, in saveDataFilter).ThrowIfFailure();
Span<SaveDataInfo> saveDataInfo = stackalloc SaveDataInfo[10];
while (true)
{
saveDataIterator.ReadSaveDataInfo(out long readCount, saveDataInfo).ThrowIfFailure();
saveDataIterator.Get.ReadSaveDataInfo(out long readCount, saveDataInfo).ThrowIfFailure();
if (readCount == 0)
{

View File

@ -1,4 +1,5 @@
using LibHac;
using LibHac.Common;
using LibHac.Ncm;
using LibHac.Ns;
using System;
@ -22,6 +23,8 @@ namespace Ryujinx.HLE.HOS.Services.Arp
return Result.Success;
}
public void Dispose() { }
public Result GetApplicationLaunchPropertyWithApplicationId(out LibHac.Arp.ApplicationLaunchProperty launchProperty, ApplicationId applicationId)
{
launchProperty = new LibHac.Arp.ApplicationLaunchProperty
@ -51,16 +54,21 @@ namespace Ryujinx.HLE.HOS.Services.Arp
internal class LibHacArpServiceObject : LibHac.Sm.IServiceObject
{
private LibHacIReader _serviceObject;
private SharedRef<LibHacIReader> _serviceObject;
public LibHacArpServiceObject(LibHacIReader serviceObject)
public LibHacArpServiceObject(ref SharedRef<LibHacIReader> serviceObject)
{
_serviceObject = serviceObject;
_serviceObject = SharedRef<LibHacIReader>.CreateCopy(in serviceObject);
}
public Result GetServiceObject(out object serviceObject)
public void Dispose()
{
serviceObject = _serviceObject;
_serviceObject.Destroy();
}
public Result GetServiceObject(ref SharedRef<IDisposable> serviceObject)
{
serviceObject.SetByCopy(in _serviceObject);
return Result.Success;
}

View File

@ -1,4 +1,5 @@
using LibHac;
using LibHac.Common;
using Ryujinx.Common;
using Ryujinx.HLE.HOS.Services.Bcat.ServiceCreator;
using Ryujinx.HLE.HOS.Services.Arp;
@ -9,14 +10,22 @@ namespace Ryujinx.HLE.HOS.Services.Bcat
[Service("bcat:m", "bcat:m")]
[Service("bcat:u", "bcat:u")]
[Service("bcat:s", "bcat:s")]
class IServiceCreator : IpcService
class IServiceCreator : DisposableIpcService
{
private LibHac.Bcat.Impl.Ipc.IServiceCreator _base;
private SharedRef<LibHac.Bcat.Impl.Ipc.IServiceCreator> _base;
public IServiceCreator(ServiceCtx context, string serviceName)
{
var applicationClient = context.Device.System.LibHacHorizonManager.ApplicationClient;
applicationClient.Sm.GetService(out _base, serviceName).ThrowIfFailure();
applicationClient.Sm.GetService(ref _base, serviceName).ThrowIfFailure();
}
protected override void Dispose(bool isDisposing)
{
if (isDisposing)
{
_base.Destroy();
}
}
[CommandHipc(0)]
@ -43,11 +52,13 @@ namespace Ryujinx.HLE.HOS.Services.Bcat
{
ulong pid = context.RequestData.ReadUInt64();
Result rc = _base.CreateDeliveryCacheStorageService(out LibHac.Bcat.Impl.Ipc.IDeliveryCacheStorageService serv, pid);
using var serv = new SharedRef<LibHac.Bcat.Impl.Ipc.IDeliveryCacheStorageService>();
Result rc = _base.Get.CreateDeliveryCacheStorageService(ref serv.Ref(), pid);
if (rc.IsSuccess())
{
MakeObject(context, new IDeliveryCacheStorageService(context, serv));
MakeObject(context, new IDeliveryCacheStorageService(context, ref serv.Ref()));
}
return (ResultCode)rc.Value;
@ -59,12 +70,13 @@ namespace Ryujinx.HLE.HOS.Services.Bcat
{
ApplicationId applicationId = context.RequestData.ReadStruct<ApplicationId>();
Result rc = _base.CreateDeliveryCacheStorageServiceWithApplicationId(out LibHac.Bcat.Impl.Ipc.IDeliveryCacheStorageService serv,
applicationId);
using var service = new SharedRef<LibHac.Bcat.Impl.Ipc.IDeliveryCacheStorageService>();
Result rc = _base.Get.CreateDeliveryCacheStorageServiceWithApplicationId(ref service.Ref(), applicationId);
if (rc.IsSuccess())
{
MakeObject(context, new IDeliveryCacheStorageService(context, serv));
MakeObject(context, new IDeliveryCacheStorageService(context, ref service.Ref()));
}
return (ResultCode)rc.Value;

View File

@ -1,5 +1,6 @@
using LibHac;
using LibHac.Bcat;
using LibHac.Common;
using Ryujinx.Common;
using System.Runtime.InteropServices;
@ -7,11 +8,19 @@ namespace Ryujinx.HLE.HOS.Services.Bcat.ServiceCreator
{
class IDeliveryCacheDirectoryService : DisposableIpcService
{
private LibHac.Bcat.Impl.Ipc.IDeliveryCacheDirectoryService _base;
private SharedRef<LibHac.Bcat.Impl.Ipc.IDeliveryCacheDirectoryService> _base;
public IDeliveryCacheDirectoryService(LibHac.Bcat.Impl.Ipc.IDeliveryCacheDirectoryService baseService)
public IDeliveryCacheDirectoryService(ref SharedRef<LibHac.Bcat.Impl.Ipc.IDeliveryCacheDirectoryService> baseService)
{
_base = baseService;
_base = SharedRef<LibHac.Bcat.Impl.Ipc.IDeliveryCacheDirectoryService>.CreateMove(ref baseService);
}
protected override void Dispose(bool isDisposing)
{
if (isDisposing)
{
_base.Destroy();
}
}
[CommandHipc(0)]
@ -20,7 +29,7 @@ namespace Ryujinx.HLE.HOS.Services.Bcat.ServiceCreator
{
DirectoryName directoryName = context.RequestData.ReadStruct<DirectoryName>();
Result result = _base.Open(ref directoryName);
Result result = _base.Get.Open(ref directoryName);
return (ResultCode)result.Value;
}
@ -34,7 +43,7 @@ namespace Ryujinx.HLE.HOS.Services.Bcat.ServiceCreator
byte[] data = new byte[size];
Result result = _base.Read(out int entriesRead, MemoryMarshal.Cast<byte, DeliveryCacheDirectoryEntry>(data));
Result result = _base.Get.Read(out int entriesRead, MemoryMarshal.Cast<byte, DeliveryCacheDirectoryEntry>(data));
context.Memory.Write(position, data);
@ -47,19 +56,11 @@ namespace Ryujinx.HLE.HOS.Services.Bcat.ServiceCreator
// GetCount() -> u32
public ResultCode GetCount(ServiceCtx context)
{
Result result = _base.GetCount(out int count);
Result result = _base.Get.GetCount(out int count);
context.ResponseData.Write(count);
return (ResultCode)result.Value;
}
protected override void Dispose(bool isDisposing)
{
if (isDisposing)
{
_base?.Dispose();
}
}
}
}

View File

@ -1,16 +1,25 @@
using LibHac;
using LibHac.Bcat;
using LibHac.Common;
using Ryujinx.Common;
namespace Ryujinx.HLE.HOS.Services.Bcat.ServiceCreator
{
class IDeliveryCacheFileService : DisposableIpcService
{
private LibHac.Bcat.Impl.Ipc.IDeliveryCacheFileService _base;
private SharedRef<LibHac.Bcat.Impl.Ipc.IDeliveryCacheFileService> _base;
public IDeliveryCacheFileService(LibHac.Bcat.Impl.Ipc.IDeliveryCacheFileService baseService)
public IDeliveryCacheFileService(ref SharedRef<LibHac.Bcat.Impl.Ipc.IDeliveryCacheFileService> baseService)
{
_base = baseService;
_base = SharedRef<LibHac.Bcat.Impl.Ipc.IDeliveryCacheFileService>.CreateMove(ref baseService);
}
protected override void Dispose(bool isDisposing)
{
if (isDisposing)
{
_base.Destroy();
}
}
[CommandHipc(0)]
@ -20,7 +29,7 @@ namespace Ryujinx.HLE.HOS.Services.Bcat.ServiceCreator
DirectoryName directoryName = context.RequestData.ReadStruct<DirectoryName>();
FileName fileName = context.RequestData.ReadStruct<FileName>();
Result result = _base.Open(ref directoryName, ref fileName);
Result result = _base.Get.Open(ref directoryName, ref fileName);
return (ResultCode)result.Value;
}
@ -36,7 +45,7 @@ namespace Ryujinx.HLE.HOS.Services.Bcat.ServiceCreator
byte[] data = new byte[size];
Result result = _base.Read(out long bytesRead, offset, data);
Result result = _base.Get.Read(out long bytesRead, offset, data);
context.Memory.Write(position, data);
@ -49,7 +58,7 @@ namespace Ryujinx.HLE.HOS.Services.Bcat.ServiceCreator
// GetSize() -> u64
public ResultCode GetSize(ServiceCtx context)
{
Result result = _base.GetSize(out long size);
Result result = _base.Get.GetSize(out long size);
context.ResponseData.Write(size);
@ -60,19 +69,11 @@ namespace Ryujinx.HLE.HOS.Services.Bcat.ServiceCreator
// GetDigest() -> nn::bcat::Digest
public ResultCode GetDigest(ServiceCtx context)
{
Result result = _base.GetDigest(out Digest digest);
Result result = _base.Get.GetDigest(out Digest digest);
context.ResponseData.WriteStruct(digest);
return (ResultCode)result.Value;
}
protected override void Dispose(bool isDisposing)
{
if (isDisposing)
{
_base?.Dispose();
}
}
}
}

View File

@ -1,27 +1,30 @@
using LibHac;
using LibHac.Bcat;
using LibHac.Common;
using System.Runtime.InteropServices;
namespace Ryujinx.HLE.HOS.Services.Bcat.ServiceCreator
{
class IDeliveryCacheStorageService : DisposableIpcService
{
private LibHac.Bcat.Impl.Ipc.IDeliveryCacheStorageService _base;
private SharedRef<LibHac.Bcat.Impl.Ipc.IDeliveryCacheStorageService> _base;
public IDeliveryCacheStorageService(ServiceCtx context, LibHac.Bcat.Impl.Ipc.IDeliveryCacheStorageService baseService)
public IDeliveryCacheStorageService(ServiceCtx context, ref SharedRef<LibHac.Bcat.Impl.Ipc.IDeliveryCacheStorageService> baseService)
{
_base = baseService;
_base = SharedRef<LibHac.Bcat.Impl.Ipc.IDeliveryCacheStorageService>.CreateMove(ref baseService);
}
[CommandHipc(0)]
// CreateFileService() -> object<nn::bcat::detail::ipc::IDeliveryCacheFileService>
public ResultCode CreateFileService(ServiceCtx context)
{
Result result = _base.CreateFileService(out LibHac.Bcat.Impl.Ipc.IDeliveryCacheFileService service);
using var service = new SharedRef<LibHac.Bcat.Impl.Ipc.IDeliveryCacheFileService>();
Result result = _base.Get.CreateFileService(ref service.Ref());
if (result.IsSuccess())
{
MakeObject(context, new IDeliveryCacheFileService(service));
MakeObject(context, new IDeliveryCacheFileService(ref service.Ref()));
}
return (ResultCode)result.Value;
@ -31,11 +34,13 @@ namespace Ryujinx.HLE.HOS.Services.Bcat.ServiceCreator
// CreateDirectoryService() -> object<nn::bcat::detail::ipc::IDeliveryCacheDirectoryService>
public ResultCode CreateDirectoryService(ServiceCtx context)
{
Result result = _base.CreateDirectoryService(out LibHac.Bcat.Impl.Ipc.IDeliveryCacheDirectoryService service);
using var service = new SharedRef<LibHac.Bcat.Impl.Ipc.IDeliveryCacheDirectoryService>();
Result result = _base.Get.CreateDirectoryService(ref service.Ref());
if (result.IsSuccess())
{
MakeObject(context, new IDeliveryCacheDirectoryService(service));
MakeObject(context, new IDeliveryCacheDirectoryService(ref service.Ref()));
}
return (ResultCode)result.Value;
@ -50,7 +55,7 @@ namespace Ryujinx.HLE.HOS.Services.Bcat.ServiceCreator
byte[] data = new byte[size];
Result result = _base.EnumerateDeliveryCacheDirectory(out int count, MemoryMarshal.Cast<byte, DirectoryName>(data));
Result result = _base.Get.EnumerateDeliveryCacheDirectory(out int count, MemoryMarshal.Cast<byte, DirectoryName>(data));
context.Memory.Write(position, data);
@ -63,7 +68,7 @@ namespace Ryujinx.HLE.HOS.Services.Bcat.ServiceCreator
{
if (isDisposing)
{
_base?.Dispose();
_base.Destroy();
}
}
}

View File

@ -23,11 +23,13 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
try
{
LocalStorage storage = new LocalStorage(pfsPath, FileAccess.Read, FileMode.Open);
ReferenceCountedDisposable<LibHac.Fs.Fsa.IFileSystem> nsp = new(new PartitionFileSystem(storage));
using SharedRef<LibHac.Fs.Fsa.IFileSystem> nsp = new(new PartitionFileSystem(storage));
ImportTitleKeysFromNsp(nsp.Target, context.Device.System.KeySet);
ImportTitleKeysFromNsp(nsp.Get, context.Device.System.KeySet);
openedFileSystem = new IFileSystem(FileSystemInterfaceAdapter.CreateShared(ref nsp));
using SharedRef<LibHac.FsSrv.Sf.IFileSystem> adapter = FileSystemInterfaceAdapter.CreateShared(ref nsp.Ref(), true);
openedFileSystem = new IFileSystem(ref adapter.Ref());
}
catch (HorizonResultException ex)
{
@ -51,9 +53,11 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
}
LibHac.Fs.Fsa.IFileSystem fileSystem = nca.OpenFileSystem(NcaSectionType.Data, context.Device.System.FsIntegrityCheckLevel);
var sharedFs = new ReferenceCountedDisposable<LibHac.Fs.Fsa.IFileSystem>(fileSystem);
using var sharedFs = new SharedRef<LibHac.Fs.Fsa.IFileSystem>(fileSystem);
openedFileSystem = new IFileSystem(FileSystemInterfaceAdapter.CreateShared(ref sharedFs));
using SharedRef<LibHac.FsSrv.Sf.IFileSystem> adapter = FileSystemInterfaceAdapter.CreateShared(ref sharedFs.Ref(), true);
openedFileSystem = new IFileSystem(ref adapter.Ref());
}
catch (HorizonResultException ex)
{
@ -89,13 +93,15 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
string filename = fullPath.Replace(archivePath.FullName, string.Empty).TrimStart('\\');
Result result = nsp.OpenFile(out LibHac.Fs.Fsa.IFile ncaFile, filename.ToU8Span(), OpenMode.Read);
using var ncaFile = new UniqueRef<LibHac.Fs.Fsa.IFile>();
Result result = nsp.OpenFile(ref ncaFile.Ref(), filename.ToU8Span(), OpenMode.Read);
if (result.IsFailure())
{
return (ResultCode)result.Value;
}
return OpenNcaFs(context, fullPath, ncaFile.AsStorage(), out openedFileSystem);
return OpenNcaFs(context, fullPath, ncaFile.Release().AsStorage(), out openedFileSystem);
}
catch (HorizonResultException ex)
{
@ -110,11 +116,13 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
foreach (DirectoryEntryEx ticketEntry in nsp.EnumerateEntries("/", "*.tik"))
{
Result result = nsp.OpenFile(out LibHac.Fs.Fsa.IFile ticketFile, ticketEntry.FullPath.ToU8Span(), OpenMode.Read);
using var ticketFile = new UniqueRef<LibHac.Fs.Fsa.IFile>();
Result result = nsp.OpenFile(ref ticketFile.Ref(), ticketEntry.FullPath.ToU8Span(), OpenMode.Read);
if (result.IsSuccess())
{
Ticket ticket = new Ticket(ticketFile.AsStream());
Ticket ticket = new Ticket(ticketFile.Get.AsStream());
keySet.ExternalKeySet.Add(new RightsId(ticket.RightsId), new AccessKey(ticket.GetTitleKey(keySet)));
}

View File

@ -1,15 +1,16 @@
using LibHac;
using LibHac.Common;
using LibHac.Sf;
namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
class IDirectory : DisposableIpcService
{
private ReferenceCountedDisposable<LibHac.FsSrv.Sf.IDirectory> _baseDirectory;
private SharedRef<LibHac.FsSrv.Sf.IDirectory> _baseDirectory;
public IDirectory(ReferenceCountedDisposable<LibHac.FsSrv.Sf.IDirectory> directory)
public IDirectory(ref SharedRef<LibHac.FsSrv.Sf.IDirectory> directory)
{
_baseDirectory = directory;
_baseDirectory = SharedRef<LibHac.FsSrv.Sf.IDirectory>.CreateMove(ref directory);
}
[CommandHipc(0)]
@ -21,7 +22,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
byte[] entryBuffer = new byte[bufferLen];
Result result = _baseDirectory.Target.Read(out long entriesRead, new OutBuffer(entryBuffer));
Result result = _baseDirectory.Get.Read(out long entriesRead, new OutBuffer(entryBuffer));
context.Memory.Write(bufferPosition, entryBuffer);
context.ResponseData.Write(entriesRead);
@ -33,7 +34,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
// GetEntryCount() -> u64
public ResultCode GetEntryCount(ServiceCtx context)
{
Result result = _baseDirectory.Target.GetEntryCount(out long entryCount);
Result result = _baseDirectory.Get.GetEntryCount(out long entryCount);
context.ResponseData.Write(entryCount);
@ -44,7 +45,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
if (isDisposing)
{
_baseDirectory?.Dispose();
_baseDirectory.Destroy();
}
}
}

View File

@ -1,4 +1,5 @@
using LibHac;
using LibHac.Common;
using LibHac.Fs;
using LibHac.Sf;
using Ryujinx.Common;
@ -7,11 +8,11 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
class IFile : DisposableIpcService
{
private ReferenceCountedDisposable<LibHac.FsSrv.Sf.IFile> _baseFile;
private SharedRef<LibHac.FsSrv.Sf.IFile> _baseFile;
public IFile(ReferenceCountedDisposable<LibHac.FsSrv.Sf.IFile> baseFile)
public IFile(ref SharedRef<LibHac.FsSrv.Sf.IFile> baseFile)
{
_baseFile = baseFile;
_baseFile = SharedRef<LibHac.FsSrv.Sf.IFile>.CreateMove(ref baseFile);
}
[CommandHipc(0)]
@ -28,7 +29,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
byte[] data = new byte[context.Request.ReceiveBuff[0].Size];
Result result = _baseFile.Target.Read(out long bytesRead, offset, new OutBuffer(data), size, readOption);
Result result = _baseFile.Get.Read(out long bytesRead, offset, new OutBuffer(data), size, readOption);
context.Memory.Write(position, data);
@ -53,14 +54,14 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
context.Memory.Read(position, data);
return (ResultCode)_baseFile.Target.Write(offset, new InBuffer(data), size, writeOption).Value;
return (ResultCode)_baseFile.Get.Write(offset, new InBuffer(data), size, writeOption).Value;
}
[CommandHipc(2)]
// Flush()
public ResultCode Flush(ServiceCtx context)
{
return (ResultCode)_baseFile.Target.Flush().Value;
return (ResultCode)_baseFile.Get.Flush().Value;
}
[CommandHipc(3)]
@ -69,14 +70,14 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
long size = context.RequestData.ReadInt64();
return (ResultCode)_baseFile.Target.SetSize(size).Value;
return (ResultCode)_baseFile.Get.SetSize(size).Value;
}
[CommandHipc(4)]
// GetSize() -> u64 fileSize
public ResultCode GetSize(ServiceCtx context)
{
Result result = _baseFile.Target.GetSize(out long size);
Result result = _baseFile.Get.GetSize(out long size);
context.ResponseData.Write(size);
@ -87,7 +88,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
if (isDisposing)
{
_baseFile?.Dispose();
_baseFile.Destroy();
}
}
}

View File

@ -1,21 +1,22 @@
using LibHac;
using LibHac.Common;
using LibHac.Fs;
using LibHac.FsSrv.Sf;
using Path = LibHac.FsSrv.Sf.Path;
namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
class IFileSystem : DisposableIpcService
{
private ReferenceCountedDisposable<LibHac.FsSrv.Sf.IFileSystem> _fileSystem;
private SharedRef<LibHac.FsSrv.Sf.IFileSystem> _fileSystem;
public IFileSystem(ReferenceCountedDisposable<LibHac.FsSrv.Sf.IFileSystem> provider)
public IFileSystem(ref SharedRef<LibHac.FsSrv.Sf.IFileSystem> provider)
{
_fileSystem = provider;
_fileSystem = SharedRef<LibHac.FsSrv.Sf.IFileSystem>.CreateMove(ref provider);
}
public ReferenceCountedDisposable<LibHac.FsSrv.Sf.IFileSystem> GetBaseFileSystem()
public SharedRef<LibHac.FsSrv.Sf.IFileSystem> GetBaseFileSystem()
{
return _fileSystem;
return SharedRef<LibHac.FsSrv.Sf.IFileSystem>.CreateCopy(in _fileSystem);
}
[CommandHipc(0)]
@ -29,7 +30,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
long size = context.RequestData.ReadInt64();
return (ResultCode)_fileSystem.Target.CreateFile(in name, size, createOption).Value;
return (ResultCode)_fileSystem.Get.CreateFile(in name, size, createOption).Value;
}
[CommandHipc(1)]
@ -38,7 +39,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
return (ResultCode)_fileSystem.Target.DeleteFile(in name).Value;
return (ResultCode)_fileSystem.Get.DeleteFile(in name).Value;
}
[CommandHipc(2)]
@ -47,7 +48,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
return (ResultCode)_fileSystem.Target.CreateDirectory(in name).Value;
return (ResultCode)_fileSystem.Get.CreateDirectory(in name).Value;
}
[CommandHipc(3)]
@ -56,7 +57,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
return (ResultCode)_fileSystem.Target.DeleteDirectory(in name).Value;
return (ResultCode)_fileSystem.Get.DeleteDirectory(in name).Value;
}
[CommandHipc(4)]
@ -65,7 +66,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
return (ResultCode)_fileSystem.Target.DeleteDirectoryRecursively(in name).Value;
return (ResultCode)_fileSystem.Get.DeleteDirectoryRecursively(in name).Value;
}
[CommandHipc(5)]
@ -75,7 +76,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
ref readonly Path currentName = ref FileSystemProxyHelper.GetSfPath(context, index: 0);
ref readonly Path newName = ref FileSystemProxyHelper.GetSfPath(context, index: 1);
return (ResultCode)_fileSystem.Target.RenameFile(in currentName, in newName).Value;
return (ResultCode)_fileSystem.Get.RenameFile(in currentName, in newName).Value;
}
[CommandHipc(6)]
@ -85,7 +86,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
ref readonly Path currentName = ref FileSystemProxyHelper.GetSfPath(context, index: 0);
ref readonly Path newName = ref FileSystemProxyHelper.GetSfPath(context, index: 1);
return (ResultCode)_fileSystem.Target.RenameDirectory(in currentName, in newName).Value;
return (ResultCode)_fileSystem.Get.RenameDirectory(in currentName, in newName).Value;
}
[CommandHipc(7)]
@ -94,7 +95,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
Result result = _fileSystem.Target.GetEntryType(out uint entryType, in name);
Result result = _fileSystem.Get.GetEntryType(out uint entryType, in name);
context.ResponseData.Write((int)entryType);
@ -108,12 +109,13 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
uint mode = context.RequestData.ReadUInt32();
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
using var file = new SharedRef<LibHac.FsSrv.Sf.IFile>();
Result result = _fileSystem.Target.OpenFile(out ReferenceCountedDisposable<LibHac.FsSrv.Sf.IFile> file, in name, mode);
Result result = _fileSystem.Get.OpenFile(ref file.Ref(), in name, mode);
if (result.IsSuccess())
{
IFile fileInterface = new IFile(file);
IFile fileInterface = new IFile(ref file.Ref());
MakeObject(context, fileInterface);
}
@ -128,12 +130,13 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
uint mode = context.RequestData.ReadUInt32();
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
using var dir = new SharedRef<LibHac.FsSrv.Sf.IDirectory>();
Result result = _fileSystem.Target.OpenDirectory(out ReferenceCountedDisposable<LibHac.FsSrv.Sf.IDirectory> dir, name, mode);
Result result = _fileSystem.Get.OpenDirectory(ref dir.Ref(), name, mode);
if (result.IsSuccess())
{
IDirectory dirInterface = new IDirectory(dir);
IDirectory dirInterface = new IDirectory(ref dir.Ref());
MakeObject(context, dirInterface);
}
@ -145,7 +148,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
// Commit()
public ResultCode Commit(ServiceCtx context)
{
return (ResultCode)_fileSystem.Target.Commit().Value;
return (ResultCode)_fileSystem.Get.Commit().Value;
}
[CommandHipc(11)]
@ -154,7 +157,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
Result result = _fileSystem.Target.GetFreeSpaceSize(out long size, in name);
Result result = _fileSystem.Get.GetFreeSpaceSize(out long size, in name);
context.ResponseData.Write(size);
@ -167,7 +170,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
Result result = _fileSystem.Target.GetTotalSpaceSize(out long size, in name);
Result result = _fileSystem.Get.GetTotalSpaceSize(out long size, in name);
context.ResponseData.Write(size);
@ -180,7 +183,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
return (ResultCode)_fileSystem.Target.CleanDirectoryRecursively(in name).Value;
return (ResultCode)_fileSystem.Get.CleanDirectoryRecursively(in name).Value;
}
[CommandHipc(14)]
@ -189,7 +192,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
Result result = _fileSystem.Target.GetFileTimeStampRaw(out FileTimeStampRaw timestamp, in name);
Result result = _fileSystem.Get.GetFileTimeStampRaw(out FileTimeStampRaw timestamp, in name);
context.ResponseData.Write(timestamp.Created);
context.ResponseData.Write(timestamp.Modified);
@ -209,7 +212,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
if (isDisposing)
{
_fileSystem?.Dispose();
_fileSystem.Destroy();
}
}
}

View File

@ -1,4 +1,5 @@
using LibHac;
using LibHac.Common;
using LibHac.Sf;
using Ryujinx.HLE.HOS.Ipc;
@ -6,11 +7,11 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
class IStorage : DisposableIpcService
{
private ReferenceCountedDisposable<LibHac.FsSrv.Sf.IStorage> _baseStorage;
private SharedRef<LibHac.FsSrv.Sf.IStorage> _baseStorage;
public IStorage(ReferenceCountedDisposable<LibHac.FsSrv.Sf.IStorage> baseStorage)
public IStorage(ref SharedRef<LibHac.FsSrv.Sf.IStorage> baseStorage)
{
_baseStorage = baseStorage;
_baseStorage = SharedRef<LibHac.FsSrv.Sf.IStorage>.CreateMove(ref baseStorage);
}
[CommandHipc(0)]
@ -32,7 +33,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
byte[] data = new byte[size];
Result result = _baseStorage.Target.Read((long)offset, new OutBuffer(data), (long)size);
Result result = _baseStorage.Get.Read((long)offset, new OutBuffer(data), (long)size);
context.Memory.Write(buffDesc.Position, data);
@ -46,7 +47,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
// GetSize() -> u64 size
public ResultCode GetSize(ServiceCtx context)
{
Result result = _baseStorage.Target.GetSize(out long size);
Result result = _baseStorage.Get.GetSize(out long size);
context.ResponseData.Write(size);
@ -57,7 +58,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
if (isDisposing)
{
_baseStorage?.Dispose();
_baseStorage.Destroy();
}
}
}

View File

@ -1,22 +1,23 @@
using LibHac;
using LibHac.Common;
using LibHac.FsSrv;
namespace Ryujinx.HLE.HOS.Services.Fs
{
class IDeviceOperator : DisposableIpcService
{
private ReferenceCountedDisposable<LibHac.FsSrv.Sf.IDeviceOperator> _baseOperator;
private SharedRef<LibHac.FsSrv.Sf.IDeviceOperator> _baseOperator;
public IDeviceOperator(ReferenceCountedDisposable<LibHac.FsSrv.Sf.IDeviceOperator> baseOperator)
public IDeviceOperator(ref SharedRef<LibHac.FsSrv.Sf.IDeviceOperator> baseOperator)
{
_baseOperator = baseOperator;
_baseOperator = SharedRef<LibHac.FsSrv.Sf.IDeviceOperator>.CreateMove(ref baseOperator);
}
[CommandHipc(0)]
// IsSdCardInserted() -> b8 is_inserted
public ResultCode IsSdCardInserted(ServiceCtx context)
{
Result result = _baseOperator.Target.IsSdCardInserted(out bool isInserted);
Result result = _baseOperator.Get.IsSdCardInserted(out bool isInserted);
context.ResponseData.Write(isInserted);
@ -27,7 +28,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
// IsGameCardInserted() -> b8 is_inserted
public ResultCode IsGameCardInserted(ServiceCtx context)
{
Result result = _baseOperator.Target.IsGameCardInserted(out bool isInserted);
Result result = _baseOperator.Get.IsGameCardInserted(out bool isInserted);
context.ResponseData.Write(isInserted);
@ -38,7 +39,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
// GetGameCardHandle() -> u32 gamecard_handle
public ResultCode GetGameCardHandle(ServiceCtx context)
{
Result result = _baseOperator.Target.GetGameCardHandle(out GameCardHandle handle);
Result result = _baseOperator.Get.GetGameCardHandle(out GameCardHandle handle);
context.ResponseData.Write(handle.Value);
@ -49,7 +50,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
{
if (isDisposing)
{
_baseOperator?.Dispose();
_baseOperator.Destroy();
}
}
}

View File

@ -1,4 +1,5 @@
using LibHac;
using LibHac.Common;
using LibHac.Fs;
using LibHac.Fs.Shim;
using LibHac.FsSrv;
@ -24,7 +25,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
[Service("fsp-srv")]
class IFileSystemProxy : DisposableIpcService
{
private ReferenceCountedDisposable<LibHac.FsSrv.Sf.IFileSystemProxy> _baseFileSystemProxy;
private SharedRef<LibHac.FsSrv.Sf.IFileSystemProxy> _baseFileSystemProxy;
public IFileSystemProxy(ServiceCtx context)
{
@ -67,7 +68,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
}
FileStream fileStream = new FileStream(fullPath, FileMode.Open, FileAccess.Read);
string extension = Path.GetExtension(fullPath);
string extension = System.IO.Path.GetExtension(fullPath);
if (extension == ".nca")
{
@ -102,11 +103,12 @@ namespace Ryujinx.HLE.HOS.Services.Fs
BisPartitionId bisPartitionId = (BisPartitionId)context.RequestData.ReadInt32();
ref readonly var path = ref FileSystemProxyHelper.GetFspPath(context);
using var fileSystem = new SharedRef<IFileSystem>();
Result result = _baseFileSystemProxy.Target.OpenBisFileSystem(out ReferenceCountedDisposable<IFileSystem> fileSystem, in path, bisPartitionId);
Result result = _baseFileSystemProxy.Get.OpenBisFileSystem(ref fileSystem.Ref(), in path, bisPartitionId);
if (result.IsFailure()) return (ResultCode)result.Value;
MakeObject(context, new FileSystemProxy.IFileSystem(fileSystem));
MakeObject(context, new FileSystemProxy.IFileSystem(ref fileSystem.Ref()));
return ResultCode.Success;
}
@ -116,11 +118,12 @@ namespace Ryujinx.HLE.HOS.Services.Fs
public ResultCode OpenBisStorage(ServiceCtx context)
{
BisPartitionId bisPartitionId = (BisPartitionId)context.RequestData.ReadInt32();
using var storage = new SharedRef<IStorage>();
Result result = _baseFileSystemProxy.Target.OpenBisStorage(out ReferenceCountedDisposable<IStorage> storage, bisPartitionId);
Result result = _baseFileSystemProxy.Get.OpenBisStorage(ref storage.Ref(), bisPartitionId);
if (result.IsFailure()) return (ResultCode)result.Value;
MakeObject(context, new FileSystemProxy.IStorage(storage));
MakeObject(context, new FileSystemProxy.IStorage(ref storage.Ref()));
return ResultCode.Success;
}
@ -129,17 +132,19 @@ namespace Ryujinx.HLE.HOS.Services.Fs
// InvalidateBisCache() -> ()
public ResultCode InvalidateBisCache(ServiceCtx context)
{
return (ResultCode)_baseFileSystemProxy.Target.InvalidateBisCache().Value;
return (ResultCode)_baseFileSystemProxy.Get.InvalidateBisCache().Value;
}
[CommandHipc(18)]
// OpenSdCardFileSystem() -> object<nn::fssrv::sf::IFileSystem>
public ResultCode OpenSdCardFileSystem(ServiceCtx context)
{
Result result = _baseFileSystemProxy.Target.OpenSdCardFileSystem(out var fileSystem);
using var fileSystem = new SharedRef<IFileSystem>();
Result result = _baseFileSystemProxy.Get.OpenSdCardFileSystem(ref fileSystem.Ref());
if (result.IsFailure()) return (ResultCode)result.Value;
MakeObject(context, new FileSystemProxy.IFileSystem(fileSystem));
MakeObject(context, new FileSystemProxy.IFileSystem(ref fileSystem.Ref()));
return ResultCode.Success;
}
@ -148,7 +153,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
// FormatSdCardFileSystem() -> ()
public ResultCode FormatSdCardFileSystem(ServiceCtx context)
{
return (ResultCode)_baseFileSystemProxy.Target.FormatSdCardFileSystem().Value;
return (ResultCode)_baseFileSystemProxy.Get.FormatSdCardFileSystem().Value;
}
[CommandHipc(21)]
@ -157,7 +162,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
{
ulong saveDataId = context.RequestData.ReadUInt64();
return (ResultCode)_baseFileSystemProxy.Target.DeleteSaveDataFileSystem(saveDataId).Value;
return (ResultCode)_baseFileSystemProxy.Get.DeleteSaveDataFileSystem(saveDataId).Value;
}
[CommandHipc(22)]
@ -168,7 +173,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
SaveDataCreationInfo creationInfo = context.RequestData.ReadStruct<SaveDataCreationInfo>();
SaveDataMetaInfo metaInfo = context.RequestData.ReadStruct<SaveDataMetaInfo>();
return (ResultCode)_baseFileSystemProxy.Target.CreateSaveDataFileSystem(in attribute, in creationInfo, in metaInfo).Value;
return (ResultCode)_baseFileSystemProxy.Get.CreateSaveDataFileSystem(in attribute, in creationInfo, in metaInfo).Value;
}
[CommandHipc(23)]
@ -178,7 +183,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
SaveDataAttribute attribute = context.RequestData.ReadStruct<SaveDataAttribute>();
SaveDataCreationInfo creationInfo = context.RequestData.ReadStruct<SaveDataCreationInfo>();
return (ResultCode)_baseFileSystemProxy.Target.CreateSaveDataFileSystemBySystemSaveDataId(in attribute, in creationInfo).Value;
return (ResultCode)_baseFileSystemProxy.Get.CreateSaveDataFileSystemBySystemSaveDataId(in attribute, in creationInfo).Value;
}
[CommandHipc(24)]
@ -188,7 +193,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
byte[] saveIdBuffer = new byte[context.Request.SendBuff[0].Size];
context.Memory.Read(context.Request.SendBuff[0].Position, saveIdBuffer);
return (ResultCode)_baseFileSystemProxy.Target.RegisterSaveDataFileSystemAtomicDeletion(new InBuffer(saveIdBuffer)).Value;
return (ResultCode)_baseFileSystemProxy.Get.RegisterSaveDataFileSystemAtomicDeletion(new InBuffer(saveIdBuffer)).Value;
}
[CommandHipc(25)]
@ -198,21 +203,21 @@ namespace Ryujinx.HLE.HOS.Services.Fs
SaveDataSpaceId spaceId = (SaveDataSpaceId)context.RequestData.ReadInt64();
ulong saveDataId = context.RequestData.ReadUInt64();
return (ResultCode)_baseFileSystemProxy.Target.DeleteSaveDataFileSystemBySaveDataSpaceId(spaceId, saveDataId).Value;
return (ResultCode)_baseFileSystemProxy.Get.DeleteSaveDataFileSystemBySaveDataSpaceId(spaceId, saveDataId).Value;
}
[CommandHipc(26)]
// FormatSdCardDryRun() -> ()
public ResultCode FormatSdCardDryRun(ServiceCtx context)
{
return (ResultCode)_baseFileSystemProxy.Target.FormatSdCardDryRun().Value;
return (ResultCode)_baseFileSystemProxy.Get.FormatSdCardDryRun().Value;
}
[CommandHipc(27)]
// IsExFatSupported() -> (u8 isSupported)
public ResultCode IsExFatSupported(ServiceCtx context)
{
Result result = _baseFileSystemProxy.Target.IsExFatSupported(out bool isSupported);
Result result = _baseFileSystemProxy.Get.IsExFatSupported(out bool isSupported);
if (result.IsFailure()) return (ResultCode)result.Value;
context.ResponseData.Write(isSupported);
@ -227,7 +232,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
SaveDataSpaceId spaceId = (SaveDataSpaceId)context.RequestData.ReadInt64();
SaveDataAttribute attribute = context.RequestData.ReadStruct<SaveDataAttribute>();
return (ResultCode)_baseFileSystemProxy.Target.DeleteSaveDataFileSystemBySaveDataAttribute(spaceId, in attribute).Value;
return (ResultCode)_baseFileSystemProxy.Get.DeleteSaveDataFileSystemBySaveDataAttribute(spaceId, in attribute).Value;
}
[CommandHipc(30)]
@ -236,11 +241,12 @@ namespace Ryujinx.HLE.HOS.Services.Fs
{
GameCardHandle handle = new GameCardHandle(context.RequestData.ReadInt32());
GameCardPartitionRaw partitionId = (GameCardPartitionRaw)context.RequestData.ReadInt32();
using var storage = new SharedRef<IStorage>();
Result result = _baseFileSystemProxy.Target.OpenGameCardStorage(out ReferenceCountedDisposable<IStorage> storage, handle, partitionId);
Result result = _baseFileSystemProxy.Get.OpenGameCardStorage(ref storage.Ref(), handle, partitionId);
if (result.IsFailure()) return (ResultCode)result.Value;
MakeObject(context, new FileSystemProxy.IStorage(storage));
MakeObject(context, new FileSystemProxy.IStorage(ref storage.Ref()));
return ResultCode.Success;
}
@ -251,11 +257,12 @@ namespace Ryujinx.HLE.HOS.Services.Fs
{
GameCardHandle handle = new GameCardHandle(context.RequestData.ReadInt32());
GameCardPartition partitionId = (GameCardPartition)context.RequestData.ReadInt32();
using var fileSystem = new SharedRef<IFileSystem>();
Result result = _baseFileSystemProxy.Target.OpenGameCardFileSystem(out ReferenceCountedDisposable<IFileSystem> fileSystem, handle, partitionId);
Result result = _baseFileSystemProxy.Get.OpenGameCardFileSystem(ref fileSystem.Ref(), handle, partitionId);
if (result.IsFailure()) return (ResultCode)result.Value;
MakeObject(context, new FileSystemProxy.IFileSystem(fileSystem));
MakeObject(context, new FileSystemProxy.IFileSystem(ref fileSystem.Ref()));
return ResultCode.Success;
}
@ -269,7 +276,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
long dataSize = context.RequestData.ReadInt64();
long journalSize = context.RequestData.ReadInt64();
return (ResultCode)_baseFileSystemProxy.Target.ExtendSaveDataFileSystem(spaceId, saveDataId, dataSize, journalSize).Value;
return (ResultCode)_baseFileSystemProxy.Get.ExtendSaveDataFileSystem(spaceId, saveDataId, dataSize, journalSize).Value;
}
[CommandHipc(33)]
@ -278,7 +285,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
{
ushort index = context.RequestData.ReadUInt16();
return (ResultCode)_baseFileSystemProxy.Target.DeleteCacheStorage(index).Value;
return (ResultCode)_baseFileSystemProxy.Get.DeleteCacheStorage(index).Value;
}
[CommandHipc(34)]
@ -287,7 +294,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
{
ushort index = context.RequestData.ReadUInt16();
Result result = _baseFileSystemProxy.Target.GetCacheStorageSize(out long dataSize, out long journalSize, index);
Result result = _baseFileSystemProxy.Get.GetCacheStorageSize(out long dataSize, out long journalSize, index);
if (result.IsFailure()) return (ResultCode)result.Value;
context.ResponseData.Write(dataSize);
@ -305,7 +312,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
SaveDataMetaInfo metaCreateInfo = context.RequestData.ReadStruct<SaveDataMetaInfo>();
HashSalt hashSalt = context.RequestData.ReadStruct<HashSalt>();
return (ResultCode)_baseFileSystemProxy.Target.CreateSaveDataFileSystemWithHashSalt(in attribute, in creationInfo, in metaCreateInfo, in hashSalt).Value;
return (ResultCode)_baseFileSystemProxy.Get.CreateSaveDataFileSystemWithHashSalt(in attribute, in creationInfo, in metaCreateInfo, in hashSalt).Value;
}
[CommandHipc(51)]
@ -314,11 +321,12 @@ namespace Ryujinx.HLE.HOS.Services.Fs
{
SaveDataSpaceId spaceId = (SaveDataSpaceId)context.RequestData.ReadInt64();
SaveDataAttribute attribute = context.RequestData.ReadStruct<SaveDataAttribute>();
using var fileSystem = new SharedRef<IFileSystem>();
Result result = _baseFileSystemProxy.Target.OpenSaveDataFileSystem(out ReferenceCountedDisposable<IFileSystem> fileSystem, spaceId, in attribute);
Result result = _baseFileSystemProxy.Get.OpenSaveDataFileSystem(ref fileSystem.Ref(), spaceId, in attribute);
if (result.IsFailure()) return (ResultCode)result.Value;
MakeObject(context, new FileSystemProxy.IFileSystem(fileSystem));
MakeObject(context, new FileSystemProxy.IFileSystem(ref fileSystem.Ref()));
return ResultCode.Success;
}
@ -329,11 +337,12 @@ namespace Ryujinx.HLE.HOS.Services.Fs
{
SaveDataSpaceId spaceId = (SaveDataSpaceId)context.RequestData.ReadInt64();
SaveDataAttribute attribute = context.RequestData.ReadStruct<SaveDataAttribute>();
using var fileSystem = new SharedRef<IFileSystem>();
Result result = _baseFileSystemProxy.Target.OpenSaveDataFileSystemBySystemSaveDataId(out ReferenceCountedDisposable<IFileSystem> fileSystem, spaceId, in attribute);
Result result = _baseFileSystemProxy.Get.OpenSaveDataFileSystemBySystemSaveDataId(ref fileSystem.Ref(), spaceId, in attribute);
if (result.IsFailure()) return (ResultCode)result.Value;
MakeObject(context, new FileSystemProxy.IFileSystem(fileSystem));
MakeObject(context, new FileSystemProxy.IFileSystem(ref fileSystem.Ref()));
return ResultCode.Success;
}
@ -344,11 +353,12 @@ namespace Ryujinx.HLE.HOS.Services.Fs
{
SaveDataSpaceId spaceId = (SaveDataSpaceId)context.RequestData.ReadInt64();
SaveDataAttribute attribute = context.RequestData.ReadStruct<SaveDataAttribute>();
using var fileSystem = new SharedRef<IFileSystem>();
Result result = _baseFileSystemProxy.Target.OpenReadOnlySaveDataFileSystem(out ReferenceCountedDisposable<IFileSystem> fileSystem, spaceId, in attribute);
Result result = _baseFileSystemProxy.Get.OpenReadOnlySaveDataFileSystem(ref fileSystem.Ref(), spaceId, in attribute);
if (result.IsFailure()) return (ResultCode)result.Value;
MakeObject(context, new FileSystemProxy.IFileSystem(fileSystem));
MakeObject(context, new FileSystemProxy.IFileSystem(ref fileSystem.Ref()));
return ResultCode.Success;
}
@ -363,7 +373,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
byte[] extraDataBuffer = new byte[context.Request.ReceiveBuff[0].Size];
context.Memory.Read(context.Request.ReceiveBuff[0].Position, extraDataBuffer);
Result result = _baseFileSystemProxy.Target.ReadSaveDataFileSystemExtraDataBySaveDataSpaceId(new OutBuffer(extraDataBuffer), spaceId, saveDataId);
Result result = _baseFileSystemProxy.Get.ReadSaveDataFileSystemExtraDataBySaveDataSpaceId(new OutBuffer(extraDataBuffer), spaceId, saveDataId);
if (result.IsFailure()) return (ResultCode)result.Value;
context.Memory.Write(context.Request.ReceiveBuff[0].Position, extraDataBuffer);
@ -380,7 +390,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
byte[] extraDataBuffer = new byte[context.Request.ReceiveBuff[0].Size];
context.Memory.Read(context.Request.ReceiveBuff[0].Position, extraDataBuffer);
Result result = _baseFileSystemProxy.Target.ReadSaveDataFileSystemExtraData(new OutBuffer(extraDataBuffer), saveDataId);
Result result = _baseFileSystemProxy.Get.ReadSaveDataFileSystemExtraData(new OutBuffer(extraDataBuffer), saveDataId);
if (result.IsFailure()) return (ResultCode)result.Value;
context.Memory.Write(context.Request.ReceiveBuff[0].Position, extraDataBuffer);
@ -398,17 +408,19 @@ namespace Ryujinx.HLE.HOS.Services.Fs
byte[] extraDataBuffer = new byte[context.Request.SendBuff[0].Size];
context.Memory.Read(context.Request.SendBuff[0].Position, extraDataBuffer);
return (ResultCode)_baseFileSystemProxy.Target.WriteSaveDataFileSystemExtraData(saveDataId, spaceId, new InBuffer(extraDataBuffer)).Value;
return (ResultCode)_baseFileSystemProxy.Get.WriteSaveDataFileSystemExtraData(saveDataId, spaceId, new InBuffer(extraDataBuffer)).Value;
}
[CommandHipc(60)]
// OpenSaveDataInfoReader() -> object<nn::fssrv::sf::ISaveDataInfoReader>
public ResultCode OpenSaveDataInfoReader(ServiceCtx context)
{
Result result = _baseFileSystemProxy.Target.OpenSaveDataInfoReader(out ReferenceCountedDisposable<LibHac.FsSrv.Sf.ISaveDataInfoReader> infoReader);
using var infoReader = new SharedRef<LibHac.FsSrv.Sf.ISaveDataInfoReader>();
Result result = _baseFileSystemProxy.Get.OpenSaveDataInfoReader(ref infoReader.Ref());
if (result.IsFailure()) return (ResultCode)result.Value;
MakeObject(context, new ISaveDataInfoReader(infoReader));
MakeObject(context, new ISaveDataInfoReader(ref infoReader.Ref()));
return ResultCode.Success;
}
@ -418,11 +430,12 @@ namespace Ryujinx.HLE.HOS.Services.Fs
public ResultCode OpenSaveDataInfoReaderBySaveDataSpaceId(ServiceCtx context)
{
SaveDataSpaceId spaceId = (SaveDataSpaceId)context.RequestData.ReadByte();
using var infoReader = new SharedRef<LibHac.FsSrv.Sf.ISaveDataInfoReader>();
Result result = _baseFileSystemProxy.Target.OpenSaveDataInfoReaderBySaveDataSpaceId(out ReferenceCountedDisposable<LibHac.FsSrv.Sf.ISaveDataInfoReader> infoReader, spaceId);
Result result = _baseFileSystemProxy.Get.OpenSaveDataInfoReaderBySaveDataSpaceId(ref infoReader.Ref(), spaceId);
if (result.IsFailure()) return (ResultCode)result.Value;
MakeObject(context, new ISaveDataInfoReader(infoReader));
MakeObject(context, new ISaveDataInfoReader(ref infoReader.Ref()));
return ResultCode.Success;
}
@ -431,10 +444,12 @@ namespace Ryujinx.HLE.HOS.Services.Fs
// OpenSaveDataInfoReaderOnlyCacheStorage() -> object<nn::fssrv::sf::ISaveDataInfoReader>
public ResultCode OpenSaveDataInfoReaderOnlyCacheStorage(ServiceCtx context)
{
Result result = _baseFileSystemProxy.Target.OpenSaveDataInfoReaderOnlyCacheStorage(out ReferenceCountedDisposable<LibHac.FsSrv.Sf.ISaveDataInfoReader> infoReader);
using var infoReader = new SharedRef<LibHac.FsSrv.Sf.ISaveDataInfoReader>();
Result result = _baseFileSystemProxy.Get.OpenSaveDataInfoReaderOnlyCacheStorage(ref infoReader.Ref());
if (result.IsFailure()) return (ResultCode)result.Value;
MakeObject(context, new ISaveDataInfoReader(infoReader));
MakeObject(context, new ISaveDataInfoReader(ref infoReader.Ref()));
return ResultCode.Success;
}
@ -445,11 +460,12 @@ namespace Ryujinx.HLE.HOS.Services.Fs
{
SaveDataSpaceId spaceId = (SaveDataSpaceId)context.RequestData.ReadInt64();
ulong saveDataId = context.RequestData.ReadUInt64();
using var fileSystem = new SharedRef<IFileSystem>();
Result result = _baseFileSystemProxy.Target.OpenSaveDataInternalStorageFileSystem(out ReferenceCountedDisposable<IFileSystem> fileSystem, spaceId, saveDataId);
Result result = _baseFileSystemProxy.Get.OpenSaveDataInternalStorageFileSystem(ref fileSystem.Ref(), spaceId, saveDataId);
if (result.IsFailure()) return (ResultCode)result.Value;
MakeObject(context, new FileSystemProxy.IFileSystem(fileSystem));
MakeObject(context, new FileSystemProxy.IFileSystem(ref fileSystem.Ref()));
return ResultCode.Success;
}
@ -461,7 +477,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
SaveDataSpaceId spaceId = (SaveDataSpaceId)context.RequestData.ReadInt64();
ulong saveDataId = context.RequestData.ReadUInt64();
return (ResultCode)_baseFileSystemProxy.Target.UpdateSaveDataMacForDebug(spaceId, saveDataId).Value;
return (ResultCode)_baseFileSystemProxy.Get.UpdateSaveDataMacForDebug(spaceId, saveDataId).Value;
}
[CommandHipc(66)]
@ -476,7 +492,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
byte[] maskBuffer = new byte[context.Request.SendBuff[1].Size];
context.Memory.Read(context.Request.SendBuff[1].Position, maskBuffer);
return (ResultCode)_baseFileSystemProxy.Target.WriteSaveDataFileSystemExtraDataWithMask(saveDataId, spaceId, new InBuffer(extraDataBuffer), new InBuffer(maskBuffer)).Value;
return (ResultCode)_baseFileSystemProxy.Get.WriteSaveDataFileSystemExtraDataWithMask(saveDataId, spaceId, new InBuffer(extraDataBuffer), new InBuffer(maskBuffer)).Value;
}
[CommandHipc(67)]
@ -490,7 +506,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
byte[] infoBuffer = new byte[bufferLen];
Result result = _baseFileSystemProxy.Target.FindSaveDataWithFilter(out long count, new OutBuffer(infoBuffer), spaceId, in filter);
Result result = _baseFileSystemProxy.Get.FindSaveDataWithFilter(out long count, new OutBuffer(infoBuffer), spaceId, in filter);
if (result.IsFailure()) return (ResultCode)result.Value;
context.Memory.Write(bufferPosition, infoBuffer);
@ -504,11 +520,12 @@ namespace Ryujinx.HLE.HOS.Services.Fs
{
SaveDataSpaceId spaceId = (SaveDataSpaceId)context.RequestData.ReadInt64();
SaveDataFilter filter = context.RequestData.ReadStruct<SaveDataFilter>();
using var infoReader = new SharedRef<LibHac.FsSrv.Sf.ISaveDataInfoReader>();
Result result = _baseFileSystemProxy.Target.OpenSaveDataInfoReaderWithFilter(out ReferenceCountedDisposable<LibHac.FsSrv.Sf.ISaveDataInfoReader> infoReader, spaceId, in filter);
Result result = _baseFileSystemProxy.Get.OpenSaveDataInfoReaderWithFilter(ref infoReader.Ref(), spaceId, in filter);
if (result.IsFailure()) return (ResultCode)result.Value;
MakeObject(context, new ISaveDataInfoReader(infoReader));
MakeObject(context, new ISaveDataInfoReader(ref infoReader.Ref()));
return ResultCode.Success;
}
@ -522,7 +539,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
byte[] outputBuffer = new byte[context.Request.ReceiveBuff[0].Size];
context.Memory.Read(context.Request.ReceiveBuff[0].Position, outputBuffer);
Result result = _baseFileSystemProxy.Target.ReadSaveDataFileSystemExtraDataBySaveDataAttribute(new OutBuffer(outputBuffer), spaceId, in attribute);
Result result = _baseFileSystemProxy.Get.ReadSaveDataFileSystemExtraDataBySaveDataAttribute(new OutBuffer(outputBuffer), spaceId, in attribute);
if (result.IsFailure()) return (ResultCode)result.Value;
context.Memory.Write(context.Request.ReceiveBuff[0].Position, outputBuffer);
@ -542,7 +559,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
byte[] maskBuffer = new byte[context.Request.SendBuff[1].Size];
context.Memory.Read(context.Request.SendBuff[1].Position, maskBuffer);
return (ResultCode)_baseFileSystemProxy.Target.WriteSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute(in attribute, spaceId, new InBuffer(extraDataBuffer), new InBuffer(maskBuffer)).Value;
return (ResultCode)_baseFileSystemProxy.Get.WriteSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute(in attribute, spaceId, new InBuffer(extraDataBuffer), new InBuffer(maskBuffer)).Value;
}
[CommandHipc(71)]
@ -557,7 +574,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
byte[] outputBuffer = new byte[context.Request.ReceiveBuff[0].Size];
context.Memory.Read(context.Request.ReceiveBuff[0].Position, outputBuffer);
Result result = _baseFileSystemProxy.Target.ReadSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute(new OutBuffer(outputBuffer), spaceId, in attribute, new InBuffer(maskBuffer));
Result result = _baseFileSystemProxy.Get.ReadSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute(new OutBuffer(outputBuffer), spaceId, in attribute, new InBuffer(maskBuffer));
if (result.IsFailure()) return (ResultCode)result.Value;
context.Memory.Write(context.Request.ReceiveBuff[0].Position, outputBuffer);
@ -571,11 +588,12 @@ namespace Ryujinx.HLE.HOS.Services.Fs
SaveDataSpaceId spaceId = (SaveDataSpaceId)context.RequestData.ReadInt32();
SaveDataMetaType metaType = (SaveDataMetaType)context.RequestData.ReadInt32();
SaveDataAttribute attribute = context.RequestData.ReadStruct<SaveDataAttribute>();
using var file = new SharedRef<LibHac.FsSrv.Sf.IFile>();
Result result = _baseFileSystemProxy.Target.OpenSaveDataMetaFile(out ReferenceCountedDisposable<LibHac.FsSrv.Sf.IFile> file, spaceId, in attribute, metaType);
Result result = _baseFileSystemProxy.Get.OpenSaveDataMetaFile(ref file.Ref(), spaceId, in attribute, metaType);
if (result.IsFailure()) return (ResultCode)result.Value;
MakeObject(context, new IFile(file));
MakeObject(context, new IFile(ref file.Ref()));
return ResultCode.Success;
}
@ -590,7 +608,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
byte[] outputBuffer = new byte[context.Request.ReceiveBuff[0].Size];
context.Memory.Read(context.Request.ReceiveBuff[0].Position, outputBuffer);
Result result = _baseFileSystemProxy.Target.ListAccessibleSaveDataOwnerId(out int readCount, new OutBuffer(outputBuffer), programId, startIndex, bufferCount);
Result result = _baseFileSystemProxy.Get.ListAccessibleSaveDataOwnerId(out int readCount, new OutBuffer(outputBuffer), programId, startIndex, bufferCount);
if (result.IsFailure()) return (ResultCode)result.Value;
context.ResponseData.Write(readCount);
@ -602,11 +620,12 @@ namespace Ryujinx.HLE.HOS.Services.Fs
public ResultCode OpenImageDirectoryFileSystem(ServiceCtx context)
{
ImageDirectoryId directoryId = (ImageDirectoryId)context.RequestData.ReadInt32();
using var fileSystem = new SharedRef<IFileSystem>();
Result result = _baseFileSystemProxy.Target.OpenImageDirectoryFileSystem(out ReferenceCountedDisposable<IFileSystem> fileSystem, directoryId);
Result result = _baseFileSystemProxy.Get.OpenImageDirectoryFileSystem(ref fileSystem.Ref(), directoryId);
if (result.IsFailure()) return (ResultCode)result.Value;
MakeObject(context, new FileSystemProxy.IFileSystem(fileSystem));
MakeObject(context, new FileSystemProxy.IFileSystem(ref fileSystem.Ref()));
return ResultCode.Success;
}
@ -615,11 +634,12 @@ namespace Ryujinx.HLE.HOS.Services.Fs
public ResultCode OpenBaseFileSystem(ServiceCtx context)
{
BaseFileSystemId fileSystemId = (BaseFileSystemId)context.RequestData.ReadInt32();
using var fileSystem = new SharedRef<IFileSystem>();
Result result = _baseFileSystemProxy.Target.OpenBaseFileSystem(out ReferenceCountedDisposable<IFileSystem> fileSystem, fileSystemId);
Result result = _baseFileSystemProxy.Get.OpenBaseFileSystem(ref fileSystem.Ref(), fileSystemId);
if (result.IsFailure()) return (ResultCode)result.Value;
MakeObject(context, new FileSystemProxy.IFileSystem(fileSystem));
MakeObject(context, new FileSystemProxy.IFileSystem(ref fileSystem.Ref()));
return ResultCode.Success;
}
@ -628,11 +648,12 @@ namespace Ryujinx.HLE.HOS.Services.Fs
public ResultCode OpenContentStorageFileSystem(ServiceCtx context)
{
ContentStorageId contentStorageId = (ContentStorageId)context.RequestData.ReadInt32();
using var fileSystem = new SharedRef<IFileSystem>();
Result result = _baseFileSystemProxy.Target.OpenContentStorageFileSystem(out ReferenceCountedDisposable<IFileSystem> fileSystem, contentStorageId);
Result result = _baseFileSystemProxy.Get.OpenContentStorageFileSystem(ref fileSystem.Ref(), contentStorageId);
if (result.IsFailure()) return (ResultCode)result.Value;
MakeObject(context, new FileSystemProxy.IFileSystem(fileSystem));
MakeObject(context, new FileSystemProxy.IFileSystem(ref fileSystem.Ref()));
return ResultCode.Success;
}
@ -641,11 +662,12 @@ namespace Ryujinx.HLE.HOS.Services.Fs
public ResultCode OpenCloudBackupWorkStorageFileSystem(ServiceCtx context)
{
CloudBackupWorkStorageId storageId = (CloudBackupWorkStorageId)context.RequestData.ReadInt32();
using var fileSystem = new SharedRef<IFileSystem>();
Result result = _baseFileSystemProxy.Target.OpenCloudBackupWorkStorageFileSystem(out ReferenceCountedDisposable<IFileSystem> fileSystem, storageId);
Result result = _baseFileSystemProxy.Get.OpenCloudBackupWorkStorageFileSystem(ref fileSystem.Ref(), storageId);
if (result.IsFailure()) return (ResultCode)result.Value;
MakeObject(context, new FileSystemProxy.IFileSystem(fileSystem));
MakeObject(context, new FileSystemProxy.IFileSystem(ref fileSystem.Ref()));
return ResultCode.Success;
}
@ -654,11 +676,12 @@ namespace Ryujinx.HLE.HOS.Services.Fs
public ResultCode OpenCustomStorageFileSystem(ServiceCtx context)
{
CustomStorageId customStorageId = (CustomStorageId)context.RequestData.ReadInt32();
using var fileSystem = new SharedRef<IFileSystem>();
Result result = _baseFileSystemProxy.Target.OpenCustomStorageFileSystem(out ReferenceCountedDisposable<IFileSystem> fileSystem, customStorageId);
Result result = _baseFileSystemProxy.Get.OpenCustomStorageFileSystem(ref fileSystem.Ref(), customStorageId);
if (result.IsFailure()) return (ResultCode)result.Value;
MakeObject(context, new FileSystemProxy.IFileSystem(fileSystem));
MakeObject(context, new FileSystemProxy.IFileSystem(ref fileSystem.Ref()));
return ResultCode.Success;
}
@ -668,10 +691,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs
public ResultCode OpenDataStorageByCurrentProcess(ServiceCtx context)
{
var storage = context.Device.FileSystem.RomFs.AsStorage(true);
var sharedStorage = new ReferenceCountedDisposable<LibHac.Fs.IStorage>(storage);
ReferenceCountedDisposable<IStorage> sfStorage = StorageInterfaceAdapter.CreateShared(ref sharedStorage);
using var sharedStorage = new SharedRef<LibHac.Fs.IStorage>(storage);
using var sfStorage = new SharedRef<IStorage>(new StorageInterfaceAdapter(ref sharedStorage.Ref()));
MakeObject(context, new FileSystemProxy.IStorage(sfStorage));
MakeObject(context, new FileSystemProxy.IStorage(ref sfStorage.Ref()));
return ResultCode.Success;
}
@ -691,10 +714,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs
Logger.Info?.Print(LogClass.Loader, $"Opened AddOnContent Data TitleID={titleId:X16}");
var storage = context.Device.FileSystem.ModLoader.ApplyRomFsMods(titleId, aocStorage);
var sharedStorage = new ReferenceCountedDisposable<LibHac.Fs.IStorage>(storage);
ReferenceCountedDisposable<IStorage> sfStorage = StorageInterfaceAdapter.CreateShared(ref sharedStorage);
using var sharedStorage = new SharedRef<LibHac.Fs.IStorage>(storage);
using var sfStorage = new SharedRef<IStorage>(new StorageInterfaceAdapter(ref sharedStorage.Ref()));
MakeObject(context, new FileSystemProxy.IStorage(sfStorage));
MakeObject(context, new FileSystemProxy.IStorage(ref sfStorage.Ref()));
return ResultCode.Success;
}
@ -726,10 +749,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs
LibHac.Fs.IStorage ncaStorage = new LocalStorage(ncaPath, FileAccess.Read, FileMode.Open);
Nca nca = new Nca(context.Device.System.KeySet, ncaStorage);
LibHac.Fs.IStorage romfsStorage = nca.OpenStorage(NcaSectionType.Data, context.Device.System.FsIntegrityCheckLevel);
var sharedStorage = new ReferenceCountedDisposable<LibHac.Fs.IStorage>(romfsStorage);
ReferenceCountedDisposable<IStorage> sfStorage = StorageInterfaceAdapter.CreateShared(ref sharedStorage);
using var sharedStorage = new SharedRef<LibHac.Fs.IStorage>(romfsStorage);
using var sfStorage = new SharedRef<IStorage>(new StorageInterfaceAdapter(ref sharedStorage.Ref()));
MakeObject(context, new FileSystemProxy.IStorage(sfStorage));
MakeObject(context, new FileSystemProxy.IStorage(ref sfStorage.Ref()));
}
catch (HorizonResultException ex)
{
@ -757,10 +780,10 @@ namespace Ryujinx.HLE.HOS.Services.Fs
public ResultCode OpenPatchDataStorageByCurrentProcess(ServiceCtx context)
{
var storage = context.Device.FileSystem.RomFs.AsStorage(true);
var sharedStorage = new ReferenceCountedDisposable<LibHac.Fs.IStorage>(storage);
ReferenceCountedDisposable<IStorage> sfStorage = StorageInterfaceAdapter.CreateShared(ref sharedStorage);
using var sharedStorage = new SharedRef<LibHac.Fs.IStorage>(storage);
using var sfStorage = new SharedRef<IStorage>(new StorageInterfaceAdapter(ref sharedStorage.Ref()));
MakeObject(context, new FileSystemProxy.IStorage(sfStorage));
MakeObject(context, new FileSystemProxy.IStorage(ref sfStorage.Ref()));
return ResultCode.Success;
}
@ -769,10 +792,12 @@ namespace Ryujinx.HLE.HOS.Services.Fs
// OpenDataStorageByCurrentProcess() -> object<nn::fssrv::sf::IStorage> dataStorage
public ResultCode OpenDeviceOperator(ServiceCtx context)
{
Result result = _baseFileSystemProxy.Target.OpenDeviceOperator(out ReferenceCountedDisposable<LibHac.FsSrv.Sf.IDeviceOperator> deviceOperator);
using var deviceOperator = new SharedRef<LibHac.FsSrv.Sf.IDeviceOperator>();
Result result = _baseFileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref());
if (result.IsFailure()) return (ResultCode)result.Value;
MakeObject(context, new IDeviceOperator(deviceOperator));
MakeObject(context, new IDeviceOperator(ref deviceOperator.Ref()));
return ResultCode.Success;
}
@ -783,7 +808,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
long dataSize = context.RequestData.ReadInt64();
long journalSize = context.RequestData.ReadInt64();
Result result = _baseFileSystemProxy.Target.QuerySaveDataTotalSize(out long totalSize, dataSize, journalSize);
Result result = _baseFileSystemProxy.Get.QuerySaveDataTotalSize(out long totalSize, dataSize, journalSize);
if (result.IsFailure()) return (ResultCode)result.Value;
context.ResponseData.Write(totalSize);
@ -794,7 +819,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
[CommandHipc(511)]
public ResultCode NotifySystemDataUpdateEvent(ServiceCtx context)
{
return (ResultCode)_baseFileSystemProxy.Target.NotifySystemDataUpdateEvent().Value;
return (ResultCode)_baseFileSystemProxy.Get.NotifySystemDataUpdateEvent().Value;
}
[CommandHipc(523)]
@ -805,7 +830,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
SdmmcPort port = context.RequestData.ReadStruct<SdmmcPort>();
SimulatingDeviceDetectionMode mode = context.RequestData.ReadStruct<SimulatingDeviceDetectionMode>();
return (ResultCode)_baseFileSystemProxy.Target.SimulateDeviceDetectionEvent(port, mode, signalEvent).Value;
return (ResultCode)_baseFileSystemProxy.Get.SimulateDeviceDetectionEvent(port, mode, signalEvent).Value;
}
[CommandHipc(602)]
@ -816,7 +841,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
byte[] readBuffer = new byte[context.Request.ReceiveBuff[0].Size];
context.Memory.Read(context.Request.ReceiveBuff[0].Position, readBuffer);
return (ResultCode)_baseFileSystemProxy.Target.VerifySaveDataFileSystem(saveDataId, new OutBuffer(readBuffer)).Value;
return (ResultCode)_baseFileSystemProxy.Get.VerifySaveDataFileSystem(saveDataId, new OutBuffer(readBuffer)).Value;
}
[CommandHipc(603)]
@ -824,7 +849,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
{
ulong saveDataId = context.RequestData.ReadUInt64();
return (ResultCode)_baseFileSystemProxy.Target.CorruptSaveDataFileSystem(saveDataId).Value;
return (ResultCode)_baseFileSystemProxy.Get.CorruptSaveDataFileSystem(saveDataId).Value;
}
[CommandHipc(604)]
@ -832,13 +857,13 @@ namespace Ryujinx.HLE.HOS.Services.Fs
{
long size = context.RequestData.ReadInt64();
return (ResultCode)_baseFileSystemProxy.Target.CreatePaddingFile(size).Value;
return (ResultCode)_baseFileSystemProxy.Get.CreatePaddingFile(size).Value;
}
[CommandHipc(605)]
public ResultCode DeleteAllPaddingFiles(ServiceCtx context)
{
return (ResultCode)_baseFileSystemProxy.Target.DeleteAllPaddingFiles().Value;
return (ResultCode)_baseFileSystemProxy.Get.DeleteAllPaddingFiles().Value;
}
[CommandHipc(606)]
@ -847,7 +872,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
LibHac.Ncm.StorageId storageId = (LibHac.Ncm.StorageId)context.RequestData.ReadInt64();
ProgramId programId = context.RequestData.ReadStruct<ProgramId>();
Result result = _baseFileSystemProxy.Target.GetRightsId(out RightsId rightsId, programId, storageId);
Result result = _baseFileSystemProxy.Get.GetRightsId(out RightsId rightsId, programId, storageId);
if (result.IsFailure()) return (ResultCode)result.Value;
context.ResponseData.WriteStruct(rightsId);
@ -861,13 +886,13 @@ namespace Ryujinx.HLE.HOS.Services.Fs
RightsId rightsId = context.RequestData.ReadStruct<RightsId>();
AccessKey accessKey = context.RequestData.ReadStruct<AccessKey>();
return (ResultCode)_baseFileSystemProxy.Target.RegisterExternalKey(in rightsId, in accessKey).Value;
return (ResultCode)_baseFileSystemProxy.Get.RegisterExternalKey(in rightsId, in accessKey).Value;
}
[CommandHipc(608)]
public ResultCode UnregisterAllExternalKey(ServiceCtx context)
{
return (ResultCode)_baseFileSystemProxy.Target.UnregisterAllExternalKey().Value;
return (ResultCode)_baseFileSystemProxy.Get.UnregisterAllExternalKey().Value;
}
[CommandHipc(609)]
@ -875,7 +900,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
{
ref readonly var path = ref FileSystemProxyHelper.GetFspPath(context);
Result result = _baseFileSystemProxy.Target.GetRightsIdByPath(out RightsId rightsId, in path);
Result result = _baseFileSystemProxy.Get.GetRightsIdByPath(out RightsId rightsId, in path);
if (result.IsFailure()) return (ResultCode)result.Value;
context.ResponseData.WriteStruct(rightsId);
@ -888,7 +913,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
{
ref readonly var path = ref FileSystemProxyHelper.GetFspPath(context);
Result result = _baseFileSystemProxy.Target.GetRightsIdAndKeyGenerationByPath(out RightsId rightsId, out byte keyGeneration, in path);
Result result = _baseFileSystemProxy.Get.GetRightsIdAndKeyGenerationByPath(out RightsId rightsId, out byte keyGeneration, in path);
if (result.IsFailure()) return (ResultCode)result.Value;
context.ResponseData.Write(keyGeneration);
@ -905,7 +930,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
context.RequestData.BaseStream.Seek(4, SeekOrigin.Current);
long time = context.RequestData.ReadInt64();
return (ResultCode)_baseFileSystemProxy.Target.SetCurrentPosixTimeWithTimeDifference(time, timeDifference).Value;
return (ResultCode)_baseFileSystemProxy.Get.SetCurrentPosixTimeWithTimeDifference(time, timeDifference).Value;
}
[CommandHipc(612)]
@ -913,7 +938,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
{
SaveDataSpaceId spaceId = context.RequestData.ReadStruct<SaveDataSpaceId>();
Result result = _baseFileSystemProxy.Target.GetFreeSpaceSizeForSaveData(out long freeSpaceSize, spaceId);
Result result = _baseFileSystemProxy.Get.GetFreeSpaceSizeForSaveData(out long freeSpaceSize, spaceId);
if (result.IsFailure()) return (ResultCode)result.Value;
context.ResponseData.Write(freeSpaceSize);
@ -930,7 +955,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
byte[] readBuffer = new byte[context.Request.ReceiveBuff[0].Size];
context.Memory.Read(context.Request.ReceiveBuff[0].Position, readBuffer);
return (ResultCode)_baseFileSystemProxy.Target.VerifySaveDataFileSystemBySaveDataSpaceId(spaceId, saveDataId, new OutBuffer(readBuffer)).Value;
return (ResultCode)_baseFileSystemProxy.Get.VerifySaveDataFileSystemBySaveDataSpaceId(spaceId, saveDataId, new OutBuffer(readBuffer)).Value;
}
[CommandHipc(614)]
@ -939,7 +964,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
SaveDataSpaceId spaceId = (SaveDataSpaceId)context.RequestData.ReadInt64();
ulong saveDataId = context.RequestData.ReadUInt64();
return (ResultCode)_baseFileSystemProxy.Target.CorruptSaveDataFileSystemBySaveDataSpaceId(spaceId, saveDataId).Value;
return (ResultCode)_baseFileSystemProxy.Get.CorruptSaveDataFileSystemBySaveDataSpaceId(spaceId, saveDataId).Value;
}
[CommandHipc(615)]
@ -948,7 +973,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
SaveDataSpaceId spaceId = (SaveDataSpaceId)context.RequestData.ReadInt64();
ulong saveDataId = context.RequestData.ReadUInt64();
Result result = _baseFileSystemProxy.Target.QuerySaveDataInternalStorageTotalSize(out long size, spaceId, saveDataId);
Result result = _baseFileSystemProxy.Get.QuerySaveDataInternalStorageTotalSize(out long size, spaceId, saveDataId);
if (result.IsFailure()) return (ResultCode)result.Value;
context.ResponseData.Write(size);
@ -962,7 +987,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
SaveDataSpaceId spaceId = (SaveDataSpaceId)context.RequestData.ReadInt64();
ulong saveDataId = context.RequestData.ReadUInt64();
Result result = _baseFileSystemProxy.Target.GetSaveDataCommitId(out long commitId, spaceId, saveDataId);
Result result = _baseFileSystemProxy.Get.GetSaveDataCommitId(out long commitId, spaceId, saveDataId);
if (result.IsFailure()) return (ResultCode)result.Value;
context.ResponseData.Write(commitId);
@ -975,7 +1000,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
{
RightsId rightsId = context.RequestData.ReadStruct<RightsId>();
return (ResultCode)_baseFileSystemProxy.Target.UnregisterExternalKey(in rightsId).Value;
return (ResultCode)_baseFileSystemProxy.Get.UnregisterExternalKey(in rightsId).Value;
}
[CommandHipc(620)]
@ -983,7 +1008,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
{
EncryptionSeed encryptionSeed = context.RequestData.ReadStruct<EncryptionSeed>();
return (ResultCode)_baseFileSystemProxy.Target.SetSdCardEncryptionSeed(in encryptionSeed).Value;
return (ResultCode)_baseFileSystemProxy.Get.SetSdCardEncryptionSeed(in encryptionSeed).Value;
}
[CommandHipc(630)]
@ -992,14 +1017,14 @@ namespace Ryujinx.HLE.HOS.Services.Fs
{
bool isAccessible = context.RequestData.ReadBoolean();
return (ResultCode)_baseFileSystemProxy.Target.SetSdCardAccessibility(isAccessible).Value;
return (ResultCode)_baseFileSystemProxy.Get.SetSdCardAccessibility(isAccessible).Value;
}
[CommandHipc(631)]
// IsSdCardAccessible() -> u8 isAccessible
public ResultCode IsSdCardAccessible(ServiceCtx context)
{
Result result = _baseFileSystemProxy.Target.IsSdCardAccessible(out bool isAccessible);
Result result = _baseFileSystemProxy.Get.IsSdCardAccessible(out bool isAccessible);
if (result.IsFailure()) return (ResultCode)result.Value;
context.ResponseData.Write(isAccessible);
@ -1012,7 +1037,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
{
ulong processId = context.RequestData.ReadUInt64();
Result result = _baseFileSystemProxy.Target.IsAccessFailureDetected(out bool isDetected, processId);
Result result = _baseFileSystemProxy.Get.IsAccessFailureDetected(out bool isDetected, processId);
if (result.IsFailure()) return (ResultCode)result.Value;
context.ResponseData.Write(isDetected);
@ -1025,7 +1050,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
{
ulong processId = context.RequestData.ReadUInt64();
return (ResultCode)_baseFileSystemProxy.Target.ResolveAccessFailure(processId).Value;
return (ResultCode)_baseFileSystemProxy.Get.ResolveAccessFailure(processId).Value;
}
[CommandHipc(720)]
@ -1033,13 +1058,13 @@ namespace Ryujinx.HLE.HOS.Services.Fs
{
ulong processId = context.RequestData.ReadUInt64();
return (ResultCode)_baseFileSystemProxy.Target.AbandonAccessFailure(processId).Value;
return (ResultCode)_baseFileSystemProxy.Get.AbandonAccessFailure(processId).Value;
}
[CommandHipc(800)]
public ResultCode GetAndClearErrorInfo(ServiceCtx context)
{
Result result = _baseFileSystemProxy.Target.GetAndClearErrorInfo(out FileSystemProxyErrorInfo errorInfo);
Result result = _baseFileSystemProxy.Get.GetAndClearErrorInfo(out FileSystemProxyErrorInfo errorInfo);
if (result.IsFailure()) return (ResultCode)result.Value;
context.ResponseData.WriteStruct(errorInfo);
@ -1055,7 +1080,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
byte[] mapInfoBuffer = new byte[context.Request.SendBuff[0].Size];
context.Memory.Read(context.Request.SendBuff[0].Position, mapInfoBuffer);
return (ResultCode)_baseFileSystemProxy.Target.RegisterProgramIndexMapInfo(new InBuffer(mapInfoBuffer), programCount).Value;
return (ResultCode)_baseFileSystemProxy.Get.RegisterProgramIndexMapInfo(new InBuffer(mapInfoBuffer), programCount).Value;
}
[CommandHipc(1000)]
@ -1064,7 +1089,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
BisPartitionId partitionId = (BisPartitionId)context.RequestData.ReadInt32();
ref readonly var path = ref FileSystemProxyHelper.GetFspPath(context);
return (ResultCode)_baseFileSystemProxy.Target.SetBisRootForHost(partitionId, in path).Value;
return (ResultCode)_baseFileSystemProxy.Get.SetBisRootForHost(partitionId, in path).Value;
}
[CommandHipc(1001)]
@ -1073,7 +1098,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
long dataSize = context.RequestData.ReadInt64();
long journalSize = context.RequestData.ReadInt64();
return (ResultCode)_baseFileSystemProxy.Target.SetSaveDataSize(dataSize, journalSize).Value;
return (ResultCode)_baseFileSystemProxy.Get.SetSaveDataSize(dataSize, journalSize).Value;
}
[CommandHipc(1002)]
@ -1081,13 +1106,13 @@ namespace Ryujinx.HLE.HOS.Services.Fs
{
ref readonly var path = ref FileSystemProxyHelper.GetFspPath(context);
return (ResultCode)_baseFileSystemProxy.Target.SetSaveDataRootPath(in path).Value;
return (ResultCode)_baseFileSystemProxy.Get.SetSaveDataRootPath(in path).Value;
}
[CommandHipc(1003)]
public ResultCode DisableAutoSaveDataCreation(ServiceCtx context)
{
return (ResultCode)_baseFileSystemProxy.Target.DisableAutoSaveDataCreation().Value;
return (ResultCode)_baseFileSystemProxy.Get.DisableAutoSaveDataCreation().Value;
}
[CommandHipc(1004)]
@ -1127,16 +1152,18 @@ namespace Ryujinx.HLE.HOS.Services.Fs
[CommandHipc(1007)]
public ResultCode RegisterUpdatePartition(ServiceCtx context)
{
return (ResultCode)_baseFileSystemProxy.Target.RegisterUpdatePartition().Value;
return (ResultCode)_baseFileSystemProxy.Get.RegisterUpdatePartition().Value;
}
[CommandHipc(1008)]
public ResultCode OpenRegisteredUpdatePartition(ServiceCtx context)
{
Result result = _baseFileSystemProxy.Target.OpenRegisteredUpdatePartition(out ReferenceCountedDisposable<IFileSystem> fileSystem);
using var fileSystem = new SharedRef<IFileSystem>();
Result result = _baseFileSystemProxy.Get.OpenRegisteredUpdatePartition(ref fileSystem.Ref());
if (result.IsFailure()) return (ResultCode)result.Value;
MakeObject(context, new FileSystemProxy.IFileSystem(fileSystem));
MakeObject(context, new FileSystemProxy.IFileSystem(ref fileSystem.Ref()));
return ResultCode.Success;
}
@ -1144,7 +1171,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
[CommandHipc(1009)]
public ResultCode GetAndClearMemoryReportInfo(ServiceCtx context)
{
Result result = _baseFileSystemProxy.Target.GetAndClearMemoryReportInfo(out MemoryReportInfo reportInfo);
Result result = _baseFileSystemProxy.Get.GetAndClearMemoryReportInfo(out MemoryReportInfo reportInfo);
if (result.IsFailure()) return (ResultCode)result.Value;
context.ResponseData.WriteStruct(reportInfo);
@ -1155,7 +1182,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
[CommandHipc(1011)]
public ResultCode GetProgramIndexForAccessLog(ServiceCtx context)
{
Result result = _baseFileSystemProxy.Target.GetProgramIndexForAccessLog(out int programIndex, out int programCount);
Result result = _baseFileSystemProxy.Get.GetProgramIndexForAccessLog(out int programIndex, out int programCount);
if (result.IsFailure()) return (ResultCode)result.Value;
context.ResponseData.Write(programIndex);
@ -1169,7 +1196,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
{
FsStackUsageThreadType threadType = context.RequestData.ReadStruct<FsStackUsageThreadType>();
Result result = _baseFileSystemProxy.Target.GetFsStackUsage(out uint usage, threadType);
Result result = _baseFileSystemProxy.Get.GetFsStackUsage(out uint usage, threadType);
if (result.IsFailure()) return (ResultCode)result.Value;
context.ResponseData.Write(usage);
@ -1180,19 +1207,19 @@ namespace Ryujinx.HLE.HOS.Services.Fs
[CommandHipc(1013)]
public ResultCode UnsetSaveDataRootPath(ServiceCtx context)
{
return (ResultCode)_baseFileSystemProxy.Target.UnsetSaveDataRootPath().Value;
return (ResultCode)_baseFileSystemProxy.Get.UnsetSaveDataRootPath().Value;
}
[CommandHipc(1014)]
public ResultCode OutputMultiProgramTagAccessLog(ServiceCtx context)
{
return (ResultCode)_baseFileSystemProxy.Target.OutputMultiProgramTagAccessLog().Value;
return (ResultCode)_baseFileSystemProxy.Get.OutputMultiProgramTagAccessLog().Value;
}
[CommandHipc(1016)]
public ResultCode FlushAccessLogOnSdCard(ServiceCtx context)
{
return (ResultCode)_baseFileSystemProxy.Target.FlushAccessLogOnSdCard().Value;
return (ResultCode)_baseFileSystemProxy.Get.FlushAccessLogOnSdCard().Value;
}
[CommandHipc(1017)]
@ -1200,7 +1227,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
{
ApplicationInfo info = context.RequestData.ReadStruct<ApplicationInfo>();
return (ResultCode)_baseFileSystemProxy.Target.OutputApplicationInfoAccessLog(in info).Value;
return (ResultCode)_baseFileSystemProxy.Get.OutputApplicationInfoAccessLog(in info).Value;
}
[CommandHipc(1100)]
@ -1209,7 +1236,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
byte[] keyBuffer = new byte[context.Request.SendBuff[0].Size];
context.Memory.Read(context.Request.SendBuff[0].Position, keyBuffer);
return (ResultCode)_baseFileSystemProxy.Target.OverrideSaveDataTransferTokenSignVerificationKey(new InBuffer(keyBuffer)).Value;
return (ResultCode)_baseFileSystemProxy.Get.OverrideSaveDataTransferTokenSignVerificationKey(new InBuffer(keyBuffer)).Value;
}
[CommandHipc(1110)]
@ -1219,17 +1246,19 @@ namespace Ryujinx.HLE.HOS.Services.Fs
ulong saveDataId = context.RequestData.ReadUInt64();
long offset = context.RequestData.ReadInt64();
return (ResultCode)_baseFileSystemProxy.Target.CorruptSaveDataFileSystemByOffset(spaceId, saveDataId, offset).Value;
return (ResultCode)_baseFileSystemProxy.Get.CorruptSaveDataFileSystemByOffset(spaceId, saveDataId, offset).Value;
}
[CommandHipc(1200)] // 6.0.0+
// OpenMultiCommitManager() -> object<nn::fssrv::sf::IMultiCommitManager>
public ResultCode OpenMultiCommitManager(ServiceCtx context)
{
Result result = _baseFileSystemProxy.Target.OpenMultiCommitManager(out ReferenceCountedDisposable<LibHac.FsSrv.Sf.IMultiCommitManager> commitManager);
using var commitManager = new SharedRef<LibHac.FsSrv.Sf.IMultiCommitManager>();
Result result = _baseFileSystemProxy.Get.OpenMultiCommitManager(ref commitManager.Ref());
if (result.IsFailure()) return (ResultCode)result.Value;
MakeObject(context, new IMultiCommitManager(commitManager));
MakeObject(context, new IMultiCommitManager(ref commitManager.Ref()));
return ResultCode.Success;
}
@ -1238,7 +1267,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
{
if (isDisposing)
{
_baseFileSystemProxy?.Dispose();
_baseFileSystemProxy.Destroy();
}
}
}

View File

@ -1,24 +1,25 @@
using LibHac;
using LibHac.Common;
using Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy;
namespace Ryujinx.HLE.HOS.Services.Fs
{
class IMultiCommitManager : DisposableIpcService // 6.0.0+
{
private ReferenceCountedDisposable<LibHac.FsSrv.Sf.IMultiCommitManager> _baseCommitManager;
private SharedRef<LibHac.FsSrv.Sf.IMultiCommitManager> _baseCommitManager;
public IMultiCommitManager(ReferenceCountedDisposable<LibHac.FsSrv.Sf.IMultiCommitManager> baseCommitManager)
public IMultiCommitManager(ref SharedRef<LibHac.FsSrv.Sf.IMultiCommitManager> baseCommitManager)
{
_baseCommitManager = baseCommitManager;
_baseCommitManager = SharedRef<LibHac.FsSrv.Sf.IMultiCommitManager>.CreateMove(ref baseCommitManager);
}
[CommandHipc(1)] // 6.0.0+
// Add(object<nn::fssrv::sf::IFileSystem>)
public ResultCode Add(ServiceCtx context)
{
IFileSystem fileSystem = GetObject<IFileSystem>(context, 0);
using SharedRef<LibHac.FsSrv.Sf.IFileSystem> fileSystem = GetObject<IFileSystem>(context, 0).GetBaseFileSystem();
Result result = _baseCommitManager.Target.Add(fileSystem.GetBaseFileSystem());
Result result = _baseCommitManager.Get.Add(ref fileSystem.Ref());
return (ResultCode)result.Value;
}
@ -27,7 +28,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
// Commit()
public ResultCode Commit(ServiceCtx context)
{
Result result = _baseCommitManager.Target.Commit();
Result result = _baseCommitManager.Get.Commit();
return (ResultCode)result.Value;
}
@ -36,7 +37,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
{
if (isDisposing)
{
_baseCommitManager?.Dispose();
_baseCommitManager.Destroy();
}
}
}

View File

@ -1,15 +1,16 @@
using LibHac;
using LibHac.Common;
using LibHac.Sf;
namespace Ryujinx.HLE.HOS.Services.Fs
{
class ISaveDataInfoReader : DisposableIpcService
{
private ReferenceCountedDisposable<LibHac.FsSrv.Sf.ISaveDataInfoReader> _baseReader;
private SharedRef<LibHac.FsSrv.Sf.ISaveDataInfoReader> _baseReader;
public ISaveDataInfoReader(ReferenceCountedDisposable<LibHac.FsSrv.Sf.ISaveDataInfoReader> baseReader)
public ISaveDataInfoReader(ref SharedRef<LibHac.FsSrv.Sf.ISaveDataInfoReader> baseReader)
{
_baseReader = baseReader;
_baseReader = SharedRef<LibHac.FsSrv.Sf.ISaveDataInfoReader>.CreateMove(ref baseReader);
}
[CommandHipc(0)]
@ -21,7 +22,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
byte[] infoBuffer = new byte[bufferLen];
Result result = _baseReader.Target.Read(out long readCount, new OutBuffer(infoBuffer));
Result result = _baseReader.Get.Read(out long readCount, new OutBuffer(infoBuffer));
context.Memory.Write(bufferPosition, infoBuffer);
context.ResponseData.Write(readCount);
@ -33,7 +34,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
{
if (isDisposing)
{
_baseReader?.Dispose();
_baseReader.Destroy();
}
}
}

View File

@ -74,9 +74,11 @@ namespace Ryujinx.HLE.HOS.Services.Sdb.Pl
Nca nca = new Nca(_device.System.KeySet, ncaFileStream);
IFileSystem romfs = nca.OpenFileSystem(NcaSectionType.Data, _device.System.FsIntegrityCheckLevel);
romfs.OpenFile(out IFile fontFile, ("/" + fontFilename).ToU8Span(), OpenMode.Read).ThrowIfFailure();
using var fontFile = new UniqueRef<IFile>();
data = DecryptFont(fontFile.AsStream());
romfs.OpenFile(ref fontFile.Ref(), ("/" + fontFilename).ToU8Span(), OpenMode.Read).ThrowIfFailure();
data = DecryptFont(fontFile.Get.AsStream());
}
FontInfo info = new FontInfo((int)fontOffset, data.Length);

View File

@ -310,13 +310,15 @@ namespace Ryujinx.HLE.HOS.Services.Settings
IFileSystem firmwareRomFs = firmwareContent.OpenFileSystem(NcaSectionType.Data, device.System.FsIntegrityCheckLevel);
Result result = firmwareRomFs.OpenFile(out IFile firmwareFile, "/file".ToU8Span(), OpenMode.Read);
using var firmwareFile = new UniqueRef<IFile>();
Result result = firmwareRomFs.OpenFile(ref firmwareFile.Ref(), "/file".ToU8Span(), OpenMode.Read);
if (result.IsFailure())
{
return null;
}
result = firmwareFile.GetSize(out long fileSize);
result = firmwareFile.Get.GetSize(out long fileSize);
if (result.IsFailure())
{
return null;
@ -324,7 +326,7 @@ namespace Ryujinx.HLE.HOS.Services.Settings
byte[] data = new byte[fileSize];
result = firmwareFile.Read(out _, 0, data);
result = firmwareFile.Get.Read(out _, 0, data);
if (result.IsFailure())
{
return null;

View File

@ -91,9 +91,11 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone
Nca nca = new Nca(_virtualFileSystem.KeySet, ncaFileStream);
IFileSystem romfs = nca.OpenFileSystem(NcaSectionType.Data, _fsIntegrityCheckLevel);
romfs.OpenFile(out IFile binaryListFile, "/binaryList.txt".ToU8Span(), OpenMode.Read).ThrowIfFailure();
using var binaryListFile = new UniqueRef<IFile>();
StreamReader reader = new StreamReader(binaryListFile.AsStream());
romfs.OpenFile(ref binaryListFile.Ref(), "/binaryList.txt".ToU8Span(), OpenMode.Read).ThrowIfFailure();
StreamReader reader = new StreamReader(binaryListFile.Get.AsStream());
List<string> locationNameList = new List<string>();
@ -135,15 +137,15 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone
continue;
}
if (romfs.OpenFile(out IFile tzif, $"/zoneinfo/{locName}".ToU8Span(), OpenMode.Read).IsFailure())
using var tzif = new UniqueRef<IFile>();
if (romfs.OpenFile(ref tzif.Ref(), $"/zoneinfo/{locName}".ToU8Span(), OpenMode.Read).IsFailure())
{
Logger.Error?.Print(LogClass.ServiceTime, $"Error opening /zoneinfo/{locName}");
continue;
}
using (tzif)
{
TimeZone.ParseTimeZoneBinary(out TimeZoneRule tzRule, tzif.AsStream());
TimeZone.ParseTimeZoneBinary(out TimeZoneRule tzRule, tzif.Get.AsStream());
TimeTypeInfo ttInfo;
if (tzRule.TimeCount > 0) // Find the current transition period
@ -174,7 +176,6 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone
outList.Add((ttInfo.GmtOffset, locName, abbrStart.Slice(0, abbrEnd).ToString()));
}
}
}
outList.Sort();
@ -262,9 +263,11 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone
Nca nca = new Nca(_virtualFileSystem.KeySet, ncaFile);
IFileSystem romfs = nca.OpenFileSystem(NcaSectionType.Data, _fsIntegrityCheckLevel);
Result result = romfs.OpenFile(out IFile timeZoneBinaryFile, $"/zoneinfo/{locationName}".ToU8Span(), OpenMode.Read);
using var timeZoneBinaryFile = new UniqueRef<IFile>();
timeZoneBinaryStream = timeZoneBinaryFile.AsStream();
Result result = romfs.OpenFile(ref timeZoneBinaryFile.Ref(), $"/zoneinfo/{locationName}".ToU8Span(), OpenMode.Read);
timeZoneBinaryStream = timeZoneBinaryFile.Release().AsStream();
return (ResultCode)result.Value;
}

View File

@ -1,3 +1,4 @@
using LibHac.Common;
using LibHac.Fs;
using LibHac.Kernel;
using System;
@ -32,11 +33,11 @@ namespace Ryujinx.HLE.Loaders.Executables
public int Version { get; }
public string Name { get; }
public KipExecutable(IStorage inStorage)
public KipExecutable(in SharedRef<IStorage> inStorage)
{
KipReader reader = new KipReader();
reader.Initialize(inStorage).ThrowIfFailure();
reader.Initialize(in inStorage).ThrowIfFailure();
TextOffset = (uint)reader.Segments[0].MemoryOffset;
RoOffset = (uint)reader.Segments[1].MemoryOffset;

View File

@ -19,7 +19,7 @@
<ItemGroup>
<PackageReference Include="Concentus" Version="1.1.7" />
<PackageReference Include="LibHac" Version="0.13.3" />
<PackageReference Include="LibHac" Version="0.14.3" />
<PackageReference Include="MsgPack.Cli" Version="1.0.1" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.4" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta11" />

View File

@ -19,6 +19,7 @@ using System.Text;
using System.Text.Json;
using JsonHelper = Ryujinx.Common.Utilities.JsonHelper;
using Path = System.IO.Path;
namespace Ryujinx.Ui.App
{
@ -106,8 +107,10 @@ namespace Ryujinx.Ui.App
public void ReadControlData(IFileSystem controlFs, Span<byte> outProperty)
{
controlFs.OpenFile(out IFile controlFile, "/control.nacp".ToU8Span(), OpenMode.Read).ThrowIfFailure();
controlFile.Read(out _, 0, outProperty, ReadOption.None).ThrowIfFailure();
using var controlFile = new UniqueRef<IFile>();
controlFs.OpenFile(ref controlFile.Ref(), "/control.nacp".ToU8Span(), OpenMode.Read).ThrowIfFailure();
controlFile.Get.Read(out _, 0, outProperty, ReadOption.None).ThrowIfFailure();
}
public void LoadApplications(List<string> appDirs, Language desiredTitleLanguage)
@ -188,12 +191,15 @@ namespace Ryujinx.Ui.App
{
if (Path.GetExtension(fileEntry.FullPath).ToLower() == ".nca")
{
pfs.OpenFile(out IFile ncaFile, fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
using var ncaFile = new UniqueRef<IFile>();
Nca nca = new Nca(_virtualFileSystem.KeySet, ncaFile.AsStorage());
pfs.OpenFile(ref ncaFile.Ref(), fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
Nca nca = new Nca(_virtualFileSystem.KeySet, ncaFile.Get.AsStorage());
int dataIndex = Nca.GetSectionIndexFromType(NcaSectionType.Data, NcaContentType.Program);
if (nca.Header.ContentType == NcaContentType.Program && !nca.Header.GetFsHeader(dataIndex).IsPatchSection())
// Some main NCAs don't have a data partition, so check if the partition exists before opening it
if (nca.Header.ContentType == NcaContentType.Program && !(nca.SectionExists(NcaSectionType.Data) && nca.Header.GetFsHeader(dataIndex).IsPatchSection()))
{
hasMainNca = true;
@ -218,11 +224,13 @@ namespace Ryujinx.Ui.App
{
applicationIcon = _nspIcon;
Result result = pfs.OpenFile(out IFile npdmFile, "/main.npdm".ToU8Span(), OpenMode.Read);
using var npdmFile = new UniqueRef<IFile>();
Result result = pfs.OpenFile(ref npdmFile.Ref(), "/main.npdm".ToU8Span(), OpenMode.Read);
if (ResultFs.PathNotFound.Includes(result))
{
Npdm npdm = new Npdm(npdmFile.AsStream());
Npdm npdm = new Npdm(npdmFile.Get.AsStream());
titleName = npdm.TitleName;
titleId = npdm.Aci0.TitleId.ToString("x16");
@ -243,11 +251,13 @@ namespace Ryujinx.Ui.App
// Read the icon from the ControlFS and store it as a byte array
try
{
controlFs.OpenFile(out IFile icon, $"/icon_{_desiredTitleLanguage}.dat".ToU8Span(), OpenMode.Read).ThrowIfFailure();
using var icon = new UniqueRef<IFile>();
controlFs.OpenFile(ref icon.Ref(), $"/icon_{_desiredTitleLanguage}.dat".ToU8Span(), OpenMode.Read).ThrowIfFailure();
using (MemoryStream stream = new MemoryStream())
{
icon.AsStream().CopyTo(stream);
icon.Get.AsStream().CopyTo(stream);
applicationIcon = stream.ToArray();
}
}
@ -260,11 +270,13 @@ namespace Ryujinx.Ui.App
continue;
}
controlFs.OpenFile(out IFile icon, entry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
using var icon = new UniqueRef<IFile>();
controlFs.OpenFile(ref icon.Ref(), entry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
using (MemoryStream stream = new MemoryStream())
{
icon.AsStream().CopyTo(stream);
icon.Get.AsStream().CopyTo(stream);
applicationIcon = stream.ToArray();
}
@ -362,7 +374,7 @@ namespace Ryujinx.Ui.App
Nca nca = new Nca(_virtualFileSystem.KeySet, new FileStream(applicationPath, FileMode.Open, FileAccess.Read).AsStorage());
int dataIndex = Nca.GetSectionIndexFromType(NcaSectionType.Data, NcaContentType.Program);
if (nca.Header.ContentType != NcaContentType.Program || nca.Header.GetFsHeader(dataIndex).IsPatchSection())
if (nca.Header.ContentType != NcaContentType.Program || (nca.SectionExists(NcaSectionType.Data) && nca.Header.GetFsHeader(dataIndex).IsPatchSection()))
{
numApplicationsFound--;
@ -540,7 +552,7 @@ namespace Ryujinx.Ui.App
private void GetNameIdDeveloper(ref ApplicationControlProperty controlData, out string titleName, out string titleId, out string publisher)
{
_ = Enum.TryParse(_desiredTitleLanguage.ToString(), out TitleLanguage desiredTitleLanguage);
_ = Enum.TryParse(_desiredTitleLanguage.ToString(), out LibHac.Settings.Language desiredTitleLanguage);
if (controlData.Titles.Length > (int)desiredTitleLanguage)
{
@ -608,10 +620,11 @@ namespace Ryujinx.Ui.App
if (patchNca != null && controlNca != null)
{
ApplicationControlProperty controlData = new ApplicationControlProperty();
using var nacpFile = new UniqueRef<IFile>();
controlNca.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.None).OpenFile(out IFile nacpFile, "/control.nacp".ToU8Span(), OpenMode.Read).ThrowIfFailure();
controlNca.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.None).OpenFile(ref nacpFile.Ref(), "/control.nacp".ToU8Span(), OpenMode.Read).ThrowIfFailure();
nacpFile.Read(out _, 0, SpanHelpers.AsByteSpan(ref controlData), ReadOption.None).ThrowIfFailure();
nacpFile.Get.Read(out _, 0, SpanHelpers.AsByteSpan(ref controlData), ReadOption.None).ThrowIfFailure();
version = controlData.DisplayVersion.ToString();

View File

@ -237,15 +237,17 @@ namespace Ryujinx.Ui.Widgets
foreach (DirectoryEntryEx fileEntry in pfs.EnumerateEntries("/", "*.nca"))
{
pfs.OpenFile(out IFile ncaFile, fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
using var ncaFile = new UniqueRef<IFile>();
Nca nca = new Nca(_virtualFileSystem.KeySet, ncaFile.AsStorage());
pfs.OpenFile(ref ncaFile.Ref(), fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
Nca nca = new Nca(_virtualFileSystem.KeySet, ncaFile.Release().AsStorage());
if (nca.Header.ContentType == NcaContentType.Program)
{
int dataIndex = Nca.GetSectionIndexFromType(NcaSectionType.Data, NcaContentType.Program);
if (nca.Header.GetFsHeader(dataIndex).IsPatchSection())
if (nca.SectionExists(NcaSectionType.Data) && nca.Header.GetFsHeader(dataIndex).IsPatchSection())
{
patchNca = nca;
}
@ -290,8 +292,11 @@ namespace Ryujinx.Ui.Widgets
string source = DateTime.Now.ToFileTime().ToString()[10..];
string output = DateTime.Now.ToFileTime().ToString()[10..];
fsClient.Register(source.ToU8Span(), ncaFileSystem);
fsClient.Register(output.ToU8Span(), new LocalFileSystem(destination));
using var uniqueSourceFs = new UniqueRef<IFileSystem>(ncaFileSystem);
using var uniqueOutputFs = new UniqueRef<IFileSystem>(new LocalFileSystem(destination));
fsClient.Register(source.ToU8Span(), ref uniqueSourceFs.Ref());
fsClient.Register(output.ToU8Span(), ref uniqueOutputFs.Ref());
(Result? resultCode, bool canceled) = CopyDirectory(fsClient, $"{source}:/", $"{output}:/");

View File

@ -130,12 +130,14 @@ namespace Ryujinx.Ui.Windows
if (item.Type == DirectoryEntryType.File && item.FullPath.Contains("chara") && item.FullPath.Contains("szs"))
{
romfs.OpenFile(out IFile file, ("/" + item.FullPath).ToU8Span(), OpenMode.Read).ThrowIfFailure();
using var file = new UniqueRef<IFile>();
romfs.OpenFile(ref file.Ref(), ("/" + item.FullPath).ToU8Span(), OpenMode.Read).ThrowIfFailure();
using (MemoryStream stream = new MemoryStream())
using (MemoryStream streamPng = new MemoryStream())
{
file.AsStream().CopyTo(stream);
file.Get.AsStream().CopyTo(stream);
stream.Position = 0;

View File

@ -89,8 +89,10 @@ namespace Ryujinx.Ui.Windows
foreach (DlcNca dlcNca in dlcContainer.DlcNcaList)
{
pfs.OpenFile(out IFile ncaFile, dlcNca.Path.ToU8Span(), OpenMode.Read).ThrowIfFailure();
Nca nca = TryCreateNca(ncaFile.AsStorage(), dlcContainer.Path);
using var ncaFile = new UniqueRef<IFile>();
pfs.OpenFile(ref ncaFile.Ref(), dlcNca.Path.ToU8Span(), OpenMode.Read).ThrowIfFailure();
Nca nca = TryCreateNca(ncaFile.Get.AsStorage(), dlcContainer.Path);
if (nca != null)
{
@ -155,9 +157,11 @@ namespace Ryujinx.Ui.Windows
foreach (DirectoryEntryEx fileEntry in pfs.EnumerateEntries("/", "*.nca"))
{
pfs.OpenFile(out IFile ncaFile, fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
using var ncaFile = new UniqueRef<IFile>();
Nca nca = TryCreateNca(ncaFile.AsStorage(), containerPath);
pfs.OpenFile(ref ncaFile.Ref(), fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
Nca nca = TryCreateNca(ncaFile.Get.AsStorage(), containerPath);
if (nca == null) continue;

View File

@ -99,8 +99,10 @@ namespace Ryujinx.Ui.Windows
{
ApplicationControlProperty controlData = new ApplicationControlProperty();
controlNca.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.None).OpenFile(out IFile nacpFile, "/control.nacp".ToU8Span(), OpenMode.Read).ThrowIfFailure();
nacpFile.Read(out _, 0, SpanHelpers.AsByteSpan(ref controlData), ReadOption.None).ThrowIfFailure();
using var nacpFile = new UniqueRef<IFile>();
controlNca.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.None).OpenFile(ref nacpFile.Ref(), "/control.nacp".ToU8Span(), OpenMode.Read).ThrowIfFailure();
nacpFile.Get.Read(out _, 0, SpanHelpers.AsByteSpan(ref controlData), ReadOption.None).ThrowIfFailure();
RadioButton radioButton = new RadioButton($"Version {controlData.DisplayVersion.ToString()} - {path}");
radioButton.JoinGroup(_noUpdateRadioButton);