commit 57be9d49eda3c2b96e9d4b14fffda4712d562094
parent 1fbfacc13950de8a17875d40a8beb99fc6ada6c2
Author: sachintaMSFT <80828309+sachintaMSFT@users.noreply.github.com>
Date: Tue, 3 Aug 2021 11:14:55 -0700
Allow Restricted source be always available to callers (#1336)
* Allow experimental Store source be always available to Store even when it is not visible to public
* Addressed PR Comments
Diffstat:
9 files changed, 77 insertions(+), 10 deletions(-)
diff --git a/src/AppInstallerCLICore/AppInstallerCLICore.vcxproj b/src/AppInstallerCLICore/AppInstallerCLICore.vcxproj
@@ -231,6 +231,7 @@
<ClInclude Include="ChannelStreams.h" />
<ClInclude Include="COMContext.h" />
<ClInclude Include="Command.h" />
+ <ClInclude Include="Commands\COMInstallCommand.h" />
<ClInclude Include="Commands\CompleteCommand.h" />
<ClInclude Include="Commands\ExperimentalCommand.h" />
<ClInclude Include="Commands\ExportCommand.h" />
@@ -275,6 +276,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="COMContext.cpp" />
+ <ClCompile Include="Commands\COMInstallCommand.cpp" />
<ClCompile Include="Commands\ImportCommand.cpp" />
<ClCompile Include="PackageCollection.cpp" />
<ClCompile Include="Argument.cpp" />
diff --git a/src/AppInstallerCLICore/AppInstallerCLICore.vcxproj.filters b/src/AppInstallerCLICore/AppInstallerCLICore.vcxproj.filters
@@ -155,6 +155,9 @@
<ClInclude Include="COMContext.h">
<Filter>Public</Filter>
</ClInclude>
+ <ClInclude Include="Commands\COMInstallCommand.h">
+ <Filter>Commands</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp">
@@ -277,6 +280,9 @@
<ClCompile Include="COMContext.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="Commands\COMInstallCommand.cpp">
+ <Filter>Commands</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="PropertySheet.props" />
diff --git a/src/AppInstallerCLICore/COMContext.cpp b/src/AppInstallerCLICore/COMContext.cpp
@@ -32,6 +32,7 @@ namespace AppInstaller
{
m_executionStage = executionStage;
m_comProgressCallback(ReportType::ExecutionPhaseUpdate, 0, 0, ProgressType::None, m_executionStage);
+ Logging::SetExecutionStage(static_cast<uint32_t>(m_executionStage));
}
void COMContext::SetLoggerContext(const std::wstring_view telemetryCorelationJson, const std::string& caller)
diff --git a/src/AppInstallerCLICore/Commands/COMInstallCommand.cpp b/src/AppInstallerCLICore/Commands/COMInstallCommand.cpp
@@ -0,0 +1,22 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT License.
+#include "pch.h"
+#include "COMInstallCommand.h"
+#include "Workflows/InstallFlow.h"
+#include "Workflows/WorkflowBase.h"
+
+using namespace AppInstaller::CLI::Execution;
+using namespace AppInstaller::CLI::Workflow;
+using namespace AppInstaller::Manifest;
+using namespace AppInstaller::Utility::literals;
+
+namespace AppInstaller::CLI
+{
+ // IMPORTANT: To use this command, the caller should have already retrieved the package manifest (GetManifest()) and added it to the Context Data
+ void COMInstallCommand::ExecuteInternal(Context& context) const
+ {
+ context <<
+ Workflow::ReportExecutionStage(ExecutionStage::Discovery) <<
+ Workflow::InstallPackageVersion;
+ }
+}
diff --git a/src/AppInstallerCLICore/Commands/COMInstallCommand.h b/src/AppInstallerCLICore/Commands/COMInstallCommand.h
@@ -0,0 +1,16 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT License.
+#pragma once
+#include "Command.h"
+
+namespace AppInstaller::CLI
+{
+ // IMPORTANT: To use this command, the caller should have already retrieved the package manifest (GetManifest()) and added it to the Context Data
+ struct COMInstallCommand final : public Command
+ {
+ COMInstallCommand(std::string_view parent) : Command("install", parent) {}
+
+ protected:
+ void ExecuteInternal(Execution::Context& context) const override;
+ };
+}
diff --git a/src/AppInstallerCLICore/ExecutionContext.cpp b/src/AppInstallerCLICore/ExecutionContext.cpp
@@ -207,5 +207,6 @@ namespace AppInstaller::CLI::Execution
}
m_executionStage = stage;
+ Logging::SetExecutionStage(static_cast<uint32_t>(m_executionStage));
}
}
diff --git a/src/AppInstallerRepositoryCore/RepositorySource.cpp b/src/AppInstallerRepositoryCore/RepositorySource.cpp
@@ -1025,7 +1025,9 @@ namespace AppInstaller::Repository
// Get the details again by name from the source list because SaveMetadata only updates the LastUpdateTime
// if the details came from the same instance of the list that's being saved.
// Some sources that do not need updating like the Installed source, do not have Name values.
- if (!details.Name.empty())
+ // Restricted sources don't have full functionality
+ if (!details.Name.empty() &&
+ !details.Restricted)
{
SourceListInternal sourceList;
auto source = sourceList.GetSource(details.Name);
@@ -1035,8 +1037,7 @@ namespace AppInstaller::Repository
return {};
}
- if (!source->Restricted &&
- ShouldUpdateBeforeOpen(*source))
+ if (ShouldUpdateBeforeOpen(*source))
{
try
{
diff --git a/src/Microsoft.Management.Deployment/PackageManager.cpp b/src/Microsoft.Management.Deployment/PackageManager.cpp
@@ -8,7 +8,8 @@
#include "ExecutionContext.h"
#include "Workflows/WorkflowBase.h"
#include <winget/UserSettings.h>
-#include "Commands/InstallCommand.h"
+#include <winget/Manifest.h>
+#include "Commands/COMInstallCommand.h"
#include <AppInstallerTelemetry.h>
#include <AppInstallerErrors.h>
#pragma warning( push )
@@ -72,7 +73,7 @@ namespace winrt::Microsoft::Management::Deployment::implementation
winrt::Microsoft::Management::Deployment::PackageCatalogReference PackageManager::GetLocalPackageCatalog(winrt::Microsoft::Management::Deployment::LocalPackageCatalog const& localPackageCatalog)
{
// InstalledPackages is the only one supported right now, so return early if it's not that.
- if(localPackageCatalog != Microsoft::Management::Deployment::LocalPackageCatalog::InstalledPackages)
+ if (localPackageCatalog != Microsoft::Management::Deployment::LocalPackageCatalog::InstalledPackages)
{
throw hresult_invalid_argument();
}
@@ -100,6 +101,24 @@ namespace winrt::Microsoft::Management::Deployment::implementation
return nullptr;
}
}
+ void AddPackageManifestToContext(winrt::Microsoft::Management::Deployment::PackageVersionInfo packageVersionInfo, ::AppInstaller::CLI::Execution::Context& context)
+ {
+ winrt::Microsoft::Management::Deployment::implementation::PackageVersionInfo* packageVersionInfoImpl = get_self<winrt::Microsoft::Management::Deployment::implementation::PackageVersionInfo>(packageVersionInfo);
+ std::shared_ptr<::AppInstaller::Repository::IPackageVersion> internalPackageVersion = packageVersionInfoImpl->GetRepositoryPackageVersion();
+ ::AppInstaller::Manifest::Manifest manifest = internalPackageVersion->GetManifest();
+
+ std::string targetLocale;
+ if (context.Args.Contains(::AppInstaller::CLI::Execution::Args::Type::Locale))
+ {
+ targetLocale = context.Args.GetArg(::AppInstaller::CLI::Execution::Args::Type::Locale);
+ }
+ manifest.ApplyLocale(targetLocale);
+
+ context.Add<::AppInstaller::CLI::Execution::Data::Manifest>(std::move(manifest));
+ context.Add<::AppInstaller::CLI::Execution::Data::PackageVersion>(std::move(internalPackageVersion));
+
+ ::AppInstaller::Logging::Telemetry().LogManifestFields(manifest.Id, manifest.DefaultLocalization.Get<::AppInstaller::Manifest::Localization::PackageName>(), manifest.Version);
+ }
winrt::Microsoft::Management::Deployment::PackageCatalogReference PackageManager::CreateCompositePackageCatalog(winrt::Microsoft::Management::Deployment::CreateCompositePackageCatalogOptions const& options)
{
for (uint32_t i = 0; i < options.Catalogs().Size(); ++i)
@@ -182,10 +201,6 @@ namespace winrt::Microsoft::Management::Deployment::implementation
context.SetLoggerContext(options.CorrelationData(), ::AppInstaller::Utility::ConvertToUTF8(callerProcessInfoString));
// Convert the options to arguments for the installer.
- context.Args.AddArg(::AppInstaller::CLI::Execution::Args::Type::Id, ::AppInstaller::Utility::ConvertToUTF8(package.Id()));
- context.Args.AddArg(::AppInstaller::CLI::Execution::Args::Type::Version, ::AppInstaller::Utility::ConvertToUTF8(packageVersionInfo.Version()));
- context.Args.AddArg(::AppInstaller::CLI::Execution::Args::Type::Channel, ::AppInstaller::Utility::ConvertToUTF8(packageVersionInfo.Channel()));
- context.Args.AddArg(::AppInstaller::CLI::Execution::Args::Type::Source, ::AppInstaller::Utility::ConvertToUTF8(packageVersionInfo.PackageCatalog().Info().Name()));
context.Args.AddArg(::AppInstaller::CLI::Execution::Args::Type::Exact);
if (options)
{
@@ -229,9 +244,11 @@ namespace winrt::Microsoft::Management::Deployment::implementation
}
}
+ AddPackageManifestToContext(packageVersionInfo, context);
+
// TODO: AdditionalPackageCatalogArguments is not currently supported by the underlying implementation.
::AppInstaller::CLI::RootCommand rootCommand;
- std::unique_ptr<::AppInstaller::CLI::Command> command = std::make_unique<::AppInstaller::CLI::InstallCommand>(rootCommand.Name());
+ std::unique_ptr<::AppInstaller::CLI::Command> command = std::make_unique<::AppInstaller::CLI::COMInstallCommand>(rootCommand.Name());
rootCommand.ValidateArguments(context.Args);
::AppInstaller::Logging::Telemetry().LogCommand(command->FullName());
diff --git a/src/Microsoft.Management.Deployment/PackageVersionInfo.h b/src/Microsoft.Management.Deployment/PackageVersionInfo.h
@@ -18,6 +18,7 @@ namespace winrt::Microsoft::Management::Deployment::implementation
winrt::Windows::Foundation::Collections::IVectorView<hstring> PackageFamilyNames();
winrt::Windows::Foundation::Collections::IVectorView<hstring> ProductCodes();
winrt::Microsoft::Management::Deployment::PackageCatalog PackageCatalog();
+ std::shared_ptr<::AppInstaller::Repository::IPackageVersion> GetRepositoryPackageVersion() { return m_packageVersion; }
private:
winrt::Microsoft::Management::Deployment::PackageCatalog m_packageCatalog{ nullptr };
std::shared_ptr<::AppInstaller::Repository::IPackageVersion> m_packageVersion;