Skip to content

Commit 1871ca7

Browse files
committed
Update
1 parent c42bc44 commit 1871ca7

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

src/Files.App.CsWin32/ManualGuid.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public static Guid* IID_IStorageProviderStatusUISourceFactory
4141

4242
[GuidRVAGen.Guid("00021500-0000-0000-C000-000000000046")]
4343
public static partial Guid* IID_IQueryInfo { get; }
44+
45+
[GuidRVAGen.Guid("000214F9-0000-0000-C000-000000000046")]
46+
public static partial Guid* IID_IShellLinkW { get; }
4447
}
4548

4649
public static unsafe partial class CLSID

src/Files.App.CsWin32/NativeMethods.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,4 @@ IQueryInfo
228228
QITIPF_FLAGS
229229
GetDiskFreeSpaceEx
230230
GetDriveType
231+
SLGP_FLAGS

src/Files.App.Storage/Storables/WindowsStorage/WindowsStorableHelpers.Shell.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,19 @@ public unsafe static HRESULT TryGetShellTooltip(this IWindowsStorable storable,
143143

144144
return HRESULT.S_OK;
145145
}
146+
147+
public unsafe static HRESULT TryGetShellLink(this IWindowsStorable storable, out ComPtr<IShellLinkW> pShellLink)
148+
{
149+
pShellLink = default;
150+
151+
using ComPtr<IShellLinkW> pShellLinkW = default;
152+
HRESULT hr = storable.ThisPtr.Get()->BindToHandler(null, BHID.BHID_SFUIObject, IID.IID_IShellLinkW, (void**)pShellLinkW.GetAddressOf());
153+
if (hr.ThrowIfFailedOnDebug().Failed)
154+
return hr;
155+
156+
pShellLink = pShellLinkW;
157+
158+
return HRESULT.S_OK;
159+
}
146160
}
147161
}

src/Files.App/ViewModels/UserControls/Widgets/NetworkLocationsWidgetViewModel.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
using Microsoft.UI.Input;
55
using Microsoft.UI.Xaml.Controls;
66
using System.Collections.Specialized;
7+
using System.Runtime.InteropServices;
78
using System.Windows.Input;
89
using Windows.System;
910
using Windows.UI.Core;
1011
using Windows.Win32;
12+
using Windows.Win32.Foundation;
1113
using Windows.Win32.UI.Shell;
1214

1315
namespace Files.App.ViewModels.UserControls.Widgets
@@ -71,13 +73,32 @@ public Task RefreshWidgetAsync()
7173

7274
await foreach (IWindowsFolder folder in HomePageContext.HomeFolder.GetNetworkLocationsAsync(default))
7375
{
76+
folder.TryGetShellLink(out ComPtr<IShellLinkW> pShellLink);
77+
string linkTargetPath = string.Empty;
78+
79+
if (pShellLink.IsNull)
80+
{
81+
folder.GetPropertyValue<string>("System.Link.TargetParsingPath", out linkTargetPath);
82+
}
83+
else
84+
{
85+
unsafe
86+
{
87+
char* pszTargetPath = (char*)NativeMemory.Alloc(1024);
88+
pShellLink.Get()->GetPath(pszTargetPath, 1024, null, (uint)SLGP_FLAGS.SLGP_RAWPATH);
89+
linkTargetPath = new(pszTargetPath);
90+
91+
NativeMemory.Free(pszTargetPath);
92+
}
93+
}
94+
7495
Items.Insert(
7596
Items.Count,
7697
new()
7798
{
7899
Item = folder,
79100
Text = folder.GetDisplayName(SIGDN.SIGDN_PARENTRELATIVEFORUI),
80-
Path = folder.GetDisplayName(SIGDN.SIGDN_FILESYSPATH),
101+
Path = linkTargetPath,
81102
DriveType = SystemIO.DriveType.Network
82103
});
83104
}

0 commit comments

Comments
 (0)