Ryujinx/Ryujinx.HLE/FileSystem/PFsProvider.cs

147 lines
3.5 KiB
C#
Raw Normal View History

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