ryujinx-mirror/Ryujinx.HLE/FileSystem/PFsProvider.cs
Alex Barney fb1d9493a3 Adjust naming conventions and general refactoring in HLE Project (#527)
* Rename enum fields

* Naming conventions

* Remove unneeded ".this"

* Remove unneeded semicolons

* Remove unused Usings

* Don't use var

* Remove unneeded enum underlying types

* Explicitly label class visibility

* Remove unneeded @ prefixes

* Remove unneeded commas

* Remove unneeded if expressions

* Method doesn't use unsafe code

* Remove unneeded casts

* Initialized objects don't need an empty constructor

* Remove settings from DotSettings

* Revert "Explicitly label class visibility"

This reverts commit ad5eb5787cc5b27a4631cd46ef5f551c4ae95e51.

* Small changes

* Revert external enum renaming

* Changes from feedback

* Apply previous refactorings to the merged code
2018-12-06 09:16:24 -02:00

146 lines
3.5 KiB
C#

using LibHac;
using Ryujinx.HLE.HOS;
using Ryujinx.HLE.HOS.Services.FspSrv;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static Ryujinx.HLE.HOS.ErrorCode;
namespace Ryujinx.HLE.FileSystem
{
class PFsProvider : IFileSystemProvider
{
private Pfs _pfs;
public PFsProvider(Pfs pfs)
{
_pfs = pfs;
}
public long CreateDirectory(string name)
{
throw new NotSupportedException();
}
public long CreateFile(string name, long size)
{
throw new NotSupportedException();
}
public long DeleteDirectory(string name, bool recursive)
{
throw new NotSupportedException();
}
public long DeleteFile(string name)
{
throw new NotSupportedException();
}
public DirectoryEntry[] GetDirectories(string path)
{
return new DirectoryEntry[0];
}
public DirectoryEntry[] GetEntries(string path)
{
List<DirectoryEntry> entries = new List<DirectoryEntry>();
foreach (PfsFileEntry file in _pfs.Files)
{
DirectoryEntry directoryEntry = new DirectoryEntry(file.Name, DirectoryEntryType.File, file.Size);
entries.Add(directoryEntry);
}
return entries.ToArray();
}
public DirectoryEntry[] GetFiles(string path)
{
List<DirectoryEntry> entries = new List<DirectoryEntry>();
foreach (PfsFileEntry file in _pfs.Files)
{
DirectoryEntry directoryEntry = new DirectoryEntry(file.Name, DirectoryEntryType.File, file.Size);
entries.Add(directoryEntry);
}
return entries.ToArray();
}
public long GetFreeSpace(ServiceCtx context)
{
return 0;
}
public string GetFullPath(string name)
{
return name;
}
public long GetTotalSpace(ServiceCtx context)
{
return _pfs.Files.Sum(x => x.Size);
}
public bool DirectoryExists(string name)
{
return name == "/";
}
public bool FileExists(string name)
{
name = name.TrimStart('/');
return _pfs.FileExists(name);
}
public long OpenDirectory(string name, int filterFlags, out IDirectory directoryInterface)
{
if (name == "/")
{
directoryInterface = new IDirectory(name, filterFlags, this);
return 0;
}
throw new NotSupportedException();
}
public long OpenFile(string name, out IFile fileInterface)
{
name = name.TrimStart('/');
if (_pfs.FileExists(name))
{
Stream stream = _pfs.OpenFile(name);
fileInterface = new IFile(stream, name);
return 0;
}
fileInterface = null;
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
}
public long RenameDirectory(string oldName, string newName)
{
throw new NotSupportedException();
}
public long RenameFile(string oldName, string newName)
{
throw new NotSupportedException();
}
public void CheckIfOutsideBasePath(string path)
{
throw new NotSupportedException();
}
}
}