diff options
| author | Ac_K <Acoustik666@gmail.com> | 2019-09-19 02:45:11 +0200 |
|---|---|---|
| committer | jduncanator <1518948+jduncanator@users.noreply.github.com> | 2019-09-19 10:45:11 +1000 |
| commit | a0720b5681852f3d786d77bd3793b0359dea321c (patch) | |
| tree | 9d8f61e540d1d1d827999902dad95e5c0c1e076e /Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IDirectory.cs | |
| parent | 4af3101b22e6957d6aa48a2768566d658699f4ed (diff) | |
Refactoring HOS folder structure (#771)
* Refactoring HOS folder structure
Refactoring HOS folder structure:
- Added some subfolders when needed (Following structure decided in private).
- Added some `Types` folders when needed.
- Little cleanup here and there.
- Add services placeholders for every HOS services (close #766 and #753).
* Remove Types namespaces
Diffstat (limited to 'Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IDirectory.cs')
| -rw-r--r-- | Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IDirectory.cs | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IDirectory.cs b/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IDirectory.cs new file mode 100644 index 00000000..4fc8a687 --- /dev/null +++ b/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IDirectory.cs @@ -0,0 +1,84 @@ +using LibHac; +using System.Collections.Generic; +using System.Text; + +namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy +{ + class IDirectory : IpcService + { + private const int DirectoryEntrySize = 0x310; + + private IEnumerator<LibHac.Fs.DirectoryEntry> _enumerator; + + private LibHac.Fs.IDirectory _baseDirectory; + + public IDirectory(LibHac.Fs.IDirectory directory) + { + _baseDirectory = directory; + _enumerator = directory.Read().GetEnumerator(); + } + + [Command(0)] + // Read() -> (u64 count, buffer<nn::fssrv::sf::IDirectoryEntry, 6, 0> entries) + public ResultCode Read(ServiceCtx context) + { + long bufferPosition = context.Request.ReceiveBuff[0].Position; + long bufferLen = context.Request.ReceiveBuff[0].Size; + + int maxReadCount = (int)(bufferLen / DirectoryEntrySize); + int readCount = 0; + + try + { + while (readCount < maxReadCount && _enumerator.MoveNext()) + { + long position = bufferPosition + readCount * DirectoryEntrySize; + + WriteDirectoryEntry(context, position, _enumerator.Current); + + readCount++; + } + } + catch (HorizonResultException ex) + { + return (ResultCode)ex.ResultValue.Value; + } + + context.ResponseData.Write((long)readCount); + + return ResultCode.Success; + } + + private void WriteDirectoryEntry(ServiceCtx context, long position, LibHac.Fs.DirectoryEntry entry) + { + for (int offset = 0; offset < 0x300; offset += 8) + { + context.Memory.WriteInt64(position + offset, 0); + } + + byte[] nameBuffer = Encoding.UTF8.GetBytes(entry.Name); + + context.Memory.WriteBytes(position, nameBuffer); + + context.Memory.WriteInt32(position + 0x300, (int)entry.Attributes); + context.Memory.WriteInt32(position + 0x304, (byte)entry.Type); + context.Memory.WriteInt64(position + 0x308, entry.Size); + } + + [Command(1)] + // GetEntryCount() -> u64 + public ResultCode GetEntryCount(ServiceCtx context) + { + try + { + context.ResponseData.Write((long)_baseDirectory.GetEntryCount()); + } + catch (HorizonResultException ex) + { + return (ResultCode)ex.ResultValue.Value; + } + + return ResultCode.Success; + } + } +} |
