1010using Files . Core . Storage . ModifiableStorage ;
1111using Files . Core . Storage . MutableStorage ;
1212using Files . Core . Storage . NestedStorage ;
13+ using System ;
14+ using System . Collections . Generic ;
15+ using System . IO ;
1316using System . Runtime . CompilerServices ;
17+ using System . Threading ;
18+ using System . Threading . Tasks ;
1419
1520namespace Files . App . Storage . NativeStorage
1621{
1722/// <inheritdoc cref="IFolder"/>
1823public class NativeFolder : NativeStorable < DirectoryInfo > , ILocatableFolder , IModifiableFolder , IMutableFolder , IFolderExtended , INestedFolder , IDirectCopy , IDirectMove
19- {
24+ {
2025public NativeFolder ( DirectoryInfo directoryInfo , string ? name = null )
21- : base ( directoryInfo , name )
22- {
23- }
24-
25- public NativeFolder ( string path , string ? name = null )
26- : this ( new DirectoryInfo ( path ) , name )
27- {
28- }
29-
30- /// <inheritdoc/>
31- public virtual Task < INestedFile > GetFileAsync ( string fileName , CancellationToken cancellationToken = default )
32- {
33- var path = SystemIO . Path . Combine ( Path , fileName ) ;
34-
35- if ( ! File . Exists ( path ) )
36- throw new FileNotFoundException ( ) ;
37-
38- return Task . FromResult < INestedFile > ( new NativeFile ( path ) ) ;
39- }
40-
41- /// <inheritdoc/>
42- public virtual Task < INestedFolder > GetFolderAsync ( string folderName , CancellationToken cancellationToken = default )
43- {
44- var path = SystemIO . Path . Combine ( Path , folderName ) ;
45- if ( ! Directory . Exists ( path ) )
46- throw new FileNotFoundException ( ) ;
47-
48- return Task . FromResult < INestedFolder > ( new NativeFolder ( path ) ) ;
49- }
50-
51- /// <inheritdoc/>
52- public virtual async IAsyncEnumerable < INestedStorable > GetItemsAsync ( StorableKind kind = StorableKind . All , [ EnumeratorCancellation ] CancellationToken cancellationToken = default )
53- {
54- if ( kind == StorableKind . Files )
55- {
56- foreach ( var item in Directory . EnumerateFiles ( Path ) )
57- yield return new NativeFile ( item ) ;
58- }
59- else if ( kind == StorableKind . Folders )
60- {
61- foreach ( var item in Directory . EnumerateDirectories ( Path ) )
62- yield return new NativeFolder ( item ) ;
63- }
64- else
65- {
66- foreach ( var item in Directory . EnumerateFileSystemEntries ( Path ) )
67- {
68- if ( File . Exists ( item ) )
69- yield return new NativeFile ( item ) ;
70- else
71- yield return new NativeFolder ( item ) ;
72- }
73- }
74-
75- await Task . CompletedTask ;
76- }
26+ : base ( directoryInfo , name )
27+ {
28+ }
29+
30+ public NativeFolder ( string path , string ? name = null )
31+ : this ( new DirectoryInfo ( path ) , name )
32+ {
33+ }
34+
35+ /// <inheritdoc/>
36+ public virtual Task < INestedFile > GetFileAsync ( string fileName , CancellationToken cancellationToken = default )
37+ {
38+ var path = System . IO . Path . Combine ( Path , fileName ) ;
39+
40+ if ( ! File . Exists ( path ) )
41+ throw new FileNotFoundException ( ) ;
42+
43+ return Task . FromResult < INestedFile > ( new NativeFile ( path ) ) ;
44+ }
45+
46+ /// <inheritdoc/>
47+ public virtual Task < INestedFolder > GetFolderAsync ( string folderName , CancellationToken cancellationToken = default )
48+ {
49+ var path = System . IO . Path . Combine ( Path , folderName ) ;
50+ if ( ! Directory . Exists ( path ) )
51+ throw new FileNotFoundException ( ) ;
52+
53+ return Task . FromResult < INestedFolder > ( new NativeFolder ( path ) ) ;
54+ }
55+
56+ /// <inheritdoc/>
57+ public virtual async IAsyncEnumerable < INestedStorable > GetItemsAsync ( StorableKind kind = StorableKind . All , [ EnumeratorCancellation ] CancellationToken cancellationToken = default )
58+ {
59+ if ( kind == StorableKind . Files )
60+ {
61+ foreach ( var item in Directory . EnumerateFiles ( Path ) )
62+ yield return new NativeFile ( item ) ;
63+ }
64+ else if ( kind == StorableKind . Folders )
65+ {
66+ foreach ( var item in Directory . EnumerateDirectories ( Path ) )
67+ yield return new NativeFolder ( item ) ;
68+ }
69+ else
70+ {
71+ foreach ( var item in Directory . EnumerateFileSystemEntries ( Path ) )
72+ {
73+ if ( File . Exists ( item ) )
74+ yield return new NativeFile ( item ) ;
75+ else
76+ yield return new NativeFolder ( item ) ;
77+ }
78+ }
79+
80+ await Task . CompletedTask ;
81+ }
7782
7883/// <inheritdoc/>
7984public virtual Task DeleteAsync ( INestedStorable item , bool permanently = false , CancellationToken cancellationToken = default )
80- {
81- _ = permanently ;
82-
83- if ( item is ILocatableFile locatableFile )
84- {
85- File . Delete ( locatableFile . Path ) ;
86- }
87- else if ( item is ILocatableFolder locatableFolder )
88- {
89- Directory . Delete ( locatableFolder . Path , true ) ;
90- }
91- else
92- throw new ArgumentException ( $ "Could not delete { item } .") ;
93-
94- return Task . CompletedTask ;
95- }
85+ {
86+ _ = permanently ;
87+
88+ if ( item is ILocatableFile locatableFile )
89+ {
90+ File . Delete ( locatableFile . Path ) ;
91+ }
92+ else if ( item is ILocatableFolder locatableFolder )
93+ {
94+ Directory . Delete ( locatableFolder . Path , true ) ;
95+ }
96+ else
97+ throw new ArgumentException ( $ "Could not delete { item } .") ;
98+
99+ return Task . CompletedTask ;
100+ }
96101
97102/// <inheritdoc/>
98103public virtual async Task < INestedStorable > CreateCopyOfAsync ( INestedStorable itemToCopy , bool overwrite = default , CancellationToken cancellationToken = default )
@@ -101,7 +106,7 @@ public virtual async Task<INestedStorable> CreateCopyOfAsync(INestedStorable ite
101106{
102107if ( itemToCopy is ILocatableFile sourceLocatableFile )
103108{
104- var newPath = SystemIO . Path . Combine ( Path , itemToCopy . Name ) ;
109+ var newPath = System . IO . Path . Combine ( Path , itemToCopy . Name ) ;
105110File . Copy ( sourceLocatableFile . Path , newPath , overwrite ) ;
106111
107112return new NativeFile ( newPath ) ;
@@ -129,7 +134,7 @@ public virtual async Task<INestedStorable> MoveFromAsync(INestedStorable itemToM
129134{
130135if ( itemToMove is ILocatableFile sourceLocatableFile )
131136{
132- var newPath = SystemIO . Path . Combine ( Path , itemToMove . Name ) ;
137+ var newPath = System . IO . Path . Combine ( Path , itemToMove . Name ) ;
133138File . Move ( sourceLocatableFile . Path , newPath , overwrite ) ;
134139
135140return new NativeFile ( newPath ) ;
@@ -154,7 +159,7 @@ public virtual async Task<INestedStorable> MoveFromAsync(INestedStorable itemToM
154159/// <inheritdoc/>
155160public virtual async Task < INestedFile > CreateFileAsync ( string desiredName , bool overwrite = default , CancellationToken cancellationToken = default )
156161{
157- var path = SystemIO . Path . Combine ( Path , desiredName ) ;
162+ var path = System . IO . Path . Combine ( Path , desiredName ) ;
158163if ( overwrite || ! File . Exists ( path ) )
159164await File . Create ( path ) . DisposeAsync ( ) ;
160165
@@ -164,7 +169,7 @@ public virtual async Task<INestedFile> CreateFileAsync(string desiredName, bool
164169/// <inheritdoc/>
165170public virtual Task < INestedFolder > CreateFolderAsync ( string desiredName , bool overwrite = default , CancellationToken cancellationToken = default )
166171{
167- var path = SystemIO . Path . Combine ( Path , desiredName ) ;
172+ var path = System . IO . Path . Combine ( Path , desiredName ) ;
168173if ( overwrite )
169174Directory . Delete ( path , true ) ;
170175
@@ -174,8 +179,8 @@ public virtual Task<INestedFolder> CreateFolderAsync(string desiredName, bool ov
174179
175180/// <inheritdoc/>
176181public Task < IFolderWatcher > GetFolderWatcherAsync ( CancellationToken cancellationToken = default )
177- {
178- return Task . FromResult < IFolderWatcher > ( new NativeFolderWatcher ( this ) ) ;
179- }
180- }
182+ {
183+ return Task . FromResult < IFolderWatcher > ( new NativeFolderWatcher ( this ) ) ;
184+ }
185+ }
181186}
0 commit comments