private void OpenProject(object sender, RoutedEventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.InitialDirectory = Properties.Settings.Default.ProjectsDirectory; dlg.Filter = "Project Files (.xml)|*.xml"; // Filter files by extension if (dlg.ShowDialog() == true) { ProjStruct.ReadProject(dlg.FileName, Path.GetDirectoryName(dlg.FileName)); } }
public MainWindow() { InitializeComponent(); // Create default projects directory if it doesn't exist (yet or was deleted) string projectDir = Properties.Settings.Default.ProjectsDirectory; if (projectDir == "") { Properties.Settings.Default.ProjectsDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\" + Constants.ProjectsFolder; } if (!Directory.Exists(Properties.Settings.Default.ProjectsDirectory)) { Directory.CreateDirectory(Properties.Settings.Default.ProjectsDirectory); } // Add default settings in case of first run if (Properties.Settings.Default.FirstRun) { // Default languages, types and frameworks Properties.Settings.Default.Languages = new List <string>() { "C++", "C#" }; Properties.Settings.Default.Types = new List <List <string> >() { new List <string>() { "Empty", "Console" }, new List <string>() { "Empty", "WPF" } }; Properties.Settings.Default.Frameworks = new List <string>() { "QT", "SDL2", ".NET" }; // Mark first run completed Properties.Settings.Default.FirstRun = false; } // Load settings TextEditor.WordWrap = Properties.Settings.Default.TextWrap; SelectedLayout = Properties.Settings.Default.Layout; // Load cache if (File.Exists(Constants.CacheFile)) { XmlSerializer serializer = new XmlSerializer(typeof(Cache)); using (TextReader reader = new StreamReader(Constants.CacheFile)) { try { Cache cache = (Cache)serializer.Deserialize(reader); List <OpenProject> openProjects = cache.OpenProjects; foreach (var openProj in openProjects) { ProjStruct.ReadProject(openProj.ProjectFileLocation, openProj.Location); } } catch { //TODO Write to pop-up Console.WriteLine("Error! Cache failed deserializing!"); } } } // Start auto-save timer DispatcherTimer dt = new DispatcherTimer() { Interval = TimeSpan.FromSeconds(Properties.Settings.Default.AutoSaveInterval) }; dt.Tick += AutoSave; dt.Start(); }