Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
1 change: 1 addition & 0 deletions src/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
{
Expand Down
7 changes: 4 additions & 3 deletions src/Models/AvatarManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand Down
45 changes: 42 additions & 3 deletions src/Native/Linux.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
5 changes: 5 additions & 0 deletions src/Native/MacOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public string GetDataDir()
"SourceGit");
}

public string GetCacheDir()
{
return GetDataDir();
}

public string FindGitExecutable()
{
var gitPathVariants = new List<string>() {
Expand Down
13 changes: 13 additions & 0 deletions src/Native/OS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public interface IBackend
void SetupWindow(Window window);

string GetDataDir();
string GetCacheDir();
string FindGitExecutable();
string FindTerminal(Models.ShellOrTerminal shell);
List<Models.ExternalTool> FindExternalTools();
Expand All @@ -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
{
Expand Down Expand Up @@ -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)
{
Expand Down
5 changes: 5 additions & 0 deletions src/Native/Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public string GetDataDir()
"SourceGit");
}

public string GetCacheDir()
{
return GetDataDir();
}

public string FindGitExecutable()
{
var reg = Microsoft.Win32.RegistryKey.OpenBaseKey(
Expand Down