Update IDirectory.cs
Fixed :)
This commit is contained in:
parent
06f5af878d
commit
856a0f328f
1 changed files with 46 additions and 34 deletions
|
@ -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
|
||||||
|
@ -9,14 +10,13 @@ namespace Ryujinx.OsHle.Objects.FspSrv
|
||||||
struct DirectoryEntry
|
struct DirectoryEntry
|
||||||
{
|
{
|
||||||
public string Name;
|
public string Name;
|
||||||
public byte Type;
|
public byte Type;
|
||||||
public long Size;
|
public long Size;
|
||||||
}
|
}
|
||||||
|
|
||||||
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,62 +24,69 @@ 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>()
|
||||||
{
|
{
|
||||||
{ 0, Read },
|
{ 0, Read },
|
||||||
{ 1, GetEntryCount }
|
{ 1, GetEntryCount }
|
||||||
};
|
};
|
||||||
|
|
||||||
this.HostPath = HostPath;
|
this.HostPath = HostPath;
|
||||||
|
|
||||||
if((flags & 1) == 1)
|
if ((flags & 1) == 1)
|
||||||
{
|
{
|
||||||
string[] Directories = Directory.GetDirectories(HostPath, "*", SearchOption.TopDirectoryOnly);
|
string[] Directories = Directory.GetDirectories(HostPath, "*", SearchOption.TopDirectoryOnly).
|
||||||
foreach(string Directory in Directories)
|
Where(x => (new FileInfo(x).Attributes & FileAttributes.Hidden) == 0).ToArray();
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const int DirectoryEntrySize = 0x310;
|
private int ReadedItem = 0;
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,4 +114,4 @@ namespace Ryujinx.OsHle.Objects.FspSrv
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue