Example #1
0
        static void Main(string[] args)
        {
            if ((args.Length == 0 && !IsUsingMono) || args.Contains("--gui"))
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                try
                {
                    Settings settings = Settings.FromBatchFile(Program.BatName);
                    settings = Settings.FromArgs(args, true, settings);
                    Application.Run(new FormMain(settings));
                }
                catch (ArgumentException e)
                {
                    MessageBox.Show(e.Message, Program.Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Environment.Exit(1);
                }
            }
            else
            {
                BindToConsole();

                if (args.Length > 0 && !args.Contains("--help"))
                {
                    try
                    {
                        ImageProcessor.Run(Settings.FromArgs(args),
                                           (output) => Console.WriteLine(output),
                                           (error) =>
                        {
                            Console.Error.WriteLine(String.Format(Translations.Get("program_error"), error));
                            Environment.Exit(1);
                        }
                                           );
                    }
                    catch (ArgumentException e)
                    {
                        Console.Error.WriteLine(String.Format(Translations.Get("program_error"), e.Message));
                        Console.Error.WriteLine(String.Format(Translations.Get("help_usage_detailed"), Program.ExeName));
                        Environment.Exit(1);
                    }
                }
                else
                {
                    if (args.Contains("--help"))
                    {
                        foreach (string line in new[] {
                            "== " + Program.Title + " ==",
                            " " + Translations.Get("help_main_1"),
                            " " + Translations.Get("help_main_2"),
                            "",
                            "== " + Translations.Get("help_title_usage") + " ==",
                            " " + Translations.Get("help_steps_1"),
                            " " + String.Format(Translations.Get("help_steps_2"), Program.ExeName),
                            " " + Translations.Get("help_steps_3"),
                            "",
                            "== " + Translations.Get("help_title_args") + " ==",
                            " " + Translations.Get("help_arg_indir"),
                            " " + Translations.Get("help_arg_outdir"),
                            " " + Translations.Get("help_arg_rotate"),
                            " " + Translations.Get("help_arg_crop_left"),
                            " " + Translations.Get("help_arg_crop_right"),
                            " " + Translations.Get("help_arg_crop_top"),
                            " " + Translations.Get("help_arg_crop_bottom"),
                            " " + Translations.Get("help_arg_inext"),
                            " " + Translations.Get("help_arg_inpaging"),
                            " " + Translations.Get("help_arg_outext"),
                            " " + Translations.Get("help_arg_basename"),
                            " " + Translations.Get("help_arg_reorder"),
                            " " + Translations.Get("help_arg_backflip"),
                            " " + Translations.Get("help_arg_gui"),
                            ""
                        })
                        {
                            Console.Error.WriteLine(line);
                        }
                    }
                    else
                    {
                        Console.Error.WriteLine(String.Format(Translations.Get("help_usage_example"), Program.ExeName));
                        Console.Error.WriteLine(String.Format(Translations.Get("help_usage_detailed"), Program.ExeName));
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Click on Launch button: Write settings to Batch file and launch operation
        /// </summary>
        private void buttonLaunch_Click(object sender, EventArgs e)
        {
            if (currentlyProcessingImages)
            {
                if (processThread != null)
                {
                    processThread.Abort();
                    processThread = null;
                    SetProcessing(false);
                }
            }
            else
            {
                try
                {
                    SetProcessing(true);
                    settings.InputDir     = textBoxInputDir.Text;
                    settings.InputPaging  = comboBoxInputPaging.Text;
                    settings.OutputDir    = textBoxOutputDir.Text;
                    settings.InputExt     = comboBoxInputExtension.Text;
                    settings.OutputExt    = comboBoxOutputExtension.Text;
                    settings.RotateAngle  = comboBoxImageRotate.Text;
                    settings.CropLeft     = (uint)numericCropLeft.Value;
                    settings.CropRight    = (uint)numericCropRight.Value;
                    settings.CropTop      = (uint)numericCropTop.Value;
                    settings.CropBottom   = (uint)numericCropBottom.Value;
                    settings.OutputNaming = textBoxOutputNaming.Text.Trim();
                    settings.Reorder      = checkBoxReorder.Checked;
                    settings.Backflip     = checkBoxBackFlip.Checked;
                    Settings.WriteBatchFile(Program.BatName, settings);

                    processThread = new Thread(() =>
                    {
                        try
                        {
                            if (ImageProcessor.Run(settings, UpdateStatusLabel, ShowErrorMessage))
                            {
                                try
                                {
                                    new System.Media.SoundPlayer("C:\\WINDOWS\\Media\\chimes.wav").Play();
                                }
                                catch { /* Failed to play finish sound */ }
                            }
                        }
                        catch (Exception exception)
                        {
                            if (!(exception is ThreadAbortException))
                            {
                                ShowErrorMessage(exception.GetType() + ": " + exception.Message);
                            }
                        }
                        SetProcessing(false);
                    });
                    processThread.Start();
                }
                catch (Exception exception)
                {
                    ShowErrorMessage(exception.GetType() + ": " + exception.Message);
                    SetProcessing(false);
                }
            }
        }