Esempio n. 1
0
        private static IEnumerable <FileJob> GetBackupJobs(IEnumerable <IFile> files, DirectoryInfo objectsDir, string password, string salt, Predicate <string> alreadyBackuped)
        {
            IList <IFile> fs = files.ToList();

            Program.log.Info("backup files total: " + fs.Count());

            IList <FileJob> copyJobs = fs.Select(x => FileJob.GetBackupJob(x, objectsDir, password, salt)).ToList();

            Dictionary <string, FileJob> hashSetUnequalFiles = new Dictionary <string, FileJob>();

            foreach (var cj in copyJobs)
            {
                if (!hashSetUnequalFiles.ContainsKey(cj.SourceFile.Sha256))
                {
                    hashSetUnequalFiles.Add(cj.SourceFile.Sha256, cj);
                }
            }

            Program.log.Info("backup unequal files: " + hashSetUnequalFiles.Count());

            IList <FileJob> notExisting = new List <FileJob>();

            foreach (var cj in hashSetUnequalFiles.Values)
            {
                if (!alreadyBackuped(cj.SourceFile.Sha256))
                {
                    notExisting.Add(cj);
                }
            }

            Program.log.Info("backup files after removing already backuped ones: " + notExisting.Count());

            return(notExisting);
        }
Esempio n. 2
0
        private static IList <FileJob> GetRestoreJobs(IEnumerable <IFile> files, Manifest manifest, PartitionManager partitionManager, DirectoryInfo diTarget, string password, string salt)
        {
            IList <IFile> fs = files.ToList();

            Program.log.Info("restore files total: " + fs.Count());

            IList <FileJob> copyJobs = fs.Select(x => FileJob.GetRestoreJob(x, partitionManager.GetDirByNumber(manifest.GetPartition(x.Sha256)), diTarget, password, salt)).ToList();

            IList <FileJob> notExistingTargets = copyJobs.Where(x => !File.Exists(x.ToPath)).ToList();

            Program.log.Info("not existing: " + notExistingTargets.Count());

            return(notExistingTargets);
        }