mlaumcherb/Млаумчерб.Клиент/классы/Буржуазия.cs
2024-09-29 08:21:48 +05:00

57 lines
1.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Runtime.InteropServices;
// ReSharper disable CollectionNeverUpdated.Global
namespace Млаумчерб.Клиент.классы;
public static class Буржуазия
{
public static bool CheckOs(Os os) =>
os.name switch
{
null => true,
"osx" => OperatingSystem.IsMacOS(),
"linux" => OperatingSystem.IsLinux(),
"windows" => OperatingSystem.IsWindows(),
_ => throw new ArgumentOutOfRangeException(os.name)
}
&& os.arch switch
{
null => true,
"x86" => RuntimeInformation.OSArchitecture == Architecture.X86,
"x64" => RuntimeInformation.OSArchitecture == Architecture.X64,
"arm64" => RuntimeInformation.OSArchitecture == Architecture.Arm64,
_ => false
};
public static bool CheckRules(ICollection<Rule> rules, ICollection<string> enabled_features)
{
bool allowed = false;
foreach (var r in rules)
{
if (r.os == null || CheckOs(r.os))
{
if (r.features != null)
{
foreach (var feature in enabled_features)
{
if(r.features.TryGetValue(feature, out bool is_enabled))
{
if (is_enabled)
{
if (r.action != "allow")
return false;
}
}
}
}
if (r.action == "allow")
allowed = true;
else return false;
}
}
return allowed;
}
}