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 ;
1613using System . Runtime . CompilerServices ;
17- using System . Threading ;
18- using System . Threading . Tasks ;
1914
2015namespace Files . App . Storage . NativeStorage
2116{
2217/// <inheritdoc cref="IFolder"/>
2318public class NativeFolder : NativeStorable < DirectoryInfo > , ILocatableFolder , IModifiableFolder , IMutableFolder , IFolderExtended , INestedFolder , IDirectCopy , IDirectMove
24- {
19+ {
2520public NativeFolder ( DirectoryInfo directoryInfo , string ? name = null )
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- }
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+ }
8277
8378/// <inheritdoc/>
8479public virtual Task DeleteAsync ( INestedStorable item , bool permanently = false , CancellationToken cancellationToken = default )
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- }
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+ }
10196
10297/// <inheritdoc/>
10398public virtual async Task < INestedStorable > CreateCopyOfAsync ( INestedStorable itemToCopy , bool overwrite = default , CancellationToken cancellationToken = default )
@@ -106,7 +101,7 @@ public virtual async Task<INestedStorable> CreateCopyOfAsync(INestedStorable ite
106101{
107102if ( itemToCopy is ILocatableFile sourceLocatableFile )
108103{
109- var newPath = System . IO . Path . Combine ( Path , itemToCopy . Name ) ;
104+ var newPath = SystemIO . Path . Combine ( Path , itemToCopy . Name ) ;
110105File . Copy ( sourceLocatableFile . Path , newPath , overwrite ) ;
111106
112107return new NativeFile ( newPath ) ;
@@ -134,7 +129,7 @@ public virtual async Task<INestedStorable> MoveFromAsync(INestedStorable itemToM
134129{
135130if ( itemToMove is ILocatableFile sourceLocatableFile )
136131{
137- var newPath = System . IO . Path . Combine ( Path , itemToMove . Name ) ;
132+ var newPath = SystemIO . Path . Combine ( Path , itemToMove . Name ) ;
138133File . Move ( sourceLocatableFile . Path , newPath , overwrite ) ;
139134
140135return new NativeFile ( newPath ) ;
@@ -159,7 +154,7 @@ public virtual async Task<INestedStorable> MoveFromAsync(INestedStorable itemToM
159154/// <inheritdoc/>
160155public virtual async Task < INestedFile > CreateFileAsync ( string desiredName , bool overwrite = default , CancellationToken cancellationToken = default )
161156{
162- var path = System . IO . Path . Combine ( Path , desiredName ) ;
157+ var path = SystemIO . Path . Combine ( Path , desiredName ) ;
163158if ( overwrite || ! File . Exists ( path ) )
164159await File . Create ( path ) . DisposeAsync ( ) ;
165160
@@ -169,7 +164,7 @@ public virtual async Task<INestedFile> CreateFileAsync(string desiredName, bool
169164/// <inheritdoc/>
170165public virtual Task < INestedFolder > CreateFolderAsync ( string desiredName , bool overwrite = default , CancellationToken cancellationToken = default )
171166{
172- var path = System . IO . Path . Combine ( Path , desiredName ) ;
167+ var path = SystemIO . Path . Combine ( Path , desiredName ) ;
173168if ( overwrite )
174169Directory . Delete ( path , true ) ;
175170
@@ -179,8 +174,8 @@ public virtual Task<INestedFolder> CreateFolderAsync(string desiredName, bool ov
179174
180175/// <inheritdoc/>
181176public Task < IFolderWatcher > GetFolderWatcherAsync ( CancellationToken cancellationToken = default )
182- {
183- return Task . FromResult < IFolderWatcher > ( new NativeFolderWatcher ( this ) ) ;
184- }
185- }
177+ {
178+ return Task . FromResult < IFolderWatcher > ( new NativeFolderWatcher ( this ) ) ;
179+ }
180+ }
186181}
0 commit comments