From 863e6f4e71936db50239cb11b5b37a32bc314245 Mon Sep 17 00:00:00 2001
From: Inestic <50652175+Inestic@users.noreply.github.com>
Date: Mon, 25 Apr 2022 15:33:07 +0300
Subject: [PATCH] Changed Microsoft Visual C++ 2015-2022 Redistributable (x64)
logic
---
.../Controls/MsCppPackageButtonGroup.xaml | 6 ++
.../Controls/MsCppPackageButtonGroup.xaml.cs | 7 +-
.../Controls/OneDriveButtonGroup.xaml | 6 ++
.../Controls/OneDriveButtonGroup.xaml.cs | 7 +-
.../Customisations/CustomisationOs.cs | 64 +++++++++----------
.../Customisations/CustomisationStatus.cs | 35 +++-------
SophiApp/SophiApp/Helpers/ExceptionsHelper.cs | 14 ++++
.../Helpers/VisualRedistrLibsHelper.cs | 49 ++++++++++++++
SophiApp/SophiApp/SophiApp.csproj | 1 +
SophiApp/SophiApp/ViewModels/Methods.cs | 4 +-
10 files changed, 130 insertions(+), 63 deletions(-)
create mode 100644 SophiApp/SophiApp/Helpers/VisualRedistrLibsHelper.cs
diff --git a/SophiApp/SophiApp/Controls/MsCppPackageButtonGroup.xaml b/SophiApp/SophiApp/Controls/MsCppPackageButtonGroup.xaml
index a532251b..0b8b44d5 100644
--- a/SophiApp/SophiApp/Controls/MsCppPackageButtonGroup.xaml
+++ b/SophiApp/SophiApp/Controls/MsCppPackageButtonGroup.xaml
@@ -41,6 +41,12 @@
Margin="0, 10, 5, 10"
VerticalAlignment="Center"
HorizontalAlignment="Left" />
+
+
+
+
+
+
diff --git a/SophiApp/SophiApp/Controls/MsCppPackageButtonGroup.xaml.cs b/SophiApp/SophiApp/Controls/MsCppPackageButtonGroup.xaml.cs
index c6a395bc..02c0ca53 100644
--- a/SophiApp/SophiApp/Controls/MsCppPackageButtonGroup.xaml.cs
+++ b/SophiApp/SophiApp/Controls/MsCppPackageButtonGroup.xaml.cs
@@ -1,4 +1,5 @@
-using System.Windows;
+using SophiApp.Helpers;
+using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
@@ -70,6 +71,10 @@ public uint Id
set { SetValue(IdProperty, value); }
}
+ private void ContextMenu_DescriptionCopyClick(object sender, RoutedEventArgs e) => ClipboardHelper.CopyText(Description);
+
+ private void ContextMenu_HeaderCopyClick(object sender, RoutedEventArgs e) => ClipboardHelper.CopyText(Header);
+
private void Panel_MouseEnter(object sender, MouseEventArgs e) => RaiseEvent(new RoutedEventArgs(MouseEnterEvent) { Source = Description });
private void Panel_MouseLeave(object sender, MouseEventArgs e) => RaiseEvent(new RoutedEventArgs(MouseLeaveEvent));
diff --git a/SophiApp/SophiApp/Controls/OneDriveButtonGroup.xaml b/SophiApp/SophiApp/Controls/OneDriveButtonGroup.xaml
index 4939551b..e4e26a99 100644
--- a/SophiApp/SophiApp/Controls/OneDriveButtonGroup.xaml
+++ b/SophiApp/SophiApp/Controls/OneDriveButtonGroup.xaml
@@ -33,6 +33,12 @@
+
+
+
+
+
+
ClipboardHelper.CopyText(Description);
+
+ private void ContextMenu_HeaderCopyClick(object sender, RoutedEventArgs e) => ClipboardHelper.CopyText(Header);
+
private void Panel_MouseEnter(object sender, MouseEventArgs e) => RaiseEvent(new RoutedEventArgs(MouseEnterEvent) { Source = Description });
private void Panel_MouseLeave(object sender, MouseEventArgs e) => RaiseEvent(new RoutedEventArgs(MouseLeaveEvent));
diff --git a/SophiApp/SophiApp/Customisations/CustomisationOs.cs b/SophiApp/SophiApp/Customisations/CustomisationOs.cs
index 1dd90d0e..4d892e86 100644
--- a/SophiApp/SophiApp/Customisations/CustomisationOs.cs
+++ b/SophiApp/SophiApp/Customisations/CustomisationOs.cs
@@ -877,44 +877,40 @@ public static void _348(bool _)
RegHelper.SetValue(RegistryHive.LocalMachine, _348_PCHC_PATH, _348_PCHC_PREVIOUS_UNINSTALL, ENABLED_VALUE, RegistryValueKind.DWord);
}
- //TODO: Del it!
- //public static void _349(bool IsChecked)
- //{
- // var temp = Environment.GetEnvironmentVariable(TEMP);
-
- // if (IsChecked)
- // {
- // var installer = $"{temp}\\{_349_VC_REDISTRX64_EXE}";
- // WebHelper.Download(_349_DOWNLOAD_URL, installer);
- // ProcessHelper.StartWait(installer, _349_VC_REDISTRX64_INSTALL_ARGS);
- // FileHelper.TryDeleteFile(installer);
- // Directory.EnumerateFileSystemEntries(temp, _349_VC_REDISTRX64_LOG_PATTERN)
- // .ToList()
- // .ForEach(log => FileHelper.TryDeleteFile(log));
- // return;
- // }
-
- // var registryPathRedistrLib = RegHelper.GetSubKeyNames(RegistryHive.ClassesRoot, _349_VC_REDISTRX64_REGISTRY_PATH).First(key => key.Contains(_349_REDISTRX64_REGISTRY_NAME_PATTERN));
- // var registryGuidRedistrLib = RegHelper.GetValue(RegistryHive.ClassesRoot, registryPathRedistrLib, null);
-
- // var localRedistrLibPath = $@"{ENVIRONMENT_PROGRAM_DATA}\{_349_PACKAGE_CACHE_NAME}\{registryGuidRedistrLib}\{_349_VC_REDISTRX64_EXE}";
- // var localRedistrLib = FileVersionInfo.GetVersionInfo(localRedistrLibPath);
-
- // if (localRedistrLib.ProductName.Contains(_349_VC_REDISTRX64_NAME_PATTERN))
- // {
- // ProcessHelper.StartWait(localRedistrLibPath, _349_VC_REDISTRX64_UNINSTALL_ARGS);
-
- // foreach (var log in Directory.EnumerateFileSystemEntries(temp, _349_VC_REDISTRX64_LOG_PATTERN))
- // {
- // FileHelper.TryDeleteFile(log);
- // }
- // }
- //}
-
public static void _351(bool _) => OneDriveHelper.Install();
public static void _352(bool _) => OneDriveHelper.Uninstall();
+ public static void _354(bool _)
+ {
+ var temp = Environment.GetEnvironmentVariable(TEMP);
+ var installer = $"{temp}\\{_349_VC_REDISTRX64_EXE}";
+ WebHelper.Download(_349_DOWNLOAD_URL, installer);
+ ProcessHelper.StartWait(installer, _349_VC_REDISTRX64_INSTALL_ARGS);
+ FileHelper.TryDeleteFile(installer);
+ Directory.EnumerateFileSystemEntries(temp, _349_VC_REDISTRX64_LOG_PATTERN)
+ .ToList()
+ .ForEach(log => FileHelper.TryDeleteFile(log));
+ }
+
+ public static void _355(bool _)
+ {
+ var temp = Environment.GetEnvironmentVariable(TEMP);
+ var registryPathRedistrLib = RegHelper.GetSubKeyNames(RegistryHive.ClassesRoot, _349_VC_REDISTRX64_REGISTRY_PATH).First(key => key.Contains(_349_REDISTRX64_REGISTRY_NAME_PATTERN));
+ var registryGuidRedistrLib = RegHelper.GetValue(RegistryHive.ClassesRoot, registryPathRedistrLib, null);
+ var localRedistrLibPath = $@"{ENVIRONMENT_PROGRAM_DATA}\{_349_PACKAGE_CACHE_NAME}\{registryGuidRedistrLib}\{_349_VC_REDISTRX64_EXE}";
+ var localRedistrLib = FileVersionInfo.GetVersionInfo(localRedistrLibPath);
+
+ if (localRedistrLib.ProductName.Contains(_349_VC_REDISTRX64_NAME_PATTERN))
+ {
+ ProcessHelper.StartWait(localRedistrLibPath, _349_VC_REDISTRX64_UNINSTALL_ARGS);
+
+ Directory.EnumerateFileSystemEntries(temp, _349_VC_REDISTRX64_LOG_PATTERN)
+ .ToList()
+ .ForEach(log => FileHelper.TryDeleteFile(log));
+ }
+ }
+
public static void _400(bool IsChecked)
{
if (IsChecked)
diff --git a/SophiApp/SophiApp/Customisations/CustomisationStatus.cs b/SophiApp/SophiApp/Customisations/CustomisationStatus.cs
index 3abf5926..93c11def 100644
--- a/SophiApp/SophiApp/Customisations/CustomisationStatus.cs
+++ b/SophiApp/SophiApp/Customisations/CustomisationStatus.cs
@@ -414,31 +414,6 @@ public static bool _348() => MsiHelper.GetProperties(Directory.GetFiles(_348_INS
? throw new UpdateNotInstalledException(KB5005463_UPD)
: false;
- //TODO: Del it!
- //public static bool _349()
- //{
- // if (HttpHelper.IsOnline)
- // {
- // var cloudRedistrLibs = WebHelper.GetJsonResponse(_349_VC_VERSION_URL);
- // var cloudCPPRedistrLib = cloudRedistrLibs.Supported.First(libs => libs.Name == _349_VC_REDISTR_FOR_VS_2022 && libs.Architecture == X64);
-
- // try
- // {
- // var registryPathRedistrLib = RegHelper.GetSubKeyNames(RegistryHive.ClassesRoot, _349_VC_REDISTRX64_REGISTRY_PATH).FirstOrDefault(key => key.Contains(_349_REDISTRX64_REGISTRY_NAME_PATTERN));
- // var registryCPPRedistrLibVersion = Version.Parse(RegHelper.GetValue(RegistryHive.ClassesRoot, registryPathRedistrLib, _349_VERSION_NAME) as string ?? "0.0.0.0");
-
- // return RegHelper.GetStringValue(RegistryHive.ClassesRoot, registryPathRedistrLib, _349_DISPLAY_NAME).Contains(_349_VC_REDISTRX64_NAME_PATTERN)
- // || registryCPPRedistrLibVersion > cloudCPPRedistrLib.Version;
- // }
- // catch (Exception)
- // {
- // return false;
- // }
- // }
-
- // throw new NoInternetConnectionException();
- //}
-
public static bool _351() => OneDriveHelper.IsInstalled()
? throw new OneDriveIsInstalledException()
: OneDriveHelper.HasSetupExe() || HttpHelper.IsOnline
@@ -447,6 +422,16 @@ public static bool _351() => OneDriveHelper.IsInstalled()
public static bool _352() => OneDriveHelper.IsInstalled() ? false : throw new OneDriveNotInstalledException();
+ public static bool _354() => HttpHelper.IsOnline
+ ? VisualRedistrLibsHelper.GetCloudLatestVersion() > VisualRedistrLibsHelper.GetInstalledVersion()
+ ? false
+ : throw new VisualRedistrLibsLastVersionException()
+ : throw new NoInternetConnectionException();
+
+ public static bool _355() => VisualRedistrLibsHelper.IsInstalled()
+ ? false
+ : throw new VisualRedistrLibsNotInstalled();
+
public static bool _400() => RegHelper.GetNullableIntValue(RegistryHive.LocalMachine, POLICIES_EXPLORER_PATH, _400_HIDE_ADDED_APPS) != _400_DISABLED_VALUE;
public static bool _401() => RegHelper.GetNullableIntValue(RegistryHive.CurrentUser, CONTENT_DELIVERY_MANAGER_PATH, _401_APP_SUGGESTIONS) == ENABLED_VALUE;
diff --git a/SophiApp/SophiApp/Helpers/ExceptionsHelper.cs b/SophiApp/SophiApp/Helpers/ExceptionsHelper.cs
index 10d7c1e5..c4b6f58d 100644
--- a/SophiApp/SophiApp/Helpers/ExceptionsHelper.cs
+++ b/SophiApp/SophiApp/Helpers/ExceptionsHelper.cs
@@ -128,6 +128,20 @@ public UwpNotSupportedVersion(string packageFullName) : base($"This UWP package
}
}
+ internal class VisualRedistrLibsLastVersionException : Exception
+ {
+ public VisualRedistrLibsLastVersionException() : base("The latest version of Visual C++ Redistributable 2015–2022 x64 is installed")
+ {
+ }
+ }
+
+ internal class VisualRedistrLibsNotInstalled : Exception
+ {
+ public VisualRedistrLibsNotInstalled() : base("The Visual C++ Redistributable 2015–2022 x64 is not installed on this PC")
+ {
+ }
+ }
+
internal class VitualizationNotSupportedException : Exception
{
public VitualizationNotSupportedException() : base("The virtualization (VT-x/SVM) isn't enabled in UEFI (BIOS)")
diff --git a/SophiApp/SophiApp/Helpers/VisualRedistrLibsHelper.cs b/SophiApp/SophiApp/Helpers/VisualRedistrLibsHelper.cs
new file mode 100644
index 00000000..65bd87e6
--- /dev/null
+++ b/SophiApp/SophiApp/Helpers/VisualRedistrLibsHelper.cs
@@ -0,0 +1,49 @@
+using Microsoft.Win32;
+using SophiApp.Dto;
+using System;
+using System.Linq;
+
+namespace SophiApp.Helpers
+{
+ internal class VisualRedistrLibsHelper
+ {
+ private const string CLOUD_VC_VERSION_URL = "https://raw.githubusercontent.com/aaronparker/vcredist/main/VcRedist/VisualCRedistributables.json";
+ private const string REDISTR_LIB_VS_2022_NAME = "Visual C++ Redistributable for Visual Studio 2022";
+ private const string MSREDISTR_LIB_VS_2022_NAME = "Microsoft Visual C++ 2015-2022 Redistributable (x64)";
+ private const string REDISTRX64_REGISTRY_NAME_PATTERN = "VC,redist.x64,amd64";
+ private const string REDISTRX64_REGISTRY_PATH = @"Installer\Dependencies";
+ private const string VERSION_NAME = "Version";
+ private const string DISPLAY_NAME = "DisplayName";
+ private const string X64 = "x64";
+
+ internal static Version GetCloudLatestVersion()
+ {
+ var cloudLibsData = WebHelper.GetJsonResponse(CLOUD_VC_VERSION_URL);
+ return cloudLibsData.Supported.First(libs => libs.Name == REDISTR_LIB_VS_2022_NAME && libs.Architecture == X64).Version;
+ }
+
+ internal static Version GetInstalledVersion()
+ {
+ var version = IsInstalled() ? GetRegistryPropertyValue(VERSION_NAME) : "0.0.0.0";
+ return Version.Parse(version);
+ }
+
+ 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 bool IsInstalled()
+ {
+ var vcRegistryPath = RegHelper.GetSubKeyNames(RegistryHive.ClassesRoot, REDISTRX64_REGISTRY_PATH)
+ .FirstOrDefault(key => key.Contains(REDISTRX64_REGISTRY_NAME_PATTERN));
+
+ return vcRegistryPath != null && RegHelper.GetStringValue(RegistryHive.ClassesRoot, vcRegistryPath, DISPLAY_NAME)
+ .Contains(MSREDISTR_LIB_VS_2022_NAME);
+ }
+ }
+}
\ No newline at end of file
diff --git a/SophiApp/SophiApp/SophiApp.csproj b/SophiApp/SophiApp/SophiApp.csproj
index 69010116..5ffbe276 100644
--- a/SophiApp/SophiApp/SophiApp.csproj
+++ b/SophiApp/SophiApp/SophiApp.csproj
@@ -120,6 +120,7 @@
OneDriveButtonGroup.xaml
+
diff --git a/SophiApp/SophiApp/ViewModels/Methods.cs b/SophiApp/SophiApp/ViewModels/Methods.cs
index 917e3d13..e23b87a6 100644
--- a/SophiApp/SophiApp/ViewModels/Methods.cs
+++ b/SophiApp/SophiApp/ViewModels/Methods.cs
@@ -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()
{