diff --git a/PInvoke/DOSvc/DOSvc.cs b/PInvoke/DOSvc/DOSvc.cs index e4accfd62..5d470321b 100644 --- a/PInvoke/DOSvc/DOSvc.cs +++ b/PInvoke/DOSvc/DOSvc.cs @@ -132,17 +132,15 @@ public enum DODownloadProperty DODownloadProperty_Id, /// - /// Use this property to set or get the remote URI path of the resource to download. This property is required only if - /// DODownloadProperty_ContentId - /// isn't provided. VARIANT type is VT_BSTR. + /// Use this property to set or get the remote URI path of the resource to download. This property is required only if + /// DODownloadProperty_ContentId isn't provided. VARIANT type is VT_BSTR. /// [CorrespondingType(typeof(string), CorrespondingAction.GetSet)] DODownloadProperty_Uri, /// - /// Use this property to set or get the download unique content ID. This property is required only if - /// DODownloadProperty_Uri - /// isn't provided. VARIANT type is VT_BSTR. + /// Use this property to set or get the download unique content ID. This property is required only if DODownloadProperty_Uri isn't + /// provided. VARIANT type is VT_BSTR. /// [CorrespondingType(typeof(string), CorrespondingAction.GetSet)] DODownloadProperty_ContentId, @@ -152,12 +150,9 @@ public enum DODownloadProperty DODownloadProperty_DisplayName, /// - /// /// Use this property to set or get the local path name to save the download file. If the path does not exist, Delivery Optimization /// will attempt to create it under the caller's privileges. This property is required only if - /// - /// DODownloadProperty_StreamInterface - /// wasn’t provided. VARIANT type is VT_BSTR. + /// DODownloadProperty_StreamInterface wasn’t provided. VARIANT type is VT_BSTR. /// [CorrespondingType(typeof(string), CorrespondingAction.GetSet)] DODownloadProperty_LocalPath, @@ -170,33 +165,18 @@ public enum DODownloadProperty DODownloadProperty_HttpCustomHeaders, /// - /// Optional. Use this property to set or get one of the - /// DODownloadCostPolicy - /// enumeration values. VARIANT type is VT_UI4. + /// Optional. Use this property to set or get one of the DODownloadCostPolicy enumeration values. VARIANT type is VT_UI4. /// [CorrespondingType(typeof(DODownloadCostPolicy), CorrespondingAction.GetSet)] DODownloadProperty_CostPolicy, /// - /// Optional write-only. Use this property to set or get the standard WinHTTP security flags ( - /// WINHTTP_OPTION_SECURITY_FLAGS - /// ). VARIANT type is VT_UI4. - /// The following flags are supported: - /// * - /// SECURITY_FLAG_IGNORE_CERT_CN_INVALID - /// . Allows an invalid common name in a certificate. - /// * - /// SECURITY_FLAG_IGNORE_CERT_DATE_INVALID - /// . Allows an invalid certificate date. - /// * - /// SECURITY_FLAG_IGNORE_UNKNOWN_CA - /// . Allows an invalid certificate authority. - /// * - /// SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE - /// . Allows the identity of a server to be established with a non-server certificate. - /// * - /// WINHTTP_ENABLE_SSL_REVOCATION - /// . Allows SSL revocation. If this flag is set, the above flags will be ignored. + /// Optional write-only. Use this property to set or get the standard WinHTTP security flags ( WINHTTP_OPTION_SECURITY_FLAGS ). + /// VARIANT type is VT_UI4. The following flags are supported: * SECURITY_FLAG_IGNORE_CERT_CN_INVALID . Allows an invalid common name + /// in a certificate. * SECURITY_FLAG_IGNORE_CERT_DATE_INVALID . Allows an invalid certificate date. * + /// SECURITY_FLAG_IGNORE_UNKNOWN_CA . Allows an invalid certificate authority. * SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE . Allows the + /// identity of a server to be established with a non-server certificate. * WINHTTP_ENABLE_SSL_REVOCATION . Allows SSL revocation. If + /// this flag is set, the above flags will be ignored. /// [CorrespondingType(typeof(uint), CorrespondingAction.Set)] DODownloadProperty_SecurityFlags, @@ -227,17 +207,16 @@ public enum DODownloadProperty DODownloadProperty_ForegroundPriority, /// - /// Optional. Use this property to set or get the current download blocking mode. VARIANT_TRUE value will cause - /// IDODownload::Start - /// to block until download is complete or error has occurred. The default is nonblocking mode. VARIANT type is VT_BOOL. + /// Optional. Use this property to set or get the current download blocking mode. VARIANT_TRUE value will cause + /// IDODownload::Start to block until download is complete or error has occurred. The default is nonblocking mode. VARIANT + /// type is VT_BOOL. /// [CorrespondingType(typeof(bool), CorrespondingAction.GetSet)] DODownloadProperty_BlockingMode, /// - /// Optional. Use this property to set or get the pointer to - /// IDODownloadStatusCallback - /// interface used for download callbacks. VARIANT type is VT_UNKNOWN. + /// Optional. Use this property to set or get the pointer to IDODownloadStatusCallback interface used for download callbacks. + /// VARIANT type is VT_UNKNOWN. /// [CorrespondingType(typeof(IDODownloadStatusCallback), CorrespondingAction.GetSet)] DODownloadProperty_CallbackInterface, @@ -298,20 +277,12 @@ public enum DODownloadProperty [CorrespondingType(typeof(bool), CorrespondingAction.GetSet)] DODownloadProperty_HttpCustomAuthHeaders, - /// - /// Https-to-http redirection. Default is - /// FALSE - /// . - /// + /// Https-to-http redirection. Default is FALSE. [CorrespondingType(typeof(bool), CorrespondingAction.GetSet)] DODownloadProperty_HttpAllowSecureToNonSecureRedirect, /// - /// Save download info to the Windows Registry. Default is - /// FALSE - /// for Delivery Optimization download jobs; - /// TRUE - /// for BITS-style jobs. + /// Save download info to the Windows Registry. Default is FALSE for Delivery Optimization download jobs; TRUE for BITS-style jobs. /// [CorrespondingType(typeof(bool), CorrespondingAction.GetSet)] DODownloadProperty_NonVolatile, @@ -329,7 +300,7 @@ public enum DODownloadProperty // DODownloadPropertyEx_DecryptionInfo, DODownloadPropertyEx_IntegrityCheckInfo, DODownloadPropertyEx_IntegrityCheckMandatory, // DODownloadPropertyEx_TotalSizeBytes, DODownloadPropertyEx_TempLocalFileUsage } DODownloadPropertyEx; [PInvokeData("DODownloadInternal.h")] - [Obsolete] + [Obsolete("The DODownloadPropertyEx enumeration is deprecated. Instead, use the DODownloadProperty enumeration with IDODownload::GetProperty and IDODownload::SetProperty.")] public enum DODownloadPropertyEx { /// Reserved. Do not use. @@ -607,17 +578,28 @@ public static IEnumerable EnumDownloads(this IDOManager mgr, DODown /// The instance. /// The required property ID to set (of type DODownloadProperty). /// The property value to set, stored in a VARIANT. - public static void SetProperty(this IDODownload download, [In] DODownloadProperty propId, [In] object propVal) + public static void SetProperty(this IDODownload download, [In] DODownloadProperty propId, [In] object? propVal) { + if (propVal is null) + { + download.SetProperty(propId, null); + return; + } + switch (propId) { case DODownloadProperty.DODownloadProperty_CallbackInterface: case DODownloadProperty.DODownloadProperty_StreamInterface: - var intf = CorrespondingTypeAttribute.GetCorrespondingTypes(propId, CorrespondingAction.Get).WhereNotNull().Where(propVal.GetType().InheritsFrom).FirstOrDefault() ?? - throw new ArgumentException($"Property {propId} requires a valid corresponding COM interface pointer.", nameof(propVal)); - var ptr = Marshal.GetComInterfaceForObject(propVal, intf); - VARIANT v = new() { vt = VARTYPE.VT_UNKNOWN, byref = ptr }; - download.SetProperty(propId, v); + if (propVal is null) + download.SetProperty(propId, null); + else + { + var intf = CorrespondingTypeAttribute.GetCorrespondingTypes(propId, CorrespondingAction.Get).WhereNotNull().Where(propVal.GetType().InheritsFrom).FirstOrDefault() ?? + throw new ArgumentException($"Property {propId} requires a valid corresponding COM interface pointer.", nameof(propVal)); + var ptr = Marshal.GetComInterfaceForObject(propVal, intf); + VARIANT v = new() { vt = VARTYPE.VT_UNKNOWN, byref = ptr }; + download.SetProperty(propId, v); + } break; default: download.SetProperty(propId, new VARIANT(propVal));