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); } }
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(); }
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); }
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); } }
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); }
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); } }
public void AddChild(string name, IDirItem item) { childs[name] = item; }
public PointTree(string path, string name, IDirItem parent) { this.path = path; this.name = name; this.parent = parent; }
public Storage(string storegePath) { this.storegePath = storegePath; this.root = new FSDirectory(Path.Combine(storegePath, "points"), "", null); }
public FSDirectory(string path, string name, IDirItem parent) { this.path = path; this.name = name; this.parent = parent; }