-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add upgrade functionality in Com api #1853
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -341,6 +341,9 @@ namespace winrt::Microsoft::Management::Deployment::implementation | |
Microsoft::Management::Deployment::PackageVersionInfo packageVersionInfo = GetPackageVersionInfo(package, options); | ||
AddPackageManifestToContext(packageVersionInfo, context.get()); | ||
|
||
// If the installer has dependencies, DependencySource needs to be set. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there not a way that we can set the actual Source object rather than adding an argument? #Resolved There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's my test manifest is pointing to invalid dependencies. I'll remove this line as it's unnecessary. |
||
context->Args.AddArg(Execution::Args::Type::DependencySource, ::AppInstaller::Utility::ConvertToUTF8(packageVersionInfo.PackageCatalog().Info().Name())); | ||
|
||
// Note: AdditionalPackageCatalogArguments is not needed during install since the manifest is already known so no additional calls to the source are needed. The property is deprecated. | ||
return context; | ||
} | ||
|
@@ -402,7 +405,8 @@ namespace winrt::Microsoft::Management::Deployment::implementation | |
std::shared_ptr<Execution::OrchestratorQueueItem> queueItemParam, | ||
winrt::Microsoft::Management::Deployment::CatalogPackage package = nullptr, | ||
winrt::Microsoft::Management::Deployment::InstallOptions options = nullptr, | ||
std::wstring callerProcessInfoString = {}) | ||
std::wstring callerProcessInfoString = {}, | ||
bool isUpgrade = false) | ||
{ | ||
winrt::hresult terminationHR = S_OK; | ||
hstring correlationData = (options) ? options.CorrelationData() : L""; | ||
|
@@ -422,6 +426,30 @@ namespace winrt::Microsoft::Management::Deployment::implementation | |
{ | ||
Microsoft::Management::Deployment::PackageVersionInfo packageVersionInfo = GetPackageVersionInfo(package, options); | ||
std::unique_ptr<COMContext> comContext = CreateContextFromInstallOptions(package, options, callerProcessInfoString); | ||
|
||
if (isUpgrade) | ||
{ | ||
AppInstaller::Utility::VersionAndChannel installedVersion{ winrt::to_string(package.InstalledVersion().Version()), winrt::to_string(package.InstalledVersion().Channel()) }; | ||
AppInstaller::Utility::VersionAndChannel upgradeVersion{ winrt::to_string(packageVersionInfo.Version()), winrt::to_string(packageVersionInfo.Channel()) }; | ||
|
||
if (installedVersion.IsUpdatedBy(upgradeVersion) || | ||
(options.AllowUpgradeToUnknownVersion() && | ||
AppInstaller::Utility::ICUCaseInsensitiveEquals(installedVersion.GetChannel().ToString(), upgradeVersion.GetChannel().ToString()) && | ||
upgradeVersion.GetVersion().IsUnknown())) | ||
{ | ||
// Set upgrade flag | ||
comContext->SetFlags(AppInstaller::CLI::Execution::ContextFlag::InstallerExecutionUseUpdate); | ||
// Add installed version | ||
winrt::Microsoft::Management::Deployment::implementation::PackageVersionInfo* installedVersionInfoImpl = get_self<winrt::Microsoft::Management::Deployment::implementation::PackageVersionInfo>(package.InstalledVersion()); | ||
std::shared_ptr<::AppInstaller::Repository::IPackageVersion> internalInstalledVersion = installedVersionInfoImpl->GetRepositoryPackageVersion(); | ||
comContext->Add<AppInstaller::CLI::Execution::Data::InstalledPackageVersion>(internalInstalledVersion); | ||
} | ||
else | ||
{ | ||
co_return GetInstallResult(executionStage, APPINSTALLER_CLI_ERROR_UPDATE_NOT_APPLICABLE, correlationData, false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that we might need to break down the specific cases more for these errors. Specifically, I'm concerned about overloading this error (based on what I think is returning it, so I could be wrong). If the update does not have an applicable installer, do we get this error? If the caller gives us a version that is less than or equal to the current version, should we have a different error? If the caller does not give us a version, but the latest version is already installed, what error will be produced, if any? |
||
} | ||
} | ||
|
||
queueItem = Execution::OrchestratorQueueItemFactory::CreateItemForInstall(std::wstring{ package.Id() }, std::wstring{ packageVersionInfo.PackageCatalog().Info().Id() }, std::move(comContext)); | ||
Execution::ContextOrchestrator::Instance().EnqueueAndRunItem(queueItem); | ||
|
||
|
@@ -552,6 +580,32 @@ namespace winrt::Microsoft::Management::Deployment::implementation | |
return GetInstallOperation(true /*canCancelQueueItem*/, nullptr /*queueItem*/, package, options, std::move(callerProcessInfoString)); | ||
} | ||
|
||
winrt::Windows::Foundation::IAsyncOperationWithProgress<winrt::Microsoft::Management::Deployment::InstallResult, winrt::Microsoft::Management::Deployment::InstallProgress> PackageManager::UpgradePackageAsync(winrt::Microsoft::Management::Deployment::CatalogPackage package, winrt::Microsoft::Management::Deployment::InstallOptions options) | ||
{ | ||
hstring correlationData = (options) ? options.CorrelationData() : L""; | ||
|
||
// options and catalog can both be null, package must be set. | ||
WINGET_RETURN_INSTALL_RESULT_HR_IF(APPINSTALLER_CLI_ERROR_INVALID_CL_ARGUMENTS, !package); | ||
// the package should have an installed version to be upgraded. | ||
WINGET_RETURN_INSTALL_RESULT_HR_IF(APPINSTALLER_CLI_ERROR_INVALID_CL_ARGUMENTS, !package.InstalledVersion()); | ||
|
||
HRESULT hr = S_OK; | ||
std::wstring callerProcessInfoString; | ||
try | ||
{ | ||
// Check for permissions and get caller info for telemetry. | ||
// This must be done before any co_awaits since it requires info from the rpc caller thread. | ||
auto [hrGetCallerId, callerProcessId] = GetCallerProcessId(); | ||
WINGET_RETURN_INSTALL_RESULT_HR_IF_FAILED(hrGetCallerId); | ||
WINGET_RETURN_INSTALL_RESULT_HR_IF_FAILED(EnsureProcessHasCapability(Capability::PackageManagement, callerProcessId)); | ||
callerProcessInfoString = TryGetCallerProcessInfo(callerProcessId); | ||
} | ||
WINGET_CATCH_STORE(hr, APPINSTALLER_CLI_ERROR_COMMAND_FAILED); | ||
WINGET_RETURN_INSTALL_RESULT_HR_IF_FAILED(hr); | ||
|
||
return GetInstallOperation(true /*canCancelQueueItem*/, nullptr /*queueItem*/, package, options, std::move(callerProcessInfoString), true /* isUpgrade */); | ||
} | ||
|
||
winrt::Windows::Foundation::IAsyncOperationWithProgress<winrt::Microsoft::Management::Deployment::InstallResult, winrt::Microsoft::Management::Deployment::InstallProgress> PackageManager::GetInstallProgress(winrt::Microsoft::Management::Deployment::CatalogPackage package, winrt::Microsoft::Management::Deployment::PackageCatalogInfo catalogInfo) | ||
{ | ||
hstring correlationData; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,9 +21,12 @@ namespace winrt::Microsoft::Management::Deployment::implementation | |
winrt::Microsoft::Management::Deployment::PackageCatalogReference CreateCompositePackageCatalog(winrt::Microsoft::Management::Deployment::CreateCompositePackageCatalogOptions const& options); | ||
winrt::Windows::Foundation::IAsyncOperationWithProgress<winrt::Microsoft::Management::Deployment::InstallResult, winrt::Microsoft::Management::Deployment::InstallProgress> | ||
InstallPackageAsync(winrt::Microsoft::Management::Deployment::CatalogPackage package, winrt::Microsoft::Management::Deployment::InstallOptions options); | ||
//Contract 2.0 | ||
// Contract 2.0 | ||
winrt::Windows::Foundation::IAsyncOperationWithProgress<winrt::Microsoft::Management::Deployment::InstallResult, winrt::Microsoft::Management::Deployment::InstallProgress> | ||
GetInstallProgress(winrt::Microsoft::Management::Deployment::CatalogPackage package, winrt::Microsoft::Management::Deployment::PackageCatalogInfo catalogInfo); | ||
// Contract 4.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happened to 3? Was that the enum value I added? #Resolved |
||
winrt::Windows::Foundation::IAsyncOperationWithProgress<winrt::Microsoft::Management::Deployment::InstallResult, winrt::Microsoft::Management::Deployment::InstallProgress> | ||
UpgradePackageAsync(winrt::Microsoft::Management::Deployment::CatalogPackage package, winrt::Microsoft::Management::Deployment::InstallOptions options); | ||
}; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: This seems overly aggressive on combining tasks. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll leave it as is for bug fix now