Skip to content

Commit cc7b884

Browse files
committed
Init
1 parent dde3ee7 commit cc7b884

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

src/Files.App.Storage/Files.App.Storage.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
<Configurations>Debug;Release</Configurations>
1010
<Platforms>x86;x64;arm64</Platforms>
1111
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
12+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1213
</PropertyGroup>
1314

1415
<ItemGroup>
1516
<PackageReference Include="FluentFTP" />
1617
</ItemGroup>
1718

1819
<ItemGroup>
20+
<ProjectReference Include="..\Files.App.CsWin32\Files.App.CsWin32.csproj" />
1921
<ProjectReference Include="..\Files.Core.Storage\Files.Core.Storage.csproj" />
2022
<ProjectReference Include="..\Files.Shared\Files.Shared.csproj" />
2123
</ItemGroup>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
using System.Runtime.CompilerServices;
5+
using Windows.Win32;
6+
using Windows.Win32.Foundation;
7+
using Windows.Win32.System.Com;
8+
using Windows.Win32.UI.Shell;
9+
10+
namespace Files.App.Storage.Storables
11+
{
12+
public sealed class WindowsBulkOperations : IDisposable
13+
{
14+
// Constants
15+
16+
private const FILEOPERATION_FLAGS defaultOptions = FILEOPERATION_FLAGS.FOF_ALLOWUNDO | FILEOPERATION_FLAGS.FOF_NOCONFIRMMKDIR;
17+
18+
// Fields
19+
20+
private readonly ComPtr<IFileOperation> _pFileOperation;
21+
private readonly ComPtr<IFileOperationProgressSink> _pProgressSink;
22+
private readonly uint _progressSinkCookie;
23+
24+
private int _disposedValue = 0;
25+
private FILEOPERATION_FLAGS _operationFlags = defaultOptions;
26+
private HWND _owner;
27+
28+
// Constructor
29+
30+
public unsafe WindowsBulkOperations(HWND owner = default)
31+
{
32+
var clsid = typeof(FileOperation).GUID;
33+
var iid = typeof(IFileOperation).GUID;
34+
void* pObj = default;
35+
36+
PInvoke.CoCreateInstance(
37+
&clsid,
38+
null,
39+
CLSCTX.CLSCTX_LOCAL_SERVER,
40+
&iid,
41+
(void**)_pFileOperation.GetAddressOf());
42+
43+
_owner = owner;
44+
if (owner != default)
45+
_pFileOperation.Get()->SetOwnerWindow(owner);
46+
47+
_pProgressSink = default;
48+
_pFileOperation.Get()->Advise(_pProgressSink.Get(), out var progressSinkCookie);
49+
_progressSinkCookie = progressSinkCookie;
50+
}
51+
52+
public unsafe HRESULT CopyItem(ComPtr<IShellItem> psiItem, ComPtr<IShellItem> psiDestinationFolder, PWSTR pszCopyName)
53+
{
54+
HRESULT hr = default;
55+
56+
try
57+
{
58+
hr = _pFileOperation.Get()->CopyItem(psiItem.Get(), psiDestinationFolder.Get(), pszCopyName, _pProgressSink.Get());
59+
hr = _pFileOperation.Get()->PerformOperations();
60+
hr.ThrowOnFailure();
61+
}
62+
finally
63+
{
64+
65+
}
66+
67+
return hr;
68+
}
69+
70+
public void Dispose()
71+
{
72+
_pFileOperation.Dispose();
73+
_pProgressSink.Dispose();
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)