public static ResultCode OpenNcaFs(ServiceCtx context, string ncaPath, LibHac.Fs.IStorage ncaStorage, out IFileSystem openedFileSystem) { openedFileSystem = null; try { Nca nca = new Nca(context.Device.System.KeySet, ncaStorage); if (!nca.SectionExists(NcaSectionType.Data)) { return(ResultCode.PartitionNotFound); } LibHac.Fs.Fsa.IFileSystem fileSystem = nca.OpenFileSystem(NcaSectionType.Data, context.Device.System.FsIntegrityCheckLevel); var sharedFs = new ReferenceCountedDisposable <LibHac.Fs.Fsa.IFileSystem>(fileSystem); openedFileSystem = new IFileSystem(FileSystemInterfaceAdapter.CreateShared(ref sharedFs)); } catch (HorizonResultException ex) { return((ResultCode)ex.ResultValue.Value); } return(ResultCode.Success); }
public static ResultCode OpenFileSystemFromInternalFile(ServiceCtx context, string fullPath, out IFileSystem openedFileSystem) { openedFileSystem = null; DirectoryInfo archivePath = new DirectoryInfo(fullPath).Parent; while (string.IsNullOrWhiteSpace(archivePath.Extension)) { archivePath = archivePath.Parent; } if (archivePath.Extension == ".nsp" && File.Exists(archivePath.FullName)) { FileStream pfsFile = new FileStream( archivePath.FullName.TrimEnd(Path.DirectorySeparatorChar), FileMode.Open, FileAccess.Read); try { PartitionFileSystem nsp = new PartitionFileSystem(pfsFile.AsStorage()); ImportTitleKeysFromNsp(nsp, context.Device.System.KeySet); string filename = fullPath.Replace(archivePath.FullName, string.Empty).TrimStart('\\'); Result result = nsp.OpenFile(out LibHac.Fs.Fsa.IFile ncaFile, filename.ToU8Span(), OpenMode.Read); if (result.IsFailure()) { return((ResultCode)result.Value); } return(OpenNcaFs(context, fullPath, ncaFile.AsStorage(), out openedFileSystem)); } catch (HorizonResultException ex) { return((ResultCode)ex.ResultValue.Value); } } return(ResultCode.PathDoesNotExist); }
public static ResultCode OpenNcaFs(ServiceCtx context, string ncaPath, LibHac.Fs.IStorage ncaStorage, out IFileSystem openedFileSystem) { openedFileSystem = null; try { Nca nca = new Nca(context.Device.System.KeySet, ncaStorage); if (!nca.SectionExists(NcaSectionType.Data)) { return(ResultCode.PartitionNotFound); } LibHac.Fs.IFileSystem fileSystem = nca.OpenFileSystem(NcaSectionType.Data, context.Device.System.FsIntegrityCheckLevel); openedFileSystem = new IFileSystem(fileSystem); } catch (HorizonResultException ex) { return((ResultCode)ex.ResultValue.Value); } return(ResultCode.Success); }