Exemplo n.º 1
0
        public void CreateBackup(BackupInfo info, string source, string target)
        {
            DirectoryInfo dir = new DirectoryInfo(target);

            if (!dir.Exists)
            {
                dir.Create();
            }
            this.info   = info;
            this.source = source;
            this.target = target;
            if (LastProgress != null)
            {
                throw new Exception("Instance already used or still in use!");
            }
            Task.Run(async() =>
            {
                LastProgress   = new BackupProgressArgs(BackupProgressState.Counting, 0, 0);
                int totalFiles = await CountFiles(new DirectoryInfo(this.source));

                LastProgress = new BackupProgressArgs(BackupProgressState.Saving, 0, totalFiles);

                CreateBackup(this.target + "\\" + info.Hash + ".data", info.Hash, this.source);

                info.save(new DirectoryInfo(this.target));

                LastProgress = new BackupProgressArgs(BackupProgressState.Finished, totalFiles, totalFiles);
            });
        }
Exemplo n.º 2
0
        public BackupProcess Create(string source, string identifier = "", string game = "", string subgame = "")
        {
            BackupProcess process = new BackupProcess();
            BackupInfo    info    = new BackupInfo(game, subgame, identifier);

            process.CreateBackup(info, source, Target.FullName);
            return(process);
        }
Exemplo n.º 3
0
 public void Reload()
 {
     Backups.Clear();
     foreach (FileInfo file in Target.GetFiles().Where((i) => { return(i.Extension.Equals(".bck")); }))
     {
         try
         {
             BackupInfo    info    = BackupInfo.read(file.FullName);
             BackupPackage package = new BackupPackage(file.Directory, info);
             Backups.Add(package);
         }
         catch (Exception)
         {
             Console.WriteLine("Invalid backup info: " + file.Name.ToString());
         }
     }
 }
        public static BackupInfo read(string file)
        {
            try
            {
                string content = File.ReadAllText(file);
                JsonSerializerSettings jsonSettings = new JsonSerializerSettings();
                jsonSettings.NullValueHandling     = NullValueHandling.Ignore;
                jsonSettings.MissingMemberHandling = MissingMemberHandling.Ignore;

                BackupInfo info = JsonConvert.DeserializeObject <BackupInfo>(content);

                DirectoryInfo dir = new DirectoryInfo(new FileInfo(file).Directory.FullName);
                info.Data = new BackupPackage(dir, info);

                return(info);
            }
            catch (Exception)
            {
                throw new Exception("Unexpected reading error!");
            }
        }
 public BackupPackage(DirectoryInfo folder, BackupInfo info)
 {
     this.BackupInfo = info;
     this.Package    = new FileInfo(folder.FullName + "\\" + info.Hash + ".data");
 }