Skip to content

Commit

Permalink
Updated CsWin32 and other dependencies (#110)
Browse files Browse the repository at this point in the history
* Update System.IO.Abstractions to 16.1.20

* Update CsWin32 to 0.1.635-beta

* Use newly cocreatable `ShellLink` from updated CsWin32

  - In CsWin32 0.1.635-beta, the `ShellLink` class became cocreatable, which allows me to restore my original method of creating a `ShellLink`. See microsoft/CsWin32#453.
  • Loading branch information
craigktreasure authored Mar 11, 2022
1 parent 20f391f commit b31a2dc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<DotNetPackageVersion>6.0.0</DotNetPackageVersion>
<SystemIOAbstractionsVersion>16.1.16</SystemIOAbstractionsVersion>
<SystemIOAbstractionsVersion>16.1.20</SystemIOAbstractionsVersion>
</PropertyGroup>

<ItemGroup>
Expand All @@ -18,7 +18,7 @@
<PackageReference Update="Microsoft.Extensions.DependencyInjection" Version="$(DotNetPackageVersion)" />
<PackageReference Update="Microsoft.Extensions.Logging" Version="$(DotNetPackageVersion)" />
<PackageReference Update="Microsoft.Extensions.Logging.Debug" Version="$(DotNetPackageVersion)" />
<PackageReference Update="Microsoft.Windows.CsWin32" Version="0.1.619-beta" />
<PackageReference Update="Microsoft.Windows.CsWin32" Version="0.1.635-beta" />
<PackageReference Update="Serilog" Version="2.10.0" />
<PackageReference Update="Serilog.Extensions.Logging" Version="3.1.0" />
<PackageReference Update="Serilog.Sinks.Console" Version="4.0.1" />
Expand Down
2 changes: 1 addition & 1 deletion src/StartMenuCleaner/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ IPersistFile
IShellLinkW
MAX_PATH
ShellLink
STGM_READ
STGM
9 changes: 3 additions & 6 deletions src/StartMenuCleaner/Utils/CsWin32ShortcutHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace StartMenuCleaner.Utils;
using Windows.Win32;
using Windows.Win32.Storage.FileSystem;
using Windows.Win32.System.Com;
using Windows.Win32.System.Com.StructuredStorage;
using Windows.Win32.UI.Shell;

internal class CsWin32ShortcutHandler : IFileShortcutHandler
Expand All @@ -15,15 +16,11 @@ public unsafe string ResolveTarget(string shortcutPath)
throw new NotSupportedException($"{nameof(ResolveTarget)} is only supported on Windows 5.1.2600+.");
}

// See the following issues for current status and new advice:
// https://github.com/microsoft/CsWin32/issues/453
// https://github.com/microsoft/CsWin32/discussions/323
IPersistFile shellLink = (IPersistFile)(Activator.CreateInstance(Type.GetTypeFromCLSID(typeof(ShellLink).GUID, throwOnError: true)!)
?? throw new InvalidOperationException("Failed to create an instance of ShellLink"));
IPersistFile shellLink = (IPersistFile)new ShellLink();

fixed (char* shortcutFilePathPcwstr = shortcutPath)
{
shellLink.Load(shortcutFilePathPcwstr, PInvoke.STGM_READ);
shellLink.Load(shortcutFilePathPcwstr, (uint)STGM.STGM_READ);
}

Span<char> szShortcutTargetPath = stackalloc char[(int)PInvoke.MAX_PATH];
Expand Down

0 comments on commit b31a2dc

Please sign in to comment.