private void RunTask() { if (TaskQueue.Items.Count == 0) { Out.Log("Nothing to do - TaskQueue empty! Please add an NSP or NSPZ!\r\n"); return; } Dispatcher.Invoke(() => { BusyTextBlock.Text = "Working..."; MainGrid.Visibility = Visibility.Hidden; MainGridBusy.Visibility = Visibility.Visible; }); try { do { var inFile = (string)TaskQueue.Items[0]; var infileLowerCase = inFile.ToLower(); var inFileNoExtension = Path.GetFileNameWithoutExtension(inFile); Dispatcher.Invoke(() => { BusyTextBlock.Text = $"Task \"{Path.GetFileNameWithoutExtension(inFile)}\" in progress...\r\nThis might take quite some time.\r\n" + $"Please take a look at the console window for more information."; TaskQueue.Items.RemoveAt(0); }); var tl = new TaskLogic(OutputFolderPath, TempFolderPath, VerifyHashes, BlockSize, ZstdLevel, Out); if (tl.checkIfAlreadyExist(inFile)) { continue; } tl.cleanFolders(); try { if (infileLowerCase.EndsWith("nsp")) { tl.CompressNSP(inFile); } else if (infileLowerCase.EndsWith("xci")) { tl.CompressXCI(inFile); } else if (infileLowerCase.EndsWith("nspz")) { tl.DecompressNSPZ(inFile); } else if (infileLowerCase.EndsWith("xciz")) { tl.DecompressXCIZ(inFile); } else { throw new InvalidDataException($"Invalid file type {inFile}"); } } catch (Exception ex) { Out.Error(ex.StackTrace + "\r\n"); Out.Error(ex.Message + "\r\n\r\n"); } finally { if (!KeepTempFilesAfterTask && tl != null) { tl.cleanFolders(); } } } while (TaskQueue.Items.Count > 0); } catch (Exception ex) { Out.Log(ex.StackTrace + "\r\n"); Out.Log(ex.Message); throw ex; } finally { Dispatcher.Invoke(() => { MainGrid.Visibility = Visibility.Visible; MainGridBusy.Visibility = Visibility.Hidden; }); switch (StandByWhenTaskDone) { case TaskDonePowerState.Suspend: Out.Log("Activate standby mode...\r\n"); Thread.Sleep(1000); System.Windows.Forms.Application.SetSuspendState(PowerState.Suspend, false, false); break; case TaskDonePowerState.Hibernate: Out.Log("Activate hibernate mode...\r\n"); Thread.Sleep(1000); System.Windows.Forms.Application.SetSuspendState(PowerState.Hibernate, false, false); break; } } }
private void Application_Startup(object sender, StartupEventArgs e) { //var outDebug = new Output(); //var tl1 = new TaskLogic(@"T:\OUT", @"T:\", true, 262144, 18, outDebug); //tl1.VerifyCompressedFolder(@"T:\NSP\input.nsp"); //return; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { try { if (ConsoleMode.TryDisablingConsoleQuickEdit()) { Console.WriteLine("Console's QuickEdit mode disabled successfully"); } else { Console.WriteLine("Failed to disable the Console's QuickEdit mode"); } } catch (Exception) { Console.WriteLine("Unimportant exception occurred while disabling Console's QuickEdit mode"); } } if (e.Args.Length > 0) { int res = 0; var args = Parser.Default.ParseArguments <Options>(e.Args); if (e.Args.Length > 0) { args.WithParsed(opts => { var Out = new Output(opts.Log); Directory.CreateDirectory(opts.OutputFolderPath); var tl = new TaskLogic(opts.OutputFolderPath, opts.TempFolderPath, true, opts.BlockSize, opts.ZstdLevel, opts.MaxDegreeOfParallelism, Out); var inFile = opts.InputFile; if (tl.checkIfAlreadyExist(inFile)) { Environment.Exit(-1); } try { tl.cleanFolders(); var infileLowerCase = inFile.ToLower(); if (infileLowerCase.EndsWith("nsp")) { tl.CompressNSP(inFile); } else if (infileLowerCase.EndsWith("xci")) { tl.CompressXCI(inFile); } else if (infileLowerCase.EndsWith("nspz")) { tl.DecompressNSPZ(inFile); } else if (infileLowerCase.EndsWith("xciz")) { tl.DecompressXCIZ(inFile); } else { throw new InvalidDataException($"Invalid file type {inFile}"); } } catch (Exception ex) { Out.LogException(ex); res = -2; } finally { tl.cleanFolders(); } }); } Environment.Exit(res); } else { MainWindow wnd = new MainWindow(); wnd.Show(); } }