/// <summary> /// Adds or replaces entry based on existing FlatBackupFile. /// </summary> /// <param name="flatBackupFile"></param> /// <param name="overwrite"></param> public void AddEntry(FlatBackupFile flatBackupFile, bool overwrite = false) { if (List.ContainsKey(flatBackupFile.DeviceSidePath) && overwrite == true) { List.Remove(flatBackupFile.DeviceSidePath); } List.Add(flatBackupFile.DeviceSidePath, flatBackupFile); }
/// <summary> /// Adds or replaces entry. /// </summary> /// <param name="pcSidePath"></param> /// <param name="deviceSidePath"></param> public void AddEntry(string pcSidePath, string deviceSidePath, bool isFolder, bool overwrite = false) { var fbf = new FlatBackupFile(); fbf.DeviceSidePath = deviceSidePath; fbf.PcSidePath = pcSidePath; fbf.InternalPath = Guid.NewGuid().ToString(); fbf.IsFolder = isFolder; if (List.ContainsKey(deviceSidePath) && overwrite == true) List.Remove(deviceSidePath); List.Add(deviceSidePath, fbf); }
public bool Extract(FlatBackupFile file, Stream stream) { if (_file != null) { if (_file[file.InternalPath] != null) { _file[file.InternalPath].Extract(stream); return(true); } } return(false); }
public bool Read(string fileName) { _file = new ZipFile(fileName); if (_file != null) { if (_file["index.wpb"] != null) { var stream = new MemoryStream(); _file["index.wpb"].Extract(stream); List.Clear(); stream.Seek(0, SeekOrigin.Begin); byte[] b = new byte[stream.Length]; stream.Read(b, 0, (int)stream.Length); int shift = 0; if (b[0] == 0xFF && b[1] == 0xFE) { shift = 2; } string[] lines = Encoding.Unicode.GetString(b, shift, b.Length - shift).Trim().Replace("\r", "").Split('\n'); foreach (var line in lines) { if (line.Contains("=")) { var intName = line.Substring(0, line.IndexOf("=")); var fsName = line.Substring(line.IndexOf("=") + 1); var fl = new FlatBackupFile(); if (intName == "dir") { fl.IsFolder = true; } else { fl.InternalPath = intName; } fl.DeviceSidePath = fsName; List.Add(fsName, fl); } } stream.Close(); } return(true); } return(false); }
/// <summary> /// Adds or replaces entry. /// </summary> /// <param name="pcSidePath"></param> /// <param name="deviceSidePath"></param> public void AddEntry(string pcSidePath, string deviceSidePath, bool isFolder, bool overwrite = false) { var fbf = new FlatBackupFile(); fbf.DeviceSidePath = deviceSidePath; fbf.PcSidePath = pcSidePath; fbf.InternalPath = Guid.NewGuid().ToString(); fbf.IsFolder = isFolder; if (List.ContainsKey(deviceSidePath) && overwrite == true) { List.Remove(deviceSidePath); } List.Add(deviceSidePath, fbf); }
/// <summary> /// Adds or replaces entry based on existing FlatBackupFile. /// </summary> /// <param name="flatBackupFile"></param> /// <param name="overwrite"></param> public void AddEntry(FlatBackupFile flatBackupFile, bool overwrite = false) { if (List.ContainsKey(flatBackupFile.DeviceSidePath) && overwrite == true) List.Remove(flatBackupFile.DeviceSidePath); List.Add(flatBackupFile.DeviceSidePath, flatBackupFile); }
public bool Read(string fileName) { _file = new ZipFile(fileName); if (_file != null) { if (_file["index.wpb"] != null) { var stream = new MemoryStream(); _file["index.wpb"].Extract(stream); List.Clear(); stream.Seek(0, SeekOrigin.Begin); byte[] b = new byte[stream.Length]; stream.Read(b, 0, (int)stream.Length); int shift = 0; if (b[0] == 0xFF && b[1] == 0xFE) shift = 2; string[] lines = Encoding.Unicode.GetString(b, shift, b.Length - shift).Trim().Replace("\r", "").Split('\n'); foreach (var line in lines) { if (line.Contains("=")) { var intName = line.Substring(0, line.IndexOf("=")); var fsName = line.Substring(line.IndexOf("=") + 1); var fl = new FlatBackupFile(); if (intName == "dir") fl.IsFolder = true; else fl.InternalPath = intName; fl.DeviceSidePath = fsName; List.Add(fsName, fl); } } stream.Close(); } return true; } return false; }
public bool Extract(FlatBackupFile file, Stream stream) { if (_file != null) { if (_file[file.InternalPath] != null) { _file[file.InternalPath].Extract(stream); return true; } } return false; }
public static FlatBackupFile CopyFileFromDeviceFLAT(string src, string destFolder) { var fbf = new FlatBackupFile(); string mangledName = Guid.NewGuid().ToString(); string destPath = destFolder + "\\" + mangledName; if (RAPI.CopyFileFromDevice(src, destPath, true) == true) { fbf.DeviceSidePath = src; fbf.PcSidePath = destPath; fbf.InternalPath = mangledName; return fbf; } return null; }
/// <summary> /// Copies files and directories to PC using flat structure. /// </summary> /// <param name="src"></param> /// <param name="dest"></param> /// <param name="exceptFolders"></param> /// <returns>A list of generated associations "PcSideFile - DeviceSideFile"</returns> public static SortedList<string, FlatBackupFile> CopyDirectoryFromDeviceFLAT(string src, string dest, string deviceSidePath, string exceptFolders = "") { if (deviceSidePath == null) deviceSidePath = src; LastError = ""; src = src.TrimEnd('\\'); dest = dest.TrimEnd('\\'); if (!Directory.Exists(dest)) Directory.CreateDirectory(dest); var retlist = new SortedList<string, FlatBackupFile>(); try { var list = RapiComm.RAPI.EnumFiles(src + "\\*"); if (list == null || list.Count == 0) { // if list is empty, let's add it this directory to be (at least) // able to restore folder structure later. var fbf = new FlatBackupFile(); fbf.IsFolder = true; fbf.DeviceSidePath = deviceSidePath; retlist.Add(fbf.DeviceSidePath, fbf); return retlist; } foreach (FileInformation item in list) { if (item.FileName != "." && item.FileName != "..") { if ((item.dwFileAttributes & (int)FileAttributes.Directory) > 0) { if (exceptFolders.Contains("(" + item.FileName + ")") == false) { var newlist = CopyDirectoryFromDeviceFLAT(src + "\\" + item.FileName, dest, deviceSidePath + "\\" + item.FileName); foreach (var newitem in newlist) retlist.Add(newitem.Value.DeviceSidePath, newitem.Value); } } else { var srcFullName = src + "\\" + item.FileName; var destShortFileName = Guid.NewGuid().ToString(); var destFullName = dest + "\\" + destShortFileName; RAPI.CopyFileFromDevice(srcFullName, destFullName, true); var fbf = new FlatBackupFile(); fbf.DeviceSidePath = deviceSidePath + "\\" + item.FileName; //srcFullName; fbf.InternalPath = destShortFileName; fbf.PcSidePath = destFullName; retlist.Add(fbf.DeviceSidePath, fbf); } } } } catch (Exception ex) { LastError = ex.ToString(); } return retlist; }