Code style fixes and nits on the HLE project (#355)
* Some style fixes and nits on ITimeZoneService * Remove some unneeded usings * Remove the Ryujinx.HLE.OsHle.Handles namespace * Remove hbmenu automatic load on process exit * Rename Ns to Device, rename Os to System, rename SystemState to State * Move Exceptions and Utilities out of OsHle * Rename OsHle to HOS * Rename OsHle folder to HOS * IManagerDisplayService and ISystemDisplayService style fixes * BsdError shouldn't be public * Add a empty new line before using static * Remove unused file * Some style fixes on NPDM * Exit gracefully when the application is closed * Code style fixes on IGeneralService * Add 0x prefix on values printed as hex * Small improvements on finalization code * Move ProcessId and ThreadId out of AThreadState * Rename VFs to FileSystem * FsAccessHeader shouldn't be public. Also fix file names casing * More case changes on NPDM * Remove unused files * Move using to the correct place on NPDM * Use properties on KernelAccessControlMmio * Address PR feedback
This commit is contained in:
parent
182d716867
commit
521751795a
258 changed files with 1574 additions and 1546 deletions
116
Ryujinx.HLE/HOS/Services/FspSrv/IDirectory.cs
Normal file
116
Ryujinx.HLE/HOS/Services/FspSrv/IDirectory.cs
Normal file
|
@ -0,0 +1,116 @@
|
|||
using Ryujinx.HLE.HOS.Ipc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.FspSrv
|
||||
{
|
||||
class IDirectory : IpcService, IDisposable
|
||||
{
|
||||
private const int DirectoryEntrySize = 0x310;
|
||||
|
||||
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
||||
|
||||
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
||||
|
||||
private List<string> DirectoryEntries;
|
||||
|
||||
private int CurrentItemIndex;
|
||||
|
||||
public event EventHandler<EventArgs> Disposed;
|
||||
|
||||
public string HostPath { get; private set; }
|
||||
|
||||
public IDirectory(string HostPath, int Flags)
|
||||
{
|
||||
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
||||
{
|
||||
{ 0, Read },
|
||||
{ 1, GetEntryCount }
|
||||
};
|
||||
|
||||
this.HostPath = HostPath;
|
||||
|
||||
DirectoryEntries = new List<string>();
|
||||
|
||||
if ((Flags & 1) != 0)
|
||||
{
|
||||
DirectoryEntries.AddRange(Directory.GetDirectories(HostPath));
|
||||
}
|
||||
|
||||
if ((Flags & 2) != 0)
|
||||
{
|
||||
DirectoryEntries.AddRange(Directory.GetFiles(HostPath));
|
||||
}
|
||||
|
||||
CurrentItemIndex = 0;
|
||||
}
|
||||
|
||||
public long Read(ServiceCtx Context)
|
||||
{
|
||||
long BufferPosition = Context.Request.ReceiveBuff[0].Position;
|
||||
long BufferLen = Context.Request.ReceiveBuff[0].Size;
|
||||
|
||||
int MaxReadCount = (int)(BufferLen / DirectoryEntrySize);
|
||||
|
||||
int Count = Math.Min(DirectoryEntries.Count - CurrentItemIndex, MaxReadCount);
|
||||
|
||||
for (int Index = 0; Index < Count; Index++)
|
||||
{
|
||||
long Position = BufferPosition + Index * DirectoryEntrySize;
|
||||
|
||||
WriteDirectoryEntry(Context, Position, DirectoryEntries[CurrentItemIndex++]);
|
||||
}
|
||||
|
||||
Context.ResponseData.Write((long)Count);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void WriteDirectoryEntry(ServiceCtx Context, long Position, string FullPath)
|
||||
{
|
||||
for (int Offset = 0; Offset < 0x300; Offset += 8)
|
||||
{
|
||||
Context.Memory.WriteInt64(Position + Offset, 0);
|
||||
}
|
||||
|
||||
byte[] NameBuffer = Encoding.UTF8.GetBytes(Path.GetFileName(FullPath));
|
||||
|
||||
Context.Memory.WriteBytes(Position, NameBuffer);
|
||||
|
||||
int Type = 0;
|
||||
long Size = 0;
|
||||
|
||||
if (File.Exists(FullPath))
|
||||
{
|
||||
Type = 1;
|
||||
Size = new FileInfo(FullPath).Length;
|
||||
}
|
||||
|
||||
Context.Memory.WriteInt32(Position + 0x300, 0); //Padding?
|
||||
Context.Memory.WriteInt32(Position + 0x304, Type);
|
||||
Context.Memory.WriteInt64(Position + 0x308, Size);
|
||||
}
|
||||
|
||||
public long GetEntryCount(ServiceCtx Context)
|
||||
{
|
||||
Context.ResponseData.Write((long)DirectoryEntries.Count);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
Disposed?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue