diff --git a/src/App.xaml.cs b/src/App.xaml.cs index c3badbf..d2a9a44 100644 --- a/src/App.xaml.cs +++ b/src/App.xaml.cs @@ -2,7 +2,6 @@ using COMPASS.Interfaces; using COMPASS.Models.Enums; using COMPASS.Services; -using COMPASS.Tools; using COMPASS.ViewModels; using System; using System.IO; @@ -26,10 +25,8 @@ public App() } catch (Exception ex) { - Logger.Error($"Failed to create folder at compass data path, so data cannot be saved", ex); - string msg = $"Failed to create a folder to store user data at {SettingsViewModel.CompassDataPath}, " + - $"please pick a new location to save your data. Creation failed with the following error {ex.Message}"; - IOService.AskNewCodexFilePath(msg); + //Cannot show notification here because app needs to finish its constructor before any UI can be shown, + //Cannot log either because the log file is located in the CompassDataPath directory } } diff --git a/src/ViewModels/CollectionViewModel.cs b/src/ViewModels/CollectionViewModel.cs index 593655e..874d546 100644 --- a/src/ViewModels/CollectionViewModel.cs +++ b/src/ViewModels/CollectionViewModel.cs @@ -40,7 +40,7 @@ public CollectionViewModel(MainViewModel? mainViewModel) { Logger.Error($"Failed to create folder to store user data, so data cannot be saved", ex); string msg = $"Failed to create a folder to store user data at {SettingsViewModel.CompassDataPath}, " + - $"please pick a new location to save your data. Creation failed with the following error {ex.Message}"; + $"please pick a new location to save your data. Creation failed with the following error: '{ex.Message}'"; IOService.AskNewCodexFilePath(msg); } @@ -140,7 +140,7 @@ private void LoadInitialCollection() { Logger.Error($"Failed to create folder to store user data, so data cannot be saved", ex); string msg = $"Failed to create a folder to store user data at {SettingsViewModel.CompassDataPath}, " + - $"please pick a new location to save your data. Creation failed with the following error {ex.Message}"; + $"please pick a new location to save your data. Creation failed with the following error: '{ex.Message}'"; IOService.AskNewCodexFilePath(msg); } } diff --git a/src/ViewModels/SettingsViewModel.cs b/src/ViewModels/SettingsViewModel.cs index 2408888..33a42f0 100644 --- a/src/ViewModels/SettingsViewModel.cs +++ b/src/ViewModels/SettingsViewModel.cs @@ -1,6 +1,8 @@ -using AutoUpdaterDotNET; +using Autofac; +using AutoUpdaterDotNET; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; +using COMPASS.Interfaces; using COMPASS.Models; using COMPASS.Models.CodexProperties; using COMPASS.Models.Enums; @@ -485,12 +487,17 @@ public bool SetNewDataPath(string newPath) NewDataPath = newPath; - //Give users choice between moving or copying + //If there is existing data, Give users choice between moving or copying if (Path.Exists(CompassDataPath)) { ChangeDataLocationWindow window = new(this); window.ShowDialog(); } + //If not, just change over + else + { + ChangeToNewDataPath(); + } return true; } @@ -542,10 +549,13 @@ private async Task CopyToNewDataPath() /// public void ChangeToNewDataPath() { - MainViewModel.CollectionVM.CurrentCollection.Save(); + MainViewModel.CollectionVM?.CurrentCollection.Save(); CompassDataPath = NewDataPath; + Notification changeSuccessful = new("Data path changed succesfully", $"Data path was successfully changed to {CompassDataPath}. COMPASS will now restart."); + App.Container.ResolveKeyed(NotificationDisplayType.Windowed).Show(changeSuccessful); + //Restart COMPASS var currentExecutablePath = Environment.ProcessPath; var args = Environment.GetCommandLineArgs(); diff --git a/src/Windows/MainWindow.xaml.cs b/src/Windows/MainWindow.xaml.cs index 0a18f49..985cd47 100644 --- a/src/Windows/MainWindow.xaml.cs +++ b/src/Windows/MainWindow.xaml.cs @@ -34,7 +34,7 @@ public MainWindow() private void Window_Closing(object sender, CancelEventArgs e) { ProgressViewModel.GetInstance().CancelBackgroundTask(); - MainViewModel.CollectionVM.CurrentCollection.Save(); + MainViewModel.CollectionVM?.CurrentCollection.Save(); PreferencesService.GetInstance().SavePreferences(); }