fix: application data dir may not have been created before crash (#161)

This commit is contained in:
leo 2024-06-03 09:44:12 +08:00
parent f1f54bf6fe
commit 49ce07443e
4 changed files with 8 additions and 12 deletions

View file

@ -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";