private void CreateFSIFile(FileInfo file, IFsiDirectoryItem diritem) { var realpath = UniqueListFileSystemInfo.GetPhysicalPath(file.FullName); var index = realpath.IndexOf(":\\") + 1; if (_sysImage.Exists(realpath.Substring(index)) == FsiItemType.FsiItemNotFound) { var crtdiritem = diritem; var name = Path.GetFileName(realpath); if (string.Compare(diritem.FullPath, Path.GetDirectoryName(realpath).Substring(index), true) != 0) { var fsipath = Path.GetDirectoryName(realpath).Substring(index + 1 + diritem.FullPath.Length); var dirs = fsipath.Split('\\'); var dInfo = new DirectoryInfo(CaptureDirectory); var subdirs = dInfo.FullName.Split('\\'); //MessageBox.Show(subdirs.Length.ToString()); //create the subdirs one by one foreach (var dir in dirs.Skip(subdirs.Length - 1)) { if (dir.Length == 0) { continue; //in the root like C:\ } try { var newpath = string.Format("{0}\\{1}", crtdiritem.FullPath, dir); if (_sysImage.Exists(newpath) != FsiItemType.FsiItemDirectory) { crtdiritem.AddDirectory(dir); } } catch { Cancel = true; throw; } crtdiritem = crtdiritem[dir] as IFsiDirectoryItem; } } COMTypes.IStream newStream = null; try { newStream = LoadCOMStream(realpath); crtdiritem.AddFile(name, newStream); } finally { Marshal.FinalReleaseComObject(newStream); } ActualSize += file.Length; if (Update != null && Update.GetInvocationList().Length > 0) { Update(file.FullName, file.Length); } } else { throw new ApplicationException(realpath.Substring(index) + " occurs in multiple source folders with the same name."); } }
private void CreateFSIFolder(DirectoryInfo fsobject, IFsiDirectoryItem diritem) { if (fsobject == null || diritem == null || _cancel) { return; } DirectoryInfo pysicalFolder = null; pysicalFolder = new DirectoryInfo(UniqueListFileSystemInfo.GetPhysicalPath(fsobject.FullName.TrimEnd('\\'))); IFsiDirectoryItem crtdiritem = null; if (diritem.FullPath.Length == 0) { try { var newpath = string.Format("{0}\\{1}", diritem.FullPath, pysicalFolder.Name); if (_sysImage.Exists(newpath) != FsiItemType.FsiItemDirectory) { diritem.AddDirectory(pysicalFolder.Name); } } catch { } crtdiritem = diritem[pysicalFolder.Name] as IFsiDirectoryItem; } else { crtdiritem = diritem; } var files = pysicalFolder.GetFiles("*"); //all files foreach (var file in files) { if (_cancel) { return; } CreateFSIFile(file, crtdiritem); } DirectoryInfo[] folders = null; folders = pysicalFolder.GetDirectories("*"); if (folders != null && folders.Length > 0) { foreach (var folder in folders) { if (_cancel) { return; } try { var newpath = string.Format("{0}\\{1}", crtdiritem.FullPath, folder.Name); if (_sysImage.Exists(newpath) != FsiItemType.FsiItemDirectory) { crtdiritem.AddDirectory(folder.Name); } } catch { Cancel = true; throw; } var subdir = crtdiritem[folder.Name] as IFsiDirectoryItem; CreateFSIFolder(folder, subdir); } } }