Ryujinx/Ryujinx.HLE/FileSystem/RomFsProvider.cs

164 lines
4.2 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 RomFsProvider : IFileSystemProvider
{
2018-12-01 21:01:59 +01:00
private Romfs _romFs;
2018-12-01 21:01:59 +01:00
public RomFsProvider(Stream storageStream)
{
2018-12-01 21:01:59 +01:00
_romFs = new Romfs(storageStream);
}
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)
{
2018-12-01 21:01:59 +01:00
List<DirectoryEntry> directories = new List<DirectoryEntry>();
2018-12-01 21:01:59 +01:00
foreach(RomfsDir directory in _romFs.Directories)
{
2018-12-01 21:01:59 +01:00
DirectoryEntry directoryEntry = new DirectoryEntry(directory.Name, DirectoryEntryType.Directory);
2018-12-01 21:01:59 +01:00
directories.Add(directoryEntry);
}
2018-12-01 21:01:59 +01:00
return directories.ToArray();
}
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 (RomfsDir directory in _romFs.Directories)
{
2018-12-01 21:01:59 +01:00
DirectoryEntry directoryEntry = new DirectoryEntry(directory.Name, DirectoryEntryType.Directory);
2018-12-01 21:01:59 +01:00
entries.Add(directoryEntry);
}
2018-12-01 21:01:59 +01:00
foreach (RomfsFile file in _romFs.Files)
{
2018-12-01 21:01:59 +01:00
DirectoryEntry directoryEntry = new DirectoryEntry(file.Name, DirectoryEntryType.File, file.DataLength);
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> files = new List<DirectoryEntry>();
2018-12-01 21:01:59 +01:00
foreach (RomfsFile file in _romFs.Files)
{
2018-12-01 21:01:59 +01:00
DirectoryEntry directoryEntry = new DirectoryEntry(file.Name, DirectoryEntryType.File, file.DataLength);
2018-12-01 21:01:59 +01:00
files.Add(directoryEntry);
}
2018-12-01 21:01:59 +01:00
return files.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 _romFs.Files.Sum(x => x.DataLength);
}
2018-12-01 21:01:59 +01:00
public bool DirectoryExists(string name)
{
2018-12-01 21:01:59 +01:00
return _romFs.Directories.Exists(x=>x.Name == name);
}
2018-12-01 21:01:59 +01:00
public bool FileExists(string name)
{
2018-12-01 21:01:59 +01:00
return _romFs.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
RomfsDir directory = _romFs.Directories.Find(x => x.Name == name);
2018-12-01 21:01:59 +01:00
if (directory != null)
{
2018-12-01 21:01:59 +01:00
directoryInterface = new IDirectory(name, filterFlags, this);
return 0;
}
2018-12-01 21:01:59 +01:00
directoryInterface = null;
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
}
2018-12-01 21:01:59 +01:00
public long OpenFile(string name, out IFile fileInterface)
{
2018-12-01 21:01:59 +01:00
if (_romFs.FileExists(name))
{
2018-12-01 21:01:59 +01:00
Stream stream = _romFs.OpenFile(name);
2018-12-01 21:01:59 +01:00
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();
}
}
}