示例#1
0
        private void RunToolsTask(ToolsTaskType toolsTaskType)
        {
            if (ToolsTaskQueue.Items.Count == 0)
            {
                Out.Log("Nothing to do - ToolsTaskQueue empty! Please select any input file first!\r\n");
                return;
            }

            Dispatcher.Invoke(() =>
            {
                BusyTextBlock.Text      = "Working...";
                MainGrid.Visibility     = Visibility.Hidden;
                MainGridBusy.Visibility = Visibility.Visible;
            });

            var extractedTitleKeys = new LibHac.Keyset();
            var keyset             = new LibHac.Keyset();

            if (toolsTaskType == ToolsTaskType.ExtractRomFS)
            {
                keyset = LibHacControl.ProcessKeyset.OpenKeyset();
            }

            try
            {
                var TitlekeysOutputFilePath = $"{OutputFolderPath}/titlekeys.txt";
                var TicketOutputPath        = $"{OutputFolderPath}/Tickets";
                if (toolsTaskType == ToolsTaskType.ExtractTickets && !Directory.Exists(TicketOutputPath))
                {
                    Directory.CreateDirectory(TicketOutputPath);
                }

                do
                {
                    var inFilePath = (string)ToolsTaskQueue.Items[0];
                    var inFile     = Path.GetFileName(inFilePath);

                    var ToolsTaskText = $"ToolsTask {toolsTaskType.ToString()} \"{inFile}\" in progress...";
                    Out.Event($"{ToolsTaskText}\r\n");
                    Dispatcher.Invoke(() =>
                    {
                        BusyTextBlock.Text =
                            $"{ToolsTaskText}\r\nThis might take quite some time.\r\n" +
                            $"Please take a look at the console window for more information.";
                        ToolsTaskQueue.Items.RemoveAt(0);
                    });

                    // Sleep 10 ms for the BusyTextBlock be longer visible for a large amount of very short tasks like ExtractTitlekeys
                    // It’s here so he sleeps even if the ToolsTask was skipped
                    Thread.Sleep(10);

                    switch (toolsTaskType)
                    {
                    case ToolsTaskType.ExtractTitlekeys:
                        FileTools.File2Titlekey(inFilePath, extractedTitleKeys, Out);
                        break;

                    case ToolsTaskType.ExtractTickets:
                        FileTools.File2Tickets(inFilePath, TicketOutputPath, keyset, Out);
                        break;

                    case ToolsTaskType.ExtractPfsHfs:
                        var PfsHfsOutputPath = $"{OutputFolderPath}/{inFile}_Extracted";
                        if (!Directory.Exists(PfsHfsOutputPath))
                        {
                            Directory.CreateDirectory(PfsHfsOutputPath);
                            FileTools.ExtractPfsHfs(inFilePath, PfsHfsOutputPath, keyset, Out);
                        }
                        else
                        {
                            Out.Event($"ToolsTask {toolsTaskType.ToString()} \"{inFile}\" skipped as it already exists in the output directory\r\n");
                            continue;
                        }
                        break;

                    case ToolsTaskType.ExtractRomFS:
                        var RomFsOutputPath = $"{OutputFolderPath}/{inFile}_RomFS";
                        if (!Directory.Exists(RomFsOutputPath))
                        {
                            Directory.CreateDirectory(RomFsOutputPath);
                            FileTools.ExtractRomFS(inFilePath, RomFsOutputPath, keyset, Out);
                        }
                        else
                        {
                            Out.Event($"ToolsTask {toolsTaskType.ToString()} \"{inFile}\" skipped as it already exists in the output directory\r\n");
                            continue;
                        }
                        break;

                    default:
                        throw new NotImplementedException($"Unknown ToolsTaskType: {toolsTaskType}!");
                    }

                    Out.Event($"ToolsTask {toolsTaskType.ToString()} \"{inFile}\" completed!\r\n");
                } while (ToolsTaskQueue.Items.Count > 0);

                if (toolsTaskType == ToolsTaskType.ExtractTitlekeys)
                {
                    Out.Log($"Writing to {TitlekeysOutputFilePath}\r\n");
                    using (var titlekeys = new StreamWriter(File.Open(TitlekeysOutputFilePath, FileMode.Create), Encoding.ASCII))
                    {
                        foreach (var entry in extractedTitleKeys.TitleKeys)
                        {
                            var line = $"{Utils.BytesToString(entry.Key)},{Utils.BytesToString(entry.Value)}\r\n";
                            titlekeys.Write(line);
                            Out.Log(line);
                        }
                    }
                }

                Out.Event($"All ToolsTasks completed!\r\n");
            }
            catch (Exception ex)
            {
                Out.LogException(ex);
            }
            finally
            {
                Dispatcher.Invoke(() =>
                {
                    MainGrid.Visibility     = Visibility.Visible;
                    MainGridBusy.Visibility = Visibility.Hidden;
                });
            }
        }
示例#2
0
        public bool checkIfAlreadyExist(string inFile)
        {
            var infileLowerCase   = inFile.ToLower();
            var inFileNoExtension = Path.GetFileNameWithoutExtension(inFile);

            if (infileLowerCase.EndsWith("nsp") && File.Exists($"{Path.Combine(OutputFolderPath, inFileNoExtension)}.nspz"))
            {
                Out.Event($"Task CompressNSP \"{inFileNoExtension}.nspz\" skipped as it already exists in the output directory\r\n");
                return(true);
            }

            if (infileLowerCase.EndsWith("xci") && File.Exists($"{Path.Combine(OutputFolderPath, inFileNoExtension)}.xciz"))
            {
                Out.Event($"Task CompressXCI \"{inFileNoExtension}.xciz\" skipped as it already exists in the output directory\r\n");
                return(true);
            }

            if (infileLowerCase.EndsWith("nspz") && File.Exists($"{Path.Combine(OutputFolderPath, inFileNoExtension)}.nsp"))
            {
                Out.Event($"Task DecompressNSPZ \"{inFileNoExtension}.nsp\" skipped as it already exists in the output directory\r\n");
                return(true);
            }

            if (infileLowerCase.EndsWith("xciz") && File.Exists($"{Path.Combine(OutputFolderPath, inFileNoExtension)}.xci"))
            {
                Out.Event($"Task DecompressXCIZ \"{inFileNoExtension}.xci\" skipped as it already exists in the output directory\r\n");
                return(true);
            }

            return(false);
        }