Basic info command

This commit is contained in:
Ádám Kovács
2022-11-02 10:33:59 +01:00
parent a36d306279
commit 4c8430d0dc
5 changed files with 68 additions and 10 deletions

View File

@@ -5,6 +5,8 @@ public class FolderService : IFolderService
public string? ConfigRoot { get; }
public string AppData { get; }
public string ApplicationSubfolderName => "alma";
public FolderService()
{
ConfigRoot = GetConfigHomePath();
@@ -13,19 +15,22 @@ public class FolderService : IFolderService
if (!Directory.Exists(AppData)) Directory.CreateDirectory(AppData);
}
private static string? GetConfigHomePath()
public string GetPreferredConfigurationFolder()
=> Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".config");
private string? GetConfigHomePath()
{
var configHomeProviders = new List<Func<string?>>
{
() => Environment.GetEnvironmentVariable("XDG_CONFIG_HOME"),
() => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".config")
() => GetPreferredConfigurationFolder()
};
var configHome = EnumerateProviders(configHomeProviders);
return configHome == null ? null : Path.Combine(configHome, "alma");
return configHome == null ? null : Path.Combine(configHome, ApplicationSubfolderName);
}
private static string GetAppDataPath()
private string GetAppDataPath()
{
var appDataProviders = new List<Func<string?>>
{
@@ -33,7 +38,7 @@ public class FolderService : IFolderService
};
var appData = EnumerateProviders(appDataProviders) ?? Environment.CurrentDirectory;
return Path.Combine(appData, "alma");
return Path.Combine(appData, ApplicationSubfolderName);
}
private static string? EnumerateProviders(List<Func<string?>> providers)