2019-07-10 17:20:01 +00:00
|
|
|
using LibHac;
|
2018-02-20 11:03:04 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Text;
|
|
|
|
|
2019-09-19 00:45:11 +00:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
|
2018-02-20 11:03:04 +00:00
|
|
|
{
|
2019-07-10 17:20:01 +00:00
|
|
|
class IDirectory : IpcService
|
2018-02-20 11:03:04 +00:00
|
|
|
{
|
2018-02-21 21:56:52 +00:00
|
|
|
private const int DirectoryEntrySize = 0x310;
|
2018-02-20 11:03:04 +00:00
|
|
|
|
2019-06-01 00:31:10 +00:00
|
|
|
private IEnumerator<LibHac.Fs.DirectoryEntry> _enumerator;
|
2018-02-21 21:56:52 +00:00
|
|
|
|
2019-07-10 17:20:01 +00:00
|
|
|
private LibHac.Fs.IDirectory _baseDirectory;
|
2018-11-18 19:37:41 +00:00
|
|
|
|
2019-06-01 00:31:10 +00:00
|
|
|
public IDirectory(LibHac.Fs.IDirectory directory)
|
2018-02-20 11:03:04 +00:00
|
|
|
{
|
2019-07-10 17:20:01 +00:00
|
|
|
_baseDirectory = directory;
|
2019-07-12 01:13:43 +00:00
|
|
|
_enumerator = directory.Read().GetEnumerator();
|
2018-02-20 11:03:04 +00:00
|
|
|
}
|
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
[Command(0)]
|
2018-11-18 19:37:41 +00:00
|
|
|
// Read() -> (u64 count, buffer<nn::fssrv::sf::IDirectoryEntry, 6, 0> entries)
|
2019-07-14 19:04:38 +00:00
|
|
|
public ResultCode Read(ServiceCtx context)
|
2018-02-20 11:03:04 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
long bufferPosition = context.Request.ReceiveBuff[0].Position;
|
|
|
|
long bufferLen = context.Request.ReceiveBuff[0].Size;
|
2018-02-20 11:03:04 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
int maxReadCount = (int)(bufferLen / DirectoryEntrySize);
|
2019-06-01 00:31:10 +00:00
|
|
|
int readCount = 0;
|
2018-02-20 11:03:04 +00:00
|
|
|
|
2019-07-10 17:20:01 +00:00
|
|
|
try
|
2018-02-21 21:56:52 +00:00
|
|
|
{
|
2019-07-10 17:20:01 +00:00
|
|
|
while (readCount < maxReadCount && _enumerator.MoveNext())
|
|
|
|
{
|
|
|
|
long position = bufferPosition + readCount * DirectoryEntrySize;
|
2019-06-01 00:31:10 +00:00
|
|
|
|
2019-07-10 17:20:01 +00:00
|
|
|
WriteDirectoryEntry(context, position, _enumerator.Current);
|
2018-02-20 11:03:04 +00:00
|
|
|
|
2019-07-10 17:20:01 +00:00
|
|
|
readCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (HorizonResultException ex)
|
|
|
|
{
|
2019-07-14 19:04:38 +00:00
|
|
|
return (ResultCode)ex.ResultValue.Value;
|
2018-02-20 11:03:04 +00:00
|
|
|
}
|
|
|
|
|
2019-06-01 00:31:10 +00:00
|
|
|
context.ResponseData.Write((long)readCount);
|
2018-02-21 21:56:52 +00:00
|
|
|
|
2019-07-14 19:04:38 +00:00
|
|
|
return ResultCode.Success;
|
2018-02-21 21:56:52 +00:00
|
|
|
}
|
|
|
|
|
2019-06-01 00:31:10 +00:00
|
|
|
private void WriteDirectoryEntry(ServiceCtx context, long position, LibHac.Fs.DirectoryEntry entry)
|
2018-02-21 21:56:52 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
for (int offset = 0; offset < 0x300; offset += 8)
|
2018-02-20 11:03:04 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
context.Memory.WriteInt64(position + offset, 0);
|
2018-02-20 11:03:04 +00:00
|
|
|
}
|
2018-02-21 21:56:52 +00:00
|
|
|
|
2019-06-01 00:31:10 +00:00
|
|
|
byte[] nameBuffer = Encoding.UTF8.GetBytes(entry.Name);
|
2018-02-21 21:56:52 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
context.Memory.WriteBytes(position, nameBuffer);
|
2018-02-21 21:56:52 +00:00
|
|
|
|
2019-06-01 00:31:10 +00:00
|
|
|
context.Memory.WriteInt32(position + 0x300, (int)entry.Attributes);
|
|
|
|
context.Memory.WriteInt32(position + 0x304, (byte)entry.Type);
|
2018-12-06 11:16:24 +00:00
|
|
|
context.Memory.WriteInt64(position + 0x308, entry.Size);
|
2018-02-20 11:03:04 +00:00
|
|
|
}
|
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
[Command(1)]
|
2018-11-18 19:37:41 +00:00
|
|
|
// GetEntryCount() -> u64
|
2019-07-14 19:04:38 +00:00
|
|
|
public ResultCode GetEntryCount(ServiceCtx context)
|
2018-02-20 11:03:04 +00:00
|
|
|
{
|
2019-07-10 17:20:01 +00:00
|
|
|
try
|
2018-02-21 21:56:52 +00:00
|
|
|
{
|
2019-07-10 17:20:01 +00:00
|
|
|
context.ResponseData.Write((long)_baseDirectory.GetEntryCount());
|
2018-02-21 21:56:52 +00:00
|
|
|
}
|
2019-07-10 17:20:01 +00:00
|
|
|
catch (HorizonResultException ex)
|
|
|
|
{
|
2019-07-14 19:04:38 +00:00
|
|
|
return (ResultCode)ex.ResultValue.Value;
|
2019-07-10 17:20:01 +00:00
|
|
|
}
|
|
|
|
|
2019-07-14 19:04:38 +00:00
|
|
|
return ResultCode.Success;
|
2018-02-21 21:56:52 +00:00
|
|
|
}
|
2018-02-20 11:03:04 +00:00
|
|
|
}
|
|
|
|
}
|