public void TestDefaultSetting() { var setting = new UserSetting(false); Assert.IsTrue(setting.Load(), "Load from registry"); setting.PostProcess = Parameter.PostProcesses.None; ExecConvert(setting, ""); }
static void Main(string[] args) { UserSetting reset = new UserSetting(); reset.Save(); UserSetting setting = new UserSetting(true); setting.Save(); }
public void TestDocument() { var setting = new UserSetting(false); Assert.IsTrue(setting.Load(), "Load from registry"); setting.FileType = Parameter.FileTypes.PDF; setting.PostProcess = Parameter.PostProcesses.None; setting.Document.Title = "テスト"; setting.Document.Author = "株式会社キューブ・ソフト"; setting.Document.Subtitle = "Document property test. 文書プロパティのテスト"; setting.Document.Keyword = "文書プロパティ, テスト, test, documents, CubePDF"; ExecConvert(setting, "-document"); }
/* ----------------------------------------------------------------- */ /// Run /* ----------------------------------------------------------------- */ public bool Run(UserSetting setting) { if (setting.PostProcess == Parameter.PostProcesses.None) return true; try { string path = setting.OutputPath; if (!File.Exists(path)) { path = Path.GetDirectoryName(path) + '\\' + Path.GetFileNameWithoutExtension(path) + "-001" + Path.GetExtension(path); } if (!File.Exists(path)) return true; // 何らかの問題で変換に失敗しているので、スキップする。 if (!IsExecutable(setting)) return false; System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(); System.Diagnostics.Process proc = new System.Diagnostics.Process(); if (setting.PostProcess == Parameter.PostProcesses.Open) { psi.FileName = path; } else { psi.FileName = setting.UserProgram; if (setting.UserArguments.Length > 0) { string replaced = "\"" + path + "\""; psi.Arguments = setting.UserArguments.Replace("%%FILE%%", replaced); } } psi.CreateNoWindow = false; psi.UseShellExecute = true; psi.LoadUserProfile = false; psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; proc.StartInfo = psi; proc.Start(); } catch (Exception err) { _messages.Add(new Message(Message.Levels.Error, err)); _messages.Add(new Message(Message.Levels.Debug, err)); return false; } return true; }
static void Main(string[] args) { var exec = System.Reflection.Assembly.GetEntryAssembly(); var dir = System.IO.Path.GetDirectoryName(exec.Location); var setting = new UserSetting(false); SetupLog(dir + @"\cubepdf.log"); Trace.WriteLine(String.Format("{0} [INFO] CubePDF version {1} ({2})", DateTime.Now.ToString(), setting.Version, ((IntPtr.Size == 4) ? "x86" : "x64"))); Trace.WriteLine(String.Format("{0} [INFO] Arguments", DateTime.Now.ToString())); foreach (var s in args) Trace.WriteLine("\t" + s); SetupUserSetting(setting, args); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm(setting)); Trace.Close(); }
public void TestSaveDefaultValue() { using (var saver = new UserSettingSaver()) { var default_value = new UserSetting(false); Assert.IsTrue(default_value.Save(), "Save to registry"); string desktop = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); var test = new UserSetting(false); Assert.IsTrue(test.Load(), "Load from registry"); // 各種デフォルト値のテスト Assert.AreEqual(desktop, test.OutputPath, "LastAccess"); Assert.AreEqual(desktop, test.InputPath, "LastInputAccess"); Assert.AreEqual("", test.UserProgram, "UserProgram"); Assert.AreEqual("%%FILE%%", test.UserArguments, "UserArguments"); Assert.AreEqual(Parameter.FileTypes.PDF, test.FileType, "FileType"); Assert.AreEqual(Parameter.PDFVersions.Ver1_7, test.PDFVersion, "PDFVersion"); Assert.AreEqual(Parameter.Resolutions.Resolution300, test.Resolution, "Resolution"); Assert.AreEqual(Parameter.ExistedFiles.Overwrite, test.ExistedFile, "ExistedFile"); Assert.AreEqual(Parameter.PostProcesses.Open, test.PostProcess, "PostProcess"); Assert.AreEqual(Parameter.ImageFilters.FlateEncode, test.ImageFilter, "ImageFilter"); Assert.IsTrue(test.PageRotation, "PageRotation"); // ページの自動回転 Assert.IsTrue(test.EmbedFont, "EmbedFont"); // フォントの埋め込み Assert.IsFalse(test.Grayscale, "Grayscale"); // グレースケール Assert.IsFalse(test.WebOptimize, "WebOptimize"); // Web 表示用に最適化 Assert.IsFalse(test.SaveSetting, "SaveSetting"); // 設定を保存する Assert.IsTrue(test.CheckUpdate, "CheckUpdate"); // 起動時にアップデートを確認する Assert.IsFalse(test.AdvancedMode, "AdvancedMode"); // ポストプロセスでユーザ―プログラムを選択可能にする Assert.IsFalse(test.SelectInputFile, "SelectInputFile"); // 入力ファイル欄を表示 Assert.IsFalse(test.DeleteOnClose, "DeleteOnClose"); // 終了時に入力ファイルを消去(レジストリには項目なし) } }
public void TestRegisterUpdateChecker() { using (var saver = new UserSettingSaver()) { var test = new UserSetting(false); Assert.IsTrue(test.Load(), "Load from registry"); test.CheckUpdate = true; Assert.IsTrue(test.Save(), "Save to registry (CheckUpdate = true)"); { var subkey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", false); Assert.IsTrue(subkey != null, @"HKCU\Software\Microsoft\Windows\CurrentVersion\Run"); Assert.IsTrue(subkey.GetValue("cubepdf-checker") != null); } test.CheckUpdate = false; Assert.IsTrue(test.Save(), "Save to registry (CheckUpdate = false)"); { var subkey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", false); Assert.IsTrue(subkey != null, @"HKCU\Software\Microsoft\Windows\CurrentVersion\Run"); Assert.IsTrue(subkey.GetValue("cubepdf-checker") == null); } } }
/* ----------------------------------------------------------------- */ /// /// ConfigImage /// /// <summary> /// bmp, png, jpeg, gif のビットマップ系ファイルに変換するために /// 必要なオプションを設定する. /// </summary> /// /* ----------------------------------------------------------------- */ public void ConfigImage(UserSetting setting, Ghostscript.Converter gs) { gs.AddOption("GraphicsAlphaBits", 4); gs.AddOption("TextAlphaBits", 4); }
/* ----------------------------------------------------------------- */ /// /// UpgradeSetting /// /// <summary> /// 古いバージョンからの以降の場合,レジストリの整合性を取るため /// にアップグレードを行う. /// </summary> /// /* ----------------------------------------------------------------- */ private void UpgradeSetting(UserSetting setting) { string v1 = @"Software\CubePDF"; if (Microsoft.Win32.Registry.CurrentUser.OpenSubKey(v1, false) != null) { setting.UpgradeFromV1(v1); Microsoft.Win32.Registry.CurrentUser.DeleteSubKey(v1, false); } }
/* ----------------------------------------------------------------- */ /// Constructor /* ----------------------------------------------------------------- */ public MainForm(UserSetting setting) { this._setting = setting; this.Initialize(); }
/* ----------------------------------------------------------------- */ /// /// Dispose /// /// <summary> /// レジストリの値をコンストラクタが呼び出された時点に戻す。 /// </summary> /// /* ----------------------------------------------------------------- */ protected virtual void Dispose(bool disposing) { if (!_disposed) { if (disposing) { if (_setting != null) { _setting.Save(); _setting = null; } } } _disposed = true; }
public void TestSaveNotFoundPath() { using (var saver = new UserSettingSaver()) { var test = new UserSetting(false); Assert.IsTrue(test.Load(), "Load from registry"); string not_found = @"C:\404_notfound\foo\bar\bas\foo.txt"; test.OutputPath = not_found; test.InputPath = not_found; Assert.IsTrue(test.Save(), "Save to registry"); Assert.IsTrue(test.Load(), "Load from registry (second)"); Assert.AreEqual(not_found, test.OutputPath, "LastAccess"); Assert.AreEqual(not_found, test.InputPath, "LastInputAccess"); } }
/* ----------------------------------------------------------------- */ /// /// Run /// /// NOTE: 文書プロパティ,パスワード関連とファイル結合は iText /// に任せる.出力パスに指定されたファイルが存在する場合がある. /// そのときは,_setting.ExistedFile の指定に従う. /// ExistedFile: 上書き,先頭に結合,末尾に結合 /// 結合部分は,iText が行う. /// /* ----------------------------------------------------------------- */ public bool Run(UserSetting setting) { // Ghostscript に指定するパスに日本語が入るとエラーが発生する // 場合があるので,作業ディレクトリを変更する. this.CreateWorkingDirectory(setting); Ghostscript.Converter gs = new Ghostscript.Converter(_messages); gs.Device = Parameter.Device(setting.FileType, setting.Grayscale); bool status = true; try { gs.AddInclude(setting.LibPath + @"\lib"); gs.PageRotation = setting.PageRotation; gs.Resolution = Parameter.ResolutionValue(setting.Resolution); this.ConfigImageOperations(setting, gs); if (Parameter.IsImageType(setting.FileType)) this.ConfigImage(setting, gs); else this.ConfigDocument(setting, gs); this.EscapeExistedFile(setting); gs.AddSource(setting.InputPath); gs.Destination = setting.OutputPath; gs.Run(); if (setting.FileType == Parameter.FileTypes.PDF) { PDFModifier modifier = new PDFModifier(_escaped, _messages); status = modifier.Run(setting); _messages.Add(new Message(Message.Levels.Info, String.Format("CubePDF.PDFModifier.Run: {0}", status.ToString()))); } if (status) { PostProcess postproc = new PostProcess(_messages); status = postproc.Run(setting); _messages.Add(new Message(Message.Levels.Info, String.Format("CubePDF.PostProcess.Run: {0}", status.ToString()))); } } catch (Exception err) { _messages.Add(new Message(Message.Levels.Error, err)); _messages.Add(new Message(Message.Levels.Debug, err)); status = false; } finally { if (Directory.Exists(Utility.WorkingDirectory)) Directory.Delete(Utility.WorkingDirectory, true); if (setting.DeleteOnClose && File.Exists(setting.InputPath)) { _messages.Add(new Message(Message.Levels.Debug, String.Format("{0}: delete on close", setting.InputPath))); File.Delete(setting.InputPath); } } return status; }
/* ----------------------------------------------------------------- */ /// /// FileExists /// /// <summary> /// ファイルが存在するかどうかをチェックする.いくつかのファイル /// タイプは,example-001.ext と言うファイル名を生成する場合が /// あるのでそれもチェックする. /// </summary> /// /* ----------------------------------------------------------------- */ public bool FileExists(UserSetting setting) { if (File.Exists(setting.OutputPath)) return true; else if (setting.FileType == Parameter.FileTypes.EPS || setting.FileType == Parameter.FileTypes.BMP || setting.FileType == Parameter.FileTypes.JPEG || setting.FileType == Parameter.FileTypes.PNG || setting.FileType == Parameter.FileTypes.TIFF) { string dir = Path.GetDirectoryName(setting.OutputPath); string basename = Path.GetFileNameWithoutExtension(setting.OutputPath); string ext = Path.GetExtension(setting.OutputPath); if (File.Exists(dir + '\\' + basename + "-001" + ext)) return true; } return false; }
/* ----------------------------------------------------------------- */ /// /// EscapeExistedFile /// /// <summary> /// マージオプションなどの関係で既に存在する同名ファイルを退避 /// させる.リネームの場合は,setting.OutputPath の値を変更する. /// </summary> /// /* ----------------------------------------------------------------- */ public void EscapeExistedFile(UserSetting setting) { if (this.FileExists(setting)) { bool merge = (setting.ExistedFile == Parameter.ExistedFiles.MergeTail || setting.ExistedFile == Parameter.ExistedFiles.MergeHead); if (setting.ExistedFile == Parameter.ExistedFiles.Rename) { string dir = Path.GetDirectoryName(setting.OutputPath); string basename = Path.GetFileNameWithoutExtension(setting.OutputPath); string ext = Path.GetExtension(setting.OutputPath); for (int i = 2; i < 10000; ++i) { setting.OutputPath = dir + '\\' + basename + '(' + i.ToString() + ')' + ext; if (!this.FileExists(setting)) break; } } else if (setting.FileType == Parameter.FileTypes.PDF && merge) { _escaped = Utility.WorkingDirectory + '\\' + Path.GetRandomFileName(); File.Copy(setting.OutputPath, _escaped, true); } } }
/* ----------------------------------------------------------------- */ /// CreateWorkingDirectory /* ----------------------------------------------------------------- */ public void CreateWorkingDirectory(UserSetting setting) { Utility.WorkingDirectory = setting.LibPath + '\\' + Path.GetRandomFileName(); if (File.Exists(Utility.WorkingDirectory)) File.Delete(Utility.WorkingDirectory); if (Directory.Exists(Utility.WorkingDirectory)) Directory.Delete(Utility.WorkingDirectory, true); Directory.CreateDirectory(Utility.WorkingDirectory); }
/* ----------------------------------------------------------------- */ /// /// ConfigPDFX /// /// <summary> /// PDF/X(1-a) の主な要求項目は以下の通り: /// - すべてのイメージのカラーは CMYKか 特色 /// - 基本 14 フォントを含む全てのフォントの埋め込み /// </summary> /// /* ----------------------------------------------------------------- */ public void ConfigPDFX(UserSetting setting, Ghostscript.Converter gs) { gs.AddOption("PDFX"); gs.AddOption("EmbedAllFonts", true); gs.AddOption("SubsetFonts", true); if (setting.Grayscale) { gs.AddOption("ProcessColorModel", "/DeviceGray"); gs.AddOption("ColorConversionStrategy", "/Gray"); } else { gs.AddOption("ProcessColorModel", "/DeviceCMYK"); gs.AddOption("ColorConversionStrategy", "/CMYK"); } gs.AddOption("UseCIEColor"); }
/* ----------------------------------------------------------------- */ /// ConfigPDF /* ----------------------------------------------------------------- */ public void ConfigPDF(UserSetting setting, Ghostscript.Converter gs) { gs.AddOption("CompatibilityLevel", Parameter.PDFVersionValue(setting.PDFVersion)); gs.AddOption("UseFlateCompression", true); if (setting.PDFVersion == Parameter.PDFVersions.VerPDFA) this.ConfigPDFA(setting, gs); else if (setting.PDFVersion == Parameter.PDFVersions.VerPDFX) this.ConfigPDFX(setting, gs); else { if (setting.EmbedFont) { gs.AddOption("EmbedAllFonts", true); gs.AddOption("SubsetFonts", true); } else gs.AddOption("EmbedAllFonts", false); if (setting.Grayscale) { gs.AddOption("ProcessColorModel", "/DeviceGray"); gs.AddOption("ColorConversionStrategy", "/Gray"); } } }
/* ----------------------------------------------------------------- */ /// ConfigImageOperations /* ----------------------------------------------------------------- */ public void ConfigImageOperations(UserSetting setting, Ghostscript.Converter gs) { // 解像度 var resolution = Parameter.ResolutionValue(setting.Resolution); gs.AddOption("ColorImageResolution", resolution); gs.AddOption("GrayImageResolution", resolution); gs.AddOption("MonoImageResolution", (resolution < 300) ? 300 : 1200); // 画像圧縮 gs.AddOption("AutoFilterColorImages", false); gs.AddOption("AutoFilterGrayImages", false); gs.AddOption("AutoFilterMonoImages", false); gs.AddOption("ColorImageFilter", "/" + setting.ImageFilter.ToString()); gs.AddOption("GrayImageFilter", "/" + setting.ImageFilter.ToString()); gs.AddOption("MonoImageFilter", "/" + setting.ImageFilter.ToString()); // ダウンサンプリング if (setting.DownSampling == Parameter.DownSamplings.None) { gs.AddOption("DownsampleColorImages", false); gs.AddOption("DownsampleGrayImages", false); gs.AddOption("DownsampleMonoImages", false); } else { gs.AddOption("DownsampleColorImages", true); gs.AddOption("DownsampleGrayImages", true); gs.AddOption("DownsampleMonoImages", true); gs.AddOption("ColorImageDownsampleType", "/" + setting.DownSampling.ToString()); gs.AddOption("GrayImageDownsampleType", "/" + setting.DownSampling.ToString()); gs.AddOption("MonoImageDownsampleType", "/" + setting.DownSampling.ToString()); } }
public void TestSaveEmptyString() { using (var saver = new UserSettingSaver()) { string dummy = "dummy"; var test = new UserSetting(false); test.InputPath = dummy; test.OutputPath = dummy; test.UserProgram = dummy; test.UserArguments = dummy; Assert.IsTrue(test.Save(), "Save from registry"); Assert.IsTrue(test.Load(), "Load from registry"); Assert.AreEqual(dummy, test.OutputPath, "LastAccess"); Assert.AreEqual(dummy, test.InputPath, "LastInputAccess"); Assert.AreEqual(dummy, test.UserProgram, "UserProgram"); Assert.AreEqual(dummy, test.UserArguments, "UserArguments"); string empty = ""; string desktop = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); test.InputPath = empty; test.OutputPath = empty; test.UserProgram = empty; test.UserArguments = empty; Assert.IsTrue(test.Save(), "Save from registry (second)"); Assert.IsTrue(test.Load(), "Load from registry (second)"); Assert.AreEqual(desktop, test.OutputPath, "LastAccess"); // empty ではない Assert.AreEqual(desktop, test.InputPath, "LastInputAccess"); // empty ではない Assert.AreEqual(empty, test.UserProgram, "UserProgram"); Assert.AreEqual(empty, test.UserArguments, "UserArguments"); } }
public void TestSaveInvalidValue() { using (var saver = new UserSettingSaver()) { try { var subkey = Registry.CurrentUser.OpenSubKey(@"Software\CubeSoft\CubePDF\v2", true); Assert.IsTrue(subkey != null, @"HKCU\Software\CubeSoft\CubePDF\v2"); // コンボボックスの値(ImageFilter のみ GUI 上はチェックボックス) subkey.SetValue("FileType", 256); subkey.SetValue("PDFVersion", 1024); subkey.SetValue("Resolution", 5012); subkey.SetValue("ExistedFile", 8252); subkey.SetValue("PostProcess", 2958739); subkey.SetValue("DownSampling", 493798); subkey.SetValue("ImageFilter", 943724); // チェックボックスの値(正常な値は、0 or 1) subkey.SetValue("PageRotation", 2); subkey.SetValue("EmbedFont", 5); subkey.SetValue("Grayscale", 8); subkey.SetValue("WebOptimize", 12); subkey.SetValue("SaveSetting", 24); subkey.SetValue("CheckUpdate", 32); subkey.SetValue("AdvancedMode", 42); subkey.SetValue("SelectInputFile", 128); } catch (Exception err) { Assert.Fail(err.ToString()); } var test = new UserSetting(false); Assert.IsTrue(test.Load(), "Load from registry"); Assert.AreEqual(Parameter.FileTypes.PDF, test.FileType, "FileType"); Assert.AreEqual(Parameter.PDFVersions.Ver1_7, test.PDFVersion, "PDFVersion"); Assert.AreEqual(Parameter.Resolutions.Resolution300, test.Resolution, "Resolution"); Assert.AreEqual(Parameter.ExistedFiles.Overwrite, test.ExistedFile, "ExistedFile"); Assert.AreEqual(Parameter.PostProcesses.Open, test.PostProcess, "PostProcess"); Assert.AreEqual(Parameter.ImageFilters.FlateEncode, test.ImageFilter, "ImageFilter"); Assert.IsTrue(test.PageRotation, "PageRotation"); Assert.IsTrue(test.EmbedFont, "EmbedFont"); Assert.IsTrue(test.Grayscale, "Grayscale"); Assert.IsTrue(test.WebOptimize, "WebOptimize"); Assert.IsTrue(test.SaveSetting, "SaveSetting"); Assert.IsTrue(test.CheckUpdate, "CheckUpdate"); Assert.IsTrue(test.AdvancedMode, "AdvancedMode"); Assert.IsTrue(test.SelectInputFile, "SelectInputFile"); } }
/* ----------------------------------------------------------------- */ /// /// ConfigDocument /// /// <summary> /// pdf, ps, eps, svg のベクター系ファイルに変換するために必要な /// オプションを設定する. /// </summary> /// /* ----------------------------------------------------------------- */ public void ConfigDocument(UserSetting setting, Ghostscript.Converter gs) { if (setting.FileType == Parameter.FileTypes.PDF) this.ConfigPDF(setting, gs); else { if (setting.EmbedFont) { gs.AddOption("EmbedAllFonts", true); gs.AddOption("SubsetFonts", true); } else gs.AddOption("EmbedAllFonts", false); } }
/* ----------------------------------------------------------------- */ /// Constructor /* ----------------------------------------------------------------- */ public UserSettingSaver() { _setting = new UserSetting(true); }
public void TestWebOptimize() { var setting = new UserSetting(false); Assert.IsTrue(setting.Load(), "Load from registry"); setting.FileType = Parameter.FileTypes.PDF; setting.PostProcess = Parameter.PostProcesses.None; setting.WebOptimize = true; ExecConvert(setting, "-webopt"); }
/* ----------------------------------------------------------------- */ /// /// LoadSetting /// /// <summary> /// UserSetting の情報を各種 GUI コンポーネントに反映する. /// TODO: 仮想プリンタ経由の場合は InputPath にその値を設定する. /// </summary> /// /* ----------------------------------------------------------------- */ private void LoadSetting(UserSetting setting) { this.UserProgramTextBox.Text = setting.UserProgram; this.OutputPathTextBox.Text = setting.OutputPath; this.InputPathTextBox.Text = setting.InputPath; // コンボボックスのインデックス関連 this.FileTypeCombBox.SelectedIndex = Translator.FileTypeToIndex(setting.FileType); this.PDFVersionComboBox.SelectedIndex = Translator.PDFVersionToIndex(setting.PDFVersion); this.ResolutionComboBox.SelectedIndex = Translator.ResolutionToIndex(setting.Resolution); this.ExistedFileComboBox.SelectedIndex = Translator.ExistedFileToIndex(setting.ExistedFile); this.DownSamplingComboBox.SelectedIndex = Translator.DownSamplingToIndex(setting.DownSampling); // チェックボックスのフラグ関連 this.PageLotationCheckBox.Checked = setting.PageRotation; this.EmbedFontCheckBox.Checked = setting.EmbedFont; this.GrayscaleCheckBox.Checked = setting.Grayscale; this.ImageFilterCheckBox.Checked = (setting.ImageFilter == Parameter.ImageFilters.DCTEncode) ? true : false; this.WebOptimizeCheckBox.Checked = setting.WebOptimize; this.SaveSettingCheckBox.Checked = setting.SaveSetting; this.UpdateCheckBox.Checked = setting.CheckUpdate; // ポストプロセス関連 _postproc = setting.AdvancedMode ? this.PostProcessComboBox : this.PostProcessLiteComboBox; _postproc.SelectedIndex = Translator.PostProcessToIndex(setting.PostProcess); this.PostProcessPanel.Enabled = setting.AdvancedMode; this.PostProcessPanel.Visible = setting.AdvancedMode; this.PostProcessLabel.Visible = setting.AdvancedMode; this.PostProcessLiteComboBox.Enabled = !setting.AdvancedMode; this.PostProcessLiteComboBox.Visible = !setting.AdvancedMode; this.PostProcessLiteLabel.Visible = !setting.AdvancedMode; // 入力パスを選択可能にするかどうか this.InputPathLabel.Visible = setting.SelectInputFile; this.InputPathPanel.Visible = setting.SelectInputFile; this.InputPathPanel.Enabled = setting.SelectInputFile && setting.InputPath.Length == 0; // ログ出力 _messages.Add(new Message(Message.Levels.Debug, "CubePDF.MainForm.LoadSetting")); _messages.Add(new Message(Message.Levels.Debug, setting.ToString())); }
public void TestDeleteStringValue() { using (var saver = new UserSettingSaver()) { // 値をレジストリ操作で無理やり消す。 try { var subkey = Registry.CurrentUser.OpenSubKey(@"Software\CubeSoft\CubePDF\v2", true); Assert.IsTrue(subkey != null, @"HKCU\Software\CubeSoft\CubePDF\v2"); subkey.DeleteValue("LastAccess", false); subkey.DeleteValue("LastInputAccess", false); subkey.DeleteValue("UserProgram", false); subkey.DeleteValue("UserArguments", false); } catch (Exception err) { Assert.Fail(err.ToString()); } string desktop = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); var test = new UserSetting(false); Assert.IsTrue(test.Load(), "Load from registry (second)"); Assert.AreEqual(desktop, test.OutputPath, "LastAccess"); Assert.AreEqual(desktop, test.InputPath, "LastInputAccess"); Assert.AreEqual("", test.UserProgram, "UserProgram"); Assert.AreEqual("%%FILE%%", test.UserArguments, "UserArguments"); } }
/* ----------------------------------------------------------------- */ /// /// SaveSetting /// /// <summary> /// 各種 GUI コンポーネントの情報を UserSetting に反映する. /// 仮想プリンタ経由など tmp パスが入力パスのテキストボックスに /// 設定されている場合,save_input を false にして反映しない /// ようにする. /// </summary> /// /* ----------------------------------------------------------------- */ private void SaveSetting(UserSetting setting, bool save_input) { setting.OutputPath = this.OutputPathTextBox.Text; if (save_input) setting.InputPath = this.InputPathTextBox.Text; setting.UserProgram = this.UserProgramTextBox.Text; // コンボボックスのインデックス関連 setting.FileType = Translator.IndexToFileType(this.FileTypeCombBox.SelectedIndex); setting.PDFVersion = Translator.IndexToPDFVersion(this.PDFVersionComboBox.SelectedIndex); setting.Resolution = Translator.IndexToResolution(this.ResolutionComboBox.SelectedIndex); setting.ExistedFile = Translator.IndexToExistedFile(this.ExistedFileComboBox.SelectedIndex); setting.PostProcess = Translator.IndexToPostProcess(_postproc.SelectedIndex); setting.DownSampling = Translator.IndexToDownSampling(this.DownSamplingComboBox.SelectedIndex); // チェックボックスのフラグ関連 setting.PageRotation = this.PageLotationCheckBox.Checked; setting.EmbedFont = this.EmbedFontCheckBox.Checked; setting.Grayscale = this.GrayscaleCheckBox.Checked; setting.ImageFilter = this.ImageFilterCheckBox.Checked ? Parameter.ImageFilters.DCTEncode : Parameter.ImageFilters.FlateEncode; setting.WebOptimize = this.WebOptimizeCheckBox.Checked; setting.SaveSetting = this.SaveSettingCheckBox.Checked; setting.CheckUpdate = this.UpdateCheckBox.Checked; // 文書プロパティ setting.Document.Title = this.DocTitleTextBox.Text; setting.Document.Author = this.DocAuthorTextBox.Text; setting.Document.Subtitle = this.DocSubtitleTextBox.Text; setting.Document.Keyword = this.DocKeywordTextBox.Text; // パスワード if (this.OwnerPasswordCheckBox.Checked) { setting.Permission.Password = String.Copy(this.OwnerPasswordTextBox.Text); setting.Permission.AllowPrint = this.AllowPrintCheckBox.Checked; setting.Permission.AllowCopy = this.AllowCopyCheckBox.Checked; setting.Permission.AllowFormInput = this.AllowFormInputCheckBox.Checked; setting.Permission.AllowModify = this.AllowModifyCheckBox.Checked; if (this.RequiredUserPasswordCheckBox.Checked) { setting.Password = String.Copy(this.UserPasswordCheckBox.Checked ? this.UserPasswordTextBox.Text : this.OwnerPasswordTextBox.Text); } } // ログ出力 _messages.Add(new Message(Message.Levels.Debug, "CubePDF.MainForm.SaveSetting")); _messages.Add(new Message(Message.Levels.Debug, setting.ToString())); }
public void TestLoadValue() { try { var load_from_constructor = new UserSetting(true); load_from_constructor = null; var load_from_method = new UserSetting(false); Assert.IsTrue(load_from_method.Load(), "Load from registry"); load_from_method = null; } catch (Exception err) { Assert.Fail(err.ToString()); } }
/* ----------------------------------------------------------------- */ /// SetupUserSetting /* ----------------------------------------------------------------- */ private static void SetupUserSetting(UserSetting setting, string[] args) { var cmdline = new CommandLine(args); var docname = cmdline.Arguments.ContainsKey("DocumentName") ? cmdline.Arguments["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 のファイル名に使用できない記号が含まれる // 場合に例外が送出されるので、その対策。 is_config = false; } if (is_config) setting.Load(docname); else { setting.Load(); var filename = FileNameModifier.GetFileName(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.Arguments.ContainsKey("InputFile") ? cmdline.Arguments["InputFile"] : ""; setting.DeleteOnClose = cmdline.Arguments.ContainsKey("DeleteOnClose"); }
/* ----------------------------------------------------------------- */ /// /// ExecConvert /// /// <summary> /// examples に存在する *.ps ファイルに対して Converter.Run /// を実行し,生成されたファイルを results ディレクトリに保存する。 /// </summary> /// /* ----------------------------------------------------------------- */ private void ExecConvert(UserSetting setting, string suffix) { string output = System.Environment.CurrentDirectory + "\\results"; if (!System.IO.Directory.Exists(output)) System.IO.Directory.CreateDirectory(output); foreach (string file in Directory.GetFiles("examples", "*.ps")) { string filename = Path.GetFileNameWithoutExtension(file); string extension = Parameter.Extension((Parameter.FileTypes)setting.FileType); setting.InputPath = Path.GetFullPath(file); setting.OutputPath = output + '\\' + filename + suffix + extension; if (File.Exists(setting.OutputPath) && setting.ExistedFile == Parameter.ExistedFiles.Overwrite) { File.Delete(setting.OutputPath); } var converter = new Converter(); Assert.IsTrue(converter.Run(setting), String.Format("Converter.Run() failed. source file: {0}", file)); bool status = File.Exists(setting.OutputPath); if (!status) { string tmp = String.Format("{0}\\{1}-001{2}", Path.GetDirectoryName(setting.OutputPath), Path.GetFileNameWithoutExtension(setting.OutputPath), Path.GetExtension(setting.OutputPath) ); status = File.Exists(tmp); Assert.IsTrue(status, String.Format("{0}: file not found", setting.OutputPath)); } } }