public object Clone() { SettingsCore sc = new SettingsCore(); sc.ApplicationSettingsFullPath = this.ApplicationSettingsFullPath; sc.ApplicationSettingsPath = this.ApplicationSettingsPath; sc.ExportCreatePdfFile = this.ExportCreatePdfFile; sc.ExportMarkupInternalFontEffects = this.ExportMarkupInternalFontEffects; sc.ExportPictures = this.ExportPictures; sc.ExportText = this.ExportText; sc.ExportPseudoTranslateFile = this.ExportPseudoTranslateFile; sc.FontFormatTags = new List <FontFormatTag>(); foreach (var fft in this.FontFormatTags) { sc.FontFormatTags.Add((FontFormatTag)fft.Clone()); } sc.ImportCreateBakFile = this.ImportCreateBakFile; sc.ImportCreatePdfFile = this.ImportCreatePdfFile; sc.ImportPictures = this.ImportPictures; sc.ImportText = this.ImportText; sc.PseudoTranslateItems = new List <PseudoTranslateItem>(); foreach (var vtsi in this.PseudoTranslateItems) { sc.PseudoTranslateItems.Add((PseudoTranslateItem)vtsi.Clone()); } return(sc); }
/// <summary> /// Save the settings /// </summary> /// <param name="settings">setting serialized from the caller</param> public static void SaveSettings(SettingsCore settings) { XmlSerializer serializer = null; FileStream stream = null; try { serializer = new XmlSerializer(typeof(SettingsCore)); stream = new FileStream(settings.ApplicationSettingsFullPath, FileMode.Create, FileAccess.Write); serializer.Serialize(stream, settings); } catch (Exception ex) { throw ex; } finally { if (stream != null) { stream.Close(); } } }
/// <summary> /// Export the translatable content from the MS Publisher file /// </summary> /// <param name="pubFilePath">The path to the MS Publisher file that you want to export content</param> /// <param name="xmlFilePath">The path to the XMl file where the exported content will be written to</param> /// <param name="imagePath">The path to the image folder where the images will be written to</param> /// <param name="settings">The settings structure</param> /// <returns>Returns a structure of the epxorted content [ConverterExportPackage]</returns> public ExportPackage Export(string pubFilePath, string xmlFilePath, string imagePath, SettingsCore settings) { Parser.Exporter exporter = new Parser.Exporter(); exporter._onChange_Progress += exporter__onChange_Progress; return(exporter.export(pubFilePath, xmlFilePath, imagePath, settings)); }
/// <summary> /// Import the updated content back into the MS Publisher file /// </summary> /// <param name="xmlFilePath">The path to the xml file containing the updated content</param> /// <param name="pubFilePath">The path to the MS Publisher file that you want to import the content</param> /// <param name="imagePath">The path to the image folder containing the updated images</param> /// <param name="settings">The settings structure</param> /// <returns>Return true if successful; if the result is false, then you can recover the processing error from [ProcessingErrors]</returns> public bool Import(string xmlFilePath, string pubFilePath, string imagePath, SettingsCore settings) { Parser.Importer importer = new Parser.Importer(); importer._onChange_Progress += importer__onChange_Progress; return(importer.Import(xmlFilePath, pubFilePath, imagePath, settings)); }
/// <summary> /// Read in the settings the default location or from the file specified by the user /// </summary> /// <param name="settingFileFullPath">if file exists, then read/save the settings from this location</param> /// <returns>The settings serialzied from the file</returns> public static SettingsCore ReadSettings(string settingFileFullPath = null) { SettingsCore settings = new SettingsCore(); // if the users provided setting file exists, then set the path info if (File.Exists(settingFileFullPath)) { settings.ApplicationSettingsFullPath = settingFileFullPath; settings.ApplicationSettingsPath = Path.GetDirectoryName(settingFileFullPath); } else if (!File.Exists(settings.ApplicationSettingsFullPath)) { // if the first time, then create the settings file in the default location SaveSettings(settings); } XmlSerializer serializer = null; FileStream stream = null; try { serializer = new XmlSerializer(typeof(SettingsCore)); stream = new FileStream(settings.ApplicationSettingsFullPath, FileMode.Open); settings = (SettingsCore)serializer.Deserialize(stream); if (settings == null) { settings = new SettingsCore(); } #region | preset the setting with some defalut settings for VTS and FFT | if (settings.PseudoTranslateItems == null || settings.PseudoTranslateItems.Count == 0) { settings.PseudoTranslateItems = new List <PseudoTranslateItem> { new PseudoTranslateItem { FindWhat = "a", ReplaceWith = "%" }, new PseudoTranslateItem { FindWhat = "e", ReplaceWith = "%" }, new PseudoTranslateItem { FindWhat = "i", ReplaceWith = "%" }, new PseudoTranslateItem { FindWhat = "o", ReplaceWith = "%" }, new PseudoTranslateItem { FindWhat = "u", ReplaceWith = "%" }, new PseudoTranslateItem { FindWhat = "A", ReplaceWith = "$" }, new PseudoTranslateItem { FindWhat = "E", ReplaceWith = "$" }, new PseudoTranslateItem { FindWhat = "I", ReplaceWith = "$" }, new PseudoTranslateItem { FindWhat = "O", ReplaceWith = "$" }, new PseudoTranslateItem { FindWhat = "U", ReplaceWith = "$" } } } ; if (settings.FontFormatTags == null || settings.FontFormatTags.Count == 0) { settings.FontFormatTags = new List <FontFormatTag> { new FontFormatTag { name = "b", formatType = FormattedRange.FormatType.Bold, regexContent = "|.*?" }, new FontFormatTag { name = "i", formatType = FormattedRange.FormatType.Italic, regexContent = "|.*?" }, new FontFormatTag { name = "del", formatType = FormattedRange.FormatType.StrikeThrough, regexContent = "|.*?" }, new FontFormatTag { name = "sup", formatType = FormattedRange.FormatType.SuperScript, regexContent = "|.*?" }, new FontFormatTag { name = "sub", formatType = FormattedRange.FormatType.SubScript, regexContent = "|.*?" }, } } ; #endregion return(settings); } catch (Exception ex) { throw ex; } finally { if (stream != null) { stream.Close(); } } }