Skip to content

Commit

Permalink
Changed Microsoft Visual C++ 2015-2022 Redistributable (x64) logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Inestic committed Apr 25, 2022
1 parent 321013b commit 863e6f4
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 63 deletions.
6 changes: 6 additions & 0 deletions SophiApp/SophiApp/Controls/MsCppPackageButtonGroup.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
Margin="0, 10, 5, 10"
VerticalAlignment="Center"
HorizontalAlignment="Left" />
<Grid.ContextMenu>
<ContextMenu>
<MenuItem Click="ContextMenu_HeaderCopyClick" Header="{DynamicResource Localization.Element.ContextMenu.Header.Copy}" />
<MenuItem Click="ContextMenu_DescriptionCopyClick" Header="{DynamicResource Localization.Element.ContextMenu.Description.Copy}" />
</ContextMenu>
</Grid.ContextMenu>
</Grid>
<ItemsControl ItemsSource="{Binding ChildElements}">
<ItemsControl.ItemsPanel>
Expand Down
7 changes: 6 additions & 1 deletion SophiApp/SophiApp/Controls/MsCppPackageButtonGroup.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Windows;
using SophiApp.Helpers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

Expand Down Expand Up @@ -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));
Expand Down
6 changes: 6 additions & 0 deletions SophiApp/SophiApp/Controls/OneDriveButtonGroup.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
<UserControl.Template>
<ControlTemplate>
<StackPanel Style="{StaticResource PanelBase}" MouseEnter="Panel_MouseEnter" MouseLeave="Panel_MouseLeave">
<StackPanel.ContextMenu>
<ContextMenu>
<MenuItem Click="ContextMenu_HeaderCopyClick" Header="{DynamicResource Localization.Element.ContextMenu.Header.Copy}" />
<MenuItem Click="ContextMenu_DescriptionCopyClick" Header="{DynamicResource Localization.Element.ContextMenu.Description.Copy}" />
</ContextMenu>
</StackPanel.ContextMenu>
<Border x:Name="BorderLine" />
<StackPanel Orientation="Horizontal">
<ContentPresenter Margin="{Binding Path=IconMargin, RelativeSource={RelativeSource Mode=TemplatedParent}}"
Expand Down
7 changes: 6 additions & 1 deletion SophiApp/SophiApp/Controls/OneDriveButtonGroup.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Windows;
using SophiApp.Helpers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

Expand Down Expand Up @@ -120,6 +121,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));
Expand Down
64 changes: 30 additions & 34 deletions SophiApp/SophiApp/Customisations/CustomisationOs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
35 changes: 10 additions & 25 deletions SophiApp/SophiApp/Customisations/CustomisationStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CPPRedistrCollection>(_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
Expand All @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions SophiApp/SophiApp/Helpers/ExceptionsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down
49 changes: 49 additions & 0 deletions SophiApp/SophiApp/Helpers/VisualRedistrLibsHelper.cs
Original file line number Diff line number Diff line change
@@ -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<CPPRedistrCollection>(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);
}
}
}
1 change: 1 addition & 0 deletions SophiApp/SophiApp/SophiApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
<DependentUpon>OneDriveButtonGroup.xaml</DependentUpon>
</Compile>
<Compile Include="Helpers\HttpHelper.cs" />
<Compile Include="Helpers\VisualRedistrLibsHelper.cs" />
<Compile Include="Helpers\WindowsDefenderHelper.cs" />
<Compile Include="Models\MsCppPackageButtonGroup.cs" />
<Compile Include="Models\OneDriveButtonGroup.cs" />
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 863e6f4

Please sign in to comment.