コード例 #1
0
        private void ButtonOK_Click(object sender, EventArgs e)
        {
            var args = ApplyToArgument();

            // validation
            if (args.FleetIDs == null || args.FleetIDs.Length == 0)
            {
                MessageBox.Show("出力する艦隊が指定されていません。", "入力値エラー", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                args.DisposeResources();
                return;
            }

            if (args.HorizontalFleetCount <= 0 || args.HorizontalShipCount <= 0)
            {
                MessageBox.Show("艦隊・艦船の横幅は 1 以上にしてください。", "入力値エラー", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                args.DisposeResources();
                return;
            }

            if (args.Fonts.Any(f => f == null))
            {
                MessageBox.Show("未入力・不正なフォントが存在します。", "入力値エラー", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                args.DisposeResources();
                return;
            }

            if (!OutputToClipboard.Checked)
            {
                if (string.IsNullOrWhiteSpace(OutputPath.Text))
                {
                    MessageBox.Show("出力先ファイル名が入力されていません。", "入力値エラー", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    args.DisposeResources();
                    return;
                }

                if (OutputPath.Text.ToCharArray().Intersect(Path.GetInvalidPathChars()).Any())
                {
                    MessageBox.Show("出力先に使用できない文字が含まれています。", "入力値エラー", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    args.DisposeResources();
                    return;
                }

                if (!DisableOverwritePrompt.Checked && File.Exists(OutputPath.Text))
                {
                    if (MessageBox.Show(Path.GetFileName(OutputPath.Text) + "\r\nは既に存在します。\r\n上書きしますか?", "上書き確認",
                                        MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2)
                        == System.Windows.Forms.DialogResult.No)
                    {
                        args.DisposeResources();
                        return;
                    }
                }
            }

            int mode;

            if (ImageTypeCard.Checked)
            {
                mode = 0;
            }
            else if (ImageTypeCutin.Checked)
            {
                mode = 1;
            }
            else if (ImageTypeBanner.Checked)
            {
                mode = 2;
            }
            else
            {
                mode = 0;
            }


            try {
                if (!OutputToClipboard.Checked)
                {
                    using (var image = GenerateFleetImage(args, mode)) {
                        if (!Directory.Exists(Path.GetDirectoryName(OutputPath.Text)))
                        {
                            Directory.CreateDirectory(Path.GetDirectoryName(OutputPath.Text));
                        }

                        switch (Path.GetExtension(OutputPath.Text).ToLower())
                        {
                        case ".png":
                        default:
                            image.Save(OutputPath.Text, System.Drawing.Imaging.ImageFormat.Png);
                            break;

                        case ".bmp":
                        case ".dib":
                            image.Save(OutputPath.Text, System.Drawing.Imaging.ImageFormat.Bmp);
                            break;

                        case ".gif":
                            image.Save(OutputPath.Text, System.Drawing.Imaging.ImageFormat.Gif);
                            break;

                        case ".tif":
                        case ".tiff":
                            image.Save(OutputPath.Text, System.Drawing.Imaging.ImageFormat.Tiff);
                            break;

                        case ".jpg":
                        case ".jpeg":
                        case ".jpe":
                        case ".jfif": {
                            // jpeg quality settings
                            var encoderParams = new System.Drawing.Imaging.EncoderParameters();
                            encoderParams.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 90L);

                            var codecInfo = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders().FirstOrDefault(codec => codec.MimeType == "image/jpeg");

                            image.Save(OutputPath.Text, codecInfo, encoderParams);
                        } break;
                        }

                        if (OpenImageAfterOutput.Checked)
                        {
                            System.Diagnostics.Process.Start(OutputPath.Text);
                        }
                    }
                }
                else
                {
                    using (var image = GenerateFleetImage(args, mode)) {
                        Clipboard.SetImage(image);
                    }
                }



                if (CurrentArgument != null)
                {
                    CurrentArgument.DisposeResources();
                }
                CurrentArgument = args;
                SaveConfiguration();

                Utility.Logger.Add(2, "編成画像を出力しました。");
            } catch (Exception ex) {
                ErrorReporter.SendErrorReport(ex, "編成画像の出力に失敗しました。");
                MessageBox.Show("編成画像の出力に失敗しました。\r\n" + ex.GetType().Name + "\r\n" + ex.Message, "編成画像出力失敗", MessageBoxButtons.OK, MessageBoxIcon.Error);
            } finally {
                args.DisposeResources();
            }


            Close();
        }
コード例 #2
0
        private void ButtonOK_Click(object sender, EventArgs e)
        {
            var args = ApplyToArgument();

            // validation
            if (args.FleetIDs == null || args.FleetIDs.Length == 0)
            {
                MessageBox.Show("Please select a fleet to export.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                args.DisposeResources();
                return;
            }

            if (args.HorizontalFleetCount <= 0 || args.HorizontalShipCount <= 0)
            {
                MessageBox.Show("The fleet must contain at least 1 ship.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                args.DisposeResources();
                return;
            }

            if (args.Fonts.Any(f => f == null))
            {
                MessageBox.Show("The specified font does not exists.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                args.DisposeResources();
                return;
            }

            if (!OutputToClipboard.Checked)
            {
                if (string.IsNullOrWhiteSpace(OutputPath.Text))
                {
                    MessageBox.Show("Please enter the destination path.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    args.DisposeResources();
                    return;
                }

                if (OutputPath.Text.ToCharArray().Intersect(Path.GetInvalidPathChars()).Any())
                {
                    MessageBox.Show("The destination path contains invalid characters.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    args.DisposeResources();
                    return;
                }

                if (!DisableOverwritePrompt.Checked && File.Exists(OutputPath.Text))
                {
                    if (MessageBox.Show(Path.GetFileName(OutputPath.Text) + " already exists.\r\nDo you want to replace it?", "Overwrite Confirmation",
                                        MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2)
                        == System.Windows.Forms.DialogResult.No)
                    {
                        args.DisposeResources();
                        return;
                    }
                }
            }

            int mode;

            if (ImageTypeCard.Checked)
            {
                mode = 0;
            }
            else if (ImageTypeCutin.Checked)
            {
                mode = 1;
            }
            else if (ImageTypeBanner.Checked)
            {
                mode = 2;
            }
            else
            {
                mode = 3;
            }


            try
            {
                if (!OutputToClipboard.Checked)
                {
                    using (var image = GenerateFleetImage(args, mode))
                    {
                        if (!Directory.Exists(Path.GetDirectoryName(OutputPath.Text)))
                        {
                            Directory.CreateDirectory(Path.GetDirectoryName(OutputPath.Text));
                        }

                        switch (Path.GetExtension(OutputPath.Text).ToLower())
                        {
                        case ".png":
                        default:
                            image.Save(OutputPath.Text, System.Drawing.Imaging.ImageFormat.Png);
                            break;

                        case ".bmp":
                        case ".dib":
                            image.Save(OutputPath.Text, System.Drawing.Imaging.ImageFormat.Bmp);
                            break;

                        case ".gif":
                            image.Save(OutputPath.Text, System.Drawing.Imaging.ImageFormat.Gif);
                            break;

                        case ".tif":
                        case ".tiff":
                            image.Save(OutputPath.Text, System.Drawing.Imaging.ImageFormat.Tiff);
                            break;

                        case ".jpg":
                        case ".jpeg":
                        case ".jpe":
                        case ".jfif":
                        {
                            // jpeg quality settings
                            var encoderParams = new System.Drawing.Imaging.EncoderParameters();
                            encoderParams.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 90L);

                            var codecInfo = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders().FirstOrDefault(codec => codec.MimeType == "image/jpeg");

                            image.Save(OutputPath.Text, codecInfo, encoderParams);
                        }
                        break;
                        }

                        if (OpenImageAfterOutput.Checked)
                        {
                            System.Diagnostics.Process.Start(OutputPath.Text);
                        }
                    }
                }
                else
                {
                    using (var image = GenerateFleetImage(args, mode))
                    {
                        Clipboard.SetImage(image);
                    }
                }



                if (CurrentArgument != null)
                {
                    CurrentArgument.DisposeResources();
                }
                CurrentArgument = args;
                SaveConfiguration();

                Utility.Logger.Add(2, "Fleet image exported successfully.");
            }
            catch (Exception ex)
            {
                ErrorReporter.SendErrorReport(ex, "Failed to export fleet image.");
                MessageBox.Show("Failed to export fleet image.\r\n" + ex.GetType().Name + "\r\n" + ex.Message, "Export Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                args.DisposeResources();
            }


            Close();
        }