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

@ -45,11 +45,11 @@ You can download the latest stable from [Releases](https://github.com/sourcegit-
This software creates a folder `$"{System.Environment.SpecialFolder.ApplicationData}/SourceGit"`, which is platform-dependent, to store user settings, downloaded avatars and crash logs.
| OS | PATH |
|---------|-------------------------------------------------|
| Windows | `C:\Users\USER_NAME\AppData\Roaming\SourceGit` |
| Linux | `${HOME}/.config/SourceGit` |
| macOS | `${HOME}/Library/Application Support/SourceGit` |
| OS | PATH |
|---------|-----------------------------------------------------|
| Windows | `C:\Users\USER_NAME\AppData\Roaming\SourceGit` |
| Linux | `${HOME}/.config/SourceGit` or `${HOME}/.Sourcegit` |
| macOS | `${HOME}/Library/Application Support/SourceGit` |
For **Windows** users:

View file

@ -44,6 +44,8 @@ namespace SourceGit
[STAThread]
public static void Main(string[] args)
{
Native.OS.SetupDataDir();
AppDomain.CurrentDomain.UnhandledException += (_, e) =>
{
LogException(e.ExceptionObject as Exception);

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()