diff options
| author | Alex Barney <thealexbarney@gmail.com> | 2019-10-17 01:17:44 -0500 |
|---|---|---|
| committer | Ac_K <Acoustik666@gmail.com> | 2019-10-17 08:17:44 +0200 |
| commit | 8a8ea4c8c00e8ba23349d9cdb0a6b681d09e6b0d (patch) | |
| tree | aee0876fbc6e5f9fd2808d942297938ab3ab9495 /Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IDirectory.cs | |
| parent | c0fe6cdca0ebe6b19f8578893ec503d432683897 (diff) | |
Update to LibHac 0.6.0 (#792)
* Update to LibHac 0.6.0
* Create an IFileSystemProxy object from LibHac
* Rename rc -> result
* Alignment and spacing
* Result formatting
* Spacing
* Sort usings
Diffstat (limited to 'Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IDirectory.cs')
| -rw-r--r-- | Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IDirectory.cs | 64 |
1 files changed, 13 insertions, 51 deletions
diff --git a/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IDirectory.cs b/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IDirectory.cs index 4fc8a687..c042ed8e 100644 --- a/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IDirectory.cs +++ b/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IDirectory.cs @@ -1,21 +1,17 @@ using LibHac; -using System.Collections.Generic; -using System.Text; +using LibHac.Fs; +using System; +using System.Runtime.InteropServices; 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)] @@ -25,60 +21,26 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy 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; + byte[] entriesBytes = new byte[bufferLen]; + Span<DirectoryEntry> entries = MemoryMarshal.Cast<byte, DirectoryEntry>(entriesBytes); - WriteDirectoryEntry(context, position, _enumerator.Current); + Result result = _baseDirectory.Read(out long entriesRead, entries); - readCount++; - } - } - catch (HorizonResultException ex) - { - return (ResultCode)ex.ResultValue.Value; - } + context.Memory.WriteBytes(bufferPosition, entriesBytes); + context.ResponseData.Write(entriesRead); - 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); + return (ResultCode)result.Value; } [Command(1)] // GetEntryCount() -> u64 public ResultCode GetEntryCount(ServiceCtx context) { - try - { - context.ResponseData.Write((long)_baseDirectory.GetEntryCount()); - } - catch (HorizonResultException ex) - { - return (ResultCode)ex.ResultValue.Value; - } + Result result = _baseDirectory.GetEntryCount(out long entryCount); + + context.ResponseData.Write(entryCount); - return ResultCode.Success; + return (ResultCode)result.Value; } } } |
