@@ -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
0 commit comments