Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

13/05/2026

Version 8.0.15.2

* Fixed [#47](https://github.com/PWagner1/Windows-API-CodePack-NET/pull/47), `WindowsAPICodePackSensors` throws a `NullReferenceException` when enumerating ambient light sensors (thanks to [xaviergonz](https://github.com/xaviergonz))
* Fixed file & NuGet package version alignment

=========

02/04/2026

Version 8.0.15.1
Expand Down
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<LibraryVersion>8.0.17</LibraryVersion>
<PackageVersion>8.0.17</PackageVersion>
<LibraryVersion>8.0.15.2</LibraryVersion>
<PackageVersion>8.0.15.2</PackageVersion>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ public RecoveryData(RecoveryCallback callback, object state)
/// </summary>
public void Invoke()
{
if (Callback != null) { Callback(State); }
Callback?.Invoke(State);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1140,10 +1140,7 @@ internal void RaiseButtonClickEvent(int id)
internal void RaiseHyperlinkClickEvent(string link)
{
EventHandler<TaskDialogHyperlinkClickedEventArgs>? handler = HyperlinkClick;
if (handler != null)
{
handler(this, new TaskDialogHyperlinkClickedEventArgs(link));
}
handler?.Invoke(this, new TaskDialogHyperlinkClickedEventArgs(link));
}

// Gives event subscriber a chance to prevent
Expand Down Expand Up @@ -1193,17 +1190,17 @@ internal int RaiseClosingEvent(int id)

internal void RaiseHelpInvokedEvent()
{
if (HelpInvoked != null) { HelpInvoked(this, EventArgs.Empty); }
HelpInvoked?.Invoke(this, EventArgs.Empty);
}

internal void RaiseOpenedEvent()
{
if (Opened != null) { Opened(this, EventArgs.Empty); }
Opened?.Invoke(this, EventArgs.Empty);
}

internal void RaiseTickEvent(int ticks)
{
if (Tick != null) { Tick(this, new TaskDialogTickEventArgs(ticks)); }
Tick?.Invoke(this, new TaskDialogTickEventArgs(ticks));
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ internal void RaiseClickEvent()
{
// Only perform click if the button is enabled.
if (!_enabled) { return; }
if (Click != null) { Click(this, EventArgs.Empty); }

Click?.Invoke(this, EventArgs.Empty);
}

private string? _text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,26 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<PlatformToolset>v145</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<PlatformToolset>v145</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<PlatformToolset>v145</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<PlatformToolset>v145</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<None Include="../../../../Assets/Icon/PNG/Windows.png" />
<None Include="../../../../Assets/Documents/Licenses/License.md" />
<None Include="../../../../../Assets/Icon/PNG/Windows.png">
<Filter>Resource Files</Filter>
</None>
<None Include="../../../../../Assets/Documents/Licenses/License.md" />
</ItemGroup>
<ItemGroup>
<Filter Include="Source Files">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,26 +333,24 @@ public override string ToString()
/// <returns>A property value.</returns>
public object? GetProperty(PropertyKey propKey)
{
using (PropVariant pv = new())
using PropVariant pv = new();
HResult hr = _nativeISensor.GetProperty(ref propKey, pv);
if (hr != HResult.Ok)
{
HResult hr = _nativeISensor.GetProperty(ref propKey, pv);
if (hr != HResult.Ok)
Exception e = Marshal.GetExceptionForHR((int)hr);
if (hr == HResult.ElementNotFound)
{
throw new ArgumentOutOfRangeException(LocalizedMessages.SensorPropertyNotFound, e);
}
else
{
Exception e = Marshal.GetExceptionForHR((int)hr);
if (hr == HResult.ElementNotFound)
if (e != null)
{
throw new ArgumentOutOfRangeException(LocalizedMessages.SensorPropertyNotFound, e);
}
else
{
if (e != null)
{
throw e;
}
throw e;
}
}
return pv.Value;
}
return pv.Value;
}

/// <summary>
Expand Down Expand Up @@ -403,11 +401,9 @@ public override string ToString()
for (uint i = 0; i < count; i++)
{
PropertyKey propKey = new();
using (PropVariant propVal = new())
{
valuesCollection.GetAt(i, ref propKey, propVal);
data.Add(propKey, propVal.Value);
}
using PropVariant propVal = new();
valuesCollection.GetAt(i, ref propKey, propVal);
data.Add(propKey, propVal.Value);
}
}
finally
Expand Down Expand Up @@ -517,13 +513,11 @@ public override string ToString()
for (uint i = 0; i < count; i++)
{
PropertyKey propKey = new();
using (PropVariant propVal = new())
{
valuesCollection.GetAt(i, ref propKey, propVal);
using PropVariant propVal = new();
valuesCollection.GetAt(i, ref propKey, propVal);

int idx = propKeyToIdx[propKey];
data[idx] = propVal.Value;
}
int idx = propKeyToIdx[propKey];
data[idx] = propVal.Value;
}
}
finally
Expand Down Expand Up @@ -570,10 +564,8 @@ public override string ToString()
{
// new PropVariant will throw an ArgumentException if the value can
// not be converted to an appropriate PropVariant.
using (PropVariant pv = PropVariant.FromObject(value))
{
pdv.SetValue(ref propKey, pv);
}
using PropVariant pv = PropVariant.FromObject(value);
pdv.SetValue(ref propKey, pv);
}
catch (ArgumentException)
{
Expand Down Expand Up @@ -607,11 +599,9 @@ public override string ToString()
for (uint i = 0; i < count; i++)
{
PropertyKey propKey = new();
using (PropVariant propVal = new())
{
pdv2.GetAt(i, ref propKey, propVal);
results.Add(propKey, propVal.Value);
}
using PropVariant propVal = new();
pdv2.GetAt(i, ref propKey, propVal);
results.Add(propKey, propVal.Value);
}
}
finally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,21 @@ public class SensorData : IDictionary<Guid, IList<object>>
for (uint index = 0; index < items; index++)
{
PropertyKey key;
using (PropVariant propValue = new())
{
keyCollection.GetAt(index, out key);
valuesCollection?.GetValue(ref key, propValue);
using PropVariant propValue = new();
keyCollection.GetAt(index, out key);
valuesCollection?.GetValue(ref key, propValue);

if (data.ContainsKey(key.FormatId))
{
if (propValue.Value != null)
{
data[key.FormatId].Add(propValue.Value);
}
}
else
if (data.ContainsKey(key.FormatId))
{
if (propValue.Value != null)
{
data.Add(key.FormatId, new List<object> { propValue.Value! });
data[key.FormatId].Add(propValue.Value);
}
}
else
{
data.Add(key.FormatId, new List<object> { propValue.Value! });
}
}

if (keyCollection != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ public static class EventHandlerExtensionMethods
/// <param name="sender">Event sender</param>
public static void SafeRaise(this EventHandler? eventHandler, object? sender)
{
if (eventHandler != null)
{
eventHandler(sender, EventArgs.Empty);
}
eventHandler?.Invoke(sender, EventArgs.Empty);
}

/// <summary>
Expand All @@ -27,10 +24,7 @@ public static void SafeRaise(this EventHandler? eventHandler, object? sender)
/// <param name="args">Event args</param>
public static void SafeRaise<T>(this EventHandler<T>? eventHandler, object? sender, T args) where T : EventArgs
{
if (eventHandler != null)
{
eventHandler(sender, args);
}
eventHandler?.Invoke(sender, args);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,17 @@ internal SearchCondition(ICondition? nativeSearchCondition)

if (ConditionType == SearchConditionType.Leaf)
{
using (PropVariant propVar = new())
{
hr = NativeSearchCondition.GetComparisonInfo(out _canonicalName, out _conditionOperation, propVar);
using PropVariant propVar = new();
hr = NativeSearchCondition.GetComparisonInfo(out _canonicalName, out _conditionOperation, propVar);

if (!CoreErrorHelper.Succeeded(hr))
{
throw new ShellException(hr);
}
if (!CoreErrorHelper.Succeeded(hr))
{
throw new ShellException(hr);
}

if (propVar.Value != null)
{
PropertyValue = propVar.Value.ToString();
}
if (propVar.Value != null)
{
PropertyValue = propVar.Value.ToString();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ public static class SearchConditionFactory
/// </remarks>
public static SearchCondition? CreateLeafCondition(string? propertyName, string? value, SearchConditionOperation operation)
{
using (PropVariant propVar = new(value))
{
return CreateLeafCondition(propertyName, propVar, null, operation);
}
using PropVariant propVar = new(value);
return CreateLeafCondition(propertyName, propVar, null, operation);
}

/// <summary>
Expand All @@ -48,10 +46,8 @@ public static class SearchConditionFactory
/// </remarks>
public static SearchCondition? CreateLeafCondition(string? propertyName, DateTime value, SearchConditionOperation operation)
{
using (PropVariant propVar = new(value))
{
return CreateLeafCondition(propertyName, propVar, "System.StructuredQuery.CustomProperty.DateTime", operation);
}
using PropVariant propVar = new(value);
return CreateLeafCondition(propertyName, propVar, "System.StructuredQuery.CustomProperty.DateTime", operation);
}

/// <summary>
Expand All @@ -69,10 +65,8 @@ public static class SearchConditionFactory
/// </remarks>
public static SearchCondition? CreateLeafCondition(string? propertyName, int value, SearchConditionOperation operation)
{
using (PropVariant propVar = new(value))
{
return CreateLeafCondition(propertyName, propVar, "System.StructuredQuery.CustomProperty.Integer", operation);
}
using PropVariant propVar = new(value);
return CreateLeafCondition(propertyName, propVar, "System.StructuredQuery.CustomProperty.Integer", operation);
}

/// <summary>
Expand All @@ -90,10 +84,8 @@ public static class SearchConditionFactory
/// </remarks>
public static SearchCondition? CreateLeafCondition(string? propertyName, bool value, SearchConditionOperation operation)
{
using (PropVariant propVar = new(value))
{
return CreateLeafCondition(propertyName, propVar, "System.StructuredQuery.CustomProperty.Boolean", operation);
}
using PropVariant propVar = new(value);
return CreateLeafCondition(propertyName, propVar, "System.StructuredQuery.CustomProperty.Boolean", operation);
}

/// <summary>
Expand All @@ -111,10 +103,8 @@ public static class SearchConditionFactory
/// </remarks>
public static SearchCondition? CreateLeafCondition(string? propertyName, double value, SearchConditionOperation operation)
{
using (PropVariant propVar = new(value))
{
return CreateLeafCondition(propertyName, propVar, "System.StructuredQuery.CustomProperty.FloatingPoint", operation);
}
using PropVariant propVar = new(value);
return CreateLeafCondition(propertyName, propVar, "System.StructuredQuery.CustomProperty.FloatingPoint", operation);
}

[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
Expand Down
Loading
Loading