Update IDirectory.cs

Fixed :)
This commit is contained in:
Ac_K 2018-02-19 19:32:29 +01:00 committed by Ezekiel Bethel
commit 856a0f328f

View file

@ -2,6 +2,7 @@ using ChocolArm64.Memory;
using Ryujinx.OsHle.Ipc; using Ryujinx.OsHle.Ipc;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Text; using System.Text;
namespace Ryujinx.OsHle.Objects.FspSrv namespace Ryujinx.OsHle.Objects.FspSrv
@ -15,8 +16,7 @@ namespace Ryujinx.OsHle.Objects.FspSrv
class IDirectory : IIpcInterface class IDirectory : IIpcInterface
{ {
private List<DirectoryEntry> DirectoryEntries; private List<DirectoryEntry> DirectoryEntries = new List<DirectoryEntry>();
private int CurrentItem;
private Dictionary<int, ServiceProcessRequest> m_Commands; private Dictionary<int, ServiceProcessRequest> m_Commands;
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands; public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
@ -24,7 +24,7 @@ namespace Ryujinx.OsHle.Objects.FspSrv
private string HostPath; private string HostPath;
const int DirectoryEntryType_Directory = 0; const int DirectoryEntryType_Directory = 0;
const int DirectoryEntryType_File = 0; const int DirectoryEntryType_File = 1;
public IDirectory(string HostPath, int flags) public IDirectory(string HostPath, int flags)
{ {
m_Commands = new Dictionary<int, ServiceProcessRequest>() m_Commands = new Dictionary<int, ServiceProcessRequest>()
@ -37,49 +37,56 @@ namespace Ryujinx.OsHle.Objects.FspSrv
if ((flags & 1) == 1) if ((flags & 1) == 1)
{ {
string[] Directories = Directory.GetDirectories(HostPath, "*", SearchOption.TopDirectoryOnly); string[] Directories = Directory.GetDirectories(HostPath, "*", SearchOption.TopDirectoryOnly).
Where(x => (new FileInfo(x).Attributes & FileAttributes.Hidden) == 0).ToArray();
foreach (string Directory in Directories) foreach (string Directory in Directories)
{ {
DirectoryEntry Info = new DirectoryEntry(); DirectoryEntry Info = new DirectoryEntry
Info.Name = Directory; {
Info.Type = DirectoryEntryType_Directory; Name = Directory,
Info.Size = 0; Type = DirectoryEntryType_Directory,
Size = 0
};
DirectoryEntries.Add(Info); DirectoryEntries.Add(Info);
} }
} }
if ((flags & 2) == 2) if ((flags & 2) == 2)
{ {
string[] Files = Directory.GetFiles(HostPath, "*", SearchOption.TopDirectoryOnly); string[] Files = Directory.GetFiles(HostPath, "*", SearchOption.TopDirectoryOnly).
Where(x => (new FileInfo(x).Attributes & FileAttributes.Hidden) == 0).ToArray();
foreach (string FileName in Files) foreach (string FileName in Files)
{ {
DirectoryEntry Info = new DirectoryEntry(); DirectoryEntry Info = new DirectoryEntry
Info.Name = FileName; {
Info.Type = DirectoryEntryType_File; Name = Path.GetFileName(FileName),
Info.Size = new FileInfo(FileName).Length; Type = DirectoryEntryType_File,
Size = new FileInfo(Path.Combine(HostPath, FileName)).Length
};
DirectoryEntries.Add(Info); DirectoryEntries.Add(Info);
} }
} }
} }
private int ReadedItem = 0;
const int DirectoryEntrySize = 0x310; const int DirectoryEntrySize = 0x310;
public long Read(ServiceCtx Context) public long Read(ServiceCtx Context)
{ {
long BufferPosition = Context.Request.PtrBuff[0].Position; long BufferPosition = Context.Request.ReceiveBuff[0].Position;
long BufferLen = Context.Request.PtrBuff[0].Size; long BufferLen = Context.Request.ReceiveBuff[0].Size;
long MaxDirectories = BufferLen / DirectoryEntrySize; long MaxDirectories = BufferLen / DirectoryEntrySize;
if(MaxDirectories == DirectoryEntries.Count) if (MaxDirectories >= DirectoryEntries.Count) MaxDirectories = DirectoryEntries.Count;
{
MaxDirectories = DirectoryEntries.Count;
}
int CurrentIndex = 0; int CurrentItem;
byte[] DirectoryEntry = new byte[DirectoryEntrySize]; byte[] DirectoryEntry = new byte[DirectoryEntrySize];
for(; CurrentItem < MaxDirectories; CurrentItem++) for (CurrentItem = 0; CurrentItem < MaxDirectories; CurrentItem++)
{ {
MemoryStream MemStream = new MemoryStream(); MemoryStream MemStream = new MemoryStream();
BinaryWriter Writer = new BinaryWriter(MemStream); BinaryWriter Writer = new BinaryWriter(MemStream);
Writer.Write(Encoding.UTF8.GetBytes(DirectoryEntries[CurrentItem].Name)); Writer.Write(Encoding.UTF8.GetBytes(DirectoryEntries[CurrentItem].Name));
Writer.Seek(0x304, SeekOrigin.Begin); Writer.Seek(0x304, SeekOrigin.Begin);
Writer.Write(DirectoryEntries[CurrentItem].Type); Writer.Write(DirectoryEntries[CurrentItem].Type);
@ -88,11 +95,16 @@ namespace Ryujinx.OsHle.Objects.FspSrv
MemStream.Seek(0, SeekOrigin.Begin); MemStream.Seek(0, SeekOrigin.Begin);
MemStream.Read(DirectoryEntry, 0, 0x310); MemStream.Read(DirectoryEntry, 0, 0x310);
AMemoryHelper.WriteBytes(Context.Memory, BufferPosition + DirectoryEntrySize * CurrentIndex, DirectoryEntry); AMemoryHelper.WriteBytes(Context.Memory, BufferPosition + DirectoryEntrySize * CurrentItem, DirectoryEntry);
CurrentIndex++;
} }
Context.ResponseData.Write(CurrentIndex + 1); if (ReadedItem == 0)
{
ReadedItem = CurrentItem;
Context.ResponseData.Write((long)CurrentItem);
}
else Context.ResponseData.Write((long)0);
return 0; return 0;
} }