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 RomFsProvider : IFileSystemProvider
|
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
private Romfs _romFs;
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public RomFsProvider(Stream storageStream)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
_romFs = new Romfs(storageStream);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public long CreateDirectory(string name)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
|
|
|
|
throw new NotSupportedException();
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public long CreateFile(string name, long size)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
|
|
|
|
throw new NotSupportedException();
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public long DeleteDirectory(string name, bool recursive)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
|
|
|
|
throw new NotSupportedException();
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public long DeleteFile(string name)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
|
|
|
|
throw new NotSupportedException();
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public DirectoryEntry[] GetDirectories(string path)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
List<DirectoryEntry> directories = new List<DirectoryEntry>();
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
foreach(RomfsDir directory in _romFs.Directories)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
DirectoryEntry directoryEntry = new DirectoryEntry(directory.Name, DirectoryEntryType.Directory);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
directories.Add(directoryEntry);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
return directories.ToArray();
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public DirectoryEntry[] GetEntries(string path)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
List<DirectoryEntry> entries = new List<DirectoryEntry>();
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
foreach (RomfsDir directory in _romFs.Directories)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
DirectoryEntry directoryEntry = new DirectoryEntry(directory.Name, DirectoryEntryType.Directory);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
entries.Add(directoryEntry);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
foreach (RomfsFile file in _romFs.Files)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
DirectoryEntry directoryEntry = new DirectoryEntry(file.Name, DirectoryEntryType.File, file.DataLength);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
entries.Add(directoryEntry);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
return entries.ToArray();
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public DirectoryEntry[] GetFiles(string path)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
List<DirectoryEntry> files = new List<DirectoryEntry>();
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
foreach (RomfsFile file in _romFs.Files)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
DirectoryEntry directoryEntry = new DirectoryEntry(file.Name, DirectoryEntryType.File, file.DataLength);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
files.Add(directoryEntry);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
return files.ToArray();
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public long GetFreeSpace(ServiceCtx context)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public string GetFullPath(string name)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
return name;
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public long GetTotalSpace(ServiceCtx context)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
return _romFs.Files.Sum(x => x.DataLength);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public bool DirectoryExists(string name)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
return _romFs.Directories.Exists(x=>x.Name == name);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public bool FileExists(string name)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
return _romFs.FileExists(name);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public long OpenDirectory(string name, int filterFlags, out IDirectory directoryInterface)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
RomfsDir directory = _romFs.Directories.Find(x => x.Name == name);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
if (directory != null)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
directoryInterface = new IDirectory(name, filterFlags, this);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
directoryInterface = null;
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public long OpenFile(string name, out IFile fileInterface)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
if (_romFs.FileExists(name))
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
Stream stream = _romFs.OpenFile(name);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
fileInterface = new IFile(stream, name);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
fileInterface = null;
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public long RenameDirectory(string oldName, string newName)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
|
|
|
|
throw new NotSupportedException();
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public long RenameFile(string oldName, string newName)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
|
|
|
|
throw new NotSupportedException();
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public void CheckIfOutsideBasePath(string path)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
|
|
|
|
throw new NotSupportedException();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|