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-04 19:52:39 -05:00
|
|
|
|
private Romfs RomFs;
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
public RomFsProvider(Stream StorageStream)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
|
RomFs = new Romfs(StorageStream);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
public long CreateDirectory(string Name)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
|
|
|
|
throw new NotSupportedException();
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
public long CreateFile(string Name, long Size)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
|
|
|
|
throw new NotSupportedException();
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
public long DeleteDirectory(string Name, bool Recursive)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
|
|
|
|
throw new NotSupportedException();
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
public long DeleteFile(string Name)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
|
|
|
|
throw new NotSupportedException();
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
public DirectoryEntry[] GetDirectories(string Path)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
|
List<DirectoryEntry> Directories = new List<DirectoryEntry>();
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
foreach(RomfsDir Directory in RomFs.Directories)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
|
DirectoryEntry DirectoryEntry = new DirectoryEntry(Directory.Name, DirectoryEntryType.Directory);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
Directories.Add(DirectoryEntry);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
return Directories.ToArray();
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
public DirectoryEntry[] GetEntries(string Path)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
|
List<DirectoryEntry> Entries = new List<DirectoryEntry>();
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
foreach (RomfsDir Directory in RomFs.Directories)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
|
DirectoryEntry DirectoryEntry = new DirectoryEntry(Directory.Name, DirectoryEntryType.Directory);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
Entries.Add(DirectoryEntry);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
foreach (RomfsFile File in RomFs.Files)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
|
DirectoryEntry DirectoryEntry = new DirectoryEntry(File.Name, DirectoryEntryType.File, File.DataLength);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
Entries.Add(DirectoryEntry);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
return Entries.ToArray();
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
public DirectoryEntry[] GetFiles(string Path)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
|
List<DirectoryEntry> Files = new List<DirectoryEntry>();
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
foreach (RomfsFile File in RomFs.Files)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
|
DirectoryEntry DirectoryEntry = new DirectoryEntry(File.Name, DirectoryEntryType.File, File.DataLength);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
Files.Add(DirectoryEntry);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
return Files.ToArray();
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
public long GetFreeSpace(ServiceCtx Context)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
public string GetFullPath(string Name)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
|
return Name;
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
public long GetTotalSpace(ServiceCtx Context)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
|
return RomFs.Files.Sum(x => x.DataLength);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
public bool DirectoryExists(string Name)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
|
return RomFs.Directories.Exists(x=>x.Name == Name);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
public bool FileExists(string Name)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
|
return RomFs.FileExists(Name);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
public long OpenDirectory(string Name, int FilterFlags, out IDirectory DirectoryInterface)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
|
RomfsDir Directory = RomFs.Directories.Find(x => x.Name == Name);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
if (Directory != null)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
|
DirectoryInterface = new IDirectory(Name, FilterFlags, this);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
DirectoryInterface = null;
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
public long OpenFile(string Name, out IFile FileInterface)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
|
if (RomFs.FileExists(Name))
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
|
Stream Stream = RomFs.OpenFile(Name);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
FileInterface = new IFile(Stream, Name);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
FileInterface = null;
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
public long RenameDirectory(string OldName, string NewName)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
|
|
|
|
throw new NotSupportedException();
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
public long RenameFile(string OldName, string NewName)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
|
|
|
|
throw new NotSupportedException();
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
public void CheckIfOutsideBasePath(string Path)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
|
|
|
|
throw new NotSupportedException();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|