1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-09-22 15:03:30 +01:00
Ryujinx/Ryujinx.HLE/HOS/Services/FspSrv/IStorage.cs
Alex Barney f723f6f39a Update to LibHac 0.5.0 (#725)
* Update to libhac 0.5

* Catch HorizonResultException in IFileSystemProxy

* Changes based on feedback
2019-07-10 19:20:01 +02:00

75 lines
1.9 KiB
C#

using LibHac;
using Ryujinx.HLE.HOS.Ipc;
using System.Collections.Generic;
namespace Ryujinx.HLE.HOS.Services.FspSrv
{
class IStorage : IpcService
{
private Dictionary<int, ServiceProcessRequest> _commands;
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
private LibHac.Fs.IStorage _baseStorage;
public IStorage(LibHac.Fs.IStorage baseStorage)
{
_commands = new Dictionary<int, ServiceProcessRequest>
{
{ 0, Read },
{ 4, GetSize }
};
_baseStorage = baseStorage;
}
// Read(u64 offset, u64 length) -> buffer<u8, 0x46, 0> buffer
public long Read(ServiceCtx context)
{
long offset = context.RequestData.ReadInt64();
long size = context.RequestData.ReadInt64();
if (context.Request.ReceiveBuff.Count > 0)
{
IpcBuffDesc buffDesc = context.Request.ReceiveBuff[0];
// Use smaller length to avoid overflows.
if (size > buffDesc.Size)
{
size = buffDesc.Size;
}
byte[] data = new byte[size];
try
{
_baseStorage.Read(data, offset);
}
catch (HorizonResultException ex)
{
return ex.ResultValue.Value;
}
context.Memory.WriteBytes(buffDesc.Position, data);
}
return 0;
}
// GetSize() -> u64 size
public long GetSize(ServiceCtx context)
{
try
{
context.ResponseData.Write(_baseStorage.GetSize());
}
catch (HorizonResultException ex)
{
return ex.ResultValue.Value;
}
return 0;
}
}
}