Skip to content

Commit

Permalink
Fixed #58 issue 🐛
Browse files Browse the repository at this point in the history
Fixed Windows G Defender bug.
  • Loading branch information
Inestic committed Apr 29, 2022
1 parent 3671e3b commit cb411a8
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 14 deletions.
4 changes: 3 additions & 1 deletion SophiApp/SophiApp/Helpers/OsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Threading;
using System.Threading.Tasks;

namespace SophiApp.Helpers
Expand All @@ -32,6 +31,7 @@ internal class OsHelper
private const int TIMEOUT_3_SECONDS = 3000;
private const string TRAY_SETTINGS = "TraySettings";
private const string UBR = "UBR";
private const string WIN_ENTERPRISE_G = "EnterpriseG";
private const uint WIN11_BUILD_NUMBER = 22;
private const string WINLOGON_PATH = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon";
private const int WM_SETTINGCHANGE = 0x1a;
Expand All @@ -50,6 +50,8 @@ internal class OsHelper
internal const uint WIN11_MIN_SUPPORTED_INSIDER_BUILD = 22509;
internal const uint WIN11_MIN_SUPPORTED_UBR = 556;

internal static bool IsEnterpriseG = GetEdition() == WIN_ENTERPRISE_G;

private static WindowsIdentity GetCurrentUser() => WindowsIdentity.GetCurrent();

[DllImport("user32.dll", SetLastError = true)]
Expand Down
13 changes: 4 additions & 9 deletions SophiApp/SophiApp/Helpers/VisualRedistrLibsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ internal class VisualRedistrLibsHelper
private const string VERSION_NAME = "Version";
private const string X64 = "x64";

private static string GetRegistryPropertyValue(string propertyName)
{
var registryData = RegHelper.GetSubKeyNames(RegistryHive.ClassesRoot, REDISTRX64_REGISTRY_PATH)
.FirstOrDefault(key => key.Contains(REDISTRX64_REGISTRY_NAME_PATTERN));

return RegHelper.GetValue(RegistryHive.ClassesRoot, registryData, propertyName) as string;
}

internal static Version GetCloudLatestVersion()
{
var cloudLibsData = WebHelper.GetJsonResponse<CPPRedistrCollection>(CLOUD_VC_VERSION_URL);
Expand All @@ -32,7 +24,10 @@ internal static Version GetCloudLatestVersion()

internal static Version GetInstalledVersion()
{
var version = IsInstalled() ? GetRegistryPropertyValue(VERSION_NAME) : "0.0.0.0";
var registryData = RegHelper.GetSubKeyNames(RegistryHive.ClassesRoot, REDISTRX64_REGISTRY_PATH)
.FirstOrDefault(key => key.Contains(REDISTRX64_REGISTRY_NAME_PATTERN));

var version = registryData is null ? "0.0.0.0" : RegHelper.GetValue(RegistryHive.ClassesRoot, registryData, VERSION_NAME) as string;
return Version.Parse(version);
}

Expand Down
2 changes: 1 addition & 1 deletion SophiApp/SophiApp/Resources/UIData.json
Original file line number Diff line number Diff line change
Expand Up @@ -4198,4 +4198,4 @@
"Windows10Supported": true,
"Windows11Supported": false
}
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal class DefenderNotCorruptedCondition : IStartupCondition

public bool Invoke()
{
if (WindowsDefenderHelper.DisabledByGroupPolicy() || WmiHelper.HasExternalAntiVirus())
if (OsHelper.IsEnterpriseG || WindowsDefenderHelper.DisabledByGroupPolicy() || WmiHelper.HasExternalAntiVirus())
{
return HasProblem;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ internal class DefenderWarningCondition : IStartupCondition

public bool Invoke()
{
if (OsHelper.IsEnterpriseG)
{
return HasProblem;
}

if (WindowsDefenderHelper.DisabledByGroupPolicy().Invert())
{
if (WmiHelper.HasExternalAntiVirus())
Expand Down
4 changes: 2 additions & 2 deletions SophiApp/SophiApp/ViewModels/Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ private void InitializeProperties()
}

private async Task InitializeTextedElements(string tag) => await Task.Run(() => TextedElements.Where(element => element.Tag == tag)
.ToList()
.ForEach(element => element.Initialize()));
.ToList()
.ForEach(element => element.Initialize()));

private async Task InitializeTextedElementsAsync()
{
Expand Down

0 comments on commit cb411a8

Please sign in to comment.