Skip to content

Commit

Permalink
Update default settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben2776 committed Mar 8, 2024
1 parent 77e51ef commit 73417c5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/PicView.Core/Config/AppSettings.cs
Expand Up @@ -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;
Expand Down
44 changes: 29 additions & 15 deletions src/PicView.Core/Config/SettingsHelper.cs
Expand Up @@ -15,25 +15,24 @@ public static class SettingsHelper

public static AppSettings? Settings { get; private set; }

public static async Task LoadSettingsAsync()
public static async Task<bool> 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)
Expand All @@ -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<bool> 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");
Expand All @@ -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()
Expand Down

0 comments on commit 73417c5

Please sign in to comment.