Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        public static List <Ticket> DumpTickets(Keyset keyset, IStorage savefile, string consoleName)
        {
            var           tickets      = new List <Ticket>();
            var           save         = new SaveDataFileSystem(keyset, savefile, IntegrityCheckLevel.ErrorOnInvalid, false);
            var           ticketList   = new BinaryReader(save.OpenFile("/ticket_list.bin", OpenMode.Read).AsStream());
            var           ticketFile   = new BinaryReader(save.OpenFile("/ticket.bin", OpenMode.Read).AsStream());
            DirectoryInfo ticketFolder = HACGUIKeyset.GetTicketsDirectory(consoleName);

            ticketFolder.Create();

            var titleId = ticketList.ReadUInt64();

            while (titleId != ulong.MaxValue)
            {
                ticketList.BaseStream.Position += 0x18;
                var    start            = ticketFile.BaseStream.Position;
                Ticket ticket           = new Ticket(ticketFile);
                Stream ticketFileStream = ticketFolder.GetFile(BitConverter.ToString(ticket.RightsId).Replace("-", "").ToLower() + ".tik").Create();
                byte[] data             = ticket.GetBytes();
                ticketFileStream.Write(data, 0, data.Length);
                ticketFileStream.Close();
                tickets.Add(ticket);
                ticketFile.BaseStream.Position = start + 0x400;
                titleId = ticketList.ReadUInt64();
            }

            return(tickets);
        }
Exemplo n.º 3
0
        private void RepackClicked(object sender, RoutedEventArgs e)
        {
            FileInfo info = new FileInfo(Path.Text);

            info.Directory.Create(); // ensure that the folder exists
            Pfs0Builder  builder = new Pfs0Builder();
            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)
                {
                    if (nca.HasRightsId)
                    {
                        string   rightsId          = BitConverter.ToString(nca.Header.RightsId).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, new FileStorage(tikFile).AsStream());
                        }
                    }
                }
            }

            foreach (Nca nca in SelectedNcas)
            {
                builder.AddFile(nca.Filename, nca.GetStorage().AsStream());
            }


            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();
        }