Skip to content

Commit 70f0755

Browse files
committed
test commit with broken code
1 parent ea4abef commit 70f0755

File tree

6 files changed

+270
-4
lines changed

6 files changed

+270
-4
lines changed

Files UWP/App.xaml.cs

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public App()
5858
}
5959
public static Filesystem.ItemViewModel ViewModel = new Filesystem.ItemViewModel();
6060
public static DisplayedPathText PathText { get; set; } = new DisplayedPathText();
61+
public static UniversalPath UniversalPath { get; set; } = new UniversalPath();
62+
public static CurrentPageName CurrentPage { get; set; } = new CurrentPageName();
6163

6264
/// <summary>
6365
/// Invoked when the application is launched normally by the end user. Other entry points

Files UWP/Filesystem/ItemViewModel.cs

+231-1
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717
using Windows.Storage.Search;
1818
using TreeView = Microsoft.UI.Xaml.Controls.TreeView;
1919
using Windows.UI.Core;
20+
using Microsoft.Toolkit.Collections;
21+
using System.Threading.Tasks;
22+
using System.Linq;
2023

2124
namespace Files.Filesystem
2225
{
23-
public class ItemViewModel
26+
public class ItemViewModel : IIncrementalSource<ListedItem>
2427
{
2528
public ObservableCollection<Classic_ListedFolderItem> ClassicFolderList { get; set; } = new ObservableCollection<Classic_ListedFolderItem>();
2629
public ObservableCollection<ListedItem> ClassicFileList { get; set; } = new ObservableCollection<ListedItem>();
@@ -62,6 +65,224 @@ private async void DisplayConsentDialog()
6265
{
6366
await MainPage.permissionBox.ShowAsync();
6467
}
68+
69+
private List<ListedItem> ListedItems = new List<ListedItem>();
70+
71+
public async void GetFilesystemItemsAsync(string path, Page passedPage)
72+
{
73+
TextState.isVisible = Visibility.Collapsed;
74+
tokenSource = new CancellationTokenSource();
75+
CancellationToken token = App.ViewModel.tokenSource.Token;
76+
pageName = passedPage.Name;
77+
Universal.path = path;
78+
// Personalize retrieved items for view they are displayed in
79+
switch (pageName)
80+
{
81+
case "GenericItemView":
82+
isPhotoAlbumMode = false;
83+
break;
84+
case "PhotoAlbumViewer":
85+
isPhotoAlbumMode = true;
86+
break;
87+
}
88+
FilesAndFolders.Clear();
89+
Stopwatch stopwatch = new Stopwatch();
90+
stopwatch.Start();
91+
Universal.path = path; // Set visible path to reflect new navigation
92+
try
93+
{
94+
95+
PVIS.isVisible = Visibility.Visible;
96+
TextState.isVisible = Visibility.Collapsed;
97+
folder = await StorageFolder.GetFolderFromPathAsync(path);
98+
QueryOptions options = new QueryOptions()
99+
{
100+
FolderDepth = FolderDepth.Shallow,
101+
IndexerOption = IndexerOption.UseIndexerWhenAvailable
102+
};
103+
string sort = "By_Name";
104+
if (sort == "By_Name")
105+
{
106+
SortEntry entry = new SortEntry()
107+
{
108+
AscendingOrder = true,
109+
PropertyName = "System.FileName"
110+
};
111+
options.SortOrder.Add(entry);
112+
}
113+
114+
uint index = 0;
115+
const uint step = 250;
116+
if (!folder.AreQueryOptionsSupported(options))
117+
{
118+
options.SortOrder.Clear();
119+
}
120+
121+
folderQueryResult = folder.CreateFolderQueryWithOptions(options);
122+
IReadOnlyList<StorageFolder> folders = await folderQueryResult.GetFoldersAsync(index, step);
123+
int foldersCountSnapshot = folders.Count;
124+
while (folders.Count != 0)
125+
{
126+
foreach (StorageFolder folder in folders)
127+
{
128+
if (token.IsCancellationRequested)
129+
{
130+
return;
131+
}
132+
133+
gotFolName = folder.Name.ToString();
134+
gotFolDate = folder.DateCreated.ToString();
135+
gotFolPath = folder.Path.ToString();
136+
gotFolType = "Folder";
137+
gotFolImg = Visibility.Visible;
138+
gotFileImgVis = Visibility.Collapsed;
139+
gotEmptyImgVis = Visibility.Collapsed;
140+
141+
ListedItems.Add(new ListedItem() { EmptyImgVis = gotEmptyImgVis, ItemIndex = FilesAndFolders.Count, FileImg = null, FileIconVis = gotFileImgVis, FolderImg = gotFolImg, FileName = gotFolName, FileDate = gotFolDate, FileExtension = gotFolType, FilePath = gotFolPath });
142+
}
143+
index += step;
144+
folders = await folderQueryResult.GetFoldersAsync(index, step);
145+
}
146+
147+
index = 0;
148+
fileQueryResult = folder.CreateFileQueryWithOptions(options);
149+
IReadOnlyList<StorageFile> files = await fileQueryResult.GetFilesAsync(index, step);
150+
int filesCountSnapshot = files.Count;
151+
while (files.Count != 0)
152+
{
153+
foreach (StorageFile file in files)
154+
{
155+
if (token.IsCancellationRequested)
156+
{
157+
return;
158+
}
159+
160+
gotName = file.DisplayName.ToString();
161+
gotDate = file.DateCreated.ToString(); // In the future, parse date to human readable format
162+
if (file.FileType.ToString() == ".exe")
163+
{
164+
gotType = "Executable";
165+
}
166+
else
167+
{
168+
gotType = file.DisplayType;
169+
}
170+
gotPath = file.Path.ToString();
171+
gotFolImg = Visibility.Collapsed;
172+
gotDotFileExtension = file.FileType;
173+
if (isPhotoAlbumMode == false)
174+
{
175+
const uint requestedSize = 20;
176+
const ThumbnailMode thumbnailMode = ThumbnailMode.ListView;
177+
const ThumbnailOptions thumbnailOptions = ThumbnailOptions.UseCurrentScale;
178+
try
179+
{
180+
gotFileImg = await file.GetThumbnailAsync(thumbnailMode, requestedSize, thumbnailOptions);
181+
BitmapImage icon = new BitmapImage();
182+
if (gotFileImg != null)
183+
{
184+
gotEmptyImgVis = Visibility.Collapsed;
185+
icon.SetSource(gotFileImg.CloneStream());
186+
}
187+
else
188+
{
189+
gotEmptyImgVis = Visibility.Visible;
190+
}
191+
gotFileImgVis = Visibility.Visible;
192+
193+
if (pageName == "ClassicModePage")
194+
{
195+
ClassicFileList.Add(new ListedItem() { FileImg = icon, FileIconVis = gotFileImgVis, FolderImg = gotFolImg, FileName = gotName, FileDate = gotDate, FileExtension = gotType, FilePath = gotPath });
196+
}
197+
else
198+
{
199+
FilesAndFolders.Add(new ListedItem() { DotFileExtension = gotDotFileExtension, EmptyImgVis = gotEmptyImgVis, FileImg = icon, FileIconVis = gotFileImgVis, FolderImg = gotFolImg, FileName = gotName, FileDate = gotDate, FileExtension = gotType, FilePath = gotPath });
200+
}
201+
}
202+
catch
203+
{
204+
// Silent catch here to avoid crash
205+
// TODO maybe some logging could be added in the future...
206+
}
207+
}
208+
else
209+
{
210+
const uint requestedSize = 275;
211+
const ThumbnailMode thumbnailMode = ThumbnailMode.PicturesView;
212+
const ThumbnailOptions thumbnailOptions = ThumbnailOptions.ResizeThumbnail;
213+
try
214+
{
215+
gotFileImg = await file.GetThumbnailAsync(thumbnailMode, requestedSize, thumbnailOptions);
216+
BitmapImage icon = new BitmapImage();
217+
if (gotFileImg != null)
218+
{
219+
gotEmptyImgVis = Visibility.Collapsed;
220+
icon.SetSource(gotFileImg.CloneStream());
221+
}
222+
else
223+
{
224+
gotEmptyImgVis = Visibility.Visible;
225+
}
226+
gotFileImgVis = Visibility.Visible;
227+
ListedItems.Add(new ListedItem() { DotFileExtension = gotDotFileExtension, EmptyImgVis = gotEmptyImgVis, FileImg = icon, FileIconVis = gotFileImgVis, FolderImg = gotFolImg, FileName = gotName, FileDate = gotDate, FileExtension = gotType, FilePath = gotPath });
228+
}
229+
catch
230+
{
231+
// Silent catch here to avoid crash
232+
// TODO maybe some logging could be added in the future...
233+
}
234+
}
235+
236+
237+
}
238+
index += step;
239+
files = await fileQueryResult.GetFilesAsync(index, step);
240+
}
241+
if (foldersCountSnapshot + filesCountSnapshot == 0)
242+
{
243+
TextState.isVisible = Visibility.Visible;
244+
}
245+
PVIS.isVisible = Visibility.Collapsed;
246+
stopwatch.Stop();
247+
Debug.WriteLine("Loading of: " + path + " completed in " + stopwatch.ElapsedMilliseconds + " Milliseconds.");
248+
}
249+
catch (UnauthorizedAccessException e)
250+
{
251+
if (path.Contains(@"C:\"))
252+
{
253+
DisplayConsentDialog();
254+
}
255+
else
256+
{
257+
MessageDialog unsupportedDevice = new MessageDialog("This device may be unsupported. Please file an issue report in Settings - About containing what device we couldn't access. Technical information: " + e, "Unsupported Device");
258+
await unsupportedDevice.ShowAsync();
259+
}
260+
stopwatch.Stop();
261+
Debug.WriteLine("Loading of: " + path + " failed in " + stopwatch.ElapsedMilliseconds + " Milliseconds.");
262+
}
263+
catch (COMException e)
264+
{
265+
stopwatch.Stop();
266+
Debug.WriteLine("Loading of: " + path + " failed in " + stopwatch.ElapsedMilliseconds + " Milliseconds.");
267+
Frame rootFrame = Window.Current.Content as Frame;
268+
MessageDialog driveGone = new MessageDialog(e.Message, "Drive Unplugged");
269+
await driveGone.ShowAsync();
270+
rootFrame.Navigate(typeof(MainPage), new SuppressNavigationTransitionInfo());
271+
}
272+
273+
History.AddToHistory(Universal.path);
274+
275+
if (History.HistoryList.Count == 1)
276+
{
277+
BS.isEnabled = false;
278+
}
279+
else if (History.HistoryList.Count > 1)
280+
{
281+
BS.isEnabled = true;
282+
}
283+
tokenSource = null;
284+
}
285+
65286
public async void MemoryFriendlyGetItemsAsync(string path, Page passedPage)
66287
{
67288
TextState.isVisible = Visibility.Collapsed;
@@ -322,5 +543,14 @@ public static async void FillTreeNode(object item, TreeView EntireControl)
322543

323544
}
324545
}
546+
547+
public async Task<IEnumerable<ListedItem>> GetPagedItemsAsync(int pageIndex, int pageSize, CancellationToken cancellationToken = default(CancellationToken))
548+
{
549+
return await Task.Run<IEnumerable<ListedItem>>(() =>
550+
{
551+
var result = (from li in ListedItems select li).Skip(pageSize * pageIndex).Take(pageSize);
552+
return result;
553+
});
554+
}
325555
}
326556
}

Files UWP/GenericFileBrowser.xaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@
294294

295295

296296

297-
<controls:DataGrid ContextRequested="AllView_ContextRequested" SelectionChanged="AllView_SelectionChanged" Margin="24,0,0,0" Grid.Row="3" CellEditEnded="AllView_CellEditEnded" FocusVisualPrimaryThickness="0" SelectionMode="Extended" IsDoubleTapEnabled="True" x:FieldModifier="public" x:Name="AllView" Drop="AllView_DropAsync" AutoGenerateColumns="False" CanDrag="False" AllowDrop="True" DragOver="AllView_DragOver" IsRightTapEnabled="True" CanUserReorderColumns="False" IsReadOnly="True" ItemsSource="{x:Bind local:App.ViewModel.FilesAndFolders}" HorizontalAlignment="Left">
297+
<controls:DataGrid ContextRequested="AllView_ContextRequested" SelectionChanged="AllView_SelectionChanged" Margin="24,0,0,0" Grid.Row="3" CellEditEnded="AllView_CellEditEnded" FocusVisualPrimaryThickness="0" SelectionMode="Extended" IsDoubleTapEnabled="True" x:FieldModifier="public" x:Name="AllView" Drop="AllView_DropAsync" AutoGenerateColumns="False" CanDrag="False" AllowDrop="True" DragOver="AllView_DragOver" IsRightTapEnabled="True" CanUserReorderColumns="False" IsReadOnly="True" HorizontalAlignment="Left">
298298

299299
<controls:DataGrid.ColumnHeaderStyle>
300300
<Style TargetType="controlsprimitives:DataGridColumnHeader">

Files UWP/GenericFileBrowser.xaml.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using Windows.UI.Popups;
2222
using System.IO;
2323
using Windows.UI.Xaml.Controls.Primitives;
24+
using Microsoft.Toolkit.Uwp;
2425

2526
namespace Files
2627
{
@@ -70,7 +71,7 @@ public GenericFileBrowser()
7071
emptySpaceContext = EmptySpaceFlyout;
7172
RefreshEmptySpace.Click += NavigationActions.Refresh_Click;
7273
PasteEmptySpace.Click += Interaction.PasteItem_ClickAsync;
73-
74+
App.CurrentPage.Name = "GenericItemView";
7475
}
7576

7677

@@ -109,7 +110,9 @@ protected override void OnNavigatedTo(NavigationEventArgs eventArgs)
109110
var parameters = (string)eventArgs.Parameter;
110111
App.ViewModel.FilesAndFolders.Clear();
111112
App.ViewModel.Universal.path = parameters;
112-
App.ViewModel.MemoryFriendlyGetItemsAsync(App.ViewModel.Universal.path, GenericItemView);
113+
App.ViewModel.GetFilesystemItemsAsync(App.ViewModel.Universal.path, GenericItemView);
114+
var collection = new IncrementalLoadingCollection<ItemViewModel, ListedItem>();
115+
data.ItemsSource = collection;
113116
if (parameters.Equals(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)))
114117
{
115118
App.PathText.Text = "Desktop";

Files UWP/Navigation/UniversalPath.cs

+30
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,34 @@ private void NotifyPropertyChanged(string info)
6161
}
6262

6363
}
64+
65+
public class CurrentPageName : INotifyPropertyChanged
66+
{
67+
68+
69+
private string name;
70+
public string Name
71+
{
72+
get
73+
{
74+
return name;
75+
}
76+
77+
set
78+
{
79+
if (value != name)
80+
{
81+
name = value;
82+
NotifyPropertyChanged("Name");
83+
}
84+
}
85+
}
86+
public event PropertyChangedEventHandler PropertyChanged;
87+
88+
private void NotifyPropertyChanged(string info)
89+
{
90+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(info));
91+
}
92+
93+
}
6494
}

Files UWP/PhotoAlbum.xaml.cs

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public PhotoAlbum()
3838
inputFromRename = RenameInput;
3939
ShareItem.Click += Interaction.ShareItem_Click;
4040
RenameItem.Click += Interaction.RenameItem_Click;
41+
App.CurrentPage.Name = "PhotoAlbumViewer";
4142
}
4243

4344

0 commit comments

Comments
 (0)