Skip to content
4 changes: 2 additions & 2 deletions src/UniGetUI.Core.IconStore/IconDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public async Task LoadIconAndScreenshotsDatabaseAsync()
try
{
Uri DownloadUrl = new("https://raw.githubusercontent.com/marticliment/UniGetUI/main/WebBasedData/screenshot-database-v2.json");
if (Settings.Get("IconDataBaseURL"))
if (Settings.Get(Settings.K.IconDataBaseURL))
{
DownloadUrl = new Uri(Settings.GetValue("IconDataBaseURL"));
DownloadUrl = new Uri(Settings.GetValue(Settings.K.IconDataBaseURL));
}

using (HttpClient client = new(CoreTools.GenericHttpClientParameters))
Expand Down
2 changes: 1 addition & 1 deletion src/UniGetUI.Core.LanguageEngine/LanguageData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private static Person[] LoadLanguageTranslatorList()
Name: (url is not null ? "@" : "") + (translator["name"] ?? "").ToString(),
ProfilePicture: url is not null ? new Uri(url.ToString() + ".png") : null,
GitHubUrl: url,
Language: !LangShown ? LanguageData.LanguageReference[langKey.Key] : ""
Language: !LangShown ? LanguageReference[langKey.Key] : ""
);
LangShown = true;
result.Add(person);
Expand Down
6 changes: 3 additions & 3 deletions src/UniGetUI.Core.LanguageEngine/LanguageEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class LanguageEngine

public LanguageEngine(string ForceLanguage = "")
{
string LangName = Settings.GetValue("PreferredLanguage");
string LangName = Settings.GetValue(Settings.K.PreferredLanguage);
if (LangName is "default" or "")
{
LangName = CultureInfo.CurrentUICulture.ToString().Replace("-", "_");
Expand Down Expand Up @@ -93,7 +93,7 @@ public Dictionary<string, string> LoadLanguageFile(string LangKey)

string CachedLangFileToLoad = Path.Join(CoreData.UniGetUICacheDirectory_Lang, "lang_" + LangKey + ".json");

if (Settings.Get("DisableLangAutoUpdater"))
if (Settings.Get(Settings.K.DisableLangAutoUpdater))
{
Logger.Warn("User has updated translations disabled");
}
Expand All @@ -120,7 +120,7 @@ public Dictionary<string, string> LoadLanguageFile(string LangKey)
}
}

if (!Settings.Get("DisableLangAutoUpdater"))
if (!Settings.Get(Settings.K.DisableLangAutoUpdater))
_ = DownloadUpdatedLanguageFile(LangKey);

return LangDict;
Expand Down
38 changes: 29 additions & 9 deletions src/UniGetUI.Core.SecureSettings/SecureSettings.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
using System.Diagnostics;
using UniGetUI.Core.Data;
using UniGetUI.Core.Tools;
using YamlDotNet.Core.Tokens;
using YamlDotNet.Serialization;

namespace UniGetUI.Core.SettingsEngine.SecureSettings;

public static class SecureSettings
{
// Various predefined secure settings keys
public const string ALLOW_CLI_ARGUMENTS = "AllowCLIArguments";
public const string ALLOW_IMPORTING_CLI_ARGUMENTS = "AllowImportingCLIArguments";
public const string ALLOW_PREPOST_OPERATIONS = "AllowPrePostInstallCommands";
public const string ALLOW_IMPORT_PREPOST_OPERATIONS = "AllowImportingPrePostInstallCommands";
public const string FORCE_USER_GSUDO = "ForceUserGSudo";
public enum K
{
AllowCLIArguments,
AllowImportingCLIArguments,
AllowPrePostOpCommand,
AllowImportPrePostOpCommands,
ForceUserGSudo,
Unset
};

public static string ResolveKey(K key)
{
return key switch
{
K.AllowCLIArguments => "AllowCLIArguments",
K.AllowImportingCLIArguments => "AllowImportingCLIArguments",
K.AllowPrePostOpCommand => "AllowPrePostInstallCommands",
K.AllowImportPrePostOpCommands => "AllowImportingPrePostInstallCommands",
K.ForceUserGSudo => "ForceUserGSudo",

K.Unset => throw new InvalidDataException("SecureSettings key was unset!"),
_ => throw new KeyNotFoundException($"The SecureSettings key {key} was not found on the ResolveKey map")
};
}


private static readonly Dictionary<string, bool> _cache = new();
Expand All @@ -23,9 +43,9 @@ public static class Args
public const string DISABLE_FOR_USER = "--disable-secure-setting-for-user";
}

public static bool Get(string setting)
public static bool Get(K key)
{
string purifiedSetting = CoreTools.MakeValidFileName(setting);
string purifiedSetting = CoreTools.MakeValidFileName(ResolveKey(key));
if (_cache.TryGetValue(purifiedSetting, out var value))
{
return value;
Expand All @@ -48,9 +68,9 @@ public static bool Get(string setting)
return exists;
}

public static async Task<bool> TrySet(string setting, bool enabled)
public static async Task<bool> TrySet(K key, bool enabled)
{
string purifiedSetting = CoreTools.MakeValidFileName(setting);
string purifiedSetting = CoreTools.MakeValidFileName(ResolveKey(key));
_cache.Remove(purifiedSetting);

string purifiedUser = CoreTools.MakeValidFileName(Environment.UserName);
Expand Down
Loading
Loading