private async void StartButton_Click(object sender, EventArgs e) { if (SourceFolderPathTextBox.Text.IsEmpty() && Program.Settings.SourceDirectory == null) { MessageBox.Show(this, "You need to specify a source folder path!", "No Source Folder Specified!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } if (!new DirectoryInfo(SourceFolderPathTextBox.Text).Exists) { MessageBox.Show(this, "The provided source folder path " + SourceFolderPathTextBox.Text + " does not exist!", "Invalid path!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } if (DestinationFolderPathTextBox.Text.IsEmpty() && Program.Settings.DestinationDirectory == null) { MessageBox.Show(this, "You need to specify a destination folder path!", "No Destination Folder Specified!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } if (!new DirectoryInfo(DestinationFolderPathTextBox.Text).Exists) { MessageBox.Show(this, "The provided destination folder path " + DestinationFolderPathTextBox.Text + " does not exist!", "Invalid path!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } if (SourceFolderPathTextBox.Text == DestinationFolderPathTextBox.Text) { MessageBox.Show(this, "The source folder path and destination folder path cannot be the same!", "The Same Is Lame", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } Invoke((MethodInvoker) delegate() { if (Program.Settings.SourceDirectory == null) { Program.Settings.SourceDirectory = new DirectoryInfo(SourceFolderPathTextBox.Text); } if (Program.Settings.DestinationDirectory == null) { Program.Settings.DestinationDirectory = new DirectoryInfo(DestinationFolderPathTextBox.Text); } if (Program.Settings.IsRecurive != RecursiveCheckBox.Checked) { Program.Settings.IsRecurive = RecursiveCheckBox.Checked; } if (Program.Settings.UseAlphaFormatOnly != UseTransparentFormatCheckBox.Checked) { Program.Settings.UseAlphaFormatOnly = UseTransparentFormatCheckBox.Checked; } if (Program.Settings.OnlyPassSquareImages != ConvertSquaresOnlyCheckBox.Checked) { Program.Settings.OnlyPassSquareImages = ConvertSquaresOnlyCheckBox.Checked; } if (Program.Settings.DownsizeLargerResolutionImages != DownsizeCheckbox.Checked) { Program.Settings.DownsizeLargerResolutionImages = DownsizeCheckbox.Checked; } if (Program.Settings.CopySkippedFiles != CopySkippedFilesCheckbox.Checked) { Program.Settings.CopySkippedFiles = CopySkippedFilesCheckbox.Checked; } if (Program.Settings.CompressionLevel == 0) { Program.Settings.CompressionLevel = int.Parse(CompressionModeDropDown.SelectedItem.ToString().Replace("%", string.Empty)); } if (Program.Settings.TargetImageWidth == 0) { Program.Settings.TargetImageWidth = !WidthTextBox.Text.IsEmpty() ? int.Parse(WidthTextBox.Text) : 0; } if (Program.Settings.TargetImageHeight == 0) { Program.Settings.TargetImageHeight = !HeightTextBox.Text.IsEmpty() ? int.Parse(HeightTextBox.Text) : 0; } if (Program.Settings.ConvertToNonAlphaValue == 0) { Program.Settings.ConvertToNonAlphaValue = (SupportedNonAlphaFileTypes)Enum.Parse(typeof(SupportedNonAlphaFileTypes), ConvertToDropDown.SelectedItem.ToString()); } if (Program.Settings.ConvertToAlphaValue == 0) { Program.Settings.ConvertToAlphaValue = (SupportedAlphaFileTypes)Enum.Parse(typeof(SupportedAlphaFileTypes), IfTransparentDropDown.SelectedItem.ToString()); } }); await ImageProcessor.Initiate(); await ImageProcessor.Run(); await ImageProcessor.PrintResults(); }
private static async Task MainAsync(string[] args) { await Logger.Log(LogLevel.Info, "Parsing arguments..."); await ArgumentHandler.ParseArgumentsFromArray(args, out List <ParsedArgument> parsedArgs); CommandMode = !RuntimeInformation.IsOSPlatform(OSPlatform.Windows); foreach (ParsedArgument a in parsedArgs) { await Logger.Log(LogLevel.Debug, a.Command + " | " + a.Value); if (a.Command == "noui") { CommandMode = true; } if (a.Command == "source") { Settings.SourceDirectory = new DirectoryInfo(a.Value); } if (a.Command == "destination") { Settings.DestinationDirectory = new DirectoryInfo(a.Value); } if (a.Command == "onlyAlpha") { Settings.UseAlphaFormatOnly = true; } if (a.Command == "recursive") { Settings.IsRecurive = true; } if (a.Command == "onlySquare") { Settings.OnlyPassSquareImages = true; } if (a.Command == "downsize") { Settings.DownsizeLargerResolutionImages = true; } if (a.Command == "copy") { Settings.CopySkippedFiles = true; } if (a.Command == "compression") { Settings.CompressionLevel = int.Parse(a.Value); } if (a.Command == "targetWidth") { Settings.TargetImageWidth = int.Parse(a.Value); } if (a.Command == "targetHeight") { Settings.TargetImageHeight = int.Parse(a.Value); } if (a.Command == "nonAlphaFormat") { Settings.ConvertToNonAlphaValue = (SupportedNonAlphaFileTypes)int.Parse(a.Value); } if (a.Command == "alphaFormat") { Settings.ConvertToAlphaValue = (SupportedAlphaFileTypes)int.Parse(a.Value); } } if (!CommandMode) { await Logger.Log(LogLevel.Info, "Starting Application UI."); Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(Form = new TooManyPixelsForm()); } else { await Logger.Log(LogLevel.Info, "Starting Application."); await ImageProcessor.Initiate(); await ImageProcessor.Run(); await ImageProcessor.PrintResults(); } }