2018-11-18 14:37:41 -05:00
|
|
|
|
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
|
|
|
|
|
{
|
2018-12-04 15:23:37 -05:00
|
|
|
|
private Pfs _pfs;
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
public PFsProvider(Pfs pfs)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-04 15:23:37 -05:00
|
|
|
|
_pfs = pfs;
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
public long CreateDirectory(string name)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
|
|
|
|
throw new NotSupportedException();
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
public long CreateFile(string name, long size)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
|
|
|
|
throw new NotSupportedException();
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
public long DeleteDirectory(string name, bool recursive)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
|
|
|
|
throw new NotSupportedException();
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
public long DeleteFile(string name)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
|
|
|
|
throw new NotSupportedException();
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
public DirectoryEntry[] GetDirectories(string path)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
|
|
|
|
return new DirectoryEntry[0];
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
public DirectoryEntry[] GetEntries(string path)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-04 15:23:37 -05:00
|
|
|
|
List<DirectoryEntry> entries = new List<DirectoryEntry>();
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
foreach (PfsFileEntry file in _pfs.Files)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-04 15:23:37 -05:00
|
|
|
|
DirectoryEntry directoryEntry = new DirectoryEntry(file.Name, DirectoryEntryType.File, file.Size);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
entries.Add(directoryEntry);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
return entries.ToArray();
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
public DirectoryEntry[] GetFiles(string path)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-04 15:23:37 -05:00
|
|
|
|
List<DirectoryEntry> entries = new List<DirectoryEntry>();
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
foreach (PfsFileEntry file in _pfs.Files)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-04 15:23:37 -05:00
|
|
|
|
DirectoryEntry directoryEntry = new DirectoryEntry(file.Name, DirectoryEntryType.File, file.Size);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
entries.Add(directoryEntry);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
return entries.ToArray();
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
public long GetFreeSpace(ServiceCtx context)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
public string GetFullPath(string name)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-04 15:23:37 -05:00
|
|
|
|
return name;
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
public long GetTotalSpace(ServiceCtx context)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-04 15:23:37 -05:00
|
|
|
|
return _pfs.Files.Sum(x => x.Size);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
public bool DirectoryExists(string name)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-04 15:23:37 -05:00
|
|
|
|
return name == "/";
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
public bool FileExists(string name)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-04 15:23:37 -05:00
|
|
|
|
name = name.TrimStart('/');
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
return _pfs.FileExists(name);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
public long OpenDirectory(string name, int filterFlags, out IDirectory directoryInterface)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-04 15:23:37 -05:00
|
|
|
|
if (name == "/")
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-04 15:23:37 -05:00
|
|
|
|
directoryInterface = new IDirectory(name, filterFlags, this);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new NotSupportedException();
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
public long OpenFile(string name, out IFile fileInterface)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-04 15:23:37 -05:00
|
|
|
|
name = name.TrimStart('/');
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
if (_pfs.FileExists(name))
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-04 15:23:37 -05:00
|
|
|
|
Stream stream = _pfs.OpenFile(name);
|
|
|
|
|
fileInterface = new IFile(stream, name);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
fileInterface = null;
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
public long RenameDirectory(string oldName, string newName)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
|
|
|
|
throw new NotSupportedException();
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
public long RenameFile(string oldName, string newName)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
|
|
|
|
throw new NotSupportedException();
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
public void CheckIfOutsideBasePath(string path)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
|
|
|
|
throw new NotSupportedException();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|