fix: Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) returns an empty string on some linux distro

* fallback the storage folder to `~/.sourcegit`
This commit is contained in:
leo 2024-08-12 21:29:18 +08:00
parent 9561f7ef64
commit 38665a61cb
No known key found for this signature in database
3 changed files with 20 additions and 9 deletions

View file

@ -21,9 +21,9 @@ namespace SourceGit.Native
void OpenWithDefaultEditor(string file);
}
public static readonly string DataDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "SourceGit");
public static string DataDir { get; private set; } = string.Empty;
public static string GitExecutable { get; set; } = string.Empty;
public static List<Models.ExternalTool> ExternalTools { get; set; } = new List<Models.ExternalTool>();
public static List<Models.ExternalTool> ExternalTools { get; set; } = [];
static OS()
{
@ -70,10 +70,19 @@ namespace SourceGit.Native
public static void SetupApp(AppBuilder builder)
{
_backend.SetupApp(builder);
}
public static void SetupDataDir()
{
var osAppDataDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
if (string.IsNullOrEmpty(osAppDataDir))
DataDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".SourceGit");
else
DataDir = Path.Combine(osAppDataDir, "SourceGit");
if (!Directory.Exists(DataDir))
Directory.CreateDirectory(DataDir);
_backend.SetupApp(builder);
}
public static void SetupEnternalTools()