Skip to content

Commit fdb6e60

Browse files
committed
Initial get headers call works
1 parent 6ea1362 commit fdb6e60

File tree

4 files changed

+43
-579
lines changed

4 files changed

+43
-579
lines changed

src/AppInstallerCommonCore/DODownloader.cpp

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,15 @@
88
#include "winget/UserSettings.h"
99

1010
// TODO: Get this from the Windows SDK when available
11-
#include "external/do.h"
11+
#define DODownloadProperty_HttpRedirectionTarget static_cast<DODownloadProperty>(DODownloadProperty_NonVolatile + 1)
12+
#define DODownloadProperty_HttpResponseHeaders static_cast<DODownloadProperty>(DODownloadProperty_HttpRedirectionTarget + 1)
13+
#define DODownloadProperty_HttpServerIPAddress static_cast<DODownloadProperty>(DODownloadProperty_HttpResponseHeaders + 1)
14+
#define DODownloadProperty_HttpStatusCode static_cast<DODownloadProperty>(DODownloadProperty_HttpServerIPAddress + 1)
1215

1316
namespace AppInstaller::Utility
1417
{
1518
namespace DeliveryOptimization
1619
{
17-
// TODO: Once the SDK headers are available, remove these defines
18-
#define DO_E_DOWNLOAD_NO_PROGRESS HRESULT(0x80D02002L) // Download of a file saw no progress within the defined period
19-
20-
#define DO_E_BLOCKED_BY_COST_TRANSFER_POLICY HRESULT(0x80D03801L) // DO core paused the job due to cost policy restrictions
21-
#define DO_E_BLOCKED_BY_CELLULAR_POLICY HRESULT(0x80D03803L) // DO core paused the job due to detection of cellular network and policy restrictions
22-
#define DO_E_BLOCKED_BY_POWER_STATE HRESULT(0x80D03804L) // DO core paused the job due to detection of power state change into non-AC mode
23-
#define DO_E_BLOCKED_BY_NO_NETWORK HRESULT(0x80D03805L) // DO core paused the job due to loss of network connectivity
24-
2520
// Represents a download work item for Delivery Optimization.
2621
struct Download
2722
{
@@ -106,6 +101,23 @@ namespace AppInstaller::Utility
106101
THROW_IF_FAILED(m_download->SetProperty(prop, &var));
107102
}
108103

104+
template<typename T>
105+
std::optional<T> TryGetProperty(DODownloadProperty prop)
106+
{
107+
std::optional<T> result;
108+
wil::unique_variant var;
109+
HRESULT hr = m_download->GetProperty(prop, &var);
110+
if (SUCCEEDED(hr))
111+
{
112+
T value;
113+
if (ExtractFromVariant(var, value))
114+
{
115+
result = std::move(value);
116+
}
117+
}
118+
return result;
119+
}
120+
109121
void Uri(std::string_view uri)
110122
{
111123
SetProperty(DODownloadProperty_Uri, uri);
@@ -186,6 +198,22 @@ namespace AppInstaller::Utility
186198
}
187199

188200
private:
201+
bool ExtractFromVariant(const VARIANT& var, std::string& value)
202+
{
203+
if (var.vt == VT_BSTR && var.bstrVal != nullptr)
204+
{
205+
value = Utility::ConvertToUTF8(var.bstrVal);
206+
return true;
207+
}
208+
else if (var.vt == (VT_BSTR | VT_BYREF) && var.pbstrVal != nullptr && *var.pbstrVal != nullptr)
209+
{
210+
value = Utility::ConvertToUTF8(*var.pbstrVal);
211+
return true;
212+
}
213+
214+
return false;
215+
}
216+
189217
wil::com_ptr<IDODownload> m_download;
190218
};
191219

@@ -221,7 +249,7 @@ namespace AppInstaller::Utility
221249
{
222250
}
223251

224-
IFACEMETHOD(OnStatusChange)(IDODownload*, DO_DOWNLOAD_STATUS* status)
252+
IFACEMETHOD(OnStatusChange)(IDODownload*, const DO_DOWNLOAD_STATUS* status)
225253
{
226254
{
227255
std::lock_guard<std::mutex> guard(m_statusMutex);
@@ -397,6 +425,9 @@ namespace AppInstaller::Utility
397425
// Wait returns true for success, false for cancellation, and throws on error.
398426
if (callback->Wait())
399427
{
428+
// Grab the headers so that we can use them later
429+
std::optional<std::string> responseHeaders = download.TryGetProperty<std::string>(DODownloadProperty_HttpResponseHeaders);
430+
400431
// Finalize is required to flush the data and change the file name.
401432
download.Finalize();
402433
AICLI_LOG(Core, Info, << "Download completed.");

src/AppInstallerCommonCore/external/README.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)