private IFileSystem CreateFileSystem() { var lowerLayerFs = new InMemoryFileSystem(); var upperLayerFs = new InMemoryFileSystem(); var layeredFs = new LayeredFileSystem(lowerLayerFs, upperLayerFs); lowerLayerFs.CreateDirectory("/dir".ToU8Span()).ThrowIfFailure(); upperLayerFs.CreateDirectory("/dir".ToU8Span()).ThrowIfFailure(); lowerLayerFs.CreateDirectory("/dir2".ToU8Span()).ThrowIfFailure(); upperLayerFs.CreateDirectory("/dir2".ToU8Span()).ThrowIfFailure(); lowerLayerFs.CreateDirectory("/dir3".ToU8Span()).ThrowIfFailure(); upperLayerFs.CreateDirectory("/dir3".ToU8Span()).ThrowIfFailure(); lowerLayerFs.CreateDirectory("/lowerDir".ToU8Span()).ThrowIfFailure(); upperLayerFs.CreateDirectory("/upperDir".ToU8Span()).ThrowIfFailure(); lowerLayerFs.CreateFile("/dir/replacedFile".ToU8Span(), 1, CreateFileOptions.None).ThrowIfFailure(); upperLayerFs.CreateFile("/dir/replacedFile".ToU8Span(), 2, CreateFileOptions.None).ThrowIfFailure(); lowerLayerFs.CreateFile("/dir2/lowerFile".ToU8Span(), 0, CreateFileOptions.None).ThrowIfFailure(); upperLayerFs.CreateFile("/dir2/upperFile".ToU8Span(), 0, CreateFileOptions.None).ThrowIfFailure(); lowerLayerFs.CreateFile("/dir3/lowerFile".ToU8Span(), 0, CreateFileOptions.None).ThrowIfFailure(); upperLayerFs.CreateFile("/dir3/upperFile".ToU8Span(), 2, CreateFileOptions.None).ThrowIfFailure(); lowerLayerFs.CreateFile("/dir3/replacedFile".ToU8Span(), 1, CreateFileOptions.None).ThrowIfFailure(); upperLayerFs.CreateFile("/dir3/replacedFile".ToU8Span(), 2, CreateFileOptions.None).ThrowIfFailure(); lowerLayerFs.CreateFile("/replacedWithDir".ToU8Span(), 0, CreateFileOptions.None).ThrowIfFailure(); upperLayerFs.CreateDirectory("/replacedWithDir".ToU8Span()).ThrowIfFailure(); upperLayerFs.CreateFile("/replacedWithDir/subFile".ToU8Span(), 0, CreateFileOptions.None).ThrowIfFailure(); return(layeredFs); }
private void MountClicked(object sender, RoutedEventArgs e) { if (ComboBox.SelectedItem == null) { return; } MountType mountType = (MountType)ComboBox.SelectedItem; NcaFormatType sectionType = NcaFormatType.Romfs; switch (mountType) { case MountType.Exefs: sectionType = NcaFormatType.Pfs0; break; case MountType.Romfs: sectionType = NcaFormatType.Romfs; break; } List <IFileSystem> filesystems = new List <IFileSystem>(); IEnumerable <Tuple <SwitchFsNca, int> > list = Indexed[sectionType]; TaskManagerPage.Current.Queue.Submit(new RunTask("Opening filesystems to mount...", new Task(() => { foreach (Tuple <SwitchFsNca, int> t in list) { SwitchFsNca nca = t.Item1; NcaFsHeader section = t.Item1.Nca.Header.GetFsHeader(t.Item2); int index = t.Item2; /*IStorage inStorage = nca.OpenStorage(index, IntegrityCheckLevel.ErrorOnInvalid); * IFile outFile = new LocalFile("./tmp.bin", OpenMode.Write | OpenMode.AllowAppend); * IStorage outStorage = outFile.AsStorage(); * inStorage.GetSize(out long size); * long buffLen = 0x10000; * for (int i = 0; i < (int)Math.Min(Math.Ceiling((double)size / buffLen), 5); i++) * { * long off = i * buffLen; * long left = size - off; * long toRead = Math.Min(buffLen, left); * * byte[] buff = new byte[toRead]; * * inStorage.Read(off, buff); * outStorage.Write(off, buff); * } * //inStorage.Dispose(); * outFile.Dispose();*/ filesystems.Add(nca.OpenFileSystem(index, IntegrityCheckLevel.ErrorOnInvalid)); } filesystems.Reverse(); LayeredFileSystem fs = new LayeredFileSystem(filesystems); string typeString = sectionType.ToString(); MountService.Mount(new MountableFileSystem(fs, $"Mounted {mountType.ToString().ToLower()}", typeString, OpenMode.Read)); }))); }
private void ExtractClicked(object sender, RoutedEventArgs e) { MountType mountType = (MountType)ComboBox.SelectedItem; NcaFormatType sectionType = NcaFormatType.Romfs; switch (mountType) { case MountType.Exefs: sectionType = NcaFormatType.Pfs0; break; case MountType.Romfs: sectionType = NcaFormatType.Romfs; break; } IEnumerable <Tuple <SwitchFsNca, int> > list = Indexed[sectionType]; string path = Path.Text; TaskManagerPage.Current.Queue.Submit(new RunTask("Opening filesystems to extract...", new Task(() => { List <IFileSystem> filesystems = new List <IFileSystem>(); foreach (Tuple <SwitchFsNca, int> t in list) { SwitchFsNca nca = t.Item1; NcaFsHeader section = t.Item1.Nca.Header.GetFsHeader(t.Item2); int index = t.Item2; filesystems.Add(nca.OpenFileSystem(index, IntegrityCheckLevel.ErrorOnInvalid)); } filesystems.Reverse(); LayeredFileSystem lfs = new LayeredFileSystem(filesystems); ExtractFileSystemTask task = new ExtractFileSystemTask($"Extracting {sectionType}...", lfs, path); Dispatcher.InvokeAsync(() => { ProgressView view = new ProgressView(new List <ProgressTask>() { task }); NavigationWindow window = new NavigationWindow { ShowsNavigationUI = false // get rid of the t r a s h }; window.Navigate(view); TaskManagerPage.Current.Queue.Submit(task); window.Owner = Window.GetWindow(this); window.ShowDialog(); }); }))); }
private void MountClicked(object sender, RoutedEventArgs e) { MountType mountType = (MountType)ComboBox.SelectedItem; NcaFormatType sectionType = NcaFormatType.Romfs; switch (mountType) { case MountType.Exefs: sectionType = NcaFormatType.Pfs0; break; case MountType.Romfs: sectionType = NcaFormatType.Romfs; break; } List <IFileSystem> filesystems = new List <IFileSystem>(); IEnumerable <Tuple <SwitchFsNca, int> > list = Indexed[sectionType]; TaskManagerPage.Current.Queue.Submit(new RunTask("Opening filesystems to mount...", new Task(() => { foreach (Tuple <SwitchFsNca, int> t in list) { SwitchFsNca nca = t.Item1; NcaFsHeader section = t.Item1.Nca.Header.GetFsHeader(t.Item2); int index = t.Item2; if (section.IsPatchSection()) { MainNca.BaseNca = nca.Nca; } filesystems.Add(nca.OpenFileSystem(index, IntegrityCheckLevel.ErrorOnInvalid)); } filesystems.Reverse(); LayeredFileSystem fs = new LayeredFileSystem(filesystems); string typeString = sectionType.ToString(); MountService.Mount(new MountableFileSystem(fs, $"Mounted {mountType.ToString().ToLower()}", typeString, OpenMode.Read)); }))); }