Ejemplo n.º 1
0
        public void LoadFile(Stream stream)
        {
            UndoManager.ClearAll();
            DeSelect();
            XDocument  xDoc = XDocument.Load(stream, LoadOptions.PreserveWhitespace);
            XElement   root = xDoc.Root;
            XAttribute fileVersionAttribute;
            XAttribute appVersionAttribute;

            if (root.Name == GetType().Name)
            {
                XElement formattingElement = root.Element("TextManager");
                textManager.DeSerialize(formattingElement);
                fileVersionAttribute = root.Attributes("fileVersion").FirstOrDefault();
                appVersionAttribute  = root.Attributes("appVersion").FirstOrDefault();
                root = root.Element("RowContainer");
            }
            else
            {
                fileVersionAttribute = root.Attributes("fileVersion").FirstOrDefault();
                appVersionAttribute  = root.Attributes("appVersion").FirstOrDefault();
            }
            string appVersion = appVersionAttribute != null ? appVersionAttribute.Value : "Unknown";

            if (fileVersionAttribute == null || fileVersionAttribute.Value != fileVersion)
            {
                MessageBox.Show("The file was created by a different version (v." + appVersion + ") of Math Editor and uses a different format." + Environment.NewLine + Environment.NewLine +
                                "Math Editor will still try to open and convert the file to the current version. The operation may fail. " + Environment.NewLine + Environment.NewLine +
                                "Please create a backup if you want to keep the original file intact.", "Message");
            }
            ActiveChild.DeSerialize(root);
            CalculateSize();
            AdjustCarets();
        }