Revert "Adjust naming conventions and general refactoring in HLE Project (#490)" (#526)

This reverts commit 85dbb9559a.
This commit is contained in:
gdkchan 2018-12-04 22:52:39 -02:00 committed by GitHub
parent 85dbb9559a
commit 3615a70cae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
299 changed files with 12276 additions and 12268 deletions

View file

@ -1,17 +1,21 @@
namespace Ryujinx.HLE.HOS.Services.FspSrv
using System;
using System.Collections.Generic;
using System.Text;
namespace Ryujinx.HLE.HOS.Services.FspSrv
{
public struct DirectoryEntry
{
public string Path { get; }
public long Size { get; }
public string Path { get; private set; }
public long Size { get; private set; }
public DirectoryEntryType EntryType { get; set; }
public DirectoryEntry(string path, DirectoryEntryType directoryEntryType, long size = 0)
public DirectoryEntry(string Path, DirectoryEntryType DirectoryEntryType, long Size = 0)
{
Path = path;
EntryType = directoryEntryType;
Size = size;
this.Path = Path;
EntryType = DirectoryEntryType;
this.Size = Size;
}
}
}

View file

@ -1,6 +1,6 @@
namespace Ryujinx.HLE.HOS.Services.FspSrv
{
enum FileSystemType
enum FileSystemType : int
{
Logo = 2,
ContentControl = 3,

View file

@ -11,88 +11,88 @@ namespace Ryujinx.HLE.HOS.Services.FspSrv
{
private const int DirectoryEntrySize = 0x310;
private Dictionary<int, ServiceProcessRequest> _commands;
private Dictionary<int, ServiceProcessRequest> m_Commands;
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
private List<DirectoryEntry> _directoryEntries;
private List<DirectoryEntry> DirectoryEntries;
private int _currentItemIndex;
private int CurrentItemIndex;
public event EventHandler<EventArgs> Disposed;
public string DirectoryPath { get; }
public string DirectoryPath { get; private set; }
private IFileSystemProvider _provider;
private IFileSystemProvider Provider;
public IDirectory(string directoryPath, int flags, IFileSystemProvider provider)
public IDirectory(string DirectoryPath, int Flags, IFileSystemProvider Provider)
{
_commands = new Dictionary<int, ServiceProcessRequest>
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
{ 0, Read },
{ 1, GetEntryCount }
};
_provider = provider;
DirectoryPath = directoryPath;
this.Provider = Provider;
this.DirectoryPath = DirectoryPath;
_directoryEntries = new List<DirectoryEntry>();
DirectoryEntries = new List<DirectoryEntry>();
if ((flags & 1) != 0)
if ((Flags & 1) != 0)
{
_directoryEntries.AddRange(provider.GetDirectories(directoryPath));
DirectoryEntries.AddRange(Provider.GetDirectories(DirectoryPath));
}
if ((flags & 2) != 0)
if ((Flags & 2) != 0)
{
_directoryEntries.AddRange(provider.GetFiles(directoryPath));
DirectoryEntries.AddRange(Provider.GetFiles(DirectoryPath));
}
_currentItemIndex = 0;
CurrentItemIndex = 0;
}
// Read() -> (u64 count, buffer<nn::fssrv::sf::IDirectoryEntry, 6, 0> entries)
public long Read(ServiceCtx context)
public long Read(ServiceCtx Context)
{
long bufferPosition = context.Request.ReceiveBuff[0].Position;
long bufferLen = context.Request.ReceiveBuff[0].Size;
long BufferPosition = Context.Request.ReceiveBuff[0].Position;
long BufferLen = Context.Request.ReceiveBuff[0].Size;
int maxReadCount = (int)(bufferLen / DirectoryEntrySize);
int MaxReadCount = (int)(BufferLen / DirectoryEntrySize);
int count = Math.Min(_directoryEntries.Count - _currentItemIndex, maxReadCount);
int Count = Math.Min(DirectoryEntries.Count - CurrentItemIndex, MaxReadCount);
for (int index = 0; index < count; index++)
for (int Index = 0; Index < Count; Index++)
{
long position = bufferPosition + index * DirectoryEntrySize;
long Position = BufferPosition + Index * DirectoryEntrySize;
WriteDirectoryEntry(context, position, _directoryEntries[_currentItemIndex++]);
WriteDirectoryEntry(Context, Position, DirectoryEntries[CurrentItemIndex++]);
}
context.ResponseData.Write((long)count);
Context.ResponseData.Write((long)Count);
return 0;
}
private void WriteDirectoryEntry(ServiceCtx context, long position, DirectoryEntry entry)
private void WriteDirectoryEntry(ServiceCtx Context, long Position, DirectoryEntry Entry)
{
for (int offset = 0; offset < 0x300; offset += 8)
for (int Offset = 0; Offset < 0x300; Offset += 8)
{
context.Memory.WriteInt64(position + offset, 0);
Context.Memory.WriteInt64(Position + Offset, 0);
}
byte[] nameBuffer = Encoding.UTF8.GetBytes(Path.GetFileName(entry.Path));
byte[] NameBuffer = Encoding.UTF8.GetBytes(Path.GetFileName(Entry.Path));
context.Memory.WriteBytes(position, nameBuffer);
Context.Memory.WriteBytes(Position, NameBuffer);
context.Memory.WriteInt32(position + 0x300, 0); //Padding?
context.Memory.WriteInt32(position + 0x304, (byte)entry.EntryType);
context.Memory.WriteInt64(position + 0x308, entry.Size);
Context.Memory.WriteInt32(Position + 0x300, 0); //Padding?
Context.Memory.WriteInt32(Position + 0x304, (byte)Entry.EntryType);
Context.Memory.WriteInt64(Position + 0x308, Entry.Size);
}
// GetEntryCount() -> u64
public long GetEntryCount(ServiceCtx context)
public long GetEntryCount(ServiceCtx Context)
{
context.ResponseData.Write((long)_directoryEntries.Count);
Context.ResponseData.Write((long)DirectoryEntries.Count);
return 0;
}

View file

@ -7,19 +7,19 @@ namespace Ryujinx.HLE.HOS.Services.FspSrv
{
class IFile : IpcService, IDisposable
{
private Dictionary<int, ServiceProcessRequest> _commands;
private Dictionary<int, ServiceProcessRequest> m_Commands;
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
private Stream _baseStream;
private Stream BaseStream;
public event EventHandler<EventArgs> Disposed;
public string HostPath { get; }
public string HostPath { get; private set; }
public IFile(Stream baseStream, string hostPath)
public IFile(Stream BaseStream, string HostPath)
{
_commands = new Dictionary<int, ServiceProcessRequest>
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
{ 0, Read },
{ 1, Write },
@ -28,71 +28,71 @@ namespace Ryujinx.HLE.HOS.Services.FspSrv
{ 4, GetSize }
};
_baseStream = baseStream;
HostPath = hostPath;
this.BaseStream = BaseStream;
this.HostPath = HostPath;
}
// Read(u32, u64 offset, u64 size) -> (u64 out_size, buffer<u8, 0x46, 0> out_buf)
public long Read(ServiceCtx context)
public long Read(ServiceCtx Context)
{
long position = context.Request.ReceiveBuff[0].Position;
long Position = Context.Request.ReceiveBuff[0].Position;
long zero = context.RequestData.ReadInt64();
long offset = context.RequestData.ReadInt64();
long size = context.RequestData.ReadInt64();
long Zero = Context.RequestData.ReadInt64();
long Offset = Context.RequestData.ReadInt64();
long Size = Context.RequestData.ReadInt64();
byte[] data = new byte[size];
byte[] Data = new byte[Size];
_baseStream.Seek(offset, SeekOrigin.Begin);
BaseStream.Seek(Offset, SeekOrigin.Begin);
int readSize = _baseStream.Read(data, 0, (int)size);
int ReadSize = BaseStream.Read(Data, 0, (int)Size);
context.Memory.WriteBytes(position, data);
Context.Memory.WriteBytes(Position, Data);
context.ResponseData.Write((long)readSize);
Context.ResponseData.Write((long)ReadSize);
return 0;
}
// Write(u32, u64 offset, u64 size, buffer<u8, 0x45, 0>)
public long Write(ServiceCtx context)
public long Write(ServiceCtx Context)
{
long position = context.Request.SendBuff[0].Position;
long Position = Context.Request.SendBuff[0].Position;
long zero = context.RequestData.ReadInt64();
long offset = context.RequestData.ReadInt64();
long size = context.RequestData.ReadInt64();
long Zero = Context.RequestData.ReadInt64();
long Offset = Context.RequestData.ReadInt64();
long Size = Context.RequestData.ReadInt64();
byte[] data = context.Memory.ReadBytes(position, size);
byte[] Data = Context.Memory.ReadBytes(Position, Size);
_baseStream.Seek(offset, SeekOrigin.Begin);
_baseStream.Write(data, 0, (int)size);
BaseStream.Seek(Offset, SeekOrigin.Begin);
BaseStream.Write(Data, 0, (int)Size);
return 0;
}
// Flush()
public long Flush(ServiceCtx context)
public long Flush(ServiceCtx Context)
{
_baseStream.Flush();
BaseStream.Flush();
return 0;
}
// SetSize(u64 size)
public long SetSize(ServiceCtx context)
public long SetSize(ServiceCtx Context)
{
long size = context.RequestData.ReadInt64();
long Size = Context.RequestData.ReadInt64();
_baseStream.SetLength(size);
BaseStream.SetLength(Size);
return 0;
}
// GetSize() -> u64 fileSize
public long GetSize(ServiceCtx context)
public long GetSize(ServiceCtx Context)
{
context.ResponseData.Write(_baseStream.Length);
Context.ResponseData.Write(BaseStream.Length);
return 0;
}
@ -104,9 +104,9 @@ namespace Ryujinx.HLE.HOS.Services.FspSrv
protected virtual void Dispose(bool disposing)
{
if (disposing && _baseStream != null)
if (disposing && BaseStream != null)
{
_baseStream.Dispose();
BaseStream.Dispose();
Disposed?.Invoke(this, EventArgs.Empty);
}

View file

@ -11,19 +11,19 @@ namespace Ryujinx.HLE.HOS.Services.FspSrv
{
class IFileSystem : IpcService
{
private Dictionary<int, ServiceProcessRequest> _commands;
private Dictionary<int, ServiceProcessRequest> m_Commands;
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
private HashSet<string> _openPaths;
private HashSet<string> OpenPaths;
private string _path;
private string Path;
private IFileSystemProvider _provider;
private IFileSystemProvider Provider;
public IFileSystem(string path, IFileSystemProvider provider)
public IFileSystem(string Path, IFileSystemProvider Provider)
{
_commands = new Dictionary<int, ServiceProcessRequest>
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
{ 0, CreateFile },
{ 1, DeleteFile },
@ -38,196 +38,196 @@ namespace Ryujinx.HLE.HOS.Services.FspSrv
{ 10, Commit },
{ 11, GetFreeSpaceSize },
{ 12, GetTotalSpaceSize },
{ 13, CleanDirectoryRecursively }
{ 13, CleanDirectoryRecursively },
//{ 14, GetFileTimeStampRaw }
};
_openPaths = new HashSet<string>();
OpenPaths = new HashSet<string>();
_path = path;
_provider = provider;
this.Path = Path;
this.Provider = Provider;
}
// CreateFile(u32 mode, u64 size, buffer<bytes<0x301>, 0x19, 0x301> path)
public long CreateFile(ServiceCtx context)
public long CreateFile(ServiceCtx Context)
{
string name = ReadUtf8String(context);
string Name = ReadUtf8String(Context);
long mode = context.RequestData.ReadInt64();
int size = context.RequestData.ReadInt32();
long Mode = Context.RequestData.ReadInt64();
int Size = Context.RequestData.ReadInt32();
string fileName = _provider.GetFullPath(name);
string FileName = Provider.GetFullPath(Name);
if (fileName == null)
if (FileName == null)
{
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
}
if (_provider.FileExists(fileName))
if (Provider.FileExists(FileName))
{
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyExists);
}
if (IsPathAlreadyInUse(fileName))
if (IsPathAlreadyInUse(FileName))
{
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyInUse);
}
return _provider.CreateFile(fileName, size);
return Provider.CreateFile(FileName, Size);
}
// DeleteFile(buffer<bytes<0x301>, 0x19, 0x301> path)
public long DeleteFile(ServiceCtx context)
public long DeleteFile(ServiceCtx Context)
{
string name = ReadUtf8String(context);
string Name = ReadUtf8String(Context);
string fileName = _provider.GetFullPath(name);
string FileName = Provider.GetFullPath(Name);
if (!_provider.FileExists(fileName))
if (!Provider.FileExists(FileName))
{
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
}
if (IsPathAlreadyInUse(fileName))
if (IsPathAlreadyInUse(FileName))
{
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyInUse);
}
return _provider.DeleteFile(fileName);
return Provider.DeleteFile(FileName);
}
// CreateDirectory(buffer<bytes<0x301>, 0x19, 0x301> path)
public long CreateDirectory(ServiceCtx context)
public long CreateDirectory(ServiceCtx Context)
{
string name = ReadUtf8String(context);
string Name = ReadUtf8String(Context);
string dirName = _provider.GetFullPath(name);
string DirName = Provider.GetFullPath(Name);
if (dirName == null)
if (DirName == null)
{
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
}
if (_provider.DirectoryExists(dirName))
if (Provider.DirectoryExists(DirName))
{
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyExists);
}
if (IsPathAlreadyInUse(dirName))
if (IsPathAlreadyInUse(DirName))
{
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyInUse);
}
_provider.CreateDirectory(dirName);
Provider.CreateDirectory(DirName);
return 0;
}
// DeleteDirectory(buffer<bytes<0x301>, 0x19, 0x301> path)
public long DeleteDirectory(ServiceCtx context)
public long DeleteDirectory(ServiceCtx Context)
{
return DeleteDirectory(context, false);
return DeleteDirectory(Context, false);
}
// DeleteDirectoryRecursively(buffer<bytes<0x301>, 0x19, 0x301> path)
public long DeleteDirectoryRecursively(ServiceCtx context)
public long DeleteDirectoryRecursively(ServiceCtx Context)
{
return DeleteDirectory(context, true);
return DeleteDirectory(Context, true);
}
private long DeleteDirectory(ServiceCtx context, bool recursive)
private long DeleteDirectory(ServiceCtx Context, bool Recursive)
{
string name = ReadUtf8String(context);
string Name = ReadUtf8String(Context);
string dirName = _provider.GetFullPath(name);
string DirName = Provider.GetFullPath(Name);
if (!Directory.Exists(dirName))
if (!Directory.Exists(DirName))
{
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
}
if (IsPathAlreadyInUse(dirName))
if (IsPathAlreadyInUse(DirName))
{
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyInUse);
}
_provider.DeleteDirectory(dirName, recursive);
Provider.DeleteDirectory(DirName, Recursive);
return 0;
}
// RenameFile(buffer<bytes<0x301>, 0x19, 0x301> oldPath, buffer<bytes<0x301>, 0x19, 0x301> newPath)
public long RenameFile(ServiceCtx context)
public long RenameFile(ServiceCtx Context)
{
string oldName = ReadUtf8String(context, 0);
string newName = ReadUtf8String(context, 1);
string OldName = ReadUtf8String(Context, 0);
string NewName = ReadUtf8String(Context, 1);
string oldFileName = _provider.GetFullPath(oldName);
string newFileName = _provider.GetFullPath(newName);
string OldFileName = Provider.GetFullPath(OldName);
string NewFileName = Provider.GetFullPath(NewName);
if (_provider.FileExists(oldFileName))
if (Provider.FileExists(OldFileName))
{
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
}
if (_provider.FileExists(newFileName))
if (Provider.FileExists(NewFileName))
{
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyExists);
}
if (IsPathAlreadyInUse(oldFileName))
if (IsPathAlreadyInUse(OldFileName))
{
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyInUse);
}
return _provider.RenameFile(oldFileName, newFileName);
return Provider.RenameFile(OldFileName, NewFileName);
}
// RenameDirectory(buffer<bytes<0x301>, 0x19, 0x301> oldPath, buffer<bytes<0x301>, 0x19, 0x301> newPath)
public long RenameDirectory(ServiceCtx context)
public long RenameDirectory(ServiceCtx Context)
{
string oldName = ReadUtf8String(context, 0);
string newName = ReadUtf8String(context, 1);
string OldName = ReadUtf8String(Context, 0);
string NewName = ReadUtf8String(Context, 1);
string oldDirName = _provider.GetFullPath(oldName);
string newDirName = _provider.GetFullPath(newName);
string OldDirName = Provider.GetFullPath(OldName);
string NewDirName = Provider.GetFullPath(NewName);
if (!_provider.DirectoryExists(oldDirName))
if (!Provider.DirectoryExists(OldDirName))
{
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
}
if (!_provider.DirectoryExists(newDirName))
if (!Provider.DirectoryExists(NewDirName))
{
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyExists);
}
if (IsPathAlreadyInUse(oldDirName))
if (IsPathAlreadyInUse(OldDirName))
{
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyInUse);
}
return _provider.RenameDirectory(oldDirName, newDirName);
return Provider.RenameDirectory(OldDirName, NewDirName);
}
// GetEntryType(buffer<bytes<0x301>, 0x19, 0x301> path) -> nn::fssrv::sf::DirectoryEntryType
public long GetEntryType(ServiceCtx context)
public long GetEntryType(ServiceCtx Context)
{
string name = ReadUtf8String(context);
string Name = ReadUtf8String(Context);
string fileName = _provider.GetFullPath(name);
string FileName = Provider.GetFullPath(Name);
if (_provider.FileExists(fileName))
if (Provider.FileExists(FileName))
{
context.ResponseData.Write(1);
Context.ResponseData.Write(1);
}
else if (_provider.DirectoryExists(fileName))
else if (Provider.DirectoryExists(FileName))
{
context.ResponseData.Write(0);
Context.ResponseData.Write(0);
}
else
{
context.ResponseData.Write(0);
Context.ResponseData.Write(0);
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
}
@ -236,167 +236,167 @@ namespace Ryujinx.HLE.HOS.Services.FspSrv
}
// OpenFile(u32 mode, buffer<bytes<0x301>, 0x19, 0x301> path) -> object<nn::fssrv::sf::IFile> file
public long OpenFile(ServiceCtx context)
public long OpenFile(ServiceCtx Context)
{
int filterFlags = context.RequestData.ReadInt32();
int FilterFlags = Context.RequestData.ReadInt32();
string name = ReadUtf8String(context);
string Name = ReadUtf8String(Context);
string fileName = _provider.GetFullPath(name);
string FileName = Provider.GetFullPath(Name);
if (!_provider.FileExists(fileName))
if (!Provider.FileExists(FileName))
{
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
}
if (IsPathAlreadyInUse(fileName))
if (IsPathAlreadyInUse(FileName))
{
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyInUse);
}
long error = _provider.OpenFile(fileName, out IFile fileInterface);
long Error = Provider.OpenFile(FileName, out IFile FileInterface);
if (error == 0)
if (Error == 0)
{
fileInterface.Disposed += RemoveFileInUse;
FileInterface.Disposed += RemoveFileInUse;
lock (_openPaths)
lock (OpenPaths)
{
_openPaths.Add(fileName);
OpenPaths.Add(FileName);
}
MakeObject(context, fileInterface);
MakeObject(Context, FileInterface);
return 0;
}
return error;
return Error;
}
// OpenDirectory(u32 filter_flags, buffer<bytes<0x301>, 0x19, 0x301> path) -> object<nn::fssrv::sf::IDirectory> directory
public long OpenDirectory(ServiceCtx context)
public long OpenDirectory(ServiceCtx Context)
{
int filterFlags = context.RequestData.ReadInt32();
int FilterFlags = Context.RequestData.ReadInt32();
string name = ReadUtf8String(context);
string Name = ReadUtf8String(Context);
string dirName = _provider.GetFullPath(name);
string DirName = Provider.GetFullPath(Name);
if (!_provider.DirectoryExists(dirName))
if (!Provider.DirectoryExists(DirName))
{
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
}
if (IsPathAlreadyInUse(dirName))
if (IsPathAlreadyInUse(DirName))
{
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyInUse);
}
long error = _provider.OpenDirectory(dirName, filterFlags, out IDirectory dirInterface);
long Error = Provider.OpenDirectory(DirName, FilterFlags, out IDirectory DirInterface);
if (error == 0)
if (Error == 0)
{
dirInterface.Disposed += RemoveDirectoryInUse;
DirInterface.Disposed += RemoveDirectoryInUse;
lock (_openPaths)
lock (OpenPaths)
{
_openPaths.Add(dirName);
OpenPaths.Add(DirName);
}
MakeObject(context, dirInterface);
MakeObject(Context, DirInterface);
}
return error;
return Error;
}
// Commit()
public long Commit(ServiceCtx context)
public long Commit(ServiceCtx Context)
{
return 0;
}
// GetFreeSpaceSize(buffer<bytes<0x301>, 0x19, 0x301> path) -> u64 totalFreeSpace
public long GetFreeSpaceSize(ServiceCtx context)
public long GetFreeSpaceSize(ServiceCtx Context)
{
string name = ReadUtf8String(context);
string Name = ReadUtf8String(Context);
context.ResponseData.Write(_provider.GetFreeSpace(context));
Context.ResponseData.Write(Provider.GetFreeSpace(Context));
return 0;
}
// GetTotalSpaceSize(buffer<bytes<0x301>, 0x19, 0x301> path) -> u64 totalSize
public long GetTotalSpaceSize(ServiceCtx context)
public long GetTotalSpaceSize(ServiceCtx Context)
{
string name = ReadUtf8String(context);
string Name = ReadUtf8String(Context);
context.ResponseData.Write(_provider.GetFreeSpace(context));
Context.ResponseData.Write(Provider.GetFreeSpace(Context));
return 0;
}
// CleanDirectoryRecursively(buffer<bytes<0x301>, 0x19, 0x301> path)
public long CleanDirectoryRecursively(ServiceCtx context)
public long CleanDirectoryRecursively(ServiceCtx Context)
{
string name = ReadUtf8String(context);
string Name = ReadUtf8String(Context);
string dirName = _provider.GetFullPath(name);
string DirName = Provider.GetFullPath(Name);
if (!_provider.DirectoryExists(dirName))
if (!Provider.DirectoryExists(DirName))
{
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
}
if (IsPathAlreadyInUse(dirName))
if (IsPathAlreadyInUse(DirName))
{
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyInUse);
}
foreach (DirectoryEntry entry in _provider.GetEntries(dirName))
foreach (DirectoryEntry Entry in Provider.GetEntries(DirName))
{
if (_provider.DirectoryExists(entry.Path))
if (Provider.DirectoryExists(Entry.Path))
{
_provider.DeleteDirectory(entry.Path, true);
Provider.DeleteDirectory(Entry.Path, true);
}
else if (_provider.FileExists(entry.Path))
else if (Provider.FileExists(Entry.Path))
{
_provider.DeleteFile(entry.Path);
Provider.DeleteFile(Entry.Path);
}
}
return 0;
}
private bool IsPathAlreadyInUse(string path)
private bool IsPathAlreadyInUse(string Path)
{
lock (_openPaths)
lock (OpenPaths)
{
return _openPaths.Contains(path);
return OpenPaths.Contains(Path);
}
}
private void RemoveFileInUse(object sender, EventArgs e)
{
IFile fileInterface = (IFile)sender;
IFile FileInterface = (IFile)sender;
lock (_openPaths)
lock (OpenPaths)
{
fileInterface.Disposed -= RemoveFileInUse;
FileInterface.Disposed -= RemoveFileInUse;
_openPaths.Remove(fileInterface.HostPath);
OpenPaths.Remove(FileInterface.HostPath);
}
}
private void RemoveDirectoryInUse(object sender, EventArgs e)
{
IDirectory dirInterface = (IDirectory)sender;
IDirectory DirInterface = (IDirectory)sender;
lock (_openPaths)
lock (OpenPaths)
{
dirInterface.Disposed -= RemoveDirectoryInUse;
DirInterface.Disposed -= RemoveDirectoryInUse;
_openPaths.Remove(dirInterface.DirectoryPath);
OpenPaths.Remove(DirInterface.DirectoryPath);
}
}
}

View file

@ -14,13 +14,13 @@ namespace Ryujinx.HLE.HOS.Services.FspSrv
{
class IFileSystemProxy : IpcService
{
private Dictionary<int, ServiceProcessRequest> _commands;
private Dictionary<int, ServiceProcessRequest> m_Commands;
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
public IFileSystemProxy()
{
_commands = new Dictionary<int, ServiceProcessRequest>
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
{ 1, Initialize },
{ 8, OpenFileSystemWithId },
@ -36,246 +36,246 @@ namespace Ryujinx.HLE.HOS.Services.FspSrv
}
// Initialize(u64, pid)
public long Initialize(ServiceCtx context)
public long Initialize(ServiceCtx Context)
{
return 0;
}
// OpenFileSystemWithId(nn::fssrv::sf::FileSystemType filesystem_type, nn::ApplicationId tid, buffer<bytes<0x301>, 0x19, 0x301> path)
// -> object<nn::fssrv::sf::IFileSystem> contentFs
public long OpenFileSystemWithId(ServiceCtx context)
public long OpenFileSystemWithId(ServiceCtx Context)
{
FileSystemType fileSystemType = (FileSystemType)context.RequestData.ReadInt32();
long titleId = context.RequestData.ReadInt64();
string switchPath = ReadUtf8String(context);
string fullPath = context.Device.FileSystem.SwitchPathToSystemPath(switchPath);
FileSystemType FileSystemType = (FileSystemType)Context.RequestData.ReadInt32();
long TitleId = Context.RequestData.ReadInt64();
string SwitchPath = ReadUtf8String(Context);
string FullPath = Context.Device.FileSystem.SwitchPathToSystemPath(SwitchPath);
if (!File.Exists(fullPath))
if (!File.Exists(FullPath))
{
if (fullPath.Contains("."))
if (FullPath.Contains("."))
{
return OpenFileSystemFromInternalFile(context, fullPath);
return OpenFileSystemFromInternalFile(Context, FullPath);
}
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
}
FileStream fileStream = new FileStream(fullPath, FileMode.Open, FileAccess.Read);
string extension = Path.GetExtension(fullPath);
FileStream FileStream = new FileStream(FullPath, FileMode.Open, FileAccess.Read);
string Extension = Path.GetExtension(FullPath);
if (extension == ".nca")
if (Extension == ".nca")
{
return OpenNcaFs(context, fullPath, fileStream);
return OpenNcaFs(Context, FullPath, FileStream);
}
else if (extension == ".nsp")
else if (Extension == ".nsp")
{
return OpenNsp(context, fullPath);
return OpenNsp(Context, FullPath);
}
return MakeError(ErrorModule.Fs, FsErr.InvalidInput);
}
// OpenBisFileSystem(nn::fssrv::sf::Partition partitionID, buffer<bytes<0x301>, 0x19, 0x301>) -> object<nn::fssrv::sf::IFileSystem> Bis
public long OpenBisFileSystem(ServiceCtx context)
public long OpenBisFileSystem(ServiceCtx Context)
{
int bisPartitionId = context.RequestData.ReadInt32();
string partitionString = ReadUtf8String(context);
string bisPartitonPath = string.Empty;
int BisPartitionId = Context.RequestData.ReadInt32();
string PartitionString = ReadUtf8String(Context);
string BisPartitonPath = string.Empty;
switch (bisPartitionId)
switch (BisPartitionId)
{
case 29:
bisPartitonPath = SafeNandPath;
BisPartitonPath = SafeNandPath;
break;
case 30:
case 31:
bisPartitonPath = SystemNandPath;
BisPartitonPath = SystemNandPath;
break;
case 32:
bisPartitonPath = UserNandPath;
BisPartitonPath = UserNandPath;
break;
default:
return MakeError(ErrorModule.Fs, FsErr.InvalidInput);
}
string fullPath = context.Device.FileSystem.GetFullPartitionPath(bisPartitonPath);
string FullPath = Context.Device.FileSystem.GetFullPartitionPath(BisPartitonPath);
FileSystemProvider fileSystemProvider = new FileSystemProvider(fullPath, context.Device.FileSystem.GetBasePath());
FileSystemProvider FileSystemProvider = new FileSystemProvider(FullPath, Context.Device.FileSystem.GetBasePath());
MakeObject(context, new IFileSystem(fullPath, fileSystemProvider));
MakeObject(Context, new IFileSystem(FullPath, FileSystemProvider));
return 0;
}
// OpenSdCardFileSystem() -> object<nn::fssrv::sf::IFileSystem>
public long OpenSdCardFileSystem(ServiceCtx context)
public long OpenSdCardFileSystem(ServiceCtx Context)
{
string sdCardPath = context.Device.FileSystem.GetSdCardPath();
string SdCardPath = Context.Device.FileSystem.GetSdCardPath();
FileSystemProvider fileSystemProvider = new FileSystemProvider(sdCardPath, context.Device.FileSystem.GetBasePath());
FileSystemProvider FileSystemProvider = new FileSystemProvider(SdCardPath, Context.Device.FileSystem.GetBasePath());
MakeObject(context, new IFileSystem(sdCardPath, fileSystemProvider));
MakeObject(Context, new IFileSystem(SdCardPath, FileSystemProvider));
return 0;
}
// OpenSaveDataFileSystem(u8 save_data_space_id, nn::fssrv::sf::SaveStruct saveStruct) -> object<nn::fssrv::sf::IFileSystem> saveDataFs
public long OpenSaveDataFileSystem(ServiceCtx context)
public long OpenSaveDataFileSystem(ServiceCtx Context)
{
LoadSaveDataFileSystem(context);
LoadSaveDataFileSystem(Context);
return 0;
}
// OpenSaveDataFileSystemBySystemSaveDataId(u8 save_data_space_id, nn::fssrv::sf::SaveStruct saveStruct) -> object<nn::fssrv::sf::IFileSystem> systemSaveDataFs
public long OpenSaveDataFileSystemBySystemSaveDataId(ServiceCtx context)
public long OpenSaveDataFileSystemBySystemSaveDataId(ServiceCtx Context)
{
LoadSaveDataFileSystem(context);
LoadSaveDataFileSystem(Context);
return 0;
}
// OpenDataStorageByCurrentProcess() -> object<nn::fssrv::sf::IStorage> dataStorage
public long OpenDataStorageByCurrentProcess(ServiceCtx context)
public long OpenDataStorageByCurrentProcess(ServiceCtx Context)
{
MakeObject(context, new IStorage(context.Device.FileSystem.RomFs));
MakeObject(Context, new IStorage(Context.Device.FileSystem.RomFs));
return 0;
}
// OpenDataStorageByDataId(u8 storageId, nn::ApplicationId tid) -> object<nn::fssrv::sf::IStorage> dataStorage
public long OpenDataStorageByDataId(ServiceCtx context)
public long OpenDataStorageByDataId(ServiceCtx Context)
{
StorageId storageId = (StorageId)context.RequestData.ReadByte();
byte[] padding = context.RequestData.ReadBytes(7);
long titleId = context.RequestData.ReadInt64();
StorageId StorageId = (StorageId)Context.RequestData.ReadByte();
byte[] Padding = Context.RequestData.ReadBytes(7);
long TitleId = Context.RequestData.ReadInt64();
StorageId installedStorage =
context.Device.System.ContentManager.GetInstalledStorage(titleId, ContentType.Data, storageId);
StorageId InstalledStorage =
Context.Device.System.ContentManager.GetInstalledStorage(TitleId, ContentType.Data, StorageId);
if (installedStorage == StorageId.None)
if (InstalledStorage == StorageId.None)
{
installedStorage =
context.Device.System.ContentManager.GetInstalledStorage(titleId, ContentType.AocData, storageId);
InstalledStorage =
Context.Device.System.ContentManager.GetInstalledStorage(TitleId, ContentType.AocData, StorageId);
}
if (installedStorage != StorageId.None)
if (InstalledStorage != StorageId.None)
{
string contentPath = context.Device.System.ContentManager.GetInstalledContentPath(titleId, storageId, ContentType.AocData);
string ContentPath = Context.Device.System.ContentManager.GetInstalledContentPath(TitleId, StorageId, ContentType.AocData);
if (string.IsNullOrWhiteSpace(contentPath))
if (string.IsNullOrWhiteSpace(ContentPath))
{
contentPath = context.Device.System.ContentManager.GetInstalledContentPath(titleId, storageId, ContentType.AocData);
ContentPath = Context.Device.System.ContentManager.GetInstalledContentPath(TitleId, StorageId, ContentType.AocData);
}
string installPath = context.Device.FileSystem.SwitchPathToSystemPath(contentPath);
string InstallPath = Context.Device.FileSystem.SwitchPathToSystemPath(ContentPath);
if (!string.IsNullOrWhiteSpace(installPath))
if (!string.IsNullOrWhiteSpace(InstallPath))
{
string ncaPath = installPath;
string NcaPath = InstallPath;
if (File.Exists(ncaPath))
if (File.Exists(NcaPath))
{
FileStream ncaStream = new FileStream(ncaPath, FileMode.Open, FileAccess.Read);
Nca nca = new Nca(context.Device.System.KeySet, ncaStream, false);
NcaSection romfsSection = nca.Sections.FirstOrDefault(x => x?.Type == SectionType.Romfs);
Stream romfsStream = nca.OpenSection(romfsSection.SectionNum, false, context.Device.System.FsIntegrityCheckLevel);
FileStream NcaStream = new FileStream(NcaPath, FileMode.Open, FileAccess.Read);
Nca Nca = new Nca(Context.Device.System.KeySet, NcaStream, false);
NcaSection RomfsSection = Nca.Sections.FirstOrDefault(x => x?.Type == SectionType.Romfs);
Stream RomfsStream = Nca.OpenSection(RomfsSection.SectionNum, false, Context.Device.System.FsIntegrityCheckLevel);
MakeObject(context, new IStorage(romfsStream));
MakeObject(Context, new IStorage(RomfsStream));
return 0;
}
else
{
throw new FileNotFoundException($"No Nca found in Path `{ncaPath}`.");
throw new FileNotFoundException($"No Nca found in Path `{NcaPath}`.");
}
}
else
{
throw new DirectoryNotFoundException($"Path for title id {titleId:x16} on Storage {storageId} was not found in Path {installPath}.");
throw new DirectoryNotFoundException($"Path for title id {TitleId:x16} on Storage {StorageId} was not found in Path {InstallPath}.");
}
}
throw new FileNotFoundException($"System archive with titleid {titleId:x16} was not found on Storage {storageId}. Found in {installedStorage}.");
throw new FileNotFoundException($"System archive with titleid {TitleId:x16} was not found on Storage {StorageId}. Found in {InstalledStorage}.");
}
// OpenPatchDataStorageByCurrentProcess() -> object<nn::fssrv::sf::IStorage>
public long OpenPatchDataStorageByCurrentProcess(ServiceCtx context)
public long OpenPatchDataStorageByCurrentProcess(ServiceCtx Context)
{
MakeObject(context, new IStorage(context.Device.FileSystem.RomFs));
MakeObject(Context, new IStorage(Context.Device.FileSystem.RomFs));
return 0;
}
// GetGlobalAccessLogMode() -> u32 logMode
public long GetGlobalAccessLogMode(ServiceCtx context)
public long GetGlobalAccessLogMode(ServiceCtx Context)
{
context.ResponseData.Write(0);
Context.ResponseData.Write(0);
return 0;
}
public void LoadSaveDataFileSystem(ServiceCtx context)
public void LoadSaveDataFileSystem(ServiceCtx Context)
{
SaveSpaceId saveSpaceId = (SaveSpaceId)context.RequestData.ReadInt64();
SaveSpaceId SaveSpaceId = (SaveSpaceId)Context.RequestData.ReadInt64();
long titleId = context.RequestData.ReadInt64();
long TitleId = Context.RequestData.ReadInt64();
UInt128 userId = new UInt128(
context.RequestData.ReadInt64(),
context.RequestData.ReadInt64());
UInt128 UserId = new UInt128(
Context.RequestData.ReadInt64(),
Context.RequestData.ReadInt64());
long saveId = context.RequestData.ReadInt64();
SaveDataType saveDataType = (SaveDataType)context.RequestData.ReadByte();
SaveInfo saveInfo = new SaveInfo(titleId, saveId, saveDataType, userId, saveSpaceId);
string savePath = context.Device.FileSystem.GetGameSavePath(saveInfo, context);
FileSystemProvider fileSystemProvider = new FileSystemProvider(savePath, context.Device.FileSystem.GetBasePath());
long SaveId = Context.RequestData.ReadInt64();
SaveDataType SaveDataType = (SaveDataType)Context.RequestData.ReadByte();
SaveInfo SaveInfo = new SaveInfo(TitleId, SaveId, SaveDataType, UserId, SaveSpaceId);
string SavePath = Context.Device.FileSystem.GetGameSavePath(SaveInfo, Context);
FileSystemProvider FileSystemProvider = new FileSystemProvider(SavePath, Context.Device.FileSystem.GetBasePath());
MakeObject(context, new IFileSystem(savePath, fileSystemProvider));
MakeObject(Context, new IFileSystem(SavePath, FileSystemProvider));
}
private long OpenNsp(ServiceCtx context, string pfsPath)
private long OpenNsp(ServiceCtx Context, string PfsPath)
{
FileStream pfsFile = new FileStream(pfsPath, FileMode.Open, FileAccess.Read);
Pfs nsp = new Pfs(pfsFile);
PfsFileEntry ticketFile = nsp.Files.FirstOrDefault(x => x.Name.EndsWith(".tik"));
FileStream PfsFile = new FileStream(PfsPath, FileMode.Open, FileAccess.Read);
Pfs Nsp = new Pfs(PfsFile);
PfsFileEntry TicketFile = Nsp.Files.FirstOrDefault(x => x.Name.EndsWith(".tik"));
if (ticketFile != null)
if (TicketFile != null)
{
Ticket ticket = new Ticket(nsp.OpenFile(ticketFile));
Ticket Ticket = new Ticket(Nsp.OpenFile(TicketFile));
context.Device.System.KeySet.TitleKeys[ticket.RightsId] =
ticket.GetTitleKey(context.Device.System.KeySet);
Context.Device.System.KeySet.TitleKeys[Ticket.RightsId] =
Ticket.GetTitleKey(Context.Device.System.KeySet);
}
IFileSystem nspFileSystem = new IFileSystem(pfsPath, new PFsProvider(nsp));
IFileSystem NspFileSystem = new IFileSystem(PfsPath, new PFsProvider(Nsp));
MakeObject(context, nspFileSystem);
MakeObject(Context, NspFileSystem);
return 0;
}
private long OpenNcaFs(ServiceCtx context,string ncaPath, Stream ncaStream)
private long OpenNcaFs(ServiceCtx Context,string NcaPath, Stream NcaStream)
{
Nca nca = new Nca(context.Device.System.KeySet, ncaStream, false);
Nca Nca = new Nca(Context.Device.System.KeySet, NcaStream, false);
NcaSection romfsSection = nca.Sections.FirstOrDefault(x => x?.Type == SectionType.Romfs);
NcaSection pfsSection = nca.Sections.FirstOrDefault(x => x?.Type == SectionType.Pfs0);
NcaSection RomfsSection = Nca.Sections.FirstOrDefault(x => x?.Type == SectionType.Romfs);
NcaSection PfsSection = Nca.Sections.FirstOrDefault(x => x?.Type == SectionType.Pfs0);
if (romfsSection != null)
if (RomfsSection != null)
{
Stream romfsStream = nca.OpenSection(romfsSection.SectionNum, false, context.Device.System.FsIntegrityCheckLevel);
IFileSystem ncaFileSystem = new IFileSystem(ncaPath, new RomFsProvider(romfsStream));
Stream RomfsStream = Nca.OpenSection(RomfsSection.SectionNum, false, Context.Device.System.FsIntegrityCheckLevel);
IFileSystem NcaFileSystem = new IFileSystem(NcaPath, new RomFsProvider(RomfsStream));
MakeObject(context, ncaFileSystem);
MakeObject(Context, NcaFileSystem);
}
else if(pfsSection !=null)
else if(PfsSection !=null)
{
Stream pfsStream = nca.OpenSection(pfsSection.SectionNum, false, context.Device.System.FsIntegrityCheckLevel);
Pfs pfs = new Pfs(pfsStream);
IFileSystem ncaFileSystem = new IFileSystem(ncaPath, new PFsProvider(pfs));
Stream PfsStream = Nca.OpenSection(PfsSection.SectionNum, false, Context.Device.System.FsIntegrityCheckLevel);
Pfs Pfs = new Pfs(PfsStream);
IFileSystem NcaFileSystem = new IFileSystem(NcaPath, new PFsProvider(Pfs));
MakeObject(context, ncaFileSystem);
MakeObject(Context, NcaFileSystem);
}
else
{
@ -285,38 +285,38 @@ namespace Ryujinx.HLE.HOS.Services.FspSrv
return 0;
}
private long OpenFileSystemFromInternalFile(ServiceCtx context, string fullPath)
private long OpenFileSystemFromInternalFile(ServiceCtx Context, string FullPath)
{
DirectoryInfo archivePath = new DirectoryInfo(fullPath).Parent;
DirectoryInfo ArchivePath = new DirectoryInfo(FullPath).Parent;
while (string.IsNullOrWhiteSpace(archivePath.Extension))
while (string.IsNullOrWhiteSpace(ArchivePath.Extension))
{
archivePath = archivePath.Parent;
ArchivePath = ArchivePath.Parent;
}
if (archivePath.Extension == ".nsp" && File.Exists(archivePath.FullName))
if (ArchivePath.Extension == ".nsp" && File.Exists(ArchivePath.FullName))
{
FileStream pfsFile = new FileStream(
archivePath.FullName.TrimEnd(Path.DirectorySeparatorChar),
FileStream PfsFile = new FileStream(
ArchivePath.FullName.TrimEnd(Path.DirectorySeparatorChar),
FileMode.Open,
FileAccess.Read);
Pfs nsp = new Pfs(pfsFile);
PfsFileEntry ticketFile = nsp.Files.FirstOrDefault(x => x.Name.EndsWith(".tik"));
Pfs Nsp = new Pfs(PfsFile);
PfsFileEntry TicketFile = Nsp.Files.FirstOrDefault(x => x.Name.EndsWith(".tik"));
if (ticketFile != null)
if (TicketFile != null)
{
Ticket ticket = new Ticket(nsp.OpenFile(ticketFile));
Ticket Ticket = new Ticket(Nsp.OpenFile(TicketFile));
context.Device.System.KeySet.TitleKeys[ticket.RightsId] =
ticket.GetTitleKey(context.Device.System.KeySet);
Context.Device.System.KeySet.TitleKeys[Ticket.RightsId] =
Ticket.GetTitleKey(Context.Device.System.KeySet);
}
string filename = fullPath.Replace(archivePath.FullName, string.Empty).TrimStart('\\');
string Filename = FullPath.Replace(ArchivePath.FullName, string.Empty).TrimStart('\\');
if (nsp.FileExists(filename))
if (Nsp.FileExists(Filename))
{
return OpenNcaFs(context, fullPath, nsp.OpenFile(filename));
return OpenNcaFs(Context, FullPath, Nsp.OpenFile(Filename));
}
}

View file

@ -6,47 +6,47 @@ namespace Ryujinx.HLE.HOS.Services.FspSrv
{
class IStorage : IpcService
{
private Dictionary<int, ServiceProcessRequest> _commands;
private Dictionary<int, ServiceProcessRequest> m_Commands;
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
private Stream _baseStream;
private Stream BaseStream;
public IStorage(Stream baseStream)
public IStorage(Stream BaseStream)
{
_commands = new Dictionary<int, ServiceProcessRequest>
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
{ 0, Read }
};
_baseStream = baseStream;
this.BaseStream = BaseStream;
}
// Read(u64 offset, u64 length) -> buffer<u8, 0x46, 0> buffer
public long Read(ServiceCtx context)
public long Read(ServiceCtx Context)
{
long offset = context.RequestData.ReadInt64();
long size = context.RequestData.ReadInt64();
long Offset = Context.RequestData.ReadInt64();
long Size = Context.RequestData.ReadInt64();
if (context.Request.ReceiveBuff.Count > 0)
if (Context.Request.ReceiveBuff.Count > 0)
{
IpcBuffDesc buffDesc = context.Request.ReceiveBuff[0];
IpcBuffDesc BuffDesc = Context.Request.ReceiveBuff[0];
//Use smaller length to avoid overflows.
if (size > buffDesc.Size)
if (Size > BuffDesc.Size)
{
size = buffDesc.Size;
Size = BuffDesc.Size;
}
byte[] data = new byte[size];
byte[] Data = new byte[Size];
lock (_baseStream)
lock (BaseStream)
{
_baseStream.Seek(offset, SeekOrigin.Begin);
_baseStream.Read(data, 0, data.Length);
BaseStream.Seek(Offset, SeekOrigin.Begin);
BaseStream.Read(Data, 0, Data.Length);
}
context.Memory.WriteBytes(buffDesc.Position, data);
Context.Memory.WriteBytes(BuffDesc.Position, Data);
}
return 0;