Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Show error during setup if installing an x64 package on an x86 system (
Browse files Browse the repository at this point in the history
…closes #35)
  • Loading branch information
caesay committed Jan 30, 2022
1 parent 9d05773 commit 644861a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
14 changes: 7 additions & 7 deletions src/Squirrel/AssemblyRuntimeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public enum RuntimeCpu : ushort
X86 = 0x014c,
/// <summary> x64 / Amd64 </summary>
X64 = 0x8664,
/// <summary> Arm64 </summary>
Arm64 = 0xAA64,
// <summary> Arm64 </summary>
// Arm64 = 0xAA64,
}

/// <summary>
Expand Down Expand Up @@ -58,7 +58,7 @@ static AssemblyRuntimeInfo()
#if !NETFRAMEWORK
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
#endif
CheckArchitectureWindows();
CheckArchitectureWindows();
#if !NETFRAMEWORK
} else {
CheckArchitectureOther();
Expand Down Expand Up @@ -99,12 +99,12 @@ private static void CheckArchitectureWindows()

if (!String.IsNullOrEmpty(pf64compat)) {
switch (pf64compat) {
//case "ARM64":
// Architecture = RuntimeCpu.Arm64;
// break;
case "AMD64":
Architecture = RuntimeCpu.X64;
break;
case "ARM64":
Architecture = RuntimeCpu.Arm64;
break;
}
}

Expand All @@ -125,7 +125,7 @@ private static void CheckArchitectureOther()
Architecture = RuntimeInformation.OSArchitecture switch {
InteropArchitecture.X86 => RuntimeCpu.X86,
InteropArchitecture.X64 => RuntimeCpu.X64,
InteropArchitecture.Arm64 => RuntimeCpu.Arm64,
//InteropArchitecture.Arm64 => RuntimeCpu.Arm64,
_ => RuntimeCpu.Unknown,
};
}
Expand Down
8 changes: 8 additions & 0 deletions src/Squirrel/NuGet/ZipPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ internal class ZipPackage : IPackage
private readonly Func<Stream> _streamFactory;
private static readonly string[] ExcludePaths = new[] { "_rels", "package" };

public ZipPackage(Stream zipStream)
{
using var zip = ZipArchive.Open(zipStream, new() { LeaveStreamOpen = true });
using var manifest = GetManifestEntry(zip).OpenEntryStream();
ReadManifest(manifest);
Frameworks = GetFrameworks(zip);
}

public ZipPackage(string filePath)
{
if (String.IsNullOrEmpty(filePath)) {
Expand Down
2 changes: 1 addition & 1 deletion src/SquirrelCli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ static void Releasify(ReleasifyOptions options)
// because of emulation support. Arm64 generally supports x86/x64 emulation, and x64
// often supports x86 emulation, so we want to pick the least compatible architecture
// for the package.
var archOrder = new[] { RuntimeCpu.Arm64, RuntimeCpu.X64, RuntimeCpu.X86 };
var archOrder = new[] { /*RuntimeCpu.Arm64,*/ RuntimeCpu.X64, RuntimeCpu.X86 };
var pkgarch = archOrder.First(o => pearchs.Contains(o));
if (pkgarch == RuntimeCpu.Unknown) {
Expand Down
7 changes: 7 additions & 0 deletions src/Update/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ static async Task Setup(string setupPath, bool silentInstall, bool checkInstall)
using var _t = Utility.WithTempDirectory(out var tempFolder);
ISplashWindow splash = new Windows.User32SplashWindow(info.AppFriendlyName, silentInstall, info.SetupIconBytes, info.SplashImageBytes);

// verify that this package can be installed on this cpu architecture
var zp = new ZipPackage(new MemoryStream(info.BundledPackageBytes));
if (AssemblyRuntimeInfo.Architecture == RuntimeCpu.X86 && zp.MachineArchitecture == RuntimeCpu.X64) {
splash.ShowErrorDialog("Incompatible System", "The current operating system uses the x86 cpu architecture, but this package requires an x64 system.");
return;
}

var missingFrameworks = info.RequiredFrameworks
.Select(f => Runtimes.GetRuntimeByName(f))
.Where(f => f != null)
Expand Down
2 changes: 1 addition & 1 deletion test/ZipPackageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void HasSameFilesAndDependenciesAsPackaging()
var inputPackage = IntegrationTestHelper.GetPath("fixtures", "slack-1.1.8-full.nupkg");

var zp = new ZipPackage(inputPackage);
var zipfw = zp.GetFrameworks();
var zipfw = zp.Frameworks;
var zipf = zp.GetFiles().OrderBy(f => f.Path).ToArray();
var zipfLib = zp.GetLibFiles().OrderBy(f => f.Path).ToArray();

Expand Down

0 comments on commit 644861a

Please sign in to comment.