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 UpgradeCode for matching MSI apps #2418

Merged
merged 16 commits into from Aug 15, 2022
1 change: 1 addition & 0 deletions .github/actions/spelling/allow.txt
Expand Up @@ -267,6 +267,7 @@ ISource
isspace
istream
istringstream
isxdigit
ITest
IUnknown
json
Expand Down
17 changes: 7 additions & 10 deletions .github/actions/spelling/expect.txt
Expand Up @@ -11,7 +11,7 @@ aicli
AICLIC
ajor
alreadyinstalled
Amd
amd
amrutha
anonymized
APARTMENTTHREADED
Expand Down Expand Up @@ -40,6 +40,8 @@ azurewebsites
badbit
Baz
bcp
BEFACEF
BEFACEFE
Beigi
bfd
BFirst
Expand Down Expand Up @@ -67,10 +69,8 @@ cend
centralus
certmgr
certs
Cfg
cfr
cgi
cgmanifest
chcp
ci
cinq
Expand All @@ -91,7 +91,6 @@ count'th
countof
countryregion
createmanifestmetadata
CSharp
cstdint
ctc
Ctx
Expand Down Expand Up @@ -127,6 +126,7 @@ execustom
EXEHASH
experimentalfeatures
fcb
FECAFEB
fd
fdw
fedorapeople
Expand Down Expand Up @@ -220,7 +220,7 @@ kayone
Keivan
KF
KNOWNFOLDERID
kp
Kp
ktf
langs
LATN
Expand Down Expand Up @@ -276,11 +276,9 @@ myinstalldir
mylog
mysilent
mysilentwithprogress
mytool
nameof
nativehandle
NESTEDINSTALLER
NETFX
netlify
Newtonsoft
NOEXPAND
Expand All @@ -302,16 +300,15 @@ ofile
openmode
Outptr
packageinuse
PACL
PARAMETERMAP
paramref
PACL
pathparts
Patil
pb
PCCERT
PCs
pcwsz
pdp
PEGI
pfn
pfxpath
Expand Down Expand Up @@ -444,6 +441,7 @@ unparsable
UNSCOPED
unvirtualized
UParse
upgradecode
UPSERT
uris
URLs
Expand All @@ -460,7 +458,6 @@ VERSIE
virtualization
vns
vscode
vstest
vy
wcslen
webpages
Expand Down
8 changes: 8 additions & 0 deletions src/AppInstallerCLICore/Workflows/InstallFlow.cpp
Expand Up @@ -691,6 +691,14 @@ namespace AppInstaller::CLI::Workflow
entries.push_back(std::move(entry));
}

auto upgradeCodes = correlationResult.Package->GetMultiProperty(PackageVersionMultiProperty::UpgradeCode);
for (auto&& upgradeCode : upgradeCodes)
{
AppsAndFeaturesEntry entry = baseEntry;
entry.UpgradeCode= std::move(upgradeCode).get();
entries.push_back(std::move(entry));
}

context.Add<Data::CorrelatedAppsAndFeaturesEntries>(std::move(entries));
}

Expand Down
19 changes: 19 additions & 0 deletions src/AppInstallerCLIE2ETests/ListCommand.cs
Expand Up @@ -57,6 +57,25 @@ public void ListWithArpVersionMapping()
ArpVersionMappingTest("AppInstallerTest.TestArpVersionSameOrder", "TestArpVersionSameOrder", "12.0", "> 2.0", "12.0");
}

[Test]
public void ListWithUpgradeCode()
{
// Installs the MSI installer using the TestMsiInstaller package.
// Then tries listing the TestMsiInstallerUpgradeCode package, which should
// be correlated to it by the UpgradeCode.
if (string.IsNullOrEmpty(TestCommon.MsiInstallerPath))
{
Assert.Ignore("MSI installer not available");
}

var installDir = TestCommon.GetRandomTestDir();
Assert.AreEqual(Constants.ErrorCode.S_OK, TestCommon.RunAICLICommand("install", $"TestMsiInstaller --silent -l {installDir}").ExitCode);

var result = TestCommon.RunAICLICommand("list", "TestMsiInstallerUpgradeCode");
Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
Assert.True(result.StdOut.Contains("AppInstallerTest.TestMsiInstallerUpgradeCode"));
}

private void ArpVersionMappingTest(string packageIdentifier, string displayNameOverride, string displayVersionOverride, string expectedListVersion, string notExpectedListVersion = "")
{
System.Guid guid = System.Guid.NewGuid();
Expand Down
@@ -0,0 +1,15 @@
# Uses the MSI installer; doesn't list the ProductCode, only the UpgradeCode
PackageIdentifier: AppInstallerTest.TestMsiInstallerUpgradeCode
PackageVersion: 1.0.0.0
PackageLocale: en-US
PackageName: TestMsiInstallerUpgradeCode
Publisher: AppInstallerTest
Installers:
- Architecture: x86
InstallerUrl: https://localhost:5001/TestKit/AppInstallerTestMsiInstaller/AppInstallerTestMsiInstaller.msi
InstallerType: msi
InstallerSha256: <MSIHASH>
AppsAndFeaturesEntries:
- UpgradeCode: '{B9CF9DD5-D46F-4CE0-BFC9-633BF9D3A6F4}'
ManifestType: singleton
ManifestVersion: 1.1.0
17 changes: 14 additions & 3 deletions src/AppInstallerRepositoryCore/ARPCorrelation.cpp
Expand Up @@ -188,15 +188,16 @@ namespace AppInstaller::Repository::Correlation
}
}

std::vector<std::string> productCodes;
std::set<std::string> productCodes;
std::set<std::string> upgradeCodes;
for (const auto& installer : manifest.Installers)
{
if (!installer.ProductCode.empty())
{
if (std::find(productCodes.begin(), productCodes.end(), installer.ProductCode) == productCodes.end())
// Add each ProductCode only once
if (productCodes.insert(installer.ProductCode).second)
{
manifestSearchRequest.Inclusions.emplace_back(PackageMatchFilter(PackageMatchField::ProductCode, MatchType::Exact, installer.ProductCode));
productCodes.emplace_back(installer.ProductCode);
}
}

Expand All @@ -208,6 +209,16 @@ namespace AppInstaller::Repository::Correlation
appsAndFeaturesEntry.DisplayName,
appsAndFeaturesEntry.Publisher.empty() ? defaultPublisher : appsAndFeaturesEntry.Publisher));
}

// Add each ProductCode and UpgradeCode only once;
if (!appsAndFeaturesEntry.ProductCode.empty() && upgradeCodes.insert(appsAndFeaturesEntry.ProductCode).second)
{
manifestSearchRequest.Inclusions.emplace_back(PackageMatchFilter(PackageMatchField::ProductCode, MatchType::Exact, appsAndFeaturesEntry.ProductCode));
}
if (!appsAndFeaturesEntry.UpgradeCode.empty() && upgradeCodes.insert(appsAndFeaturesEntry.UpgradeCode).second)
{
manifestSearchRequest.Inclusions.emplace_back(PackageMatchFilter(PackageMatchField::UpgradeCode, MatchType::Exact, appsAndFeaturesEntry.UpgradeCode));
}
}
}

Expand Down
Expand Up @@ -269,6 +269,9 @@
<ClInclude Include="Microsoft\Schema\1_4\Interface.h" />
<ClInclude Include="Microsoft\Schema\1_5\ArpVersionVirtualTable.h" />
<ClInclude Include="Microsoft\Schema\1_5\Interface.h" />
<ClInclude Include="Microsoft\Schema\1_6\Interface.h" />
<ClInclude Include="Microsoft\Schema\1_6\SearchResultsTable.h" />
<ClInclude Include="Microsoft\Schema\1_6\UpgradeCodeTable.h" />
<ClInclude Include="Microsoft\Schema\ISQLiteIndex.h" />
<ClInclude Include="Microsoft\Schema\MetadataTable.h" />
<ClInclude Include="Microsoft\Schema\Version.h" />
Expand Down Expand Up @@ -344,6 +347,8 @@
<ClCompile Include="Microsoft\Schema\1_4\DependenciesTable.cpp" />
<ClCompile Include="Microsoft\Schema\1_4\Interface_1_4.cpp" />
<ClCompile Include="Microsoft\Schema\1_5\Interface_1_5.cpp" />
<ClCompile Include="Microsoft\Schema\1_6\Interface_1_6.cpp" />
<ClCompile Include="Microsoft\Schema\1_6\SearchResultsTable_1_6.cpp" />
<ClCompile Include="Microsoft\Schema\MetadataTable.cpp" />
<ClCompile Include="Microsoft\Schema\Version.cpp" />
<ClCompile Include="Microsoft\SQLiteIndex.cpp" />
Expand Down
Expand Up @@ -64,6 +64,9 @@
<Filter Include="Microsoft\Schema\1_5">
<UniqueIdentifier>{e31c8e5b-ed2c-43c8-b91b-db8ec4c52f71}</UniqueIdentifier>
</Filter>
<Filter Include="Microsoft\Schema\1_6">
<UniqueIdentifier>{84a55def-9fb8-4c90-8d5a-2cedc171940b}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h">
Expand Down Expand Up @@ -288,6 +291,15 @@
<ClInclude Include="Microsoft\Schema\1_0\VirtualTableBase.h">
<Filter>Microsoft\Schema\1_0</Filter>
</ClInclude>
<ClInclude Include="Microsoft\Schema\1_6\Interface.h">
<Filter>Microsoft\Schema\1_6</Filter>
</ClInclude>
<ClInclude Include="Microsoft\Schema\1_6\UpgradeCodeTable.h">
<Filter>Microsoft\Schema\1_6</Filter>
</ClInclude>
<ClInclude Include="Microsoft\Schema\1_6\SearchResultsTable.h">
<Filter>Microsoft\Schema\1_6</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp">
Expand Down Expand Up @@ -452,6 +464,12 @@
<ClCompile Include="ArpVersionValidation.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Microsoft\Schema\1_6\Interface_1_6.cpp">
<Filter>Microsoft\Schema\1_6</Filter>
</ClCompile>
<ClCompile Include="Microsoft\Schema\1_6\SearchResultsTable_1_6.cpp">
<Filter>Microsoft\Schema\1_6</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="PropertySheet.props" />
Expand Down
7 changes: 7 additions & 0 deletions src/AppInstallerRepositoryCore/CompositeSource.cpp
Expand Up @@ -24,6 +24,7 @@ namespace AppInstaller::Repository
{
case AppInstaller::Repository::PackageMatchField::PackageFamilyName:
case AppInstaller::Repository::PackageMatchField::ProductCode:
case AppInstaller::Repository::PackageMatchField::UpgradeCode:
return true;
}

Expand Down Expand Up @@ -738,6 +739,12 @@ namespace AppInstaller::Repository
PackageMatchField::ProductCode,
data);

GetSystemReferenceStrings(
version,
PackageVersionMultiProperty::UpgradeCode,
PackageMatchField::UpgradeCode,
data);

GetNameAndPublisher(
version,
data);
Expand Down