Skip to content

Commit bc1e68f

Browse files
committed
Re-Introduce Code Cleanup for New Code
1 parent 11fabe8 commit bc1e68f

25 files changed

+677
-630
lines changed

AddItem.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using Windows.UI.Xaml;
44
using Windows.UI.Xaml.Controls;
55
using System;
6-
using ItemListPresenter;
6+
using Files.Filesystem;
77

88
namespace Files
99
{

App.xaml.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99

1010
namespace Files
1111
{
12-
1312
sealed partial class App : Application
14-
{
15-
13+
{
1614
public App()
1715
{
1816
this.InitializeComponent();

ClassicMode.xaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
x:Class="Files.ClassicMode"
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5-
xmlns:local1="using:ItemListPresenter"
5+
xmlns:local1="using:Files.Filesystem"
66
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
77
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
88
xmlns:UILib="using:Microsoft.UI.Xaml.Controls"

ClassicMode.xaml.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
using ItemListPresenter;
2-
using Windows.ApplicationModel.Core;
1+
using Windows.ApplicationModel.Core;
32
using Windows.UI;
43
using Windows.UI.ViewManagement;
54
using Windows.UI.Xaml;
65
using Windows.UI.Xaml.Controls;
7-
6+
using Files.Filesystem;
87

98
namespace Files
109
{

Files.csproj

+13-3
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,25 @@
111111
<Compile Include="ClassicMode.xaml.cs">
112112
<DependentUpon>ClassicMode.xaml</DependentUpon>
113113
</Compile>
114-
<Compile Include="FileLoader.cs" />
114+
<Compile Include="Filesystem\Classic_ListedFolderItem.cs" />
115+
<Compile Include="Filesystem\ItemViewModel.cs" />
116+
<Compile Include="Filesystem\ListedItem.cs" />
115117
<Compile Include="GenericFileBrowser.xaml.cs">
116118
<DependentUpon>GenericFileBrowser.xaml</DependentUpon>
117119
</Compile>
118-
<Compile Include="ItemInteractions.cs" />
120+
<Compile Include="Interacts\Interaction.cs" />
121+
<Compile Include="Interacts\ItemInteractions.cs" />
119122
<Compile Include="LocationsList.cs" />
120123
<Compile Include="MainPage.xaml.cs">
121124
<DependentUpon>MainPage.xaml</DependentUpon>
122125
</Compile>
123-
<Compile Include="NavigationSystem.cs" />
126+
<Compile Include="Navigation\ArrayDiag.cs" />
127+
<Compile Include="Navigation\BackState.cs" />
128+
<Compile Include="Navigation\ForwardState.cs" />
129+
<Compile Include="Navigation\History.cs" />
130+
<Compile Include="Navigation\NavigationActions.cs" />
131+
<Compile Include="Navigation\PhotoAlbumNavActions.cs" />
132+
<Compile Include="Navigation\UniversalPath.cs" />
124133
<Compile Include="PhotoAlbum.xaml.cs">
125134
<DependentUpon>PhotoAlbum.xaml</DependentUpon>
126135
</Compile>
@@ -280,6 +289,7 @@
280289
<ItemGroup>
281290
<None Include="Files_TemporaryKey.pfx" />
282291
</ItemGroup>
292+
<ItemGroup />
283293
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
284294
<VisualStudioVersion>14.0</VisualStudioVersion>
285295
</PropertyGroup>
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Collections.ObjectModel;
2+
3+
namespace Files.Filesystem
4+
{
5+
public class Classic_ListedFolderItem
6+
{
7+
public string FileName { get; set; }
8+
public string FileDate { get; set; }
9+
public string FileExtension { get; set; }
10+
public string FilePath { get; set; }
11+
public ObservableCollection<Classic_ListedFolderItem> Children { get; set; } = new ObservableCollection<Classic_ListedFolderItem>();
12+
}
13+
}

FileLoader.cs renamed to Filesystem/ItemViewModel.cs

+61-76
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,29 @@
11
using System;
2-
using Files;
3-
using Navigation;
42
using System.Collections.Generic;
53
using System.Collections.ObjectModel;
64
using System.Diagnostics;
5+
using System.Globalization;
6+
using System.Runtime.InteropServices;
77
using Windows.Storage;
88
using Windows.Storage.FileProperties;
9-
using Windows.UI.Xaml;
10-
using Windows.UI.Xaml.Media.Imaging;
11-
using Windows.Storage.Search;
129
using Windows.UI.Popups;
13-
using Interacts;
10+
using Windows.UI.Xaml;
1411
using Windows.UI.Xaml.Controls;
1512
using Windows.UI.Xaml.Media.Animation;
13+
using Windows.UI.Xaml.Media.Imaging;
1614
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;
1819

19-
namespace ItemListPresenter
20+
namespace Files.Filesystem
2021
{
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-
4622
public class ItemViewModel
4723
{
4824
public static ObservableCollection<Classic_ListedFolderItem> classicFolderList = new ObservableCollection<Classic_ListedFolderItem>();
4925
public static ObservableCollection<Classic_ListedFolderItem> ClassicFolderList { get { return classicFolderList; } }
50-
26+
5127
public static ObservableCollection<ListedItem> classicFileList = new ObservableCollection<ListedItem>();
5228
public static ObservableCollection<ListedItem> ClassicFileList { get { return classicFileList; } }
5329

@@ -82,10 +58,6 @@ public static BackState BS
8258
{
8359
return bs;
8460
}
85-
set
86-
{
87-
88-
}
8961
}
9062

9163
public static ForwardState fs = new ForwardState();
@@ -95,10 +67,6 @@ public static ForwardState FS
9567
{
9668
return fs;
9769
}
98-
set
99-
{
100-
101-
}
10270
}
10371

10472
public static ProgressUIVisibility pvis = new ProgressUIVisibility();
@@ -108,10 +76,6 @@ public static ProgressUIVisibility PVIS
10876
{
10977
return pvis;
11078
}
111-
set
112-
{
113-
114-
}
11579
}
11680

11781
private ListedItem li = new ListedItem();
@@ -154,33 +118,33 @@ public static ProgressUIVisibility PVIS
154118
public static CancellationToken token;
155119
public static CancellationTokenSource tokenSource;
156120

157-
public ItemViewModel(string ViewPath, Page p)
121+
public ItemViewModel(string viewPath, Page p)
158122
{
159-
123+
160124
pageName = p.Name;
161125
// 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")
163127
{
164128
isPhotoAlbumMode = false;
165129
}
166130
else if (p.Name == "PhotoAlbumViewer")
167131
{
168132
isPhotoAlbumMode = true;
169133
}
170-
171-
if(pageName != "ClassicModePage")
134+
135+
if (pageName != "ClassicModePage")
172136
{
173-
GenericFileBrowser.P.path = ViewPath;
137+
GenericFileBrowser.P.path = viewPath;
174138
FilesAndFolders.Clear();
175139
}
176140

177141
tokenSource = new CancellationTokenSource();
178142
token = tokenSource.Token;
179-
MemoryFriendlyGetItemsAsync(ViewPath, token);
143+
MemoryFriendlyGetItemsAsync(viewPath, token);
180144

181145
if (pageName != "ClassicModePage")
182146
{
183-
History.AddToHistory(ViewPath);
147+
History.AddToHistory(viewPath);
184148

185149
if (History.HistoryList.Count == 1)
186150
{
@@ -195,15 +159,15 @@ public ItemViewModel(string ViewPath, Page p)
195159
//Debug.WriteLine("Enabled Property");
196160
}
197161
}
198-
162+
199163

200164
}
201165

202166
private async void DisplayConsentDialog()
203167
{
204168
MessageDialog message = new MessageDialog("This app is not able to access your files. You need to allow it to by granting permission in Settings.");
205169
message.Title = "Permission Denied";
206-
message.Commands.Add(new UICommand("Allow...", new UICommandInvokedHandler(Interaction.GrantAccessPermissionHandler)));
170+
message.Commands.Add(new UICommand("Allow...", Interaction.GrantAccessPermissionHandler));
207171
await message.ShowAsync();
208172
}
209173
string sort = "By_Name";
@@ -248,13 +212,13 @@ public async void MemoryFriendlyGetItemsAsync(string path, CancellationToken tok
248212
int foldersCountSnapshot = folders.Count;
249213
while (folders.Count != 0)
250214
{
251-
foreach(StorageFolder folder in folders)
215+
foreach (StorageFolder folder in folders)
252216
{
253217
if (token.IsCancellationRequested)
254218
{
255219
return;
256220
}
257-
221+
258222
gotFolName = folder.Name.ToString();
259223
gotFolDate = folder.DateCreated.ToString();
260224
gotFolPath = folder.Path.ToString();
@@ -288,7 +252,7 @@ public async void MemoryFriendlyGetItemsAsync(string path, CancellationToken tok
288252
{
289253
return;
290254
}
291-
255+
292256
gotName = file.Name.ToString();
293257
gotDate = file.DateCreated.ToString(); // In the future, parse date to human readable format
294258
if (file.FileType.ToString() == ".exe")
@@ -306,7 +270,15 @@ public async void MemoryFriendlyGetItemsAsync(string path, CancellationToken tok
306270
const uint requestedSize = 20;
307271
const ThumbnailMode thumbnailMode = ThumbnailMode.ListView;
308272
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+
}
310282
}
311283
else
312284
{
@@ -335,7 +307,7 @@ public async void MemoryFriendlyGetItemsAsync(string path, CancellationToken tok
335307
index += step;
336308
files = await fileQueryResult.GetFilesAsync(index, step);
337309
}
338-
if(foldersCountSnapshot + filesCountSnapshot == 0)
310+
if (foldersCountSnapshot + filesCountSnapshot == 0)
339311
{
340312
TextState.isVisible = Visibility.Visible;
341313
}
@@ -344,23 +316,36 @@ public async void MemoryFriendlyGetItemsAsync(string path, CancellationToken tok
344316
PVIS.isVisible = Visibility.Collapsed;
345317
}
346318
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)
349323
{
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.");
351335
}
352-
catch (System.Runtime.InteropServices.COMException e)
336+
catch (COMException e)
353337
{
338+
stopwatch.Stop();
339+
Debug.WriteLine("Loading of: " + path + " failed in " + stopwatch.ElapsedMilliseconds + " Milliseconds.");
354340
Frame rootFrame = Window.Current.Content as Frame;
355341
MessageDialog driveGone = new MessageDialog(e.Message, "Drive Unplugged");
356342
await driveGone.ShowAsync();
357343
rootFrame.Navigate(typeof(MainPage), new SuppressNavigationTransitionInfo());
358344
}
359-
stopwatch.Stop();
360-
Debug.WriteLine("Loading of: " + path + " completed in " + stopwatch.ElapsedMilliseconds + " Milliseconds.");
345+
361346
}
362-
363-
347+
348+
364349

365350
public static ProgressPercentage progressPER = new ProgressPercentage();
366351

@@ -396,18 +381,18 @@ public static async void DisplayReviewUIWithArgs(string header, string subHeader
396381
await GenericFileBrowser.reviewBox.ShowAsync();
397382
}
398383

399-
public static async void FillTreeNode(object item, Microsoft.UI.Xaml.Controls.TreeView EntireControl)
384+
public static async void FillTreeNode(object item, TreeView EntireControl)
400385
{
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)
405390
{
406391
var name = fol.Name;
407-
var date = fol.DateCreated.LocalDateTime.ToString();
392+
var date = fol.DateCreated.LocalDateTime.ToString(CultureInfo.InvariantCulture);
408393
var ext = fol.DisplayType;
409394
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 });
411396

412397
}
413398
}

Filesystem/ListedItem.cs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Windows.UI.Xaml;
2+
using Windows.UI.Xaml.Media.Imaging;
3+
4+
namespace Files.Filesystem
5+
{
6+
public class ListedItem
7+
{
8+
public Visibility FolderImg { get; set; }
9+
public Visibility FileIconVis { get; set; }
10+
public BitmapImage FileImg { get; set; }
11+
public string FileName { get; set; }
12+
public string FileDate { get; set; }
13+
public string FileExtension { get; set; }
14+
public string FilePath { get; set; }
15+
public int ItemIndex { get; set; }
16+
public ListedItem()
17+
{
18+
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)