Exemplo n.º 1
0
        public PointFile(string path, string hash, Int64 size, PointTree tree)
        {
            this.hash = hash;
            this.tree = tree;
            this.path = path;
            this.size = size;
            var dir = System.IO.Path.GetDirectoryName(path);

            name = System.IO.Path.GetFileName(path);
            if (dir != "")
            {
                parent = tree.getDir(dir);
            }
            else
            {
                parent = tree;
            }
            if (parent is IAddSize)
            {
                ((IAddSize)parent).AddSize(size);
            }
            if (parent is IAddChild)
            {
                ((IAddChild)parent).AddChild(name, this);
            }
        }
Exemplo n.º 2
0
 private void showList(IDirItem node)
 {
     listView1.BeginUpdate();
     listView1.Items.Clear();
     LItems.Clear();
     if (node.IsDir())
     {
         foreach (IDirItem di in node.Childs())
         {
             var item = new ListViewItem();
             LItems.Add(item, di);
             item.Name = di.Name();
             item.Text = di.Name();
             var itemSize  = new ListViewItem.ListViewSubItem();
             var itemType  = new ListViewItem.ListViewSubItem();
             var itemCount = new ListViewItem.ListViewSubItem();
             itemSize.Name  = di.Name();
             itemSize.Text  = "";
             itemType.Name  = di.Name();
             itemType.Text  = "";
             itemCount.Name = di.Name();
             itemCount.Text = "1";
             if (di is ISize)
             {
                 itemSize.Text = SizeStr(((ISize)di).Size());
             }
             if (di is ICount)
             {
                 itemCount.Text = ((ICount)di).Count().ToString();
             }
             var group = GroupFile;
             if (di is PointFile)
             {
                 itemType.Text = "Файл";
                 group         = GroupFile;
             }
             else if (di is PointTree)
             {
                 itemType.Text = "Точка востановления";
                 group         = GroupDir;
             }
             else if (di.IsDir())
             {
                 itemType.Text = "Папка";
                 group         = GroupDir;
             }
             item.Group = group;
             item.SubItems.Add(itemSize);
             item.SubItems.Add(itemType);
             item.SubItems.Add(itemCount);
             listView1.Items.Add(item);
         }
     }
     listView1.EndUpdate();
 }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
0
 private void SelectItem(IDirItem item, bool open = true)
 {
     restoreItem = item;
     if (open && this.Nodes.ContainsKey(item))
     {
         var node = Nodes[item];
         treeView1.SelectedNode = node;
         showItem(node);
     }
     restoreItem     = item;
     statusName.Text = item.Name();
     if (item is PointFile)
     {
         statusTypeObject.Text = "Файл";
     }
     else if (item is PointDir)
     {
         statusTypeObject.Text = "Папка";
     }
     else if (item is PointTree)
     {
         statusTypeObject.Text = "Точка востановления";
     }
     else
     {
         statusTypeObject.Text = "";
     }
     if (item is ISize)
     {
         statusSize.Text = SizeStr(((ISize)item).Size());
     }
     else
     {
         statusSize.Text = "";
     }
     if (item is ICount)
     {
         statusCount.Text = ((ICount)item).Count().ToString();
     }
     else
     {
         statusCount.Text = "";
     }
     if (open)
     {
         showList(item);
     }
 }
Exemplo n.º 5
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);
 }
Exemplo n.º 6
0
        public PointDir(string path, PointTree tree)
        {
            this.path = path;
            this.tree = tree;
            this.name = System.IO.Path.GetFileName(path);
            var dir = System.IO.Path.GetDirectoryName(path);

            if (dir != "")
            {
                var pdir = tree.getDir(dir);
                pdir.AddChild(this.name, this);
                parent = pdir;
            }
            else
            {
                parent = tree;
                tree.AddChild(this.name, this);
            }
        }
Exemplo n.º 7
0
 public void AddChild(string name, IDirItem item)
 {
     childs[name] = item;
 }
Exemplo n.º 8
0
 public PointTree(string path, string name, IDirItem parent)
 {
     this.path   = path;
     this.name   = name;
     this.parent = parent;
 }
Exemplo n.º 9
0
 public Storage(string storegePath)
 {
     this.storegePath = storegePath;
     this.root        = new FSDirectory(Path.Combine(storegePath, "points"), "", null);
 }
Exemplo n.º 10
0
 public FSDirectory(string path, string name, IDirItem parent)
 {
     this.path   = path;
     this.name   = name;
     this.parent = parent;
 }