private void Open_Click(object sender, RoutedEventArgs e) { if (Project.IsModified) { switch (MessageBox.Show( "You have unsaved changes in this project!\r\nDo you want to save them?", "Confuser", MessageBoxButton.YesNoCancel, MessageBoxImage.Question)) { case MessageBoxResult.Yes: Save_Click(this, new RoutedEventArgs()); break; case MessageBoxResult.No: break; case MessageBoxResult.Cancel: return; } } OpenFileDialog sfd = new OpenFileDialog(); sfd.Filter = "Confuser Project (*.crproj)|*.crproj|All Files (*.*)|*.*"; if (sfd.ShowDialog() ?? false) { try { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(sfd.FileName); ConfuserProject proj = new ConfuserProject(); proj.Load(xmlDoc); Prj prj = new Prj(); prj.FromConfuserProject(proj); prj.FileName = sfd.FileName; Project = prj; foreach (ConfuserTab i in Tab.Items) { i.InitProj(); } prj.PropertyChanged += new PropertyChangedEventHandler(ProjectChanged); prj.IsModified = false; ProjectChanged(Project, new PropertyChangedEventArgs("")); Tab.SelectedIndex = 0; } catch (Exception ex) { MessageBox.Show(string.Format( @"Invalid project file! Message : {0} Stack Trace : {1}", ex.Message, ex.StackTrace), "Confuser", MessageBoxButton.OK, MessageBoxImage.Error); } } }
public void LoadPrj(string path) { if (Project.IsModified) { switch (MessageBox.Show( "You have unsaved changes in this project!\r\nDo you want to save them?", "Confuser", MessageBoxButton.YesNoCancel, MessageBoxImage.Question)) { case MessageBoxResult.Yes: Save_Click(this, new RoutedEventArgs()); break; case MessageBoxResult.No: break; case MessageBoxResult.Cancel: return; } } try { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(path); ConfuserProject proj = new ConfuserProject(); proj.Load(xmlDoc); Prj prj = new Prj(); prj.FileName = path; prj.FromConfuserProject(proj); Project = prj; foreach (ConfuserTab i in Tab.Items) { i.InitProj(); } prj.PropertyChanged += new PropertyChangedEventHandler(ProjectChanged); prj.IsModified = false; ProjectChanged(Project, new PropertyChangedEventArgs("")); Tab.SelectedIndex = 0; } catch (Exception ex) { MessageBox.Show(string.Format( @"Invalid project file! Message : {0} Stack Trace : {1}", ex.Message, ex.StackTrace), "Confuser", MessageBoxButton.OK, MessageBoxImage.Error); } }