diff --git a/src/App.axaml.cs b/src/App.axaml.cs index 151c6e92..df491dd0 100644 --- a/src/App.axaml.cs +++ b/src/App.axaml.cs @@ -62,9 +62,7 @@ namespace SourceGit builder.Append(ex.StackTrace); var time = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"); - var file = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), - "SourceGit", - $"crash_{time}.log"); + var file = Path.Combine(Native.OS.DataDir, $"crash_{time}.log"); File.WriteAllText(file, builder.ToString()); } } diff --git a/src/Models/AvatarManager.cs b/src/Models/AvatarManager.cs index fded94e3..50d890e1 100644 --- a/src/Models/AvatarManager.cs +++ b/src/Models/AvatarManager.cs @@ -25,7 +25,7 @@ namespace SourceGit.Models static AvatarManager() { - _storePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "SourceGit", "avatars"); + _storePath = Path.Combine(Native.OS.DataDir, "avatars"); if (!Directory.Exists(_storePath)) Directory.CreateDirectory(_storePath); diff --git a/src/Native/OS.cs b/src/Native/OS.cs index 46a49e6a..451362ca 100644 --- a/src/Native/OS.cs +++ b/src/Native/OS.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using Avalonia; @@ -20,6 +21,7 @@ namespace SourceGit.Native void OpenWithDefaultEditor(string file); } + public static readonly string DataDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "SourceGit"); public static string GitExecutable { get; set; } = string.Empty; public static List ExternalTools { get; set; } = new List(); @@ -72,6 +74,9 @@ namespace SourceGit.Native public static void SetupApp(AppBuilder builder) { + if (!Directory.Exists(DataDir)) + Directory.CreateDirectory(DataDir); + _backend.SetupApp(builder); } diff --git a/src/ViewModels/Preference.cs b/src/ViewModels/Preference.cs index ee387e35..68dd3532 100644 --- a/src/ViewModels/Preference.cs +++ b/src/ViewModels/Preference.cs @@ -459,10 +459,6 @@ namespace SourceGit.ViewModels public static void Save() { - var dir = Path.GetDirectoryName(_savePath); - if (!Directory.Exists(dir)) - Directory.CreateDirectory(dir); - var data = JsonSerializer.Serialize(_instance, JsonCodeGen.Default.Preference); File.WriteAllText(_savePath, data); } @@ -515,10 +511,7 @@ namespace SourceGit.ViewModels } private static Preference _instance = null; - private static readonly string _savePath = Path.Combine( - Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), - "SourceGit", - "preference.json"); + private static readonly string _savePath = Path.Combine(Native.OS.DataDir, "preference.json"); private string _locale = "en_US"; private string _theme = "Default";