diff --git a/src/PicView.Core/Config/AppSettings.cs b/src/PicView.Core/Config/AppSettings.cs index 78b5ae91..d582de76 100644 --- a/src/PicView.Core/Config/AppSettings.cs +++ b/src/PicView.Core/Config/AppSettings.cs @@ -15,8 +15,8 @@ public class AppSettings public class WindowProperties { - public double Top { get; set; } = 150; - public double Left { get; set; } = 200; + public double Top { get; set; } = 0; + public double Left { get; set; } = 0; public double Width { get; set; } = 750; public double Height { get; set; } = 1024; public bool AutoFit { get; set; } = false; diff --git a/src/PicView.Core/Config/SettingsHelper.cs b/src/PicView.Core/Config/SettingsHelper.cs index 36bcabe5..bde811c0 100644 --- a/src/PicView.Core/Config/SettingsHelper.cs +++ b/src/PicView.Core/Config/SettingsHelper.cs @@ -15,25 +15,24 @@ public static class SettingsHelper public static AppSettings? Settings { get; private set; } - public static async Task LoadSettingsAsync() + public static async Task LoadSettingsAsync() { try { - var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config/UserSettings.json"); - if (File.Exists(path)) + var path = GetUserSettingsPath(); + if (string.IsNullOrEmpty(path)) { - try - { - await PerformRead(path).ConfigureAwait(false); - } - catch (Exception) - { - await Retry().ConfigureAwait(false); - } + SetDefaults(); + return false; } - else + + try { - await Retry().ConfigureAwait(false); + await PerformRead(path).ConfigureAwait(false); + } + catch (Exception) + { + return await Retry().ConfigureAwait(false); } } catch (Exception ex) @@ -42,10 +41,11 @@ public static async Task LoadSettingsAsync() Trace.WriteLine($"{nameof(LoadSettingsAsync)} error loading settings:\n {ex.Message}"); #endif SetDefaults(); + return false; } - return; + return true; - async Task Retry() + async Task Retry() { // TODO test saving location for macOS https://johnkoerner.com/csharp/special-folder-values-on-windows-versus-mac/ var appData = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Ruben2776/PicView/Config/UserSettings.json"); @@ -58,13 +58,27 @@ async Task Retry() catch (Exception) { SetDefaults(); + return false; } } else { SetDefaults(); + return false; } + return true; + } + } + + public static string GetUserSettingsPath() + { + var appData = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Ruben2776/PicView/Config/UserSettings.json"); + if (File.Exists(appData)) + { + return appData; } + var baseDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config/UserSettings.json"); + return File.Exists(baseDirectory) ? baseDirectory : string.Empty; } private static void SetDefaults()