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