1
1
using System ;
2
- using Files ;
3
- using Navigation ;
4
2
using System . Collections . Generic ;
5
3
using System . Collections . ObjectModel ;
6
4
using System . Diagnostics ;
5
+ using System . Globalization ;
6
+ using System . Runtime . InteropServices ;
7
7
using Windows . Storage ;
8
8
using Windows . Storage . FileProperties ;
9
- using Windows . UI . Xaml ;
10
- using Windows . UI . Xaml . Media . Imaging ;
11
- using Windows . Storage . Search ;
12
9
using Windows . UI . Popups ;
13
- using Interacts ;
10
+ using Windows . UI . Xaml ;
14
11
using Windows . UI . Xaml . Controls ;
15
12
using Windows . UI . Xaml . Media . Animation ;
13
+ using Windows . UI . Xaml . Media . Imaging ;
16
14
using System . Threading ;
17
- using System . Threading . Tasks ;
15
+ using Files . Interacts ;
16
+ using Files . Navigation ;
17
+ using Windows . Storage . Search ;
18
+ using TreeView = Microsoft . UI . Xaml . Controls . TreeView ;
18
19
19
- namespace ItemListPresenter
20
+ namespace Files . Filesystem
20
21
{
21
- public class ListedItem
22
- {
23
- public Visibility FolderImg { get ; set ; }
24
- public Visibility FileIconVis { get ; set ; }
25
- public BitmapImage FileImg { get ; set ; }
26
- public string FileName { get ; set ; }
27
- public string FileDate { get ; set ; }
28
- public string FileExtension { get ; set ; }
29
- public string FilePath { get ; set ; }
30
- public int ItemIndex { get ; set ; }
31
- public ListedItem ( )
32
- {
33
-
34
- }
35
- }
36
-
37
- public class Classic_ListedFolderItem
38
- {
39
- public string FileName { get ; set ; }
40
- public string FileDate { get ; set ; }
41
- public string FileExtension { get ; set ; }
42
- public string FilePath { get ; set ; }
43
- public ObservableCollection < Classic_ListedFolderItem > Children { get ; set ; } = new ObservableCollection < Classic_ListedFolderItem > ( ) ;
44
- }
45
-
46
22
public class ItemViewModel
47
23
{
48
24
public static ObservableCollection < Classic_ListedFolderItem > classicFolderList = new ObservableCollection < Classic_ListedFolderItem > ( ) ;
49
25
public static ObservableCollection < Classic_ListedFolderItem > ClassicFolderList { get { return classicFolderList ; } }
50
-
26
+
51
27
public static ObservableCollection < ListedItem > classicFileList = new ObservableCollection < ListedItem > ( ) ;
52
28
public static ObservableCollection < ListedItem > ClassicFileList { get { return classicFileList ; } }
53
29
@@ -82,10 +58,6 @@ public static BackState BS
82
58
{
83
59
return bs ;
84
60
}
85
- set
86
- {
87
-
88
- }
89
61
}
90
62
91
63
public static ForwardState fs = new ForwardState ( ) ;
@@ -95,10 +67,6 @@ public static ForwardState FS
95
67
{
96
68
return fs ;
97
69
}
98
- set
99
- {
100
-
101
- }
102
70
}
103
71
104
72
public static ProgressUIVisibility pvis = new ProgressUIVisibility ( ) ;
@@ -108,10 +76,6 @@ public static ProgressUIVisibility PVIS
108
76
{
109
77
return pvis ;
110
78
}
111
- set
112
- {
113
-
114
- }
115
79
}
116
80
117
81
private ListedItem li = new ListedItem ( ) ;
@@ -154,33 +118,33 @@ public static ProgressUIVisibility PVIS
154
118
public static CancellationToken token ;
155
119
public static CancellationTokenSource tokenSource ;
156
120
157
- public ItemViewModel ( string ViewPath , Page p )
121
+ public ItemViewModel ( string viewPath , Page p )
158
122
{
159
-
123
+
160
124
pageName = p . Name ;
161
125
// Personalize retrieved items for view they are displayed in
162
- if ( p . Name == "GenericItemView" || p . Name == "ClassicModePage" )
126
+ if ( p . Name == "GenericItemView" || p . Name == "ClassicModePage" )
163
127
{
164
128
isPhotoAlbumMode = false ;
165
129
}
166
130
else if ( p . Name == "PhotoAlbumViewer" )
167
131
{
168
132
isPhotoAlbumMode = true ;
169
133
}
170
-
171
- if ( pageName != "ClassicModePage" )
134
+
135
+ if ( pageName != "ClassicModePage" )
172
136
{
173
- GenericFileBrowser . P . path = ViewPath ;
137
+ GenericFileBrowser . P . path = viewPath ;
174
138
FilesAndFolders . Clear ( ) ;
175
139
}
176
140
177
141
tokenSource = new CancellationTokenSource ( ) ;
178
142
token = tokenSource . Token ;
179
- MemoryFriendlyGetItemsAsync ( ViewPath , token ) ;
143
+ MemoryFriendlyGetItemsAsync ( viewPath , token ) ;
180
144
181
145
if ( pageName != "ClassicModePage" )
182
146
{
183
- History . AddToHistory ( ViewPath ) ;
147
+ History . AddToHistory ( viewPath ) ;
184
148
185
149
if ( History . HistoryList . Count == 1 )
186
150
{
@@ -195,15 +159,15 @@ public ItemViewModel(string ViewPath, Page p)
195
159
//Debug.WriteLine("Enabled Property");
196
160
}
197
161
}
198
-
162
+
199
163
200
164
}
201
165
202
166
private async void DisplayConsentDialog ( )
203
167
{
204
168
MessageDialog message = new MessageDialog ( "This app is not able to access your files. You need to allow it to by granting permission in Settings." ) ;
205
169
message . Title = "Permission Denied" ;
206
- message . Commands . Add ( new UICommand ( "Allow..." , new UICommandInvokedHandler ( Interaction . GrantAccessPermissionHandler ) ) ) ;
170
+ message . Commands . Add ( new UICommand ( "Allow..." , Interaction . GrantAccessPermissionHandler ) ) ;
207
171
await message . ShowAsync ( ) ;
208
172
}
209
173
string sort = "By_Name" ;
@@ -248,13 +212,13 @@ public async void MemoryFriendlyGetItemsAsync(string path, CancellationToken tok
248
212
int foldersCountSnapshot = folders . Count ;
249
213
while ( folders . Count != 0 )
250
214
{
251
- foreach ( StorageFolder folder in folders )
215
+ foreach ( StorageFolder folder in folders )
252
216
{
253
217
if ( token . IsCancellationRequested )
254
218
{
255
219
return ;
256
220
}
257
-
221
+
258
222
gotFolName = folder . Name . ToString ( ) ;
259
223
gotFolDate = folder . DateCreated . ToString ( ) ;
260
224
gotFolPath = folder . Path . ToString ( ) ;
@@ -288,7 +252,7 @@ public async void MemoryFriendlyGetItemsAsync(string path, CancellationToken tok
288
252
{
289
253
return ;
290
254
}
291
-
255
+
292
256
gotName = file . Name . ToString ( ) ;
293
257
gotDate = file . DateCreated . ToString ( ) ; // In the future, parse date to human readable format
294
258
if ( file . FileType . ToString ( ) == ".exe" )
@@ -306,7 +270,15 @@ public async void MemoryFriendlyGetItemsAsync(string path, CancellationToken tok
306
270
const uint requestedSize = 20 ;
307
271
const ThumbnailMode thumbnailMode = ThumbnailMode . ListView ;
308
272
const ThumbnailOptions thumbnailOptions = ThumbnailOptions . UseCurrentScale ;
309
- gotFileImg = await file . GetThumbnailAsync ( thumbnailMode , requestedSize , thumbnailOptions ) ;
273
+ try
274
+ {
275
+ gotFileImg = await file . GetThumbnailAsync ( thumbnailMode , requestedSize , thumbnailOptions ) ;
276
+ }
277
+ catch
278
+ {
279
+ // Silent catch here to avoid crash
280
+ // TODO maybe some logging could be added in the future...
281
+ }
310
282
}
311
283
else
312
284
{
@@ -335,7 +307,7 @@ public async void MemoryFriendlyGetItemsAsync(string path, CancellationToken tok
335
307
index += step ;
336
308
files = await fileQueryResult . GetFilesAsync ( index , step ) ;
337
309
}
338
- if ( foldersCountSnapshot + filesCountSnapshot == 0 )
310
+ if ( foldersCountSnapshot + filesCountSnapshot == 0 )
339
311
{
340
312
TextState . isVisible = Visibility . Visible ;
341
313
}
@@ -344,23 +316,36 @@ public async void MemoryFriendlyGetItemsAsync(string path, CancellationToken tok
344
316
PVIS . isVisible = Visibility . Collapsed ;
345
317
}
346
318
PVIS . isVisible = Visibility . Collapsed ;
347
- }
348
- catch ( UnauthorizedAccessException )
319
+ stopwatch . Stop ( ) ;
320
+ Debug . WriteLine ( "Loading of: " + path + " completed in " + stopwatch . ElapsedMilliseconds + " Milliseconds." ) ;
321
+ }
322
+ catch ( UnauthorizedAccessException e )
349
323
{
350
- DisplayConsentDialog ( ) ;
324
+ if ( path . Contains ( @"C:\" ) )
325
+ {
326
+ DisplayConsentDialog ( ) ;
327
+ }
328
+ else
329
+ {
330
+ MessageDialog unsupportedDevice = new MessageDialog ( "This device is unsupported. Please file an issue report in Settings - About containing what device we couldn't access. Technical information: " + e , "Unsupported Device" ) ;
331
+ await unsupportedDevice . ShowAsync ( ) ;
332
+ }
333
+ stopwatch . Stop ( ) ;
334
+ Debug . WriteLine ( "Loading of: " + path + " failed in " + stopwatch . ElapsedMilliseconds + " Milliseconds." ) ;
351
335
}
352
- catch ( System . Runtime . InteropServices . COMException e )
336
+ catch ( COMException e )
353
337
{
338
+ stopwatch . Stop ( ) ;
339
+ Debug . WriteLine ( "Loading of: " + path + " failed in " + stopwatch . ElapsedMilliseconds + " Milliseconds." ) ;
354
340
Frame rootFrame = Window . Current . Content as Frame ;
355
341
MessageDialog driveGone = new MessageDialog ( e . Message , "Drive Unplugged" ) ;
356
342
await driveGone . ShowAsync ( ) ;
357
343
rootFrame . Navigate ( typeof ( MainPage ) , new SuppressNavigationTransitionInfo ( ) ) ;
358
344
}
359
- stopwatch . Stop ( ) ;
360
- Debug . WriteLine ( "Loading of: " + path + " completed in " + stopwatch . ElapsedMilliseconds + " Milliseconds." ) ;
345
+
361
346
}
362
-
363
-
347
+
348
+
364
349
365
350
public static ProgressPercentage progressPER = new ProgressPercentage ( ) ;
366
351
@@ -396,18 +381,18 @@ public static async void DisplayReviewUIWithArgs(string header, string subHeader
396
381
await GenericFileBrowser . reviewBox . ShowAsync ( ) ;
397
382
}
398
383
399
- public static async void FillTreeNode ( object item , Microsoft . UI . Xaml . Controls . TreeView EntireControl )
384
+ public static async void FillTreeNode ( object item , TreeView EntireControl )
400
385
{
401
- var PathToFillFrom = ( item as Classic_ListedFolderItem ) . FilePath ;
402
- StorageFolder FolderFromPath = await StorageFolder . GetFolderFromPathAsync ( PathToFillFrom ) ;
403
- IReadOnlyList < StorageFolder > SubFolderList = await FolderFromPath . GetFoldersAsync ( ) ;
404
- foreach ( StorageFolder fol in SubFolderList )
386
+ var pathToFillFrom = ( item as Classic_ListedFolderItem ) ? . FilePath ;
387
+ StorageFolder folderFromPath = await StorageFolder . GetFolderFromPathAsync ( pathToFillFrom ) ;
388
+ IReadOnlyList < StorageFolder > SubFolderList = await folderFromPath . GetFoldersAsync ( ) ;
389
+ foreach ( StorageFolder fol in SubFolderList )
405
390
{
406
391
var name = fol . Name ;
407
- var date = fol . DateCreated . LocalDateTime . ToString ( ) ;
392
+ var date = fol . DateCreated . LocalDateTime . ToString ( CultureInfo . InvariantCulture ) ;
408
393
var ext = fol . DisplayType ;
409
394
var path = fol . Path ;
410
- ( item as Classic_ListedFolderItem ) . Children . Add ( new Classic_ListedFolderItem ( ) { FileName = name , FilePath = path , FileDate = date , FileExtension = ext } ) ;
395
+ ( item as Classic_ListedFolderItem ) ? . Children . Add ( new Classic_ListedFolderItem ( ) { FileName = name , FilePath = path , FileDate = date , FileExtension = ext } ) ;
411
396
412
397
}
413
398
}
0 commit comments