private void OpenFile(string fileName) { try { using (Stream stream = File.OpenRead(fileName)) { MainTabControl.Items.Clear(); Stream finstr = null; try { ZipInputStream zipInputStream = new ZipInputStream(stream); ZipEntry zipEntry = zipInputStream.GetNextEntry(); MemoryStream outputStream = new MemoryStream(); if (zipEntry != null) { byte[] buffer = new byte[4096]; StreamUtils.Copy(zipInputStream, outputStream, buffer); } outputStream.Position = 0; finstr = outputStream; } catch { stream.Position = 0; finstr = stream; } XDocument xDoc = XDocument.Load(finstr, LoadOptions.PreserveWhitespace); XElement root = xDoc.Root; XElement formattingElement = root.Element("TextManager"); XAttribute fileVersionAttribute = root.Attributes("fileVersion").FirstOrDefault(); XAttribute 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"); } foreach (XElement rowCont in root.Elements("RowContainer")) { EditorControl newEditorControl = new EditorControl(); //newEditorControl.Background = Transparent; newEditorControl.Focusable = true; //newEditorControl.FocusVisualStyle = "{x:Null}"; newEditorControl.LoadTab(rowCont, formattingElement); newEditorControl.ZoomChanged += new EventHandler(editor_ZoomChanged); newEditorControl.IsVisibleChanged += new DependencyPropertyChangedEventHandler(IsVisibleChanged); ScrollViewer newScrollViewer = new ScrollViewer(); //FocusVisualStyle = "{x:Null}" newScrollViewer.Focusable = true; newScrollViewer.ScrollChanged += scrollViewer_ScrollChanged; newScrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto; newScrollViewer.Content = newEditorControl; TabItem newTabItem = new TabItem(); newTabItem.Content = newScrollViewer; newTabItem.Header = (rowCont.Attribute("Name") != null ? rowCont.Attribute("Name").Value : "Tab " + (MainTabControl.Items.Count + 1)); MainTabControl.Items.Add(newTabItem); } TabItem newTI = new TabItem(); newTI.Header = "+"; MainTabControl.Items.Add(newTI); } currentLocalFile = fileName; } catch (Exception e) { currentLocalFile = ""; MessageBox.Show("File is corrupt or inaccessible OR it was created by an incompatible version of Math Editor.\n\n" + e.ToString(), "Error"); } SetTitle(); }