예제 #1
0
        public static void Main(string[] args)
        {
            if (Environment.OSVersion.Platform != PlatformID.Win32NT)
            {
                MessageBox.Show(Properties.Resources.MessageApplicationCannotRun, GetTitle() + Constants.Space + Constants.EnDash + Constants.Space + Properties.Resources.CaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Settings settings = new Settings();

            if (!settings.DisableThemes)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                settings.RenderWithVisualStyles = Application.RenderWithVisualStyles;
            }
            ArgumentParser argumentParser = new ArgumentParser();

            try {
                argumentParser.Arguments = args;
            } catch (Exception exception) {
                Debug.WriteLine(exception);
                ErrorLog.WriteLine(exception);
                MessageBox.Show(exception.Message, GetTitle() + Constants.Space + Constants.EnDash + Constants.Space + Properties.Resources.CaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (argumentParser.HasArguments)
            {
                if (argumentParser.IsHelp)
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.AppendLine(Properties.Resources.HelpLine1.Replace("\\t", "\t")).AppendLine();
                    stringBuilder.AppendLine(Properties.Resources.HelpLine2.Replace("\\t", "\t")).AppendLine();
                    stringBuilder.AppendLine(Properties.Resources.HelpLine3.Replace("\\t", "\t")).AppendLine();
                    stringBuilder.AppendLine(Properties.Resources.HelpLine4.Replace("\\t", "\t")).AppendLine();
                    stringBuilder.AppendLine(Properties.Resources.HelpLine5.Replace("\\t", "\t")).AppendLine();
                    stringBuilder.AppendLine(Properties.Resources.HelpLine6.Replace("\\t", "\t")).AppendLine();
                    stringBuilder.AppendLine(Properties.Resources.HelpLine7.Replace("\\t", "\t")).AppendLine();
                    stringBuilder.AppendLine(Properties.Resources.HelpLine8.Replace("\\t", "\t")).AppendLine();
                    stringBuilder.AppendLine(Properties.Resources.HelpLine9.Replace("\\t", "\t")).AppendLine();
                    stringBuilder.AppendLine(Properties.Resources.HelpLine10.Replace("\\t", "\t")).AppendLine();
                    stringBuilder.AppendLine(Properties.Resources.HelpLine11.Replace("\\t", "\t")).AppendLine();
                    stringBuilder.AppendLine(Properties.Resources.HelpLine12.Replace("\\t", "\t"));
                    MessageBox.Show(stringBuilder.ToString(), GetTitle() + Constants.Space + Constants.EnDash + Constants.Space + Properties.Resources.CaptionHelp, MessageBoxButtons.OK, MessageBoxIcon.Question);
                }
                else if (argumentParser.IsThisTest)
                {
                    try {
                        Application.Run(new ArgumentParserForm());
                    } catch (Exception exception) {
                        Debug.WriteLine(exception);
                        ErrorLog.WriteLine(exception);
                        MessageBox.Show(exception.Message, GetTitle() + Constants.Space + Constants.EnDash + Constants.Space + Properties.Resources.CaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        MessageBox.Show(Properties.Resources.MessageApplicationError, GetTitle(), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    MessageForm    messageForm    = null;
                    BackgroundForm backgroundForm = null;
                    try {
                        if (Directory.Exists(Path.GetDirectoryName(argumentParser.OutputFilePath)) && !string.IsNullOrWhiteSpace(Path.GetFileNameWithoutExtension(argumentParser.OutputFilePath)))
                        {
                            messageForm = new MessageForm(argumentParser.Text, argumentParser.Caption, argumentParser.Buttons, argumentParser.BoxIcon, argumentParser.DefaultButton, true, argumentParser.DisplayHelpButton, argumentParser.MaximumWidth, argumentParser.NoWrap);
                            if (argumentParser.BasicTheme)
                            {
                                messageForm.Show();
                                using (Bitmap bitmap = new Bitmap(messageForm.Width, messageForm.Height, PixelFormat.Format32bppArgb)) {
                                    messageForm.DrawToBitmap(bitmap, new Rectangle(Point.Empty, bitmap.Size));
                                    switch (Path.GetExtension(argumentParser.OutputFilePath).ToLowerInvariant())
                                    {
                                    case Constants.ExtensionBmp:
                                        bitmap.Save(argumentParser.OutputFilePath, ImageFormat.Bmp);
                                        break;

                                    case Constants.ExtensionGif:
                                        bitmap.Save(argumentParser.OutputFilePath, ImageFormat.Gif);
                                        break;

                                    case Constants.ExtensionJpg:
                                        bitmap.Save(argumentParser.OutputFilePath, ImageFormat.Jpeg);
                                        break;

                                    case Constants.ExtensionTif:
                                        bitmap.Save(argumentParser.OutputFilePath, ImageFormat.Tiff);
                                        break;

                                    case Constants.ExtensionWebP:
                                        using (WebP webP = new WebP()) {
                                            File.WriteAllBytes(argumentParser.OutputFilePath, webP.EncodeLossless(bitmap));
                                        }
                                        break;

                                    default:
                                        bitmap.Save(argumentParser.OutputFilePath, ImageFormat.Png);
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                backgroundForm = new BackgroundForm();
                                backgroundForm.Show();
                                backgroundForm.Location = new Point(SystemInformation.WorkingArea.Location.X - Constants.BackgroundFormOverShoot, SystemInformation.WorkingArea.Location.Y - Constants.BackgroundFormOverShoot);
                                backgroundForm.Size     = new Size(messageForm.Width + Constants.BackgroundFormOverShoot * 2, messageForm.Height + Constants.BackgroundFormOverShoot * 2);
                                messageForm.Show();
                                messageForm.Location = SystemInformation.WorkingArea.Location;
                                Application.DoEvents();
                                System.Threading.Thread.Sleep(Constants.ScreenFormCaptureDelay);
                                using (Bitmap bitmap = new Bitmap(Math.Min(SystemInformation.WorkingArea.Width, messageForm.Width), Math.Min(SystemInformation.WorkingArea.Height, messageForm.Height), PixelFormat.Format32bppArgb)) {
                                    Graphics graphics = Graphics.FromImage(bitmap);
                                    graphics.CopyFromScreen(SystemInformation.WorkingArea.Location.X, SystemInformation.WorkingArea.Location.Y, 0, 0, new Size(Math.Min(SystemInformation.WorkingArea.Width, messageForm.Width), Math.Min(SystemInformation.WorkingArea.Height, messageForm.Height)), CopyPixelOperation.SourceCopy);
                                    switch (Path.GetExtension(argumentParser.OutputFilePath).ToLowerInvariant())
                                    {
                                    case Constants.ExtensionBmp:
                                        bitmap.Save(argumentParser.OutputFilePath, ImageFormat.Bmp);
                                        break;

                                    case Constants.ExtensionGif:
                                        bitmap.Save(argumentParser.OutputFilePath, ImageFormat.Gif);
                                        break;

                                    case Constants.ExtensionJpg:
                                        bitmap.Save(argumentParser.OutputFilePath, ImageFormat.Jpeg);
                                        break;

                                    case Constants.ExtensionTif:
                                        bitmap.Save(argumentParser.OutputFilePath, ImageFormat.Tiff);
                                        break;

                                    case Constants.ExtensionWebP:
                                        using (WebP webP = new WebP()) {
                                            File.WriteAllBytes(argumentParser.OutputFilePath, webP.EncodeLossless(bitmap));
                                        }
                                        break;

                                    default:
                                        bitmap.Save(argumentParser.OutputFilePath, ImageFormat.Png);
                                        break;
                                    }
                                }
                            }
                        }
                    } catch (Exception exception) {
                        Debug.WriteLine(exception);
                        ErrorLog.WriteLine(exception);
                    } finally {
                        if (messageForm != null)
                        {
                            messageForm.Close();
                        }
                        if (backgroundForm != null)
                        {
                            backgroundForm.Close();
                        }
                    }
                }
            }
            else
            {
                try {
                    SingleMainForm.Run(new MainForm(settings));
                } catch (Exception exception) {
                    Debug.WriteLine(exception);
                    ErrorLog.WriteLine(exception);
                    MessageBox.Show(exception.Message, GetTitle() + Constants.Space + Constants.EnDash + Constants.Space + Properties.Resources.CaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    MessageBox.Show(Properties.Resources.MessageApplicationError, GetTitle(), MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
예제 #2
0
        public static void Main(string[] args)
        {
            if (Environment.OSVersion.Platform != PlatformID.Win32NT)
            {
                MessageBox.Show(Properties.Resources.MessageApplicationCannotRun, GetTitle() + Constants.Space + Constants.EnDash + Constants.Space + Properties.Resources.CaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Settings settings = new Settings();

            if (!settings.DisableThemes)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                settings.RenderWithVisualStyles = Application.RenderWithVisualStyles;
            }
            ArgumentParser argumentParser = new ArgumentParser();

            try {
                argumentParser.Arguments = args;
            } catch (Exception exception) {
                Debug.WriteLine(exception);
                ErrorLog.WriteLine(exception);
                MessageBox.Show(exception.Message, GetTitle() + Constants.Space + Constants.EnDash + Constants.Space + Properties.Resources.CaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (argumentParser.HasArguments)
            {
                if (argumentParser.IsHelp)
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.AppendLine(Properties.Resources.HelpLine1.Replace("\\t", "\t")).AppendLine();
                    stringBuilder.AppendLine(Properties.Resources.HelpLine2.Replace("\\t", "\t"));
                    stringBuilder.AppendLine(Properties.Resources.HelpLine3.Replace("\\t", "\t"));
                    stringBuilder.AppendLine(Properties.Resources.HelpLine4.Replace("\\t", "\t")).AppendLine();
                    stringBuilder.AppendLine(Properties.Resources.HelpLine5.Replace("\\t", "\t"));
                    stringBuilder.AppendLine(Properties.Resources.HelpLine6.Replace("\\t", "\t")).AppendLine();
                    stringBuilder.AppendLine(Properties.Resources.HelpLine7.Replace("\\t", "\t"));
                    stringBuilder.AppendLine(Properties.Resources.HelpLine8.Replace("\\t", "\t")).AppendLine();
                    stringBuilder.AppendLine(Properties.Resources.HelpLine9.Replace("\\t", "\t"));
                    stringBuilder.AppendLine(Properties.Resources.HelpLine10.Replace("\\t", "\t")).AppendLine();
                    stringBuilder.AppendLine(Properties.Resources.HelpLine11.Replace("\\t", "\t"));
                    stringBuilder.AppendLine(Properties.Resources.HelpLine12.Replace("\\t", "\t")).AppendLine();
                    stringBuilder.AppendLine(Properties.Resources.HelpLine13.Replace("\\t", "\t")).AppendLine();
                    stringBuilder.AppendLine(Properties.Resources.HelpLine14.Replace("\\t", "\t"));
                    stringBuilder.AppendLine(Properties.Resources.HelpLine15.Replace("\\t", "\t")).AppendLine();
                    stringBuilder.AppendLine(Properties.Resources.HelpLine16.Replace("\\t", "\t")).AppendLine();
                    stringBuilder.AppendLine(Properties.Resources.HelpLine17.Replace("\\t", "\t")).AppendLine();
                    stringBuilder.AppendLine(Properties.Resources.HelpLine18.Replace("\\t", "\t"));
                    MessageBox.Show(stringBuilder.ToString(), GetTitle() + Constants.Space + Constants.EnDash + Constants.Space + Properties.Resources.CaptionHelp, MessageBoxButtons.OK, MessageBoxIcon.Question);
                }
                else if (argumentParser.IsTest)
                {
                    try {
                        Application.Run(new TestForm(args));
                    } catch (Exception exception) {
                        Debug.WriteLine(exception);
                        ErrorLog.WriteLine(exception);
                        MessageBox.Show(exception.Message, GetTitle() + Constants.Space + Constants.EnDash + Constants.Space + Properties.Resources.CaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        MessageBox.Show(Properties.Resources.MessageApplicationError, GetTitle(), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else if (argumentParser.IsThisTest)
                {
                    try {
                        Application.Run(new ArgumentParserForm());
                    } catch (Exception exception) {
                        Debug.WriteLine(exception);
                        ErrorLog.WriteLine(exception);
                        MessageBox.Show(exception.Message, GetTitle() + Constants.Space + Constants.EnDash + Constants.Space + Properties.Resources.CaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        MessageBox.Show(Properties.Resources.MessageApplicationError, GetTitle(), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    try {
                        LauncherAsDate launcherAsDate = new LauncherAsDate()
                        {
                            ApplicationFilePath   = argumentParser.ApplicationFilePath,
                            DateTime              = argumentParser.DateTime.Value,
                            Arguments             = argumentParser.ApplicationArguments,
                            WorkingFolderPath     = argumentParser.WorkingFolderPath,
                            OneInstance           = argumentParser.OneInstance,
                            Interval              = argumentParser.Interval,
                            DisableTimeCorrection = settings.DisableTimeCorrection,
                            ForceTimeCorrection   = settings.ForceTimeCorrection
                        };
                        launcherAsDate.Launch();
                    } catch (Exception exception) {
                        Debug.WriteLine(exception);
                        ErrorLog.WriteLine(exception);
                        MessageBox.Show(exception.Message, GetTitle() + Constants.Space + Constants.EnDash + Constants.Space + Properties.Resources.CaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            else
            {
                try {
                    SingleMainForm.Run(new MainForm(settings));
                } catch (Exception exception) {
                    Debug.WriteLine(exception);
                    ErrorLog.WriteLine(exception);
                    MessageBox.Show(exception.Message, GetTitle() + Constants.Space + Constants.EnDash + Constants.Space + Properties.Resources.CaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    MessageBox.Show(Properties.Resources.MessageApplicationError, GetTitle(), MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }