Example #1
0
        /// <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());
        }
Example #2
0
        /// <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);
        }
Example #3
0
        /// <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);
        }
Example #4
0
        /// <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);
            }
        }
Example #5
0
        /// <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);
            }
        }
Example #6
0
        /// <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();
        }
Example #7
0
        /// <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());
        }
Example #8
0
 /// <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);
 }
Example #9
0
        /// <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);
        }
Example #10
0
 /// <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();
 }
Example #11
0
 /// <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();
 }
Example #12
0
 /// <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);
 }