public void Backup(BackupedFiles backupedFiles)
 {
     try
     {
         Restart(allFiles.Count);
         Parallel.ForEach(allFiles, f => DoBackupFile(f, backupedFiles));
         SetProgress(1);
     }
     finally
     {
         Finished = true;
     }
 }
        private void DoBackupFile(BackupFile file, BackupedFiles backupedFiles)
        {
            try
            {
                if (cancelToken.IsCanceled ||
                    IsHidden(file.Info) ||
                    ExcludePath(file.Info.FullName))
                {
                    return;
                }

                string backupFileName;
                string fileHash = BackupUtils.GetHash(file.Info.FullName);

                if (cancelToken.IsCanceled)
                {
                    return;
                }
                if (backupedFiles.Add(fileHash, file.Info.Extension, out backupFileName))
                {
                    string destPath = Path.Combine(FilesDestFolderPath, backupFileName);

                    do
                    {
                        File.Copy(file.Info.FullName, destPath, true);
                    } while (fileHash != BackupUtils.GetHash(file.Info.FullName));

                    addedFiles.Add(destPath);
                }

                lock (addedToDbFoldersFiles)
                {
                    (DbFile? dbFile, DbFolderFile folderFile) = db.AddFile(file.Info.Name, fileHash, backupFileName, file.FolderId);

                    if (dbFile.HasValue)
                    {
                        addedToDbFiles.Add(dbFile.Value);
                    }
                    addedToDbFoldersFiles.Add(folderFile);
                }
            }
            catch { }
            finally
            {
                IncreaseProgressLocked();
            }
        }