Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repair-WinGetPackageManager improvements #4774

Merged
merged 2 commits into from
Sep 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ internal class AppxModuleHelper
private const string AppInstallerName = "Microsoft.DesktopAppInstaller";
private const string AppxManifest = "AppxManifest.xml";
private const string PackageFullName = "PackageFullName";
private const string Version = "Version";

// Assets
private const string MsixBundleName = "Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle";
Expand Down Expand Up @@ -130,6 +131,26 @@ public AppxModuleHelper(PowerShellCmdlet pwshCmdlet)
/// <param name="releaseTag">Release tag of GitHub release.</param>
public void RegisterAppInstaller(string releaseTag)
{
if (string.IsNullOrEmpty(releaseTag))
{
string? versionFromLocalPackage = this.GetAppInstallerPropertyValue(Version);

if (versionFromLocalPackage == null)
{
throw new ArgumentNullException(Version);
}

var packageVersion = new Version(versionFromLocalPackage);
if (packageVersion.Major == 1 && packageVersion.Minor > 15)
{
releaseTag = $"1.{packageVersion.Minor - 15}.{packageVersion.Build}";
}
else
{
releaseTag = $"{packageVersion.Major}.{packageVersion.Minor}.{packageVersion.Build}";
}
}

// Ensure that all dependencies are present when attempting to register.
// If dependencies are missing, a provisioned package can appear to only need registration,
// but will fail to register. `InstallDependenciesAsync` checks for the packages before
Expand Down Expand Up @@ -319,10 +340,32 @@ private async Task InstallVCLibsDependenciesAsync()

// See if the minimum (or greater) version is installed.
// TODO: Pull the minimum version from the target package
// TODO: This does not check architecture of the package
Version minimumVersion = new Version(VCLibsUWPDesktopVersion);

bool isInstalled = false;
// Construct the list of frameworks that we want present.
Dictionary<string, string> vcLibsDependencies = new Dictionary<string, string>();
var arch = RuntimeInformation.OSArchitecture;
if (arch == Architecture.X64)
{
vcLibsDependencies.Add("x64", VCLibsUWPDesktopX64);
}
else if (arch == Architecture.X86)
{
vcLibsDependencies.Add("x86", VCLibsUWPDesktopX86);
}
else if (arch == Architecture.Arm64)
{
// Deployment please figure out for me.
vcLibsDependencies.Add("x64", VCLibsUWPDesktopX64);
vcLibsDependencies.Add("x86", VCLibsUWPDesktopX86);
vcLibsDependencies.Add("arm", VCLibsUWPDesktopArm);
vcLibsDependencies.Add("arm64", VCLibsUWPDesktopArm64);
}
else
{
throw new PSNotSupportedException(arch.ToString());
}

if (result != null &&
result.Count > 0)
{
Expand All @@ -338,42 +381,35 @@ private async Task InstallVCLibsDependenciesAsync()

if (packageVersion >= minimumVersion)
{
this.pwshCmdlet.Write(StreamType.Verbose, $"VCLibs dependency satisfied by: {psobject?.PackageFullName ?? "<null>"}");
isInstalled = true;
break;
string? architectureString = psobject?.Architecture?.ToString();
if (architectureString == null)
{
this.pwshCmdlet.Write(StreamType.Verbose, $"VCLibs dependency has no architecture value: {psobject?.PackageFullName ?? "<null>"}");
continue;
}

architectureString = architectureString.ToLower();

if (vcLibsDependencies.ContainsKey(architectureString))
{
this.pwshCmdlet.Write(StreamType.Verbose, $"VCLibs {architectureString} dependency satisfied by: {psobject?.PackageFullName ?? "<null>"}");
vcLibsDependencies.Remove(architectureString);
}
}
else
{
this.pwshCmdlet.Write(StreamType.Verbose, $"VCLibs is lower than minimum required version [{minimumVersion}]: {psobject?.PackageFullName ?? "<null>"}");
}
}
}

if (!isInstalled)
if (vcLibsDependencies.Count != 0)
{
this.pwshCmdlet.Write(StreamType.Verbose, "Couldn't find required VCLibs package");

var vcLibsDependencies = new List<string>();
var arch = RuntimeInformation.OSArchitecture;
if (arch == Architecture.X64)
{
vcLibsDependencies.Add(VCLibsUWPDesktopX64);
}
else if (arch == Architecture.X86)
{
vcLibsDependencies.Add(VCLibsUWPDesktopX86);
}
else if (arch == Architecture.Arm64)
{
// Deployment please figure out for me.
vcLibsDependencies.Add(VCLibsUWPDesktopX64);
vcLibsDependencies.Add(VCLibsUWPDesktopX86);
vcLibsDependencies.Add(VCLibsUWPDesktopArm);
vcLibsDependencies.Add(VCLibsUWPDesktopArm64);
}
else
{
throw new PSNotSupportedException(arch.ToString());
}
this.pwshCmdlet.Write(StreamType.Verbose, "Couldn't find required VCLibs packages");

foreach (var vclib in vcLibsDependencies)
foreach (var vclibPair in vcLibsDependencies)
{
string vclib = vclibPair.Value;
await this.AddAppxPackageAsUriAsync(vclib, vclib.Substring(vclib.LastIndexOf('/') + 1));
}
}
Expand Down
Loading