private void ExtractClicked(object sender, RoutedEventArgs e) { DirectoryInfo root = new DirectoryInfo(Path.Text); root.Create(); // ensure that the folder exists List <ProgressTask> tasks = new List <ProgressTask>(); if (TicketCheckbox.IsChecked == true) { DirectoryInfo ticketDir = HACGUIKeyset.GetTicketsDirectory(Preferences.Current.DefaultConsoleName); // TODO: load console name from continuous location List <string> foundTickets = new List <string>(); foreach (Nca nca in SelectedNcas.Select(n => n.Nca)) { if (nca.Header.HasRightsId) { string rightsId = nca.Header.RightsId.ToHexString(); string ticketFileName = rightsId + ".tik"; FileInfo sourceTikFileInfo = ticketDir.GetFile(ticketFileName); if (sourceTikFileInfo.Exists) { FileInfo destinationTikFileInfo = root.GetFile(ticketFileName); if (!foundTickets.Contains(rightsId)) { foundTickets.Add(rightsId); destinationTikFileInfo.CreateAndClose(); LocalFile sourceTikFile = new LocalFile(sourceTikFileInfo.FullName, OpenMode.Read); LocalFile destinationTikFile = new LocalFile(destinationTikFileInfo.FullName, OpenMode.Write); destinationTikFile.SetSize(sourceTikFile.GetSize()); tasks.Add(new CopyTask($"Copying {ticketFileName}...", new FileStorage(sourceTikFile), new FileStorage(destinationTikFile))); } } } } } foreach (SwitchFsNca nca in SelectedNcas) { FileInfo destinationNcaFileInfo = root.GetFile(nca.Filename); destinationNcaFileInfo.CreateAndClose(); LocalFile destinationNcaFile = new LocalFile(destinationNcaFileInfo.FullName, OpenMode.Write); IStorage source = nca.Nca.BaseStorage; tasks.Add(new RunTask($"Allocating space for {nca.Filename}...", new Task(() => { destinationNcaFile.SetSize(source.GetSize()); }))); tasks.Add(new CopyTask($"Copying {nca.Filename}...", source, new FileStorage(destinationNcaFile))); } ProgressView view = new ProgressView(tasks); NavigationWindow window = new NavigationWindow { ShowsNavigationUI = false // get rid of the t r a s h }; window.Navigate(view); TaskManagerPage.Current.Queue.Submit(tasks); window.Owner = Window.GetWindow(this); window.ShowDialog(); }
private void RepackClicked(object sender, RoutedEventArgs e) { FileInfo info = new FileInfo(Path.Text); info.Directory.Create(); // ensure that the folder exists PartitionFileSystemBuilder builder = new PartitionFileSystemBuilder(); NspPackTask logger = new NspPackTask(builder, info); ProgressView view = new ProgressView(new List <ProgressTask> { logger }); if (TicketCheckbox.IsChecked == true) { DirectoryInfo ticketDir = HACGUIKeyset.GetTicketsDirectory(Preferences.Current.DefaultConsoleName); // TODO: load console name from continuous location List <string> foundTickets = new List <string>(); foreach (Nca nca in SelectedNcas.Select(n => n.Nca)) { if (nca.Header.HasRightsId) { string rightsId = BitConverter.ToString(nca.Header.RightsId.ToArray()).Replace("-", "").ToLower(); string ticketFileName = rightsId + ".tik"; FileInfo sourceTikFileInfo = ticketDir.GetFile(ticketFileName); if (sourceTikFileInfo.Exists && !foundTickets.Contains(rightsId)) { foundTickets.Add(rightsId); LocalFile tikFile = new LocalFile(sourceTikFileInfo.FullName, OpenMode.Read); builder.AddFile(ticketFileName, tikFile); } } } } foreach (SwitchFsNca nca in SelectedNcas) { builder.AddFile(nca.Filename, nca.Nca.BaseStorage.AsFile(OpenMode.Read)); } NavigationWindow window = new NavigationWindow { ShowsNavigationUI = false // get rid of the t r a s h }; window.Navigate(view); TaskManagerPage.Current.Queue.Submit(logger); window.Owner = Window.GetWindow(this); window.ShowDialog(); }