GetExtension() 공개 정적인 메소드

ファイル形式に対応する拡張子を取得します。
public static GetExtension ( FileTypes id ) : string
id FileTypes
리턴 string
예제 #1
0
        /* ----------------------------------------------------------------- */
        ///
        /// AssertRun
        ///
        /// <summary>
        /// Converter クラスの実行をチェックします。
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        private void AssertRun(UserSetting setting, string suffix)
        {
            var basename  = IoEx.Path.GetFileNameWithoutExtension(setting.InputPath);
            var extension = Parameter.GetExtension((Parameter.FileTypes)setting.FileType);

            setting.LibPath    = IoEx.Path.Combine(_root, "Ghostscript");
            setting.OutputPath = IoEx.Path.Combine(_results, basename + suffix + extension);
            if (setting.ExistedFile == Parameter.ExistedFiles.Overwrite)
            {
                IoEx.File.Delete(setting.OutputPath);
            }

            var converter = new Converter();

            converter.Run(setting);
            var error = GetErrorMessage(converter);

            Assert.IsTrue(string.IsNullOrEmpty(error), string.Format("{0}:{1}", setting.InputPath, error));
            if (!IoEx.File.Exists(setting.OutputPath))
            {
                var dest = String.Format("{0}\\{1}-001{2}",
                                         IoEx.Path.GetDirectoryName(setting.OutputPath),
                                         IoEx.Path.GetFileNameWithoutExtension(setting.OutputPath),
                                         IoEx.Path.GetExtension(setting.OutputPath)
                                         );
                Assert.IsTrue(IoEx.File.Exists(dest), setting.OutputPath);
            }
            else if (setting.FileType == Parameter.FileTypes.PDF)
            {
                AssertPdf(setting);
            }
        }
예제 #2
0
        /* ----------------------------------------------------------------- */
        ///
        /// OutputPathButton_Click
        ///
        /// <summary>
        /// 出力先ファイルのボタンが押下された時に実行されるイベントハンドラ
        /// です。ファイル保存ダイアログを表示します。
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        private void OutputPathButton_Click(object sender, EventArgs e)
        {
            var dialog = new SaveFileDialog();

            dialog.AddExtension = true;
            dialog.FileName     = !string.IsNullOrEmpty(OutputPathTextBox.Text) ?
                                  IoEx.Path.GetFileNameWithoutExtension(OutputPathTextBox.Text) :
                                  IoEx.Path.GetFileNameWithoutExtension(InputPathTextBox.Text);
            dialog.Filter          = Properties.Resources.OutputPathFilter;
            dialog.FilterIndex     = FileTypeCombBox.SelectedIndex + 1;
            dialog.OverwritePrompt = false;
            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            if (dialog.FilterIndex != 0 && dialog.FilterIndex - 1 != FileTypeCombBox.SelectedIndex)
            {
                FileTypeCombBox.SelectedIndex = dialog.FilterIndex - 1;
            }

            // 拡張子が選択されているファイルタイプと異なる場合は、末尾に拡張子を追加する。
            var extension = IoEx.Path.GetExtension(OutputPathTextBox.Text);
            var type      = Translator.ToFileType(FileTypeCombBox.SelectedIndex);
            var compared  = Parameter.GetExtension(type);

            OutputPathTextBox.Text = dialog.FileName;
            if (extension != compared)
            {
                OutputPathTextBox.Text += compared;
            }
            SettingChanged(sender, e);
        }
예제 #3
0
        /* ----------------------------------------------------------------- */
        ///
        /// IsValidOutput
        ///
        /// <summary>
        /// 出力先パスが正しいかどうかをチェックします。出力先パスが指定
        /// されていない場合はエラーメッセージを表示します。また、指定された
        /// 出力先パスが既に存在する場合には確認ダイアログを表示します。
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        private bool IsValidOutput(int do_existed_file)
        {
            if (string.IsNullOrEmpty(OutputPathTextBox.Text))
            {
                ShowMessage(new CubePdf.Message(Message.Levels.Error, Properties.Resources.FileNotSpecified));
                return(false);
            }

            var extension = IoEx.Path.GetExtension(OutputPathTextBox.Text);
            var compared  = Parameter.GetExtension(Translator.ToFileType(FileTypeCombBox.SelectedIndex));

            if (extension != compared)
            {
                OutputPathTextBox.Text += compared;
            }

            // パスは 260 文字未満、ディレクトリ名は 248 文字未満と言う Windows パス制限のチェック
            if (OutputPathTextBox.TextLength >= 260 ||
                IoEx.Path.GetDirectoryName(OutputPathTextBox.Text).Length >= 248)
            {
                ShowMessage(new CubePdf.Message(Message.Levels.Error, Properties.Resources.TooLongFilenam));
                return(false);
            }

            if (IoEx.File.Exists(OutputPathTextBox.Text) &&
                Translator.ToExistedFile(ExistedFileComboBox.SelectedIndex) != Parameter.ExistedFiles.Rename)
            {
                var message = new CubePdf.Message(Message.Levels.Warn, string.Format(Properties.Resources.FileExists,
                                                                                     OutputPathTextBox.Text, Appearance.GetString((Parameter.ExistedFiles)do_existed_file)));
                return(ShowMessage(message, MessageBoxButtons.OKCancel) != DialogResult.Cancel);
            }
            else
            {
                return(true);
            }
        }
예제 #4
0
        /* ----------------------------------------------------------------- */
        ///
        /// SetupUserSetting
        ///
        /// <summary>
        /// プログラムに指定された引数等を用いて、UserSetting オブジェクトを
        /// 初期化します。
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        private static void SetupUserSetting(UserSetting setting, CubePdf.Settings.CommandLine cmdline)
        {
            var  docname   = cmdline.Options.ContainsKey("DocumentName") ? cmdline.Options["DocumentName"] : "";
            bool is_config = false;

            try
            {
                if (!string.IsNullOrEmpty(docname) &&
                    IoEx.Path.GetExtension(docname) == setting.Extension &&
                    IoEx.File.Exists(docname))
                {
                    is_config = true;
                }
            }
            catch (Exception err)
            {
                // docname に Windows のファイル名に使用できない記号が含まれる
                // 場合に例外が送出されるので、その対策。
                CubePdf.Message.Trace(err.ToString());
                is_config = false;
            }

            if (is_config)
            {
                setting.LoadXml(docname);
            }
            else
            {
                LoadUserSetting(setting, cmdline);
                var filename = DocumentName.CreateFileName(docname);
                if (filename != null)
                {
                    string ext = Parameter.GetExtension((Parameter.FileTypes)setting.FileType);
                    filename = IoEx.Path.ChangeExtension(filename, ext);
                    string dir = "";
                    if (setting.OutputPath == String.Empty)
                    {
                        dir = setting.LibPath;
                    }
                    else
                    {
                        dir = (IoEx.Directory.Exists(setting.OutputPath)) ?
                              setting.OutputPath : IoEx.Path.GetDirectoryName(setting.OutputPath);
                    }
                    setting.OutputPath = dir + '\\' + filename;
                    CubePdf.Message.Debug(setting.OutputPath);
                }
            }

            setting.UserName      = cmdline.Options.ContainsKey("UserName") ? cmdline.Options["UserName"] : "";
            setting.InputPath     = cmdline.Options.ContainsKey("InputFile") ? cmdline.Options["InputFile"] : "";
            setting.DeleteOnClose = cmdline.Options.ContainsKey("DeleteOnClose");

            if (IoEx.Directory.Exists(setting.LibPath))
            {
                System.Environment.SetEnvironmentVariable("TEMP", setting.LibPath, EnvironmentVariableTarget.Process);
            }
            else
            {
                CubePdf.Message.Trace("LibPath Not Found");
            }
        }
예제 #5
0
        /* ----------------------------------------------------------------- */
        ///
        /// FileTypeCombBox_SelectedIndexChanged
        ///
        /// <summary>
        /// ファイルの種類が変更された時に実行されるイベントハンドラです。
        /// 変換するファイルの種類によって無効なオプションがあるため、
        /// 有効/無効を切り替えます。
        /// </summary>
        ///
        /// <remarks>
        /// ファイルタイプに依存するオプションは以下の通りです。
        ///
        /// PDF, PS, EPS: フォントの埋め込み
        /// PDF: バージョン、 文書プロパティ、セキュリティ、Web 最適化
        ///
        /// 尚、Ghostscript のバグで現在のところ PS, EPS は
        /// グレースケール設定ができないようです。また,フォント埋め込みを
        /// 無効にすると文字化けが発生するので、暫定的に強制無効設定にして
        /// います。
        /// </remarks>
        ///
        /* ----------------------------------------------------------------- */
        private void FileTypeCombBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            var control = sender as ComboBox;

            if (control == null)
            {
                return;
            }

            var id         = Translator.ToFileType(control.SelectedIndex);
            var ispdf      = (id == Parameter.FileTypes.PDF);
            var isbmp      = (id == Parameter.FileTypes.BMP || id == Parameter.FileTypes.JPEG || id == Parameter.FileTypes.PNG || id == Parameter.FileTypes.TIFF);
            var isweb      = WebOptimizeCheckBox.Checked;
            var issecurity = (RequiredUserPasswordCheckBox.Checked || OwnerPasswordCheckBox.Checked);

            PdfVersionComboBox.Enabled  = ispdf;
            DocPanel.Enabled            = ispdf;
            SecurityGroupBox.Enabled    = ispdf && !isweb;
            EmbedFontCheckBox.Enabled   = false; //!is_bitmap;
            ImageFilterCheckBox.Enabled = !isbmp;
            WebOptimizeCheckBox.Enabled = ispdf && !issecurity;

            // 出力パスの拡張子を変更後のファイルタイプに合わせる.
            if (!string.IsNullOrEmpty(OutputPathTextBox.Text))
            {
                OutputPathTextBox.Text = IoEx.Path.ChangeExtension(OutputPathTextBox.Text, Parameter.GetExtension(id));
            }
            SettingChanged(sender, e);
        }