Skip to content

Commit 25f2c6e

Browse files
committed
Improved Delete Reliability
1 parent 3f5bd18 commit 25f2c6e

File tree

6 files changed

+94
-82
lines changed

6 files changed

+94
-82
lines changed

AddItem.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ private async void ListView_ItemClick(object sender, ItemClickEventArgs e)
4646
{
4747
await folderToCreateItem.CreateFileAsync("New Bitmap Image.bmp", CreationCollisionOption.GenerateUniqueName);
4848
}
49-
Navigation.NavigationActions.Refresh_Click(null, null);
49+
//Navigation.NavigationActions.Refresh_Click(null, null);
5050

5151
}
5252

Filesystem/ItemViewModel.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using Files.Navigation;
1717
using Windows.Storage.Search;
1818
using TreeView = Microsoft.UI.Xaml.Controls.TreeView;
19+
using Windows.UI.Core;
1920

2021
namespace Files.Filesystem
2122
{
@@ -116,6 +117,8 @@ public static ProgressUIVisibility PVIS
116117
public static int NumItemsRead;
117118
public static int NumOfFiles;
118119
public static int NumOfFolders;
120+
StorageFileQueryResult fileQueryResult;
121+
StorageFolderQueryResult folderQueryResult;
119122
public static CancellationToken token;
120123
public static CancellationTokenSource tokenSource;
121124

@@ -208,7 +211,7 @@ public async void MemoryFriendlyGetItemsAsync(string path, CancellationToken tok
208211
options.SortOrder.Clear();
209212
}
210213

211-
StorageFolderQueryResult folderQueryResult = folder.CreateFolderQueryWithOptions(options);
214+
folderQueryResult = folder.CreateFolderQueryWithOptions(options);
212215
IReadOnlyList<StorageFolder> folders = await folderQueryResult.GetFoldersAsync(index, step);
213216
int foldersCountSnapshot = folders.Count;
214217
while (folders.Count != 0)
@@ -243,7 +246,7 @@ public async void MemoryFriendlyGetItemsAsync(string path, CancellationToken tok
243246
}
244247

245248
index = 0;
246-
StorageFileQueryResult fileQueryResult = folder.CreateFileQueryWithOptions(options);
249+
fileQueryResult = folder.CreateFileQueryWithOptions(options);
247250
IReadOnlyList<StorageFile> files = await fileQueryResult.GetFilesAsync(index, step);
248251
int filesCountSnapshot = files.Count;
249252
while (files.Count != 0)
@@ -381,8 +384,6 @@ public async void MemoryFriendlyGetItemsAsync(string path, CancellationToken tok
381384

382385
}
383386

384-
385-
386387
public static ProgressPercentage progressPER = new ProgressPercentage();
387388

388389
public static ProgressPercentage PROGRESSPER

GenericFileBrowser.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ private async void AllView_CellEditEnded(object sender, DataGridCellEditEndedEve
209209
await fileToRename.RenameAsync(newCellText);
210210
}
211211
}
212-
Navigation.NavigationActions.Refresh_Click(null, null);
212+
//Navigation.NavigationActions.Refresh_Click(null, null);
213213
}
214214

215215
private void ContentDialog_Loaded(object sender, RoutedEventArgs e)

Interacts/Interaction.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,9 @@ public static async void DeleteItem_Click(object sender, RoutedEventArgs e)
529529
await item.DeleteAsync(StorageDeleteOption.Default);
530530

531531
}
532+
ItemViewModel.FilesAndFolders.Remove(storItem);
532533
}
533-
NavigationActions.Refresh_Click(null, null);
534+
//NavigationActions.Refresh_Click(null, null);
534535
History.ForwardList.Clear();
535536
ItemViewModel.FS.isEnabled = false;
536537
}
@@ -548,9 +549,10 @@ public static async void DeleteItem_Click(object sender, RoutedEventArgs e)
548549
var item = await StorageFolder.GetFolderFromPathAsync(storItem.FilePath);
549550
await item.DeleteAsync(StorageDeleteOption.Default);
550551
}
552+
ItemViewModel.FilesAndFolders.Remove(storItem);
551553
}
552-
553-
PhotoAlbumNavActions.Refresh_Click(null, null);
554+
555+
//PhotoAlbumNavActions.Refresh_Click(null, null);
554556
History.ForwardList.Clear();
555557
ItemViewModel.FS.isEnabled = false;
556558
}
@@ -719,7 +721,7 @@ public static async void PasteItem_ClickAsync(object sender, RoutedEventArgs e)
719721

720722
}
721723

722-
NavigationActions.Refresh_Click(null, null);
724+
//NavigationActions.Refresh_Click(null, null);
723725

724726
}
725727
static int passNum = 0;

Navigation/NavigationActions.cs

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.ComponentModel;
55
using System.Diagnostics;
66
using System.Linq;
7+
using Windows.UI.Core;
78
using Windows.UI.Xaml;
89
using Windows.UI.Xaml.Media.Animation;
910

@@ -315,53 +316,55 @@ public static void Forward_Click(object sender, RoutedEventArgs e)
315316
}
316317
}
317318

318-
public static void Refresh_Click(object sender, RoutedEventArgs e)
319+
public async static void Refresh_Click(object sender, RoutedEventArgs e)
319320
{
320-
ItemViewModel.tokenSource.Cancel();
321-
ItemViewModel.TextState.isVisible = Visibility.Collapsed;
322-
ItemViewModel.FilesAndFolders.Clear();
323-
ItemViewModel.ViewModel = new ItemViewModel(ItemViewModel.PUIP.Path, GenericFileBrowser.GFBPageName);
324-
if ((History.HistoryList[History.HistoryList.Count - 1]) == Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory))
321+
await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
325322
{
326-
GenericFileBrowser.P.path = "Desktop";
327-
328-
}
329-
else if ((History.HistoryList[History.HistoryList.Count - 1]) == Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments))
330-
{
331-
GenericFileBrowser.P.path = "Documents";
323+
ItemViewModel.tokenSource.Cancel();
324+
ItemViewModel.TextState.isVisible = Visibility.Collapsed;
325+
ItemViewModel.FilesAndFolders.Clear();
326+
ItemViewModel.ViewModel = new ItemViewModel(ItemViewModel.PUIP.Path, GenericFileBrowser.GFBPageName);
327+
if ((History.HistoryList[History.HistoryList.Count - 1]) == Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory))
328+
{
329+
GenericFileBrowser.P.path = "Desktop";
332330

333-
}
334-
else if ((History.HistoryList[History.HistoryList.Count - 1]) == (Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\Downloads"))
335-
{
336-
GenericFileBrowser.P.path = "Downloads";
331+
}
332+
else if ((History.HistoryList[History.HistoryList.Count - 1]) == Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments))
333+
{
334+
GenericFileBrowser.P.path = "Documents";
337335

338-
}
339-
else if ((History.HistoryList[History.HistoryList.Count - 1]) == Environment.GetFolderPath(Environment.SpecialFolder.MyPictures))
340-
{
336+
}
337+
else if ((History.HistoryList[History.HistoryList.Count - 1]) == (Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\Downloads"))
338+
{
339+
GenericFileBrowser.P.path = "Downloads";
341340

342-
GenericFileBrowser.P.path = "Pictures";
343-
}
344-
else if ((History.HistoryList[History.HistoryList.Count - 1]) == Environment.GetFolderPath(Environment.SpecialFolder.MyMusic))
345-
{
346-
GenericFileBrowser.P.path = "Music";
341+
}
342+
else if ((History.HistoryList[History.HistoryList.Count - 1]) == Environment.GetFolderPath(Environment.SpecialFolder.MyPictures))
343+
{
347344

348-
}
349-
else if ((History.HistoryList[History.HistoryList.Count - 1]) == (Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\OneDrive"))
350-
{
351-
GenericFileBrowser.P.path = "OneDrive";
345+
GenericFileBrowser.P.path = "Pictures";
346+
}
347+
else if ((History.HistoryList[History.HistoryList.Count - 1]) == Environment.GetFolderPath(Environment.SpecialFolder.MyMusic))
348+
{
349+
GenericFileBrowser.P.path = "Music";
352350

353-
}
354-
else if ((History.HistoryList[History.HistoryList.Count - 1]) == Environment.GetFolderPath(Environment.SpecialFolder.MyVideos))
355-
{
356-
GenericFileBrowser.P.path = "Videos";
351+
}
352+
else if ((History.HistoryList[History.HistoryList.Count - 1]) == (Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\OneDrive"))
353+
{
354+
GenericFileBrowser.P.path = "OneDrive";
357355

358-
}
359-
else
360-
{
361-
GenericFileBrowser.P.path = (History.HistoryList[History.HistoryList.Count - 1]);
356+
}
357+
else if ((History.HistoryList[History.HistoryList.Count - 1]) == Environment.GetFolderPath(Environment.SpecialFolder.MyVideos))
358+
{
359+
GenericFileBrowser.P.path = "Videos";
362360

363-
}
361+
}
362+
else
363+
{
364+
GenericFileBrowser.P.path = (History.HistoryList[History.HistoryList.Count - 1]);
364365

366+
}
367+
});
365368
}
366369
}
367370
}

Navigation/PhotoAlbumNavActions.cs

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Windows.UI.Xaml;
55
using Windows.UI.Xaml.Media.Animation;
66
using Files.Filesystem;
7+
using Windows.UI.Core;
78

89
namespace Files.Navigation
910
{
@@ -190,52 +191,57 @@ public static void Forward_Click(object sender, RoutedEventArgs e)
190191
}
191192
}
192193

193-
public static void Refresh_Click(object sender, RoutedEventArgs e)
194+
public async static void Refresh_Click(object sender, RoutedEventArgs e)
194195
{
195196
//ItemViewModel.IsStopRequested = true;
196-
ItemViewModel.TextState.isVisible = Visibility.Collapsed;
197-
ItemViewModel.FilesAndFolders.Clear();
198-
ItemViewModel.ViewModel = new ItemViewModel(ItemViewModel.PUIP.Path, PhotoAlbum.PAPageName);
199-
if ((History.HistoryList[History.HistoryList.Count - 1]) == Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory))
197+
await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
200198
{
201-
GenericFileBrowser.P.path = "Desktop";
199+
ItemViewModel.tokenSource.Cancel();
200+
ItemViewModel.TextState.isVisible = Visibility.Collapsed;
201+
ItemViewModel.FilesAndFolders.Clear();
202+
ItemViewModel.ViewModel = new ItemViewModel(ItemViewModel.PUIP.Path, PhotoAlbum.PAPageName);
203+
if ((History.HistoryList[History.HistoryList.Count - 1]) == Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory))
204+
{
205+
GenericFileBrowser.P.path = "Desktop";
202206

203-
}
204-
else if ((History.HistoryList[History.HistoryList.Count - 1]) == Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments))
205-
{
206-
GenericFileBrowser.P.path = "Documents";
207+
}
208+
else if ((History.HistoryList[History.HistoryList.Count - 1]) == Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments))
209+
{
210+
GenericFileBrowser.P.path = "Documents";
207211

208-
}
209-
else if ((History.HistoryList[History.HistoryList.Count - 1]) == (Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\Downloads"))
210-
{
211-
GenericFileBrowser.P.path = "Downloads";
212+
}
213+
else if ((History.HistoryList[History.HistoryList.Count - 1]) == (Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\Downloads"))
214+
{
215+
GenericFileBrowser.P.path = "Downloads";
212216

213-
}
214-
else if ((History.HistoryList[History.HistoryList.Count - 1]) == Environment.GetFolderPath(Environment.SpecialFolder.MyPictures))
215-
{
217+
}
218+
else if ((History.HistoryList[History.HistoryList.Count - 1]) == Environment.GetFolderPath(Environment.SpecialFolder.MyPictures))
219+
{
216220

217-
GenericFileBrowser.P.path = "Pictures";
218-
}
219-
else if ((History.HistoryList[History.HistoryList.Count - 1]) == Environment.GetFolderPath(Environment.SpecialFolder.MyMusic))
220-
{
221-
GenericFileBrowser.P.path = "Music";
221+
GenericFileBrowser.P.path = "Pictures";
222+
}
223+
else if ((History.HistoryList[History.HistoryList.Count - 1]) == Environment.GetFolderPath(Environment.SpecialFolder.MyMusic))
224+
{
225+
GenericFileBrowser.P.path = "Music";
222226

223-
}
224-
else if ((History.HistoryList[History.HistoryList.Count - 1]) == (Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\OneDrive"))
225-
{
226-
GenericFileBrowser.P.path = "OneDrive";
227+
}
228+
else if ((History.HistoryList[History.HistoryList.Count - 1]) == (Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\OneDrive"))
229+
{
230+
GenericFileBrowser.P.path = "OneDrive";
227231

228-
}
229-
else if ((History.HistoryList[History.HistoryList.Count - 1]) == Environment.GetFolderPath(Environment.SpecialFolder.MyVideos))
230-
{
231-
GenericFileBrowser.P.path = "Videos";
232+
}
233+
else if ((History.HistoryList[History.HistoryList.Count - 1]) == Environment.GetFolderPath(Environment.SpecialFolder.MyVideos))
234+
{
235+
GenericFileBrowser.P.path = "Videos";
232236

233-
}
234-
else
235-
{
236-
GenericFileBrowser.P.path = (History.HistoryList[History.HistoryList.Count - 1]);
237+
}
238+
else
239+
{
240+
GenericFileBrowser.P.path = (History.HistoryList[History.HistoryList.Count - 1]);
237241

238-
}
242+
}
243+
});
244+
239245
}
240246
}
241247
}

0 commit comments

Comments
 (0)