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

Allow winget to install MS Store packages without account #2095

Merged
merged 10 commits into from
Apr 26, 2022
32 changes: 23 additions & 9 deletions src/AppInstallerCLICore/Workflows/MSStoreInstallerHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,28 +78,42 @@ namespace AppInstaller::CLI::Workflow
context.Reporter.Info() << Resource::String::MSStoreInstallTryGetEntitlement << std::endl;
GetEntitlementResult enr = installManager.GetFreeUserEntitlementAsync(productId, winrt::hstring(), winrt::hstring()).get();

return GetSuccessOfEntitlementRequest(context, productId, enr, "User");
}

bool GetFreeDeviceEntitlement(Execution::Context& context, const std::wstring& productId)
{
AppInstallManager installManager;

// Verifying/Acquiring product ownership
context.Reporter.Info() << Resource::String::MSStoreInstallTryGetEntitlement << std::endl;
zachcwillson marked this conversation as resolved.
Show resolved Hide resolved
GetEntitlementResult enr = installManager.GetFreeDeviceEntitlementAsync(productId, winrt::hstring(), winrt::hstring()).get();

return GetSuccessOfEntitlementRequest(context, productId, enr, "Device");
}

bool GetSuccessOfEntitlementRequest(Execution::Context& context, const std::wstring& productId, GetEntitlementResult enr, std::string entitlementType)
zachcwillson marked this conversation as resolved.
Show resolved Hide resolved
{
if (enr.Status() == GetEntitlementStatus::Succeeded)
{
context.Reporter.Info() << Resource::String::MSStoreInstallGetEntitlementSuccess << std::endl;
AICLI_LOG(CLI, Error, << "Get entitlement succeeded.");

AICLI_LOG(CLI, Error, << "Get " + entitlementType + " entitlement succeeded.");
zachcwillson marked this conversation as resolved.
Show resolved Hide resolved
}
else if (enr.Status() == GetEntitlementStatus::NoStoreAccount)
{
context.Reporter.Info() << Resource::String::MSStoreInstallGetEntitlementNoStoreAccount << std::endl;
AICLI_LOG(CLI, Error, << "Get entitlement failed. No Store account.");
AICLI_LOG(CLI, Error, << "Get " + entitlementType + " entitlement failed. No Store account.");
}
else if (enr.Status() == GetEntitlementStatus::NetworkError)
{
context.Reporter.Info() << Resource::String::MSStoreInstallGetEntitlementNetworkError << std::endl;
AICLI_LOG(CLI, Error, << "Get entitlement failed. Network error.");
AICLI_LOG(CLI, Error, << "Get " + entitlementType + " entitlement failed. Network error.");
}
else if (enr.Status() == GetEntitlementStatus::ServerError)
{
context.Reporter.Info() << Resource::String::MSStoreInstallGetEntitlementServerError << std::endl;
AICLI_LOG(CLI, Error, << "Get entitlement succeeded. Server error. ProductId: " << Utility::ConvertToUTF8(productId));
AICLI_LOG(CLI, Error, << "Get " + entitlementType + " entitlement succeeded. Server error. ProductId: " << Utility::ConvertToUTF8(productId));
}

return enr.Status() == GetEntitlementStatus::Succeeded;
}
}
Expand All @@ -111,7 +125,7 @@ namespace AppInstaller::CLI::Workflow
AppInstallManager installManager;

// Verifying/Acquiring product ownership
if (!GetFreeUserEntitlement(context, productId))
if (!GetFreeUserEntitlement(context, productId) || !GetFreeDeviceEntitlement(context, productId))
zachcwillson marked this conversation as resolved.
Show resolved Hide resolved
{
AICLI_TERMINATE_CONTEXT(APPINSTALLER_CLI_ERROR_MSSTORE_INSTALL_FAILED);
}
Expand Down Expand Up @@ -149,7 +163,7 @@ namespace AppInstaller::CLI::Workflow
AppInstallManager installManager;

// Verifying/Acquiring product ownership
if (!GetFreeUserEntitlement(context, productId))
if (!GetFreeUserEntitlement(context, productId) || !GetFreeDeviceEntitlement(context, productId))
{
AICLI_TERMINATE_CONTEXT(APPINSTALLER_CLI_ERROR_MSSTORE_INSTALL_FAILED);
}
Expand All @@ -160,7 +174,7 @@ namespace AppInstaller::CLI::Workflow
AppInstallItem installItem = installManager.SearchForUpdatesAsync(
productId, // ProductId
winrt::hstring() // SkuId
).get();
).get();

if (!installItem)
{
Expand Down