Skip to content

Commit 50dfcf1

Browse files
committed
Update
1 parent 4f72f55 commit 50dfcf1

File tree

5 files changed

+243
-218
lines changed

5 files changed

+243
-218
lines changed

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

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,24 @@
22
// Licensed under the MIT License.
33

44
using System.Runtime.CompilerServices;
5+
using System.Runtime.InteropServices;
56
using Windows.Win32;
67
using Windows.Win32.Foundation;
78
using Windows.Win32.System.Com;
89
using Windows.Win32.UI.Shell;
910

1011
namespace Files.App.Storage.Storables
1112
{
12-
public sealed class WindowsBulkOperations : IDisposable
13+
public sealed partial class WindowsBulkOperations : IDisposable
1314
{
14-
// Constants
15-
16-
private const FILEOPERATION_FLAGS defaultOptions = FILEOPERATION_FLAGS.FOF_ALLOWUNDO | FILEOPERATION_FLAGS.FOF_NOCONFIRMMKDIR;
17-
1815
// Fields
1916

2017
private readonly ComPtr<IFileOperation> _pFileOperation;
2118
private readonly ComPtr<IFileOperationProgressSink> _pProgressSink;
2219
private readonly uint _progressSinkCookie;
2320

2421
private int _disposedValue = 0;
25-
private FILEOPERATION_FLAGS _operationFlags = defaultOptions;
22+
private FILEOPERATION_FLAGS _operationFlags;
2623
private HWND _owner;
2724

2825
// Events
@@ -43,11 +40,10 @@ public sealed class WindowsBulkOperations : IDisposable
4340

4441
// Constructor
4542

46-
public unsafe WindowsBulkOperations(HWND owner = default)
43+
public unsafe WindowsBulkOperations(HWND owner = default, FILEOPERATION_FLAGS flags = FILEOPERATION_FLAGS.FOF_ALLOWUNDO | FILEOPERATION_FLAGS.FOF_NOCONFIRMMKDIR)
4744
{
4845
var clsid = typeof(FileOperation).GUID;
4946
var iid = typeof(IFileOperation).GUID;
50-
void* pObj = default;
5147

5248
PInvoke.CoCreateInstance(
5349
&clsid,
@@ -59,13 +55,14 @@ public unsafe WindowsBulkOperations(HWND owner = default)
5955
_owner = owner;
6056
if (owner != default)
6157
_pFileOperation.Get()->SetOwnerWindow(owner);
58+
_operationFlags = flags;
6259

6360
_pProgressSink.Attach((IFileOperationProgressSink*)WindowsBulkOperationsSink.Create(this));
6461
_pFileOperation.Get()->Advise(_pProgressSink.Get(), out var progressSinkCookie);
6562
_progressSinkCookie = progressSinkCookie;
6663
}
6764

68-
public unsafe HRESULT CopyItem(ComPtr<IShellItem> psiItem, ComPtr<IShellItem> psiDestinationFolder, PCWSTR pszCopyName)
65+
public unsafe HRESULT QueueCopyItem(ComPtr<IShellItem> psiItem, ComPtr<IShellItem> psiDestinationFolder, PCWSTR pszCopyName)
6966
{
7067
HRESULT hr = default;
7168

@@ -82,7 +79,7 @@ public unsafe HRESULT CopyItem(ComPtr<IShellItem> psiItem, ComPtr<IShellItem> ps
8279
return hr;
8380
}
8481

85-
public unsafe HRESULT DeleteItem(ComPtr<IShellItem> psiItem)
82+
public unsafe HRESULT QueueDeleteItem(ComPtr<IShellItem> psiItem)
8683
{
8784
HRESULT hr = default;
8885

@@ -98,7 +95,7 @@ public unsafe HRESULT DeleteItem(ComPtr<IShellItem> psiItem)
9895
return hr;
9996
}
10097

101-
public unsafe HRESULT MoveItem(ComPtr<IShellItem> psiItem, ComPtr<IShellItem> psiDestinationFolder, PCWSTR pszNewName)
98+
public unsafe HRESULT QueueMoveItem(ComPtr<IShellItem> psiItem, ComPtr<IShellItem> psiDestinationFolder, PCWSTR pszNewName)
10299
{
103100
HRESULT hr = default;
104101

@@ -114,7 +111,7 @@ public unsafe HRESULT MoveItem(ComPtr<IShellItem> psiItem, ComPtr<IShellItem> ps
114111
return hr;
115112
}
116113

117-
public unsafe HRESULT NewItem(ComPtr<IShellItem> psiDestinationFolder, uint dwFileAttributes, PCWSTR pszName, PCWSTR pszTemplateName)
114+
public unsafe HRESULT QueueNewItem(ComPtr<IShellItem> psiDestinationFolder, uint dwFileAttributes, PCWSTR pszName, PCWSTR pszTemplateName)
118115
{
119116
HRESULT hr = default;
120117

@@ -130,7 +127,7 @@ public unsafe HRESULT NewItem(ComPtr<IShellItem> psiDestinationFolder, uint dwFi
130127
return hr;
131128
}
132129

133-
public unsafe HRESULT RenameItem(ComPtr<IShellItem> psiItem, PCWSTR pszNewName)
130+
public unsafe HRESULT QueueRenameItem(ComPtr<IShellItem> psiItem, PCWSTR pszNewName)
134131
{
135132
HRESULT hr = default;
136133

@@ -146,6 +143,22 @@ public unsafe HRESULT RenameItem(ComPtr<IShellItem> psiItem, PCWSTR pszNewName)
146143
return hr;
147144
}
148145

146+
public unsafe HRESULT PerformOperations()
147+
{
148+
HRESULT hr = default;
149+
150+
try
151+
{
152+
hr = _pFileOperation.Get()->PerformOperations();
153+
hr.ThrowOnFailure();
154+
}
155+
finally
156+
{
157+
}
158+
159+
return hr;
160+
}
161+
149162
public void Dispose()
150163
{
151164
_pFileOperation.Dispose();

src/Files.App.Storage/Storables/WindowsStorage/WindowsBulkOperationsSink.Methods.cs

Lines changed: 94 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -9,86 +9,101 @@
99

1010
namespace Files.App.Storage.Storables
1111
{
12-
public unsafe partial struct WindowsBulkOperationsSink : IFileOperationProgressSink.Interface
12+
public sealed partial class WindowsBulkOperations : IDisposable
1313
{
14-
public HRESULT StartOperations()
15-
{
16-
throw new NotImplementedException();
17-
}
18-
19-
public HRESULT FinishOperations(HRESULT hrResult)
20-
{
21-
throw new NotImplementedException();
22-
}
23-
24-
public unsafe HRESULT PreRenameItem(uint dwFlags, IShellItem* psiItem, PCWSTR pszNewName)
25-
{
26-
throw new NotImplementedException();
27-
}
28-
29-
public unsafe HRESULT PostRenameItem(uint dwFlags, IShellItem* psiItem, PCWSTR pszNewName, HRESULT hrRename, IShellItem* psiNewlyCreated)
30-
{
31-
throw new NotImplementedException();
32-
}
33-
34-
public unsafe HRESULT PreMoveItem(uint dwFlags, IShellItem* psiItem, IShellItem* psiDestinationFolder, PCWSTR pszNewName)
35-
{
36-
throw new NotImplementedException();
37-
}
38-
39-
public unsafe HRESULT PostMoveItem(uint dwFlags, IShellItem* psiItem, IShellItem* psiDestinationFolder, PCWSTR pszNewName, HRESULT hrMove, IShellItem* psiNewlyCreated)
40-
{
41-
throw new NotImplementedException();
42-
}
43-
44-
public unsafe HRESULT PreCopyItem(uint dwFlags, IShellItem* psiItem, IShellItem* psiDestinationFolder, PCWSTR pszNewName)
45-
{
46-
throw new NotImplementedException();
47-
}
48-
49-
public unsafe HRESULT PostCopyItem(uint dwFlags, IShellItem* psiItem, IShellItem* psiDestinationFolder, PCWSTR pszNewName, HRESULT hrCopy, IShellItem* psiNewlyCreated)
50-
{
51-
throw new NotImplementedException();
52-
}
53-
54-
public unsafe HRESULT PreDeleteItem(uint dwFlags, IShellItem* psiItem)
55-
{
56-
throw new NotImplementedException();
57-
}
58-
59-
public unsafe HRESULT PostDeleteItem(uint dwFlags, IShellItem* psiItem, HRESULT hrDelete, IShellItem* psiNewlyCreated)
60-
{
61-
throw new NotImplementedException();
62-
}
63-
64-
public unsafe HRESULT PreNewItem(uint dwFlags, IShellItem* psiDestinationFolder, PCWSTR pszNewName)
65-
{
66-
throw new NotImplementedException();
67-
}
68-
69-
public unsafe HRESULT PostNewItem(uint dwFlags, IShellItem* psiDestinationFolder, PCWSTR pszNewName, PCWSTR pszTemplateName, uint dwFileAttributes, HRESULT hrNew, IShellItem* psiNewItem)
70-
{
71-
throw new NotImplementedException();
72-
}
73-
74-
public HRESULT UpdateProgress(uint iWorkTotal, uint iWorkSoFar)
75-
{
76-
throw new NotImplementedException();
77-
}
78-
79-
public HRESULT ResetTimer()
80-
{
81-
throw new NotImplementedException();
82-
}
83-
84-
public HRESULT PauseTimer()
85-
{
86-
throw new NotImplementedException();
87-
}
88-
89-
public HRESULT ResumeTimer()
90-
{
91-
throw new NotImplementedException();
14+
private unsafe partial struct WindowsBulkOperationsSink : IFileOperationProgressSink.Interface
15+
{
16+
public HRESULT StartOperations()
17+
{
18+
throw new NotImplementedException();
19+
}
20+
21+
public HRESULT FinishOperations(HRESULT hrResult)
22+
{
23+
throw new NotImplementedException();
24+
}
25+
26+
public unsafe HRESULT PreRenameItem(uint dwFlags, IShellItem* psiItem, PCWSTR pszNewName)
27+
{
28+
throw new NotImplementedException();
29+
}
30+
31+
public unsafe HRESULT PostRenameItem(uint dwFlags, IShellItem* psiItem, PCWSTR pszNewName, HRESULT hrRename, IShellItem* psiNewlyCreated)
32+
{
33+
throw new NotImplementedException();
34+
}
35+
36+
public unsafe HRESULT PreMoveItem(uint dwFlags, IShellItem* psiItem, IShellItem* psiDestinationFolder, PCWSTR pszNewName)
37+
{
38+
if (_operationsHandle.Target is WindowsBulkOperations operations)
39+
{
40+
operations.PreMoveItem?.Invoke(this, new());
41+
return HRESULT.S_OK;
42+
}
43+
44+
return HRESULT.E_INVALIDARG;
45+
}
46+
47+
public unsafe HRESULT PostMoveItem(uint dwFlags, IShellItem* psiItem, IShellItem* psiDestinationFolder, PCWSTR pszNewName, HRESULT hrMove, IShellItem* psiNewlyCreated)
48+
{
49+
if (_operationsHandle.Target is WindowsBulkOperations operations)
50+
{
51+
operations.PostMoveItem?.Invoke(this, new());
52+
return HRESULT.S_OK;
53+
}
54+
55+
return HRESULT.E_INVALIDARG;
56+
}
57+
58+
public unsafe HRESULT PreCopyItem(uint dwFlags, IShellItem* psiItem, IShellItem* psiDestinationFolder, PCWSTR pszNewName)
59+
{
60+
throw new NotImplementedException();
61+
}
62+
63+
public unsafe HRESULT PostCopyItem(uint dwFlags, IShellItem* psiItem, IShellItem* psiDestinationFolder, PCWSTR pszNewName, HRESULT hrCopy, IShellItem* psiNewlyCreated)
64+
{
65+
throw new NotImplementedException();
66+
}
67+
68+
public unsafe HRESULT PreDeleteItem(uint dwFlags, IShellItem* psiItem)
69+
{
70+
throw new NotImplementedException();
71+
}
72+
73+
public unsafe HRESULT PostDeleteItem(uint dwFlags, IShellItem* psiItem, HRESULT hrDelete, IShellItem* psiNewlyCreated)
74+
{
75+
throw new NotImplementedException();
76+
}
77+
78+
public unsafe HRESULT PreNewItem(uint dwFlags, IShellItem* psiDestinationFolder, PCWSTR pszNewName)
79+
{
80+
throw new NotImplementedException();
81+
}
82+
83+
public unsafe HRESULT PostNewItem(uint dwFlags, IShellItem* psiDestinationFolder, PCWSTR pszNewName, PCWSTR pszTemplateName, uint dwFileAttributes, HRESULT hrNew, IShellItem* psiNewItem)
84+
{
85+
throw new NotImplementedException();
86+
}
87+
88+
public HRESULT UpdateProgress(uint iWorkTotal, uint iWorkSoFar)
89+
{
90+
throw new NotImplementedException();
91+
}
92+
93+
public HRESULT ResetTimer()
94+
{
95+
throw new NotImplementedException();
96+
}
97+
98+
public HRESULT PauseTimer()
99+
{
100+
throw new NotImplementedException();
101+
}
102+
103+
public HRESULT ResumeTimer()
104+
{
105+
throw new NotImplementedException();
106+
}
92107
}
93108
}
94109
}

0 commit comments

Comments
 (0)