namespace Xdg.Directories;
///
public static class BaseDirectory
{
///
public static string DataHome
{
get =>
GetEnvironmentVariable("XDG_DATA_HOME")
?? Helpers.GetCurrentOperatingSystem() switch
{
Helpers.OS.Windows
=> GetEnvironmentVariable("LOCALAPPDATA")
?? GetFolderPath(SpecialFolder.LocalApplicationData),
Helpers.OS.MacOS => Path.Combine(Other.Home, "Library", "Application Support"),
Helpers.OS.UnixLike => Path.Combine(Other.Home, ".local", "share"),
_ => string.Empty
};
}
///
public static string ConfigHome
{
get =>
GetEnvironmentVariable("XDG_CONFIG_HOME")
?? Helpers.GetCurrentOperatingSystem() switch
{
Helpers.OS.Windows
=> GetEnvironmentVariable("LOCALAPPDATA")
?? GetFolderPath(SpecialFolder.LocalApplicationData),
Helpers.OS.MacOS => Path.Combine(Other.Home, "Library", "Application Support"),
Helpers.OS.UnixLike => Path.Combine(Other.Home, ".config"),
_ => string.Empty
};
}
///
public static string StateHome
{
get =>
GetEnvironmentVariable("XDG_STATE_HOME")
?? Helpers.GetCurrentOperatingSystem() switch
{
Helpers.OS.Windows
=> GetEnvironmentVariable("LOCALAPPDATA")
?? GetFolderPath(SpecialFolder.LocalApplicationData),
Helpers.OS.MacOS => Path.Combine(Other.Home, "Library", "Application Support"),
Helpers.OS.UnixLike => Path.Combine(Other.Home, ".local", "state"),
_ => string.Empty
};
}
///
public static string BinHome
{
get =>
GetEnvironmentVariable("XDG_BIN_HOME")
?? Helpers.GetCurrentOperatingSystem() switch
{
Helpers.OS.Windows => string.Empty,
Helpers.OS.MacOS => string.Empty,
Helpers.OS.UnixLike => Path.Combine(Other.Home, ".local", "bin"),
_ => string.Empty
};
}
///
public static IList DataDirs
{
get =>
GetEnvironmentVariable("XDG_DATA_DIRS")?.Split(':')
?? Helpers.GetCurrentOperatingSystem() switch
{
Helpers.OS.Windows
=>
[
GetEnvironmentVariable("APPDATA")
?? GetFolderPath(SpecialFolder.ApplicationData),
GetEnvironmentVariable("PROGRAMDATA")
?? GetFolderPath(SpecialFolder.CommonApplicationData)
],
Helpers.OS.MacOS => ["/Library/Application Support"],
Helpers.OS.UnixLike => ["/usr/local/share", "/usr/share"],
_ => []
};
}
///
public static IList ConfigDirs
{
get =>
GetEnvironmentVariable("XDG_CONFIG_DIRS")?.Split(':')
?? Helpers.GetCurrentOperatingSystem() switch
{
Helpers.OS.Windows
=>
[
GetEnvironmentVariable("ProgramData")
?? GetFolderPath(SpecialFolder.CommonApplicationData),
GetEnvironmentVariable("APPDATA")
?? GetFolderPath(SpecialFolder.ApplicationData)
],
Helpers.OS.MacOS
=>
[
Path.Combine(Other.Home, "Library", "Preferences"),
"/Library/Application Support",
"/Library/Preferences"
],
Helpers.OS.UnixLike => ["/etc/xdg"],
_ => []
};
}
///
public static string CacheHome
{
get =>
GetEnvironmentVariable("XDG_CACHE_HOME")
?? Helpers.GetCurrentOperatingSystem() switch
{
Helpers.OS.Windows
=> GetEnvironmentVariable("LOCALAPPDATA") is not null
? Path.Combine(GetEnvironmentVariable("LOCALAPPDATA")!, "cache")
: Path.Combine(GetFolderPath(SpecialFolder.LocalApplicationData), "cache"),
Helpers.OS.MacOS => Path.Combine(Other.Home, "Library", "Caches"),
Helpers.OS.UnixLike => Path.Combine(Other.Home, ".cache"),
_ => string.Empty
};
}
///
public static string RuntimeDir
{
get =>
GetEnvironmentVariable("XDG_RUNTIME_DIR")
?? Helpers.GetCurrentOperatingSystem() switch
{
Helpers.OS.Windows
=> GetEnvironmentVariable("LOCALAPPDATA")
?? GetFolderPath(SpecialFolder.LocalApplicationData),
Helpers.OS.MacOS => Path.Combine(Other.Home, "Library", "Application Support"),
Helpers.OS.UnixLike => Path.Combine("/run", "user", GetEnvironmentVariable("UID") ?? "0"),
_ => string.Empty
};
}
}