diff --git a/README.md b/README.md index 38a7e99fa2..ed177d89a4 100644 --- a/README.md +++ b/README.md @@ -72,11 +72,11 @@ You can download the latest stable from [Releases](https://github.com/sourcegit- This software creates a folder, which is platform-dependent, to store user settings, downloaded avatars and crash logs. -| OS | PATH | -|---------|-------------------------------------------| -| Windows | `%APPDATA%\SourceGit` | -| Linux | `~/.sourcegit` | -| macOS | `~/Library/Application Support/SourceGit` | +| OS | PATH | +|---------|--------------------------------------------------| +| Windows | `%APPDATA%\SourceGit` | +| Linux | `~/.local/share/SourceGit`, `~/.cache/SourceGit` | +| macOS | `~/Library/Application Support/SourceGit` | > [!TIP] > * You can open this data storage directory from the main menu `Open Data Storage Directory`. diff --git a/src/App.axaml.cs b/src/App.axaml.cs index a22f764d6f..e4dc4dd252 100644 --- a/src/App.axaml.cs +++ b/src/App.axaml.cs @@ -24,6 +24,7 @@ public partial class App : Application public static void Main(string[] args) { Native.OS.SetupDataDir(); + Native.OS.SetupCacheDir(); AppDomain.CurrentDomain.UnhandledException += (_, e) => { diff --git a/src/Models/AvatarManager.cs b/src/Models/AvatarManager.cs index 9616ac64d2..1eb084242c 100644 --- a/src/Models/AvatarManager.cs +++ b/src/Models/AvatarManager.cs @@ -44,9 +44,7 @@ public static AvatarManager Instance public void Start() { - _storePath = Path.Combine(Native.OS.DataDir, "avatars"); - if (!Directory.Exists(_storePath)) - Directory.CreateDirectory(_storePath); + _storePath = Path.Combine(Native.OS.CacheDir, "avatars"); LoadDefaultAvatar("noreply@github.com", "github.png"); LoadDefaultAvatar("unrealbot@epicgames.com", "unreal.png"); @@ -87,6 +85,9 @@ public void Start() url = $"https://avatars.githubusercontent.com/{githubUser}"; } + if (!Directory.Exists(_storePath)) + Directory.CreateDirectory(_storePath); + var localFile = Path.Combine(_storePath, md5); Bitmap img = null; try diff --git a/src/Native/Linux.cs b/src/Native/Linux.cs index a28d88ebe1..8d528cbcde 100644 --- a/src/Native/Linux.cs +++ b/src/Native/Linux.cs @@ -46,11 +46,50 @@ public string GetDataDir() return portableDir; } - // Runtime data dir: ~/.sourcegit - var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); - return Path.Combine(home, ".sourcegit"); + var homeDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); + var dataDir = GetXdgDir("XDG_DATA_HOME"); + + if (!Directory.Exists(dataDir)) { + foreach (var oldDataDir in new[] { ".SourceGit", ".config/SourceGit" }) { + if (!Directory.Exists(Path.Combine(homeDir, oldDataDir))) continue; + + Directory.Delete(Path.Combine(oldDataDir, "avatars"), true); + Directory.Move(oldDataDir, dataDir!); + break; + } + } + + return GetXdgDir("XDG_DATA_HOME"); } + public string GetCacheDir() + { + + return GetXdgDir("XDG_CACHE_HOME"); + } + + // Directories according to the XDG user directory standard + // https://specifications.freedesktop.org/basedir/latest/ + private static string GetXdgDir(string name) + { + string fallback; + + switch(name) + { + default: + case "XDG_DATA_HOME": fallback = ".local/share/SourceGit"; break; + case "XDG_CONFIG_HOME": fallback = ".config/SourceGit"; break; + case "XDG_CACHE_HOME": fallback = ".cache/SourceGit"; break; + } + + var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); + string dir = Environment.GetEnvironmentVariable(name); + if (dir == null || !Path.IsPathRooted(dir)) + dir = Path.Combine(home, fallback); + + return dir; + } + public string FindGitExecutable() { return FindExecutable("git"); diff --git a/src/Native/MacOS.cs b/src/Native/MacOS.cs index 54a2a8a723..a72eecd1aa 100644 --- a/src/Native/MacOS.cs +++ b/src/Native/MacOS.cs @@ -54,6 +54,11 @@ public string GetDataDir() "SourceGit"); } + public string GetCacheDir() + { + return GetDataDir(); + } + public string FindGitExecutable() { var gitPathVariants = new List() { diff --git a/src/Native/OS.cs b/src/Native/OS.cs index ceaa69c84a..413b796b48 100644 --- a/src/Native/OS.cs +++ b/src/Native/OS.cs @@ -20,6 +20,7 @@ public interface IBackend void SetupWindow(Window window); string GetDataDir(); + string GetCacheDir(); string FindGitExecutable(); string FindTerminal(Models.ShellOrTerminal shell); List FindExternalTools(); @@ -35,6 +36,12 @@ public static string DataDir get; private set; } = string.Empty; + + public static string CacheDir + { + get; + private set; + } = string.Empty; public static string GitExecutable { @@ -139,6 +146,12 @@ public static void SetupDataDir() if (!Directory.Exists(DataDir)) Directory.CreateDirectory(DataDir); } + + public static void SetupCacheDir() + { + // cache directory is created when placing data in it + return; + } public static void SetupApp(AppBuilder builder) { diff --git a/src/Native/Windows.cs b/src/Native/Windows.cs index 2ec98ca40c..a076709ed1 100644 --- a/src/Native/Windows.cs +++ b/src/Native/Windows.cs @@ -54,6 +54,11 @@ public string GetDataDir() "SourceGit"); } + public string GetCacheDir() + { + return GetDataDir(); + } + public string FindGitExecutable() { var reg = Microsoft.Win32.RegistryKey.OpenBaseKey(