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); }
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); }