プリンタの文書名からファイル名として問題ない文字列へ変換するための クラスです。
Beispiel #1
0
        /* ----------------------------------------------------------------- */
        ///
        /// SetupUserSetting
        ///
        /// <summary>
        /// プログラムに指定された引数等を用いて、UserSetting オブジェクトを
        /// 初期化します。
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        private static void SetupUserSetting(UserSetting setting, string[] args)
        {
            var cmdline = new CubePdf.Settings.CommandLine(args);

            var  docname   = cmdline.Options.ContainsKey("DocumentName") ? cmdline.Options["DocumentName"] : "";
            bool is_config = false;

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

            if (is_config)
            {
                setting.Load(docname);
            }
            else
            {
                setting.Load();
                var filename = DocumentName.CreateFileName(docname);
                if (filename != null)
                {
                    string ext = Parameter.Extension((Parameter.FileTypes)setting.FileType);
                    filename = Path.ChangeExtension(filename, ext);
                    string dir = (setting.OutputPath.Length == 0 || Directory.Exists(setting.OutputPath)) ?
                                 setting.OutputPath : Path.GetDirectoryName(setting.OutputPath);
                    setting.OutputPath = dir + '\\' + filename;
                }
            }

            setting.InputPath     = cmdline.Options.ContainsKey("InputFile") ? cmdline.Options["InputFile"] : "";
            setting.DeleteOnClose = cmdline.Options.ContainsKey("DeleteOnClose");
        }
Beispiel #2
0
 public void TestCreateFilename()
 {
     try
     {
         Assert.AreEqual("sample.txt", DocumentName.CreateFileName("sample.txt"));
         Assert.AreEqual("日本語.txt", DocumentName.CreateFileName("日本語.txt"));
         Assert.AreEqual("sample.doc", DocumentName.CreateFileName("Microsoft Word 2010 - sample.doc"));
         Assert.AreEqual("芸能界構わない.doc", DocumentName.CreateFileName("芸能界構わない.doc - Microsoft Word 2020"));
         Assert.AreEqual("無題 - メモ帳", DocumentName.CreateFileName("無題 - メモ帳"));
         Assert.AreEqual("C__folder_to_sample.txt", DocumentName.CreateFileName(@"C:\folder\to\sample.txt"));
         Assert.AreEqual("http___example.com_index.html", DocumentName.CreateFileName(@"http://example.com/index.html"));
         Assert.AreEqual("_foo_bar_bas_hoge__", DocumentName.CreateFileName("<foo?bar:bas|hoge*>"));
         Assert.AreEqual("CubePDF", DocumentName.CreateFileName(string.Empty));
         Assert.AreEqual("CubePDF", DocumentName.CreateFileName(null));
     }
     catch (Exception err)
     {
         Assert.Fail(err.ToString());
     }
 }
Beispiel #3
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");
            }
        }
Beispiel #4
0
 public void TestCreateFilename(string src, string expected)
 {
     try { Assert.AreEqual(expected, DocumentName.CreateFileName(src)); }
     catch (Exception err) { Assert.Fail(err.ToString()); }
 }