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 12 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
8 changes: 8 additions & 0 deletions src/AppInstallerCLIE2ETests/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,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)0x8A150202);
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)0x8A150206);
public const int INSTALLED_STATUS_FILE_ACCESS_ERROR = unchecked((int)0x8A150207);
}
}
}
251 changes: 251 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.3.0
5 changes: 5 additions & 0 deletions src/AppInstallerCLITests/TestSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ namespace TestCommon
return false;
}

std::vector<InstallerInstalledStatus> TestPackage::CheckInstalledStatus(InstalledStatusType) const
{
return {};
}

bool TestPackage::IsSame(const IPackage* other) const
{
if (IsSameOverride)
Expand Down
1 change: 1 addition & 0 deletions src/AppInstallerCLITests/TestSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ namespace TestCommon
std::shared_ptr<AppInstaller::Repository::IPackageVersion> GetLatestAvailableVersion() const override;
std::shared_ptr<AppInstaller::Repository::IPackageVersion> GetAvailableVersion(const AppInstaller::Repository::PackageVersionKey& versionKey) const override;
bool IsUpdateAvailable() const override;
std::vector<AppInstaller::Repository::InstallerInstalledStatus> CheckInstalledStatus(AppInstaller::Repository::InstalledStatusType types) const override;
bool IsSame(const IPackage* other) const override;

std::shared_ptr<AppInstaller::Repository::IPackageVersion> InstalledVersion;
Expand Down
26 changes: 26 additions & 0 deletions src/AppInstallerCommonCore/Filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.
#include "pch.h"
#include "Public/AppInstallerStrings.h"
#include "public/winget/FileSystem.h"

namespace AppInstaller::Filesystem
{
Expand Down Expand Up @@ -131,4 +132,29 @@ namespace AppInstaller::Filesystem
// but it is better to succeed the operation and leave a file around than to fail.
std::filesystem::copy_file(from, to, std::filesystem::copy_options::overwrite_existing);
}

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

if (trimPath.empty())
{
return {};
}

std::wstring widePath = Utility::ConvertToUTF16(trimPath);
DWORD count = ExpandEnvironmentStrings(widePath.c_str(), nullptr, 0);
std::wstring buffer;
buffer.resize(count);
if (ExpandEnvironmentStrings(widePath.c_str(), buffer.data(), count) > 0)
{
buffer.resize(count - 1);
return buffer;
}
else
{
return trimPath;
}
}
}
8 changes: 8 additions & 0 deletions src/AppInstallerCommonCore/Manifest/ManifestValidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ namespace AppInstaller::Manifest
{
return in1.InstallerType < in2.InstallerType;
}
else if (IsArchiveType(in1.InstallerType))
{
// Compare nested installer type if installer type is archive.
if (in1.NestedInstallerType != in2.NestedInstallerType)
{
return in1.NestedInstallerType != in2.NestedInstallerType;
}
}

if (in1.Arch != in2.Arch)
{
Expand Down
12 changes: 12 additions & 0 deletions src/AppInstallerCommonCore/Public/AppInstallerErrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@
#define APPINSTALLER_CLI_ERROR_INSTALL_BLOCKED_BY_POLICY ((HRESULT)0x8A15010F)
#define APPINSTALLER_CLI_ERROR_INSTALL_DEPENDENCIES ((HRESULT)0x8A150110)

// Status values for check package installed status results.
#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)0x8A150202)
Copy link
Member

@JohnMcPMS JohnMcPMS Aug 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these actually be success codes when it is a case of not full success? (not have the error bit set) #Resolved

#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)0x8A150206)
#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 @@ -19,4 +19,7 @@ namespace AppInstaller::Filesystem

// Renames the file to a new path.
void RenameFile(const std::filesystem::path& from, const std::filesystem::path& to);

// 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 @@ -276,6 +276,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
Loading