Skip to content

Commit 4465445

Browse files
committed
Test code
1 parent 05a34b4 commit 4465445

File tree

4 files changed

+18
-66
lines changed

4 files changed

+18
-66
lines changed

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

Lines changed: 9 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public unsafe WindowsBulkOperations(HWND owner = default, FILEOPERATION_FLAGS fl
4545
var clsid = typeof(FileOperation).GUID;
4646
var iid = typeof(IFileOperation).GUID;
4747

48-
PInvoke.CoCreateInstance(
48+
HRESULT hr = PInvoke.CoCreateInstance(
4949
&clsid,
5050
null,
5151
CLSCTX.CLSCTX_LOCAL_SERVER,
@@ -54,112 +54,59 @@ public unsafe WindowsBulkOperations(HWND owner = default, FILEOPERATION_FLAGS fl
5454

5555
_owner = owner;
5656
if (owner != default)
57-
_pFileOperation.Get()->SetOwnerWindow(owner);
57+
hr = _pFileOperation.Get()->SetOwnerWindow(owner);
5858
_operationFlags = flags;
5959

6060
_pProgressSink.Attach((IFileOperationProgressSink*)WindowsBulkOperationsSink.Create(this));
61-
62-
// Test code
63-
_pProgressSink.Get()->PostDeleteItem(0, null, default, null);
64-
65-
_pFileOperation.Get()->Advise(_pProgressSink.Get(), out var progressSinkCookie);
61+
hr = _pFileOperation.Get()->Advise(_pProgressSink.Get(), out var progressSinkCookie);
6662
_progressSinkCookie = progressSinkCookie;
6763
}
6864

6965
public unsafe HRESULT QueueCopyItem(ComPtr<IShellItem> psiItem, ComPtr<IShellItem> psiDestinationFolder, PCWSTR pszCopyName)
7066
{
7167
HRESULT hr = default;
7268

73-
try
74-
{
75-
hr = _pFileOperation.Get()->CopyItem(psiItem.Get(), psiDestinationFolder.Get(), pszCopyName, _pProgressSink.Get());
76-
hr.ThrowOnFailure();
77-
}
78-
finally
79-
{
80-
81-
}
82-
69+
hr = _pFileOperation.Get()->CopyItem(psiItem.Get(), psiDestinationFolder.Get(), pszCopyName, _pProgressSink.Get());
8370
return hr;
8471
}
8572

8673
public unsafe HRESULT QueueDeleteItem(ComPtr<IShellItem> psiItem)
8774
{
8875
HRESULT hr = default;
8976

90-
try
91-
{
92-
hr = _pFileOperation.Get()->DeleteItem(psiItem.Get(), _pProgressSink.Get());
93-
hr.ThrowOnFailure();
94-
}
95-
finally
96-
{
97-
}
98-
77+
hr = _pFileOperation.Get()->DeleteItem(psiItem.Get(), _pProgressSink.Get());
9978
return hr;
10079
}
10180

10281
public unsafe HRESULT QueueMoveItem(ComPtr<IShellItem> psiItem, ComPtr<IShellItem> psiDestinationFolder, PCWSTR pszNewName)
10382
{
10483
HRESULT hr = default;
10584

106-
try
107-
{
108-
hr = _pFileOperation.Get()->MoveItem(psiItem.Get(), psiDestinationFolder.Get(), pszNewName, null);
109-
hr.ThrowOnFailure();
110-
}
111-
finally
112-
{
113-
}
114-
85+
hr = _pFileOperation.Get()->MoveItem(psiItem.Get(), psiDestinationFolder.Get(), pszNewName, null);
11586
return hr;
11687
}
11788

11889
public unsafe HRESULT QueueNewItem(ComPtr<IShellItem> psiDestinationFolder, uint dwFileAttributes, PCWSTR pszName, PCWSTR pszTemplateName)
11990
{
12091
HRESULT hr = default;
12192

122-
try
123-
{
124-
hr = _pFileOperation.Get()->NewItem(psiDestinationFolder.Get(), dwFileAttributes, pszName, pszTemplateName, _pProgressSink.Get());
125-
hr.ThrowOnFailure();
126-
}
127-
finally
128-
{
129-
}
130-
93+
hr = _pFileOperation.Get()->NewItem(psiDestinationFolder.Get(), dwFileAttributes, pszName, pszTemplateName, _pProgressSink.Get());
13194
return hr;
13295
}
13396

13497
public unsafe HRESULT QueueRenameItem(ComPtr<IShellItem> psiItem, PCWSTR pszNewName)
13598
{
13699
HRESULT hr = default;
137100

138-
try
139-
{
140-
hr = _pFileOperation.Get()->RenameItem(psiItem.Get(), pszNewName, _pProgressSink.Get());
141-
hr.ThrowOnFailure();
142-
}
143-
finally
144-
{
145-
}
146-
101+
hr = _pFileOperation.Get()->RenameItem(psiItem.Get(), pszNewName, _pProgressSink.Get());
147102
return hr;
148103
}
149104

150105
public unsafe HRESULT PerformOperations()
151106
{
152107
HRESULT hr = default;
153108

154-
try
155-
{
156-
hr = _pFileOperation.Get()->PerformOperations();
157-
hr.ThrowOnFailure();
158-
}
159-
finally
160-
{
161-
}
162-
109+
hr = _pFileOperation.Get()->PerformOperations();
163110
return hr;
164111
}
165112

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public unsafe HRESULT PreMoveItem(uint dwFlags, IShellItem* psiItem, IShellItem*
3737
{
3838
if (_operationsHandle.Target is WindowsBulkOperations operations)
3939
{
40-
operations.PreMoveItem?.Invoke(this, new());
40+
operations.PreMoveItem?.Invoke(operations, new());
4141
return HRESULT.S_OK;
4242
}
4343

@@ -48,7 +48,7 @@ public unsafe HRESULT PostMoveItem(uint dwFlags, IShellItem* psiItem, IShellItem
4848
{
4949
if (_operationsHandle.Target is WindowsBulkOperations operations)
5050
{
51-
operations.PostMoveItem?.Invoke(this, new());
51+
operations.PostMoveItem?.Invoke(operations, new());
5252
return HRESULT.S_OK;
5353
}
5454

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ private unsafe partial struct WindowsBulkOperationsSink
2525
{
2626
WindowsBulkOperationsSink* operationsSink = (WindowsBulkOperationsSink*)NativeMemory.Alloc((nuint)sizeof(WindowsBulkOperationsSink));
2727
operationsSink->_lpVtbl = Vtbl;
28-
operationsSink->_refCount = 0;
28+
operationsSink->_refCount = 1;
2929
operationsSink->_operationsHandle = GCHandle.Alloc(operations);
3030

3131
return operationsSink;
@@ -83,7 +83,7 @@ public static int AddRef(WindowsBulkOperationsSink* @this)
8383
public static int Release(WindowsBulkOperationsSink* @this)
8484
{
8585
int newRefCount = Interlocked.Decrement(ref @this->_refCount);
86-
if (newRefCount is 1)
86+
if (newRefCount is 0)
8787
{
8888
if (@this->_operationsHandle.IsAllocated)
8989
@this->_operationsHandle.Free();

src/Files.App/Services/Storage/StorageTrashBinService.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ private unsafe bool RestoreAllTrashesInternal()
133133
hr = bulkOperations.QueueMoveItem(pShellItem, pOriginalPathShellItem, default);
134134
}
135135

136+
bulkOperations.PostMoveItem += (s, e) =>
137+
{
138+
Debug.WriteLine("An item was moved.");
139+
};
140+
136141
// Perform
137142
hr = bulkOperations.PerformOperations();
138143

0 commit comments

Comments
 (0)