1
- using Files . Extensions ;
2
- using Files . Filesystem . StorageItems ;
1
+ using Files . Filesystem . StorageItems ;
3
2
using System ;
4
3
using System . Collections . Generic ;
5
4
using System . IO ;
6
- using System . Threading ;
7
5
using System . Threading . Tasks ;
8
- using Windows . ApplicationModel . Core ;
9
- using Windows . UI . Core ;
10
6
using static Files . Helpers . NativeFindStorageItemHelper ;
11
7
12
8
namespace Files . Filesystem
@@ -15,10 +11,8 @@ public static class FolderHelpers
15
11
{
16
12
public static bool CheckFolderAccessWithWin32 ( string path )
17
13
{
18
- FINDEX_INFO_LEVELS findInfoLevel = FINDEX_INFO_LEVELS . FindExInfoBasic ;
19
- int additionalFlags = FIND_FIRST_EX_LARGE_FETCH ;
20
- IntPtr hFileTsk = FindFirstFileExFromApp ( path + "\\ *.*" , findInfoLevel , out WIN32_FIND_DATA findDataTsk , FINDEX_SEARCH_OPS . FindExSearchNameMatch , IntPtr . Zero ,
21
- additionalFlags ) ;
14
+ IntPtr hFileTsk = FindFirstFileExFromApp ( $ "{ path } { Path . DirectorySeparatorChar } *.*", FINDEX_INFO_LEVELS . FindExInfoBasic ,
15
+ out WIN32_FIND_DATA _ , FINDEX_SEARCH_OPS . FindExSearchNameMatch , IntPtr . Zero , FIND_FIRST_EX_LARGE_FETCH ) ;
22
16
if ( hFileTsk . ToInt64 ( ) != - 1 )
23
17
{
24
18
FindClose ( hFileTsk ) ;
@@ -29,13 +23,14 @@ public static bool CheckFolderAccessWithWin32(string path)
29
23
30
24
public static async Task < bool > CheckBitlockerStatusAsync ( BaseStorageFolder rootFolder , string path )
31
25
{
32
- if ( rootFolder == null || rootFolder . Properties == null )
26
+ if ( rootFolder ? . Properties is null )
33
27
{
34
28
return false ;
35
29
}
36
30
if ( Path . IsPathRooted ( path ) && Path . GetPathRoot ( path ) == path )
37
31
{
38
- IDictionary < string , object > extraProperties = await rootFolder . Properties . RetrievePropertiesAsync ( new string [ ] { "System.Volume.BitLockerProtection" } ) ;
32
+ IDictionary < string , object > extraProperties =
33
+ await rootFolder . Properties . RetrievePropertiesAsync ( new string [ ] { "System.Volume.BitLockerProtection" } ) ;
39
34
return ( int ? ) extraProperties [ "System.Volume.BitLockerProtection" ] == 6 ; // Drive is bitlocker protected and locked
40
35
}
41
36
return false ;
@@ -48,85 +43,12 @@ public static async Task<bool> CheckBitlockerStatusAsync(BaseStorageFolder rootF
48
43
///
49
44
public static bool CheckForFilesFolders ( string targetPath )
50
45
{
51
- FINDEX_INFO_LEVELS findInfoLevel = FINDEX_INFO_LEVELS . FindExInfoBasic ;
52
- int additionalFlags = FIND_FIRST_EX_LARGE_FETCH ;
53
-
54
- IntPtr hFile = FindFirstFileExFromApp ( targetPath + "\\ *.*" , findInfoLevel , out WIN32_FIND_DATA _ , FINDEX_SEARCH_OPS . FindExSearchNameMatch , IntPtr . Zero , additionalFlags ) ;
46
+ IntPtr hFile = FindFirstFileExFromApp ( $ "{ targetPath } { Path . DirectorySeparatorChar } *.*", FINDEX_INFO_LEVELS . FindExInfoBasic ,
47
+ out WIN32_FIND_DATA _ , FINDEX_SEARCH_OPS . FindExSearchNameMatch , IntPtr . Zero , FIND_FIRST_EX_LARGE_FETCH ) ;
55
48
FindNextFile ( hFile , out _ ) ;
56
49
var result = FindNextFile ( hFile , out _ ) ;
57
50
FindClose ( hFile ) ;
58
51
return result ;
59
52
}
60
-
61
- public static async void UpdateFolder ( ListedItem folder , CancellationToken cancellationToken )
62
- {
63
- CoreDispatcher dispatcher ;
64
-
65
- if ( folder . PrimaryItemAttribute == Windows . Storage . StorageItemTypes . Folder && folder . FileSizeBytes == 0 && folder . ContainsFilesOrFolders )
66
- {
67
- dispatcher = CoreApplication . MainView . CoreWindow . Dispatcher ;
68
-
69
- await dispatcher . RunAsync ( CoreDispatcherPriority . Low , ( ) =>
70
- {
71
- folder . FileSize = 0L . ToSizeString ( ) ;
72
- } ) ;
73
-
74
- _ = await Calculate ( folder . ItemPath ) ;
75
- }
76
-
77
- async Task < long > Calculate ( string folderPath )
78
- {
79
- if ( string . IsNullOrEmpty ( folderPath ) )
80
- {
81
- return 0 ;
82
- }
83
-
84
- FINDEX_INFO_LEVELS findInfoLevel = FINDEX_INFO_LEVELS . FindExInfoBasic ;
85
- int additionalFlags = FIND_FIRST_EX_LARGE_FETCH ;
86
-
87
- IntPtr hFile = FindFirstFileExFromApp ( folderPath + "\\ *.*" , findInfoLevel , out WIN32_FIND_DATA findData ,
88
- FINDEX_SEARCH_OPS . FindExSearchNameMatch , IntPtr . Zero , additionalFlags ) ;
89
-
90
- long size = 0 ;
91
- if ( hFile . ToInt64 ( ) != - 1 )
92
- {
93
- do
94
- {
95
- if ( ( ( FileAttributes ) findData . dwFileAttributes & FileAttributes . Directory ) != FileAttributes . Directory )
96
- {
97
- size += findData . GetSize ( ) ;
98
- }
99
- else if ( ( ( FileAttributes ) findData . dwFileAttributes & FileAttributes . Directory ) == FileAttributes . Directory )
100
- {
101
- if ( findData . cFileName is not "." and not ".." )
102
- {
103
- string path = Path . Combine ( folderPath , findData . cFileName ) ;
104
- size += await Calculate ( path ) ;
105
- }
106
- }
107
-
108
- await dispatcher . RunAsync ( CoreDispatcherPriority . Low , ( ) =>
109
- {
110
- if ( size > folder . FileSizeBytes )
111
- {
112
- folder . FileSizeBytes = size ;
113
- folder . FileSize = size . ToSizeString ( ) ;
114
- } ;
115
- } ) ;
116
-
117
- if ( cancellationToken . IsCancellationRequested )
118
- {
119
- break ;
120
- }
121
- } while ( FindNextFile ( hFile , out findData ) ) ;
122
- FindClose ( hFile ) ;
123
- return size ;
124
- }
125
- else
126
- {
127
- return 0 ;
128
- }
129
- }
130
- }
131
53
}
132
54
}
0 commit comments