Skip to content

Commit 4f72f55

Browse files
committed
Init
1 parent dde3ee7 commit 4f72f55

File tree

7 files changed

+429
-314
lines changed

7 files changed

+429
-314
lines changed

src/Files.App.CsWin32/NativeMethods.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,5 @@ FILE_FILE_COMPRESSION
172172
WM_WINDOWPOSCHANGING
173173
WINDOWPOS
174174
UnregisterClass
175+
E_POINTER
176+
E_NOINTERFACE

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: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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+
// Events
29+
30+
public event EventHandler<WindowsBulkOperationsEventArgs>? FinishOperations;
31+
public event EventHandler<WindowsBulkOperationsEventArgs>? PostCopyItem;
32+
public event EventHandler<WindowsBulkOperationsEventArgs>? PostDeleteItem;
33+
public event EventHandler<WindowsBulkOperationsEventArgs>? PostMoveItem;
34+
public event EventHandler<WindowsBulkOperationsEventArgs>? PostNewItem;
35+
public event EventHandler<WindowsBulkOperationsEventArgs>? PostRenameItem;
36+
public event EventHandler<WindowsBulkOperationsEventArgs>? PreCopyItem;
37+
public event EventHandler<WindowsBulkOperationsEventArgs>? PreDeleteItem;
38+
public event EventHandler<WindowsBulkOperationsEventArgs>? PreMoveItem;
39+
public event EventHandler<WindowsBulkOperationsEventArgs>? PreNewItem;
40+
public event EventHandler<WindowsBulkOperationsEventArgs>? PreRenameItem;
41+
public event EventHandler? StartOperations;
42+
public event ProgressChangedEventHandler? UpdateProgress;
43+
44+
// Constructor
45+
46+
public unsafe WindowsBulkOperations(HWND owner = default)
47+
{
48+
var clsid = typeof(FileOperation).GUID;
49+
var iid = typeof(IFileOperation).GUID;
50+
void* pObj = default;
51+
52+
PInvoke.CoCreateInstance(
53+
&clsid,
54+
null,
55+
CLSCTX.CLSCTX_LOCAL_SERVER,
56+
&iid,
57+
(void**)_pFileOperation.GetAddressOf());
58+
59+
_owner = owner;
60+
if (owner != default)
61+
_pFileOperation.Get()->SetOwnerWindow(owner);
62+
63+
_pProgressSink.Attach((IFileOperationProgressSink*)WindowsBulkOperationsSink.Create(this));
64+
_pFileOperation.Get()->Advise(_pProgressSink.Get(), out var progressSinkCookie);
65+
_progressSinkCookie = progressSinkCookie;
66+
}
67+
68+
public unsafe HRESULT CopyItem(ComPtr<IShellItem> psiItem, ComPtr<IShellItem> psiDestinationFolder, PCWSTR pszCopyName)
69+
{
70+
HRESULT hr = default;
71+
72+
try
73+
{
74+
hr = _pFileOperation.Get()->CopyItem(psiItem.Get(), psiDestinationFolder.Get(), pszCopyName, _pProgressSink.Get());
75+
hr.ThrowOnFailure();
76+
}
77+
finally
78+
{
79+
80+
}
81+
82+
return hr;
83+
}
84+
85+
public unsafe HRESULT DeleteItem(ComPtr<IShellItem> psiItem)
86+
{
87+
HRESULT hr = default;
88+
89+
try
90+
{
91+
hr = _pFileOperation.Get()->DeleteItem(psiItem.Get(), _pProgressSink.Get());
92+
hr.ThrowOnFailure();
93+
}
94+
finally
95+
{
96+
}
97+
98+
return hr;
99+
}
100+
101+
public unsafe HRESULT MoveItem(ComPtr<IShellItem> psiItem, ComPtr<IShellItem> psiDestinationFolder, PCWSTR pszNewName)
102+
{
103+
HRESULT hr = default;
104+
105+
try
106+
{
107+
hr = _pFileOperation.Get()->MoveItem(psiItem.Get(), psiDestinationFolder.Get(), pszNewName, _pProgressSink.Get());
108+
hr.ThrowOnFailure();
109+
}
110+
finally
111+
{
112+
}
113+
114+
return hr;
115+
}
116+
117+
public unsafe HRESULT NewItem(ComPtr<IShellItem> psiDestinationFolder, uint dwFileAttributes, PCWSTR pszName, PCWSTR pszTemplateName)
118+
{
119+
HRESULT hr = default;
120+
121+
try
122+
{
123+
hr = _pFileOperation.Get()->NewItem(psiDestinationFolder.Get(), dwFileAttributes, pszName, pszTemplateName, _pProgressSink.Get());
124+
hr.ThrowOnFailure();
125+
}
126+
finally
127+
{
128+
}
129+
130+
return hr;
131+
}
132+
133+
public unsafe HRESULT RenameItem(ComPtr<IShellItem> psiItem, PCWSTR pszNewName)
134+
{
135+
HRESULT hr = default;
136+
137+
try
138+
{
139+
hr = _pFileOperation.Get()->RenameItem(psiItem.Get(), pszNewName, _pProgressSink.Get());
140+
hr.ThrowOnFailure();
141+
}
142+
finally
143+
{
144+
}
145+
146+
return hr;
147+
}
148+
149+
public void Dispose()
150+
{
151+
_pFileOperation.Dispose();
152+
_pProgressSink.Dispose();
153+
}
154+
}
155+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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 class WindowsBulkOperationsEventArgs : EventArgs
13+
{
14+
}
15+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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 unsafe partial struct WindowsBulkOperationsSink : IFileOperationProgressSink.Interface
13+
{
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();
92+
}
93+
}
94+
}

0 commit comments

Comments
 (0)