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

Expose deeper installation detection through Com #2420

Merged
merged 19 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,12 @@ installinprogress
installshield
insufficientmemory
Intelli
IObject
ishelp
ISQ
ISVs
itr
IWin
jdk
jfearn
JObject
Expand Down
8 changes: 8 additions & 0 deletions src/AppInstallerCLIE2ETests/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,14 @@ public class ErrorCode
public const int ERROR_INSTALL_DOWNGRADE = unchecked((int)0x8A15010E);
public const int ERROR_INSTALL_BLOCKED_BY_POLICY = unchecked((int)0x8A15010F);
public const int ERROR_INSTALL_DEPENDENCIES = unchecked((int)0x8A150110);

public const int INSTALLED_STATUS_ARP_ENTRY_NOT_FOUND = unchecked((int)0x8A150201);
public const int INSTALLED_STATUS_INSTALL_LOCATION_NOT_APPLICABLE = unchecked((int)0x0A150202);
public const int INSTALLED_STATUS_INSTALL_LOCATION_NOT_FOUND = unchecked((int)0x8A150203);
public const int INSTALLED_STATUS_FILE_HASH_MISMATCH = unchecked((int)0x8A150204);
public const int INSTALLED_STATUS_FILE_NOT_FOUND = unchecked((int)0x8A150205);
public const int INSTALLED_STATUS_FILE_FOUND_WITHOUT_HASH_CHECK = unchecked((int)0x0A150206);
public const int INSTALLED_STATUS_FILE_ACCESS_ERROR = unchecked((int)0x8A150207);
}
}
}
271 changes: 271 additions & 0 deletions src/AppInstallerCLIE2ETests/Interop/CheckInstalledStatusInterop.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
PackageIdentifier: AppInstallerTest.TestCheckInstalledStatus
PackageVersion: 1.0
PackageName: TestCheckInstalledStatus
PackageLocale: en-US
Publisher: Microsoft
License: Test
ShortDescription: E2E test for check installed status test.
Installers:
- Architecture: neutral
InstallerUrl: https://localhost:5001/TestKit/AppInstallerTestExeInstaller/AppInstallerTestExeInstaller.exe
InstallerType: exe
InstallerSha256: <EXEHASH>
ProductCode: CheckInstalledStatusProductId
InstallationMetadata:
DefaultInstallLocation: "%TEMP%\\TestInstalledStatus"
Files:
- RelativeFilePath: "data.txt"
# Hash value is for a txt file with "Test" as content in utf8
FileSha256: 532eaabd9574880dbf76b9b8cc00832c20a6ec113d682299550d7a6e0f345e25
FileType: other
- RelativeFilePath: "TestExeInstalled.txt"
FileType: other
ManifestType: singleton
ManifestVersion: 1.4.0
17 changes: 16 additions & 1 deletion src/AppInstallerCommonCore/Filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.
#include "pch.h"
#include "Public/AppInstallerStrings.h"
#include "winget/Filesystem.h"
#include "public/winget/Filesystem.h"

namespace AppInstaller::Filesystem
{
Expand Down Expand Up @@ -167,4 +167,19 @@ namespace AppInstaller::Filesystem
}
}
}

std::filesystem::path GetExpandedPath(const std::string& path)
{
std::string trimPath = path;
Utility::Trim(trimPath);

try
{
return Utility::ExpandEnvironmentVariables(Utility::ConvertToUTF16(trimPath));
}
catch (...)
{
return path;
}
}
}
12 changes: 10 additions & 2 deletions src/AppInstallerCommonCore/Manifest/ManifestValidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,17 @@ namespace AppInstaller::Manifest
// Todo: use the comparator from ManifestComparator when that one is fully implemented.
auto installerCmp = [](const ManifestInstaller& in1, const ManifestInstaller& in2)
{
if (in1.EffectiveInstallerType() != in2.EffectiveInstallerType())
if (in1.BaseInstallerType != in2.BaseInstallerType)
{
return in1.EffectiveInstallerType() < in2.EffectiveInstallerType();
return in1.BaseInstallerType < in2.BaseInstallerType;
}
else if (IsArchiveType(in1.BaseInstallerType))
{
// Compare nested installer type if base installer type is archive.
if (in1.NestedInstallerType != in2.NestedInstallerType)
{
return in1.NestedInstallerType < in2.NestedInstallerType;
}
}

if (in1.Arch != in2.Arch)
Expand Down
13 changes: 13 additions & 0 deletions src/AppInstallerCommonCore/Public/AppInstallerErrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@
#define APPINSTALLER_CLI_ERROR_INSTALL_DEPENDENCIES ((HRESULT)0x8A150110)
#define APPINSTALLER_CLI_ERROR_INSTALL_PACKAGE_IN_USE_BY_APPLICATION ((HRESULT)0x8A150111)

// Status values for check package installed status results.
// Partial success has the success bit(first bit) set to 0.
#define WINGET_INSTALLED_STATUS_ARP_ENTRY_FOUND S_OK
#define WINGET_INSTALLED_STATUS_ARP_ENTRY_NOT_FOUND ((HRESULT)0x8A150201)
#define WINGET_INSTALLED_STATUS_INSTALL_LOCATION_FOUND S_OK
#define WINGET_INSTALLED_STATUS_INSTALL_LOCATION_NOT_APPLICABLE ((HRESULT)0x0A150202)
#define WINGET_INSTALLED_STATUS_INSTALL_LOCATION_NOT_FOUND ((HRESULT)0x8A150203)
#define WINGET_INSTALLED_STATUS_FILE_HASH_MATCH S_OK
#define WINGET_INSTALLED_STATUS_FILE_HASH_MISMATCH ((HRESULT)0x8A150204)
#define WINGET_INSTALLED_STATUS_FILE_NOT_FOUND ((HRESULT)0x8A150205)
#define WINGET_INSTALLED_STATUS_FILE_FOUND_WITHOUT_HASH_CHECK ((HRESULT)0x0A150206)
#define WINGET_INSTALLED_STATUS_FILE_ACCESS_ERROR ((HRESULT)0x8A150207)


namespace AppInstaller
{
Expand Down
3 changes: 3 additions & 0 deletions src/AppInstallerCommonCore/Public/AppInstallerVersions.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ namespace AppInstaller::Utility
// Returns if the version is an approximate version.
bool IsApproximate() const { return m_approximateComparator != ApproximateComparator::None; }

// Get the base version from approximate version, or return a copy if the version is not approximate.
Version GetBaseVersion() const;

protected:

bool IsBaseVersionLatest() const;
Expand Down
5 changes: 4 additions & 1 deletion src/AppInstallerCommonCore/Public/winget/Filesystem.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#pragma once
#include "pch.h"
#include <filesystem>

namespace AppInstaller::Filesystem
{
Expand All @@ -22,4 +22,7 @@ namespace AppInstaller::Filesystem

// Creates a symlink that points to the target path.
bool CreateSymlink(const std::filesystem::path& path, const std::filesystem::path& target);

// Get expanded file system path.
std::filesystem::path GetExpandedPath(const std::string& path);
}
3 changes: 3 additions & 0 deletions src/AppInstallerCommonCore/Public/winget/ManifestCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ namespace AppInstaller::Manifest
{
string_t DefaultInstallLocation;
std::vector<InstalledFile> Files;

// Checks if there are any installation metadata available.
bool HasData() const { return !DefaultInstallLocation.empty() || !Files.empty(); }
};

InstallerTypeEnum ConvertToInstallerTypeEnum(const std::string& in);
Expand Down
16 changes: 16 additions & 0 deletions src/AppInstallerCommonCore/Versions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,22 @@ namespace AppInstaller::Utility
return s_zero;
}
}

Version Version::GetBaseVersion() const
{
Version baseVersion = *this;
baseVersion.m_approximateComparator = ApproximateComparator::None;
if (m_approximateComparator == ApproximateComparator::LessThan)
{
baseVersion.m_version = m_version.substr(s_Approximate_Less_Than.size());
}
else if (m_approximateComparator == ApproximateComparator::GreaterThan)
{
baseVersion.m_version = m_version.substr(s_Approximate_Greater_Than.size());
}

return baseVersion;
}

bool Version::IsBaseVersionLatest() const
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@
<ClCompile Include="Microsoft\SQLiteIndexSource.cpp" />
<ClCompile Include="Microsoft\SQLiteStorageBase.cpp" />
<ClCompile Include="PackageDependenciesValidation.cpp" />
<ClCompile Include="PackageInstalledStatus.cpp" />
<ClCompile Include="PackageTrackingCatalog.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,9 @@
<ClCompile Include="Microsoft\SQLiteStorageBase.cpp">
<Filter>Microsoft</Filter>
</ClCompile>
<ClCompile Include="PackageInstalledStatus.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="PropertySheet.props" />
Expand Down
6 changes: 3 additions & 3 deletions src/AppInstallerRepositoryCore/CompositeSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,17 +417,17 @@ namespace AppInstaller::Repository
return true;
}

const std::shared_ptr<IPackage>& GetInstalledPackage()
const std::shared_ptr<IPackage>& GetInstalledPackage() const
{
return m_installedPackage;
}

const std::shared_ptr<IPackage>& GetAvailablePackage()
const std::shared_ptr<IPackage>& GetAvailablePackage() const
{
return m_availablePackage;
}

const std::shared_ptr<IPackage>& GetTrackingPackage()
const std::shared_ptr<IPackage>& GetTrackingPackage() const
{
return m_trackingPackage;
}
Expand Down
Loading