Skip to content

Commit 4dfbaae

Browse files
committed
Update
1 parent b91982c commit 4dfbaae

File tree

6 files changed

+66
-64
lines changed

6 files changed

+66
-64
lines changed

src/Files.App.CsWin32/NativeMethods.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,5 @@ IContextMenu2
234234
GetSubMenu
235235
GetMenuItemCount
236236
GetMenuItemInfo
237+
IsWow64Process2
238+
GetCurrentProcess
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Files.App.Storage
8+
{
9+
public enum JumpListDestinationType
10+
{
11+
Pinned,
12+
13+
Recent,
14+
15+
Frequent,
16+
}
17+
}

src/Files.App.Storage/Storables/WindowsStorage/JumpListManager.cs

Lines changed: 10 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -12,83 +12,29 @@ namespace Files.App.Storage
1212
{
1313
public unsafe class JumpListManager : IDisposable
1414
{
15-
private ComPtr<ICustomDestinationList> pCustomDestinationList = default;
15+
public string AppId { get; }
1616

17-
private static string? AppId
17+
public JumpListManager(string appId)
1818
{
19-
get
20-
{
21-
PWSTR pszAppId = default;
22-
HRESULT hr = PInvoke.GetCurrentProcessExplicitAppUserModelID(&pszAppId);
23-
if (hr == HRESULT.E_FAIL)
24-
hr = HRESULT.S_OK;
19+
if (string.IsNullOrEmpty(appId))
20+
throw new ArgumentException("App ID cannot be null or empty.", nameof(appId));
2521

26-
hr.ThrowIfFailedOnDebug();
27-
28-
return pszAppId.ToString();
29-
}
22+
AppId = appId;
23+
//_jumpList = new ConcurrentDictionary<string, IObjectArray>();
3024
}
3125

32-
public ConcurrentBag<JumpListItem> JumpListItems { get; private set; } = [];
33-
34-
public ConcurrentBag<JumpListItem> RemovedItems { get; private set; } = [];
35-
36-
public ConcurrentBag<JumpListItem> RejectedItems { get; private set; } = [];
37-
38-
// A special "Frequent" category managed by Windows
39-
public bool ShowFrequentCategory { get; set; }
40-
41-
// A special "Recent" category managed by Windows
42-
public bool ShowRecentCategory { get; set; }
43-
44-
private static JumpListManager? _Default = null;
45-
public static JumpListManager Default { get; } = _Default ??= new JumpListManager();
46-
47-
public JumpListManager()
26+
public IEnumerable<WindowsStorable> GetAutomaticDestinations()
4827
{
49-
Guid CLSID_CustomDestinationList = typeof(DestinationList).GUID;
50-
Guid IID_ICustomDestinationList = ICustomDestinationList.IID_Guid;
51-
HRESULT hr = PInvoke.CoCreateInstance(
52-
&CLSID_CustomDestinationList,
53-
null,
54-
CLSCTX.CLSCTX_INPROC_SERVER,
55-
&IID_ICustomDestinationList,
56-
(void**)pCustomDestinationList.GetAddressOf());
57-
58-
// Should not happen but as a sanity check at an early stage
59-
hr.ThrowOnFailure();
28+
return [];
6029
}
6130

62-
public HRESULT Save()
31+
public IEnumerable<WindowsStorable> GetCustomDestinations()
6332
{
64-
Debug.Assert(Thread.CurrentThread.GetApartmentState() is ApartmentState.STA);
65-
66-
HRESULT hr = pCustomDestinationList.Get()->SetAppID(AppId);
67-
68-
uint cMinSlots = 0;
69-
ComPtr<IObjectArray> pDeletedItemsObjectArray = default;
70-
Guid IID_IObjectArray = IObjectArray.IID_Guid;
71-
72-
hr = pCustomDestinationList.Get()->BeginList(&cMinSlots, &IID_IObjectArray, (void**)pDeletedItemsObjectArray.GetAddressOf());
73-
74-
// TODO: Validate items
75-
76-
// TODO: Group them as categories
77-
78-
// TODO: Append a custom category or to the Tasks
79-
80-
if (ShowFrequentCategory)
81-
pCustomDestinationList.Get()->AppendKnownCategory(KNOWNDESTCATEGORY.KDC_FREQUENT);
82-
83-
if (ShowRecentCategory)
84-
pCustomDestinationList.Get()->AppendKnownCategory(KNOWNDESTCATEGORY.KDC_RECENT);
85-
86-
return HRESULT.S_OK;
33+
return [];
8734
}
8835

8936
public void Dispose()
9037
{
91-
pCustomDestinationList.Dispose();
9238
}
9339
}
9440
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
using Windows.Win32;
5+
using Windows.Win32.Foundation;
6+
using Windows.Win32.System.SystemInformation;
7+
8+
namespace Files.App.Storage
9+
{
10+
public unsafe static partial class WindowsStorableHelpers
11+
{
12+
public static bool IsOnArmProcessor()
13+
{
14+
IMAGE_FILE_MACHINE dwMachineType = default;
15+
16+
// Assumes the current process token has "PROCESS_QUERY_INFORMATION" or "PROCESS_QUERY_LIMITED_INFORMATION" access right
17+
bool fResult = PInvoke.IsWow64Process2(PInvoke.GetCurrentProcess(), null, &dwMachineType);
18+
if (!fResult)
19+
Debug.WriteLine($"{nameof(PInvoke.IsWow64Process2)} has failed.");
20+
21+
return dwMachineType is
22+
IMAGE_FILE_MACHINE.IMAGE_FILE_MACHINE_THUMB or
23+
IMAGE_FILE_MACHINE.IMAGE_FILE_MACHINE_ARMNT or
24+
IMAGE_FILE_MACHINE.IMAGE_FILE_MACHINE_ARM64 or
25+
IMAGE_FILE_MACHINE.IMAGE_FILE_MACHINE_ARM;
26+
}
27+
}
28+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,12 @@ public static bool TryShowFormatDriveDialog(HWND hWnd, uint driveLetterIndex, SH
8484
var result = PInvoke.SHFormatDrive(hWnd, driveLetterIndex, id, options);
8585
return result is 0xFFFF;
8686
}
87+
88+
public static bool TryRenameVolumeLabel(string path, string newLabel)
89+
{
90+
// TODO: Use shell32.dll!CMountPointRename (CLSID: 60173D16-A550-47f0-A14B-C6F9E4DA0831, IID: 92F8D886-AB61-4113-BD4F-2E894397386F)
91+
92+
return false;
93+
}
8794
}
8895
}

src/Files.App/Helpers/Win32/Win32Helper.Process.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace Files.App.Helpers
1313
public static partial class Win32Helper
1414
{
1515
private static bool? isRunningOnArm = null;
16+
[Obsolete]
1617
public static bool IsRunningOnArm
1718
{
1819
get
@@ -158,6 +159,7 @@ public static List<Process> WhoIsLocking(string[] resources)
158159
return processes;
159160
}
160161

162+
[Obsolete]
161163
private static bool IsArmProcessor()
162164
{
163165
var handle = Process.GetCurrentProcess().Handle;

0 commit comments

Comments
 (0)