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

Use FolderId_ProgramFiles for non x86 default machine portable folder #3137

Merged
merged 3 commits into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion src/AppInstallerCLICore/Commands/RootCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ namespace AppInstaller::CLI
keyDirectories.OutputLine({ Resource::LocString{ Resource::String::PortableLinksMachine }, Runtime::GetPathTo(Runtime::PathName::PortableLinksMachineLocation, true).u8string() });
keyDirectories.OutputLine({ Resource::LocString{ Resource::String::PortableRootUser }, Runtime::GetPathTo(Runtime::PathName::PortablePackageUserRoot, true).u8string() });
keyDirectories.OutputLine({ Resource::LocString{ Resource::String::PortableRoot86 }, Runtime::GetPathTo(Runtime::PathName::PortablePackageMachineRootX86, true).u8string() });
if (Utility::GetSystemArchitecture() == Utility::Architecture::X64 || Utility::GetSystemArchitecture() == Utility::Architecture::Arm64)
// Do not output Portable root 64 on non applicable cases.
auto processArchitecture = Utility::GetProcessArchitecture();
if (processArchitecture != Utility::Architecture::X86 && processArchitecture != Utility::Architecture::Arm)
{
keyDirectories.OutputLine({ Resource::LocString{ Resource::String::PortableRoot64 }, Runtime::GetPathTo(Runtime::PathName::PortablePackageMachineRootX64, true).u8string() });
}
Expand Down
28 changes: 28 additions & 0 deletions src/AppInstallerCommonCore/Architecture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,34 @@ namespace AppInstaller::Utility
return systemArchitecture;
}

Architecture GetProcessArchitecture()
{
Architecture processArchitecture = GetSystemArchitecture();

USHORT ushortProcessArchitecture = 0;
if (IsWow64Process2(GetCurrentProcess(), &ushortProcessArchitecture, nullptr))
{
// If success, the process is running under emulation. Set the real process architecture.
switch (ushortProcessArchitecture)
{
case IMAGE_FILE_MACHINE_I386:
processArchitecture = Architecture::X86;
break;
case IMAGE_FILE_MACHINE_ARM:
processArchitecture = Architecture::Arm;
break;
case IMAGE_FILE_MACHINE_AMD64:
processArchitecture = Architecture::X64;
break;
case IMAGE_FILE_MACHINE_ARM64:
processArchitecture = Architecture::Arm64;
break;
}
}

return processArchitecture;
}

const std::vector<Architecture>& GetApplicableArchitectures()
{
static std::vector<Architecture> applicableArchs = CreateApplicableArchitecturesVector();
Expand Down
3 changes: 3 additions & 0 deletions src/AppInstallerCommonCore/Public/AppInstallerArchitecture.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ namespace AppInstaller::Utility
// Gets the system's architecture as Architecture enum
AppInstaller::Utility::Architecture GetSystemArchitecture();

// Gets the process architecture as Architecture enum
AppInstaller::Utility::Architecture GetProcessArchitecture();

// Gets the set of architectures that are applicable to the current system
const std::vector<Architecture>& GetApplicableArchitectures();

Expand Down
1 change: 1 addition & 0 deletions src/AppInstallerCommonCore/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <SoftPub.h>
#include <WinTrust.h>
#include <wincrypt.h>
#include <wow64apiset.h>

#include "TraceLogging.h"

Expand Down