Exemple #1
0
 public bool Restore(IDirItem item, string path, StatRestore stat = null)
 {
     if (item.IsDir())
     {
         if (Directory.Exists(path))
         {
             return(true);
         }
         Directory.CreateDirectory(path);
         return(true);
     }
     else if (item is PointFile)
     {
         var file = (PointFile)item;
         if (File.Exists(path))
         {
             return(false);
         }
         var filePath = Path.Combine(storegePath, file.hash.Substring(file.hash.Length - 2, 2), file.hash.Substring(file.hash.Length - 4, 2), file.hash + "." + SizeToInvHexByte(file.Size(), 8));
         if (File.Exists(filePath + ".bin"))
         {
             using (var rfile = new FileStream(filePath + ".bin", FileMode.Open, FileAccess.Read))
                 using (var wfile = new FileStream(path, FileMode.CreateNew, FileAccess.Write))
                     rfile.CopyTo(wfile);
             if (stat != null)
             {
                 stat.NumFiles++; stat.SizeFiles += file.Size(); stat.Change(this);
             }
         }
         else if (File.Exists(filePath + ".gzip"))
         {
             using (var rofile = new FileStream(filePath + ".gzip", FileMode.Open, FileAccess.Read))
                 using (var rfile = new GZipStream(rofile, CompressionMode.Decompress))
                     using (var wfile = new FileStream(path, FileMode.CreateNew, FileAccess.Write))
                         rfile.CopyTo(wfile);
             if (stat != null)
             {
                 stat.NumFiles++; stat.SizeFiles += file.Size(); stat.Change(this);
             }
         }
         else
         {
             if (stat != null)
             {
                 stat.NumFaildFiles++; stat.Change(this);
             }
             return(false);
         }
     }
     return(true);
 }
Exemple #2
0
 public bool RestoreAll(IDirItem item, string path, StatRestore stat = null)
 {
     if (!Restore(item, path, stat))
     {
         return(false);
     }
     if (item.IsDir())
     {
         foreach (IDirItem subitem in item.Childs())
         {
             if (!RestoreAll(subitem, Path.Combine(path, subitem.Name()), stat))
             {
                 return(false);
             }
         }
     }
     return(true);
 }