From 1b563e31912c52530344767cb967b92410ee0937 Mon Sep 17 00:00:00 2001 From: Yao Sun Date: Fri, 7 Apr 2023 18:28:39 -0700 Subject: [PATCH 1/3] Fix tests --- .../Commands/RootCommand.cpp | 4 ++- src/AppInstallerCommonCore/Architecture.cpp | 28 +++++++++++++++++++ .../Public/AppInstallerArchitecture.h | 3 ++ src/AppInstallerCommonCore/pch.h | 1 + 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/AppInstallerCLICore/Commands/RootCommand.cpp b/src/AppInstallerCLICore/Commands/RootCommand.cpp index a385fbcd4b..96fce52881 100644 --- a/src/AppInstallerCLICore/Commands/RootCommand.cpp +++ b/src/AppInstallerCLICore/Commands/RootCommand.cpp @@ -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() }); } diff --git a/src/AppInstallerCommonCore/Architecture.cpp b/src/AppInstallerCommonCore/Architecture.cpp index ffab223d45..7aaed2c97f 100644 --- a/src/AppInstallerCommonCore/Architecture.cpp +++ b/src/AppInstallerCommonCore/Architecture.cpp @@ -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& GetApplicableArchitectures() { static std::vector applicableArchs = CreateApplicableArchitecturesVector(); diff --git a/src/AppInstallerCommonCore/Public/AppInstallerArchitecture.h b/src/AppInstallerCommonCore/Public/AppInstallerArchitecture.h index e75e0c7918..1e5f2d2edf 100644 --- a/src/AppInstallerCommonCore/Public/AppInstallerArchitecture.h +++ b/src/AppInstallerCommonCore/Public/AppInstallerArchitecture.h @@ -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& GetApplicableArchitectures(); diff --git a/src/AppInstallerCommonCore/pch.h b/src/AppInstallerCommonCore/pch.h index c9f24fb664..4d9608415e 100644 --- a/src/AppInstallerCommonCore/pch.h +++ b/src/AppInstallerCommonCore/pch.h @@ -17,6 +17,7 @@ #include #include #include +#include #include "TraceLogging.h" From fa69f06d7089eeffbb72ddb3c2ee7a61cd5aed1f Mon Sep 17 00:00:00 2001 From: Yao Sun Date: Fri, 7 Apr 2023 20:30:55 -0700 Subject: [PATCH 2/3] Revert "Fix tests" This reverts commit 1b563e31912c52530344767cb967b92410ee0937. --- .../Commands/RootCommand.cpp | 4 +-- src/AppInstallerCommonCore/Architecture.cpp | 28 ------------------- .../Public/AppInstallerArchitecture.h | 3 -- src/AppInstallerCommonCore/pch.h | 1 - 4 files changed, 1 insertion(+), 35 deletions(-) diff --git a/src/AppInstallerCLICore/Commands/RootCommand.cpp b/src/AppInstallerCLICore/Commands/RootCommand.cpp index 96fce52881..a385fbcd4b 100644 --- a/src/AppInstallerCLICore/Commands/RootCommand.cpp +++ b/src/AppInstallerCLICore/Commands/RootCommand.cpp @@ -136,9 +136,7 @@ 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() }); - // Do not output Portable root 64 on non applicable cases. - auto processArchitecture = Utility::GetProcessArchitecture(); - if (processArchitecture != Utility::Architecture::X86 && processArchitecture != Utility::Architecture::Arm) + if (Utility::GetSystemArchitecture() == Utility::Architecture::X64 || Utility::GetSystemArchitecture() == Utility::Architecture::Arm64) { keyDirectories.OutputLine({ Resource::LocString{ Resource::String::PortableRoot64 }, Runtime::GetPathTo(Runtime::PathName::PortablePackageMachineRootX64, true).u8string() }); } diff --git a/src/AppInstallerCommonCore/Architecture.cpp b/src/AppInstallerCommonCore/Architecture.cpp index 7aaed2c97f..ffab223d45 100644 --- a/src/AppInstallerCommonCore/Architecture.cpp +++ b/src/AppInstallerCommonCore/Architecture.cpp @@ -233,34 +233,6 @@ 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& GetApplicableArchitectures() { static std::vector applicableArchs = CreateApplicableArchitecturesVector(); diff --git a/src/AppInstallerCommonCore/Public/AppInstallerArchitecture.h b/src/AppInstallerCommonCore/Public/AppInstallerArchitecture.h index 1e5f2d2edf..e75e0c7918 100644 --- a/src/AppInstallerCommonCore/Public/AppInstallerArchitecture.h +++ b/src/AppInstallerCommonCore/Public/AppInstallerArchitecture.h @@ -28,9 +28,6 @@ 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& GetApplicableArchitectures(); diff --git a/src/AppInstallerCommonCore/pch.h b/src/AppInstallerCommonCore/pch.h index 4d9608415e..c9f24fb664 100644 --- a/src/AppInstallerCommonCore/pch.h +++ b/src/AppInstallerCommonCore/pch.h @@ -17,7 +17,6 @@ #include #include #include -#include #include "TraceLogging.h" From 0e237363416125b685aeea5d671a14393b528e1f Mon Sep 17 00:00:00 2001 From: Yao Sun Date: Fri, 7 Apr 2023 20:40:46 -0700 Subject: [PATCH 3/3] do not explicitly cal x64 folder id --- .../Commands/RootCommand.cpp | 5 +---- src/AppInstallerCLICore/PortableInstaller.cpp | 2 +- src/AppInstallerCLICore/Resources.h | 2 +- .../Shared/Strings/en-us/winget.resw | 6 +++--- .../Public/AppInstallerRuntime.h | 4 ++-- src/AppInstallerCommonCore/Runtime.cpp | 18 ++++++++++++------ 6 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/AppInstallerCLICore/Commands/RootCommand.cpp b/src/AppInstallerCLICore/Commands/RootCommand.cpp index a385fbcd4b..8a8c51cb16 100644 --- a/src/AppInstallerCLICore/Commands/RootCommand.cpp +++ b/src/AppInstallerCLICore/Commands/RootCommand.cpp @@ -135,11 +135,8 @@ namespace AppInstaller::CLI keyDirectories.OutputLine({ Resource::LocString{ Resource::String::PortableLinksUser }, Runtime::GetPathTo(Runtime::PathName::PortableLinksUserLocation, true).u8string() }); 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::PortableRoot }, Runtime::GetPathTo(Runtime::PathName::PortablePackageMachineRoot, 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) - { - keyDirectories.OutputLine({ Resource::LocString{ Resource::String::PortableRoot64 }, Runtime::GetPathTo(Runtime::PathName::PortablePackageMachineRootX64, true).u8string() }); - } keyDirectories.Complete(); context.Reporter.Info() << std::endl; } diff --git a/src/AppInstallerCLICore/PortableInstaller.cpp b/src/AppInstallerCLICore/PortableInstaller.cpp index b5d8cd4df9..19d7a0a396 100644 --- a/src/AppInstallerCLICore/PortableInstaller.cpp +++ b/src/AppInstallerCLICore/PortableInstaller.cpp @@ -44,7 +44,7 @@ namespace AppInstaller::CLI::Portable } else { - return Runtime::GetPathTo(Runtime::PathName::PortablePackageMachineRootX64); + return Runtime::GetPathTo(Runtime::PathName::PortablePackageMachineRoot); } } else diff --git a/src/AppInstallerCLICore/Resources.h b/src/AppInstallerCLICore/Resources.h index 945d573406..536dd0bd37 100644 --- a/src/AppInstallerCLICore/Resources.h +++ b/src/AppInstallerCLICore/Resources.h @@ -317,7 +317,7 @@ namespace AppInstaller::CLI::Resource WINGET_DEFINE_RESOURCE_STRINGID(PortableLinksUser); WINGET_DEFINE_RESOURCE_STRINGID(PortablePackageAlreadyExists); WINGET_DEFINE_RESOURCE_STRINGID(PortableRegistryCollisionOverridden); - WINGET_DEFINE_RESOURCE_STRINGID(PortableRoot64); + WINGET_DEFINE_RESOURCE_STRINGID(PortableRoot); WINGET_DEFINE_RESOURCE_STRINGID(PortableRoot86); WINGET_DEFINE_RESOURCE_STRINGID(PortableRootUser); WINGET_DEFINE_RESOURCE_STRINGID(PositionArgumentDescription); diff --git a/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw b/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw index e17431b031..e567fa12a4 100644 --- a/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw +++ b/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw @@ -1415,11 +1415,11 @@ Please specify one of them using the --source option to proceed. Portable Package Root (User) - - Portable Package Root (x86) + + Portable Package Root - Portable Package Root (x64) + Portable Package Root (x86) Portable install failed; Cleaning up... diff --git a/src/AppInstallerCommonCore/Public/AppInstallerRuntime.h b/src/AppInstallerCommonCore/Public/AppInstallerRuntime.h index 0031b4febf..b7b2d8d10e 100644 --- a/src/AppInstallerCommonCore/Public/AppInstallerRuntime.h +++ b/src/AppInstallerCommonCore/Public/AppInstallerRuntime.h @@ -52,8 +52,8 @@ namespace AppInstaller::Runtime UserProfile, // The location where portable packages are installed to with user scope. PortablePackageUserRoot, - // The location where portable packages are installed to with machine scope (x64). - PortablePackageMachineRootX64, + // The location where portable packages are installed to with machine scope. + PortablePackageMachineRoot, // The location where portable packages are installed to with machine scope (x86). PortablePackageMachineRootX86, // The location where symlinks to portable packages are stored under user scope. diff --git a/src/AppInstallerCommonCore/Runtime.cpp b/src/AppInstallerCommonCore/Runtime.cpp index 55a5d9b905..e1ec80974e 100644 --- a/src/AppInstallerCommonCore/Runtime.cpp +++ b/src/AppInstallerCommonCore/Runtime.cpp @@ -448,11 +448,11 @@ namespace AppInstaller::Runtime result.Path /= s_PortablePackagesDirectory; } break; - case PathName::PortablePackageMachineRootX64: + case PathName::PortablePackageMachineRoot: result.Path = Settings::User().Get(); if (result.Path.empty()) { - result.Path = GetKnownFolderPath(FOLDERID_ProgramFilesX64); + result.Path = GetKnownFolderPath(FOLDERID_ProgramFiles); result.Path /= s_PortablePackageRoot; result.Path /= s_PortablePackagesDirectory; } @@ -534,7 +534,7 @@ namespace AppInstaller::Runtime } break; case PathName::UserProfile: - case PathName::PortablePackageMachineRootX64: + case PathName::PortablePackageMachineRoot: case PathName::PortablePackageMachineRootX86: case PathName::PortableLinksMachineLocation: result = GetPathDetailsCommon(path); @@ -618,13 +618,19 @@ namespace AppInstaller::Runtime } break; case PathName::UserProfile: - case PathName::PortablePackageUserRoot: - case PathName::PortablePackageMachineRootX64: + case PathName::PortablePackageMachineRoot: case PathName::PortablePackageMachineRootX86: - case PathName::PortableLinksUserLocation: case PathName::PortableLinksMachineLocation: result = GetPathDetailsCommon(path); break; + case PathName::PortableLinksUserLocation: + case PathName::PortablePackageUserRoot: + result = GetPathDetailsCommon(path); + if (forDisplay) + { + ReplaceCommonPathPrefix(result.Path, GetKnownFolderPath(FOLDERID_LocalAppData), "%LOCALAPPDATA%"); + } + break; case PathName::SelfPackageRoot: result.Path = GetBinaryDirectoryPath(); result.Create = false;