/// <summary> /// Reads stream and returns features file in XML format. /// </summary> /// <param name="stream"></param> /// <returns></returns> /// <exception cref="EndOfStreamException"></exception> /// <exception cref="NotSupportedException"></exception> public static string CompiledToXml(Stream stream) { var ff = new FeaturesFile(); ff.LoadFromCompiled(stream); return(ff.GetXml()); }
/// <summary> /// Writes XML to stream in compiled format. /// </summary> /// <param name="xmlStream"></param> /// <param name="compiledStream"></param> public static void SaveXmlAsCompiled(string xml, Stream compiledStream) { var ff = new FeaturesFile(); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(xml))) ff.LoadFromXml(ms); ff.SaveAsCompiled(compiledStream); }
/// <summary> /// Saves given XML file at path in compiled format. /// </summary> /// <param name="filePath"></param> /// <returns></returns> public static void SaveCompiledFromXml(string filePath, string xml) { var ff = new FeaturesFile(); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(xml))) ff.LoadFromXml(ms); ff.SaveAsCompiled(filePath); }
/// <summary> /// Updates feature names list. /// </summary> private void UpdateFeatureNames() { var featuresPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "features.txt"); if (File.Exists(featuresPath)) { FeaturesFile.LoadFeatureNames(featuresPath); } }
/// <summary> /// Tries to open compiled XML file at the given path in the editor. /// </summary> /// <param name="filePath"></param> private void OpenFile(string filePath) { // Check file's existence if (!File.Exists(filePath)) { MessageBox.Show("File not found: " + filePath, _windowTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Check file extension if (!Path.GetFileName(filePath).EndsWith(".xml.compiled")) { MessageBox.Show("Unknown file type, expected: *.xml.compiled", _windowTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Read file try { string xml; using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) xml = FeaturesFile.CompiledToXml(fs); this.TxtEditor.Text = xml; this.Text = _windowTitle + " - " + filePath; _openedFilePath = filePath; var known = Regex.Matches(xml, @"Name=""[^\?\""]+""").Count; var total = Regex.Matches(xml, @"Name=""").Count; this.LblKnownFeatureCount.Text = string.Format("Known features: {0}/{1}", known, total); _fileChanged = false; this.ResetUndo(); this.UpdateSaveButtons(); this.UpdateFeatureList(); } catch (InvalidDataException) { MessageBox.Show("Invalid file format.", _windowTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (EndOfStreamException) { MessageBox.Show("Corrupted file.", _windowTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (NotSupportedException) { MessageBox.Show("Unsupported file.", _windowTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message, _windowTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Creates new instance. /// </summary> public FrmMain() { this.InitializeComponent(); this.SetUpEditor(); var featuresPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "features.txt"); if (File.Exists(featuresPath)) { FeaturesFile.LoadFeatureNames(featuresPath); } _windowTitle = Text; this.LblKnownFeatureCount.Text = ""; this.ToolStrip.Renderer = new MySR(); this.UpdateSaveButtons(); }
/// <summary> /// Returns compiled features file in XML format. /// </summary> /// <param name="filePath"></param> /// <returns></returns> public static string GetXmlFromCompiled(string filePath) { var ff = new FeaturesFile(filePath); return(ff.GetXml()); }
/// <summary> /// Returns compiled features file in XML format. /// </summary> /// <param name="filePath"></param> /// <returns></returns> public static void SaveCompiledFromXml(string filePath, string xml) { var ff = new FeaturesFile(); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(xml))) ff.LoadFromXml(ms); ff.SaveAsCompiled(filePath); }
/// <summary> /// Returns compiled features file in XML format. /// </summary> /// <param name="filePath"></param> /// <returns></returns> public static string GetXmlFromCompiled(string filePath) { var ff = new FeaturesFile(filePath); return ff.GetXml(); }
/// <summary> /// Reads stream and returns features file in XML format. /// </summary> /// <param name="stream"></param> /// <returns></returns> /// <exception cref="EndOfStreamException"></exception> /// <exception cref="NotSupportedException"></exception> public static string CompiledToXml(Stream stream) { var ff = new FeaturesFile(); ff.LoadFromCompiled(stream); return ff.GetXml(); }
/// <summary> /// Saves file to given path. /// </summary> /// <param name="filePath"></param> private void SaveFile(string filePath) { using (var fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)) FeaturesFile.SaveXmlAsCompiled(TxtEditor.Text, fs); }