/// <summary> /// Open the project's settings for use. /// </summary> /// <param name="MAPWfile">Path to the chosen project</param> private void OpenProject(string MAPWfile) { try { string settings_json = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MapWizard", "settings.json"); if (!string.IsNullOrEmpty(MAPWfile) && File.Exists(MAPWfile)) { model.ProjectName = Path.GetFileName(MAPWfile); settingsService.LoadSettings(MAPWfile); string depositType = settingsService.Data.DepositType; // Gets in store the depostitype so it can be later saved into project's MAPW-file. settingsService.LoadSettings(settings_json); // Settings don't have memory of the last deposittype, which is why it have to be saved in store. settingsService.AddToRegistry(MAPWfile); // Save path to the project into registry, this updates recent projects in the mainview. GetRecentProjects(); viewModelLocator.ClearTools(); // Closes all tools, so that the tools can initialized correctly. Does not clear settings. settingsService.Data.RootFolderPath = Path.GetDirectoryName(MAPWfile); // Get location of the project so it can be saved into json file. settingsService.Data.DepositType = depositType; // Get deposittype so it can be saved into json file. settingsService.SaveSettings(settings_json); // Save only the root path and the deposittype into projects json file. Model.ProjectLocation = Directory.GetParent(settingsService.RootPath).ToString(); // Shows the project that is being used in the user interface. viewModelLocator.SettingsViewModel.UpdateSettings(depositType); // Depositype is the only setting that is project specific. mapWizardView = new MapWizardView(); // The view must be initialized again so that it will be updated. ChangeToWizardView(); viewModelLocator.SettingsViewModel.WriteLogText("Project '" + model.ProjectName + "' opened from directory: " + settingsService.Data.RootFolderPath, "Success"); } } catch (Exception ex) { logger.Error(ex, "Failed to open a project"); dialogService.ShowNotification("Failed to open a project.", "Error"); viewModelLocator.SettingsViewModel.WriteLogText("Failed to open a project.", "Error"); } }
/// <summary> /// Initialize a new instance of the MainViewModel class. /// </summary> private void Initialize() { mainWindowView = new OldMainWindowView(); mapWizardView = new MapWizardView(); model = new MainWindowModel(); viewModelLocator = new ViewModelLocator(); activeView = mainWindowView; }