Skip to content
Permalink
Browse files

Properly continue when deleting many files

  • Loading branch information...
da3dsoul committed Jan 24, 2019
1 parent 26b6eb0 commit cef9f9d3b4b574171076d8fac454153b7c8a48c3
Showing with 30 additions and 9 deletions.
  1. +30 −9 Shoko.Desktop/Forms/DeleteFilesForm.xaml.cs
@@ -9,6 +9,7 @@
using System.Windows.Input;
using System.Windows.Media.Imaging;
using Shoko.Commons.Extensions;
using Shoko.Commons.Utils;
using Shoko.Desktop.Utilities;
using Shoko.Desktop.ViewModel;
using Shoko.Desktop.ViewModel.Server;
@@ -141,39 +142,59 @@ void deleteFilesWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEvent
void deleteFilesWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
FilesDeleted = true;
string msg = e.UserState as string;
DeleteStatus = msg;
if (e.UserState is string msg)
DeleteStatus = msg;

if (e.ProgressPercentage == 100)
{
Cursor = Cursors.Arrow;
if (e.UserState is List<string> list)
{
MessageBox.Show(string.Join("\n", list), Commons.Properties.Resources.Confirm, MessageBoxButton.OK, MessageBoxImage.Warning);
}
}
}

void deleteFilesWorker_DoWork(object sender, DoWorkEventArgs e)
{
if (vids == null) return;

int i = 0;
List<string> errors = new List<string>();
foreach (VM_VideoDetailed vid in vids)
{
i++;
string msg = string.Format(Commons.Properties.Resources.DeleteFiles_Deleting, i, vids.Count);
deleteFilesWorker.ReportProgress(0, msg);
//Thread.Sleep(500);


foreach (CL_VideoLocal_Place n in vid.Places)
{
string g = dict[n.ImportFolder.CloudID ?? 0].Item1;
if (!chks.ContainsKey(g) || chks[g])
{
string result = VM_ShokoServer.Instance.ShokoServices.DeleteVideoLocalPlaceAndFile(n.VideoLocal_Place_ID);
if (result.Length > 0)
try
{
string result =
VM_ShokoServer.Instance.ShokoServices.DeleteVideoLocalPlaceAndFile(
n.VideoLocal_Place_ID);
if (result.Length > 0)
{
deleteFilesWorker.ReportProgress(0, result);
errors.Add("Unable to delete file: " + n.GetFullPath() + " Error: " + result);
}
}
catch
{
deleteFilesWorker.ReportProgress(0, result);
return;
// ignore
}
}
}


}

deleteFilesWorker.ReportProgress(100, Commons.Properties.Resources.Done);
if (errors.Count > 0) deleteFilesWorker.ReportProgress(100, errors);
else deleteFilesWorker.ReportProgress(100, Commons.Properties.Resources.Done);
}
Dictionary<string, bool> chks=new Dictionary<string, bool>();
private Dictionary<int, Tuple<string, BitmapImage>> dict=new Dictionary<int, Tuple<string, BitmapImage>>();

0 comments on commit cef9f9d

Please sign in to comment.
You can’t perform that action at this time.