From 0a498d827b13fb69062dd8c997a7d5e85c5bcaa1 Mon Sep 17 00:00:00 2001 From: Lukas H Date: Thu, 14 Dec 2023 12:01:27 +0100 Subject: [PATCH 1/2] fix: removed cancel check in get file info --- EasyLib/Files/TransferManager.cs | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/EasyLib/Files/TransferManager.cs b/EasyLib/Files/TransferManager.cs index 537be66..91bf90d 100644 --- a/EasyLib/Files/TransferManager.cs +++ b/EasyLib/Files/TransferManager.cs @@ -57,8 +57,6 @@ private void _getFileInfo(BackupFolder folder) { foreach (var file in folder.Files) { - if (_job.CancellationToken.IsCancellationRequested) - return; _job.FilesSizeBytes += file.Size; _job.FilesCount++; } @@ -67,8 +65,6 @@ private void _getFileInfo(BackupFolder folder) foreach (var subFolder in folder.SubFolders) { - if (_job.CancellationToken.IsCancellationRequested) - return; _getFileInfo(subFolder); } } @@ -127,8 +123,6 @@ private List _compareFolders(List source, List(); var sourceFolder = source.Find(s => s.Name == folder.Name); if (sourceFolder == null) @@ -178,10 +172,10 @@ public void CreateDestinationStructure() /// private void _createTree(string parentPath, BackupFolder folder) { - if (_job.CancellationToken.IsCancellationRequested) - return; foreach (var subFolder in folder.SubFolders) { + if (_job.CancellationToken.IsCancellationRequested) + return; var actualSubFolderPath = Path.Combine(parentPath, subFolder.Name); _notifySubscribersForChange(); Directory.CreateDirectory(actualSubFolderPath); @@ -203,8 +197,6 @@ public void TransferFiles() InstructionsFolder = filteredFiles[1]; _transferFile(PriorityFileFolder, "", PriorityFileFolder.Name); Interlocked.Decrement(ref Job.Job.CurrentPriorityRunning); - if (_job.CancellationToken.IsCancellationRequested) - return; Job.Job.NotifyWaitingJobs.Set(); } @@ -218,8 +210,6 @@ public void TransferFiles() } } - if (_job.CancellationToken.IsCancellationRequested) - return; _transferFile(InstructionsFolder, "", InstructionsFolder.Name); } @@ -251,8 +241,6 @@ private void _transferFile(BackupFolder folder, string sourcePath, string destin _job.FilesCopied++; _job.FilesBytesCopied += file.Size; _notifySubscribersForChange(); - if (_job.CancellationToken.IsCancellationRequested) - return; var cryptoStart = DateTime.Now; var cryptoEnd = cryptoStart; From 5294412ef4d4123a09862f930cf6935f63d2c1db Mon Sep 17 00:00:00 2001 From: Lukas H Date: Thu, 14 Dec 2023 12:17:06 +0100 Subject: [PATCH 2/2] fix: job reset --- EasyLib/Job/Job.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/EasyLib/Job/Job.cs b/EasyLib/Job/Job.cs index 2c60c95..3f22c71 100644 --- a/EasyLib/Job/Job.cs +++ b/EasyLib/Job/Job.cs @@ -150,7 +150,7 @@ private bool Start(bool resume) // Reset the job stats if the job is not resumed if (!resume) { - Cancel(); + _resetJobStats(); } // Create the transfer manager and the folder selector @@ -212,6 +212,12 @@ public bool Pause() public bool Cancel() { CancellationToken.Cancel(); + _resetJobStats(); + return true; + } + + private bool _resetJobStats() + { FilesCount = 0; FilesSizeBytes = 0; FilesCopied = 0;