mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2025-07-24 17:17:11 +02:00
Split main project into core,graphics and chocolarm4 subproject (#29)
This commit is contained in:
parent
cb665bb715
commit
62b827f474
257 changed files with 415 additions and 285 deletions
133
Ryujinx.Core/OsHle/Objects/FspSrv/IDirectory.cs
Normal file
133
Ryujinx.Core/OsHle/Objects/FspSrv/IDirectory.cs
Normal file
|
@ -0,0 +1,133 @@
|
|||
using ChocolArm64.Memory;
|
||||
using Ryujinx.Core.OsHle.Ipc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace Ryujinx.Core.OsHle.Objects.FspSrv
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0x310)]
|
||||
struct DirectoryEntry
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 0x300)]
|
||||
public byte[] Name;
|
||||
public int Unknown;
|
||||
public byte Type;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 0x3)]
|
||||
public byte[] Padding;
|
||||
public long Size;
|
||||
}
|
||||
|
||||
enum DirectoryEntryType
|
||||
{
|
||||
Directory,
|
||||
File
|
||||
}
|
||||
|
||||
class IDirectory : IIpcInterface
|
||||
{
|
||||
private List<DirectoryEntry> DirectoryEntries = new List<DirectoryEntry>();
|
||||
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
||||
|
||||
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
||||
|
||||
private string HostPath;
|
||||
|
||||
public IDirectory(string HostPath, int flags)
|
||||
{
|
||||
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
||||
{
|
||||
{ 0, Read },
|
||||
{ 1, GetEntryCount }
|
||||
};
|
||||
|
||||
this.HostPath = HostPath;
|
||||
|
||||
if ((flags & 1) == 1)
|
||||
{
|
||||
string[] Directories = Directory.GetDirectories(HostPath, "*", SearchOption.TopDirectoryOnly).
|
||||
Where(x => (new FileInfo(x).Attributes & FileAttributes.Hidden) == 0).ToArray();
|
||||
|
||||
foreach (string Directory in Directories)
|
||||
{
|
||||
DirectoryEntry Info = new DirectoryEntry
|
||||
{
|
||||
Name = Encoding.UTF8.GetBytes(Directory),
|
||||
Type = (byte)DirectoryEntryType.Directory,
|
||||
Size = 0
|
||||
};
|
||||
|
||||
Array.Resize(ref Info.Name, 0x300);
|
||||
DirectoryEntries.Add(Info);
|
||||
}
|
||||
}
|
||||
|
||||
if ((flags & 2) == 2)
|
||||
{
|
||||
string[] Files = Directory.GetFiles(HostPath, "*", SearchOption.TopDirectoryOnly).
|
||||
Where(x => (new FileInfo(x).Attributes & FileAttributes.Hidden) == 0).ToArray();
|
||||
|
||||
foreach (string FileName in Files)
|
||||
{
|
||||
DirectoryEntry Info = new DirectoryEntry
|
||||
{
|
||||
Name = Encoding.UTF8.GetBytes(Path.GetFileName(FileName)),
|
||||
Type = (byte)DirectoryEntryType.File,
|
||||
Size = new FileInfo(Path.Combine(HostPath, FileName)).Length
|
||||
};
|
||||
|
||||
Array.Resize(ref Info.Name, 0x300);
|
||||
DirectoryEntries.Add(Info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int LastItem = 0;
|
||||
public long Read(ServiceCtx Context)
|
||||
{
|
||||
long BufferPosition = Context.Request.ReceiveBuff[0].Position;
|
||||
long BufferLen = Context.Request.ReceiveBuff[0].Size;
|
||||
long MaxDirectories = BufferLen / Marshal.SizeOf(typeof(DirectoryEntry));
|
||||
|
||||
if (MaxDirectories > DirectoryEntries.Count - LastItem)
|
||||
{
|
||||
MaxDirectories = DirectoryEntries.Count - LastItem;
|
||||
}
|
||||
|
||||
int CurrentIndex;
|
||||
for (CurrentIndex = 0; CurrentIndex < MaxDirectories; CurrentIndex++)
|
||||
{
|
||||
int CurrentItem = LastItem + CurrentIndex;
|
||||
|
||||
byte[] DirectoryEntry = new byte[Marshal.SizeOf(typeof(DirectoryEntry))];
|
||||
IntPtr Ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DirectoryEntry)));
|
||||
Marshal.StructureToPtr(DirectoryEntries[CurrentItem], Ptr, true);
|
||||
Marshal.Copy(Ptr, DirectoryEntry, 0, Marshal.SizeOf(typeof(DirectoryEntry)));
|
||||
Marshal.FreeHGlobal(Ptr);
|
||||
|
||||
AMemoryHelper.WriteBytes(Context.Memory, BufferPosition + Marshal.SizeOf(typeof(DirectoryEntry)) * CurrentIndex, DirectoryEntry);
|
||||
}
|
||||
|
||||
if (LastItem < DirectoryEntries.Count)
|
||||
{
|
||||
LastItem += CurrentIndex;
|
||||
Context.ResponseData.Write((long)CurrentIndex); // index = number of entries written this call.
|
||||
}
|
||||
else
|
||||
{
|
||||
Context.ResponseData.Write((long)0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long GetEntryCount(ServiceCtx Context)
|
||||
{
|
||||
Context.ResponseData.Write((long)DirectoryEntries.Count);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
93
Ryujinx.Core/OsHle/Objects/FspSrv/IFile.cs
Normal file
93
Ryujinx.Core/OsHle/Objects/FspSrv/IFile.cs
Normal file
|
@ -0,0 +1,93 @@
|
|||
using ChocolArm64.Memory;
|
||||
using Ryujinx.Core.OsHle.Ipc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace Ryujinx.Core.OsHle.Objects.FspSrv
|
||||
{
|
||||
class IFile : IIpcInterface, IDisposable
|
||||
{
|
||||
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
||||
|
||||
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
||||
|
||||
private Stream BaseStream;
|
||||
|
||||
public IFile(Stream BaseStream)
|
||||
{
|
||||
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
||||
{
|
||||
{ 0, Read },
|
||||
{ 1, Write },
|
||||
// { 2, Flush },
|
||||
{ 3, SetSize },
|
||||
{ 4, GetSize }
|
||||
};
|
||||
|
||||
this.BaseStream = BaseStream;
|
||||
}
|
||||
|
||||
public long Read(ServiceCtx Context)
|
||||
{
|
||||
long Position = Context.Request.ReceiveBuff[0].Position;
|
||||
|
||||
long Zero = Context.RequestData.ReadInt64();
|
||||
long Offset = Context.RequestData.ReadInt64();
|
||||
long Size = Context.RequestData.ReadInt64();
|
||||
|
||||
byte[] Data = new byte[Size];
|
||||
|
||||
BaseStream.Seek(Offset, SeekOrigin.Begin);
|
||||
int ReadSize = BaseStream.Read(Data, 0, (int)Size);
|
||||
|
||||
AMemoryHelper.WriteBytes(Context.Memory, Position, Data);
|
||||
|
||||
Context.ResponseData.Write((long)ReadSize);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long Write(ServiceCtx Context)
|
||||
{
|
||||
long Position = Context.Request.SendBuff[0].Position;
|
||||
|
||||
long Zero = Context.RequestData.ReadInt64();
|
||||
long Offset = Context.RequestData.ReadInt64();
|
||||
long Size = Context.RequestData.ReadInt64();
|
||||
|
||||
byte[] Data = AMemoryHelper.ReadBytes(Context.Memory, Position, (int)Size);
|
||||
|
||||
BaseStream.Seek(Offset, SeekOrigin.Begin);
|
||||
BaseStream.Write(Data, 0, (int)Size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long GetSize(ServiceCtx Context)
|
||||
{
|
||||
Context.ResponseData.Write(BaseStream.Length);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long SetSize(ServiceCtx Context)
|
||||
{
|
||||
long Size = Context.RequestData.ReadInt64();
|
||||
BaseStream.SetLength(Size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && BaseStream != null)
|
||||
{
|
||||
BaseStream.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
247
Ryujinx.Core/OsHle/Objects/FspSrv/IFileSystem.cs
Normal file
247
Ryujinx.Core/OsHle/Objects/FspSrv/IFileSystem.cs
Normal file
|
@ -0,0 +1,247 @@
|
|||
using ChocolArm64.Memory;
|
||||
using Ryujinx.Core.OsHle.Ipc;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
using static Ryujinx.Core.OsHle.Objects.ObjHelper;
|
||||
|
||||
namespace Ryujinx.Core.OsHle.Objects.FspSrv
|
||||
{
|
||||
class IFileSystem : IIpcInterface
|
||||
{
|
||||
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
||||
|
||||
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
||||
|
||||
private string Path;
|
||||
|
||||
public IFileSystem(string Path)
|
||||
{
|
||||
//TODO: implement.
|
||||
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
||||
{
|
||||
{ 0, CreateFile },
|
||||
{ 1, DeleteFile },
|
||||
{ 2, CreateDirectory },
|
||||
{ 3, DeleteDirectory },
|
||||
{ 4, DeleteDirectoryRecursively },
|
||||
{ 5, RenameFile },
|
||||
{ 6, RenameDirectory },
|
||||
{ 7, GetEntryType },
|
||||
{ 8, OpenFile },
|
||||
{ 9, OpenDirectory },
|
||||
{ 10, Commit },
|
||||
//{ 11, GetFreeSpaceSize },
|
||||
//{ 12, GetTotalSpaceSize },
|
||||
//{ 13, CleanDirectoryRecursively },
|
||||
//{ 14, GetFileTimeStampRaw }
|
||||
};
|
||||
|
||||
this.Path = Path;
|
||||
}
|
||||
|
||||
public long CreateFile(ServiceCtx Context)
|
||||
{
|
||||
long Position = Context.Request.PtrBuff[0].Position;
|
||||
string Name = AMemoryHelper.ReadAsciiString(Context.Memory, Position);
|
||||
ulong Mode = Context.RequestData.ReadUInt64();
|
||||
uint Size = Context.RequestData.ReadUInt32();
|
||||
string FileName = Context.Ns.VFs.GetFullPath(Path, Name);
|
||||
|
||||
if (FileName != null)
|
||||
{
|
||||
FileStream NewFile = File.Create(FileName);
|
||||
NewFile.SetLength(Size);
|
||||
NewFile.Close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
//TODO: Correct error code.
|
||||
return -1;
|
||||
}
|
||||
|
||||
public long DeleteFile(ServiceCtx Context)
|
||||
{
|
||||
long Position = Context.Request.PtrBuff[0].Position;
|
||||
string Name = AMemoryHelper.ReadAsciiString(Context.Memory, Position);
|
||||
string FileName = Context.Ns.VFs.GetFullPath(Path, Name);
|
||||
|
||||
if (FileName != null)
|
||||
{
|
||||
File.Delete(FileName);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//TODO: Correct error code.
|
||||
return -1;
|
||||
}
|
||||
|
||||
public long CreateDirectory(ServiceCtx Context)
|
||||
{
|
||||
long Position = Context.Request.PtrBuff[0].Position;
|
||||
string Name = AMemoryHelper.ReadAsciiString(Context.Memory, Position);
|
||||
string FileName = Context.Ns.VFs.GetFullPath(Path, Name);
|
||||
|
||||
if (FileName != null)
|
||||
{
|
||||
Directory.CreateDirectory(FileName);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//TODO: Correct error code.
|
||||
return -1;
|
||||
}
|
||||
|
||||
public long DeleteDirectory(ServiceCtx Context)
|
||||
{
|
||||
long Position = Context.Request.PtrBuff[0].Position;
|
||||
string Name = AMemoryHelper.ReadAsciiString(Context.Memory, Position);
|
||||
string FileName = Context.Ns.VFs.GetFullPath(Path, Name);
|
||||
|
||||
if (FileName != null)
|
||||
{
|
||||
Directory.Delete(FileName);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO: Correct error code.
|
||||
return -1;
|
||||
}
|
||||
|
||||
public long DeleteDirectoryRecursively(ServiceCtx Context)
|
||||
{
|
||||
long Position = Context.Request.PtrBuff[0].Position;
|
||||
string Name = AMemoryHelper.ReadAsciiString(Context.Memory, Position);
|
||||
string FileName = Context.Ns.VFs.GetFullPath(Path, Name);
|
||||
|
||||
if (FileName != null)
|
||||
{
|
||||
Directory.Delete(FileName, true); // recursive = true
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO: Correct error code.
|
||||
return -1;
|
||||
}
|
||||
|
||||
public long RenameFile(ServiceCtx Context)
|
||||
{
|
||||
long OldPosition = Context.Request.PtrBuff[0].Position;
|
||||
long NewPosition = Context.Request.PtrBuff[0].Position;
|
||||
string OldName = AMemoryHelper.ReadAsciiString(Context.Memory, OldPosition);
|
||||
string NewName = AMemoryHelper.ReadAsciiString(Context.Memory, NewPosition);
|
||||
string OldFileName = Context.Ns.VFs.GetFullPath(Path, OldName);
|
||||
string NewFileName = Context.Ns.VFs.GetFullPath(Path, NewName);
|
||||
|
||||
if (OldFileName != null && NewFileName != null)
|
||||
{
|
||||
File.Move(OldFileName, NewFileName);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO: Correct error code.
|
||||
return -1;
|
||||
}
|
||||
|
||||
public long RenameDirectory(ServiceCtx Context)
|
||||
{
|
||||
long OldPosition = Context.Request.PtrBuff[0].Position;
|
||||
long NewPosition = Context.Request.PtrBuff[0].Position;
|
||||
string OldName = AMemoryHelper.ReadAsciiString(Context.Memory, OldPosition);
|
||||
string NewName = AMemoryHelper.ReadAsciiString(Context.Memory, NewPosition);
|
||||
string OldDirName = Context.Ns.VFs.GetFullPath(Path, OldName);
|
||||
string NewDirName = Context.Ns.VFs.GetFullPath(Path, NewName);
|
||||
|
||||
if (OldDirName != null && NewDirName != null)
|
||||
{
|
||||
Directory.Move(OldDirName, NewDirName);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO: Correct error code.
|
||||
return -1;
|
||||
}
|
||||
|
||||
public long GetEntryType(ServiceCtx Context)
|
||||
{
|
||||
long Position = Context.Request.PtrBuff[0].Position;
|
||||
|
||||
string Name = AMemoryHelper.ReadAsciiString(Context.Memory, Position);
|
||||
|
||||
string FileName = Context.Ns.VFs.GetFullPath(Path, Name);
|
||||
|
||||
if (FileName == null)
|
||||
{
|
||||
//TODO: Correct error code.
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool IsFile = File.Exists(FileName);
|
||||
|
||||
Context.ResponseData.Write(IsFile ? 1 : 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long OpenFile(ServiceCtx Context)
|
||||
{
|
||||
long Position = Context.Request.PtrBuff[0].Position;
|
||||
|
||||
int FilterFlags = Context.RequestData.ReadInt32();
|
||||
|
||||
string Name = AMemoryHelper.ReadAsciiString(Context.Memory, Position);
|
||||
|
||||
string FileName = Context.Ns.VFs.GetFullPath(Path, Name);
|
||||
|
||||
if (FileName == null)
|
||||
{
|
||||
//TODO: Correct error code.
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (File.Exists(FileName))
|
||||
{
|
||||
FileStream Stream = new FileStream(FileName, FileMode.OpenOrCreate);
|
||||
MakeObject(Context, new IFile(Stream));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//TODO: Correct error code.
|
||||
return -1;
|
||||
}
|
||||
|
||||
public long OpenDirectory(ServiceCtx Context)
|
||||
{
|
||||
long Position = Context.Request.PtrBuff[0].Position;
|
||||
|
||||
int FilterFlags = Context.RequestData.ReadInt32();
|
||||
|
||||
string Name = AMemoryHelper.ReadAsciiString(Context.Memory, Position);
|
||||
|
||||
string DirName = Context.Ns.VFs.GetFullPath(Path, Name);
|
||||
|
||||
if(DirName != null)
|
||||
{
|
||||
if (Directory.Exists(DirName))
|
||||
{
|
||||
MakeObject(Context, new IDirectory(DirName, FilterFlags));
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: correct error code.
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Correct error code.
|
||||
return -1;
|
||||
}
|
||||
|
||||
public long Commit(ServiceCtx Context)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
52
Ryujinx.Core/OsHle/Objects/FspSrv/IStorage.cs
Normal file
52
Ryujinx.Core/OsHle/Objects/FspSrv/IStorage.cs
Normal file
|
@ -0,0 +1,52 @@
|
|||
using ChocolArm64.Memory;
|
||||
using Ryujinx.Core.OsHle.Ipc;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace Ryujinx.Core.OsHle.Objects.FspSrv
|
||||
{
|
||||
class IStorage : IIpcInterface
|
||||
{
|
||||
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
||||
|
||||
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
||||
|
||||
private Stream BaseStream;
|
||||
|
||||
public IStorage(Stream BaseStream)
|
||||
{
|
||||
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
||||
{
|
||||
{ 0, Read }
|
||||
};
|
||||
|
||||
this.BaseStream = BaseStream;
|
||||
}
|
||||
|
||||
public long Read(ServiceCtx Context)
|
||||
{
|
||||
long Offset = Context.RequestData.ReadInt64();
|
||||
long Size = Context.RequestData.ReadInt64();
|
||||
|
||||
if (Context.Request.ReceiveBuff.Count > 0)
|
||||
{
|
||||
IpcBuffDesc BuffDesc = Context.Request.ReceiveBuff[0];
|
||||
|
||||
//Use smaller length to avoid overflows.
|
||||
if (Size > BuffDesc.Size)
|
||||
{
|
||||
Size = BuffDesc.Size;
|
||||
}
|
||||
|
||||
byte[] Data = new byte[Size];
|
||||
|
||||
BaseStream.Seek(Offset, SeekOrigin.Begin);
|
||||
BaseStream.Read(Data, 0, Data.Length);
|
||||
|
||||
AMemoryHelper.WriteBytes(Context.Memory, BuffDesc.Position, Data);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue