public void CloseContainer() { fsHandler = null; discFs.Dispose(); fsInfo = null; volume = null; disk.Dispose(); File.Delete(originalPath); Crypto.EncryptFile(temporaryPath, originalPath, pwdKey, new AesEngine(), 128, 128); File.Delete(temporaryPath); }
private void GetChildren(string path, bool recurse, bool namesOnly) { if (string.IsNullOrEmpty(path)) { return; } object obj = FindItemByPath(path, false, true); if (obj is VirtualDisk) { VirtualDisk vd = (VirtualDisk)obj; EnumerateDisk(vd, path, recurse, namesOnly); } else if (obj is LogicalVolumeInfo) { LogicalVolumeInfo lvi = (LogicalVolumeInfo)obj; bool dispose; DiscFileSystem fs = GetFileSystem(lvi, out dispose); try { if (fs != null) { EnumerateDirectory(fs.Root, path, recurse, namesOnly); } } finally { if (dispose && fs != null) { fs.Dispose(); } } } else if (obj is DiscDirectoryInfo) { DiscDirectoryInfo ddi = (DiscDirectoryInfo)obj; EnumerateDirectory(ddi, path, recurse, namesOnly); } else { WriteError(new ErrorRecord( new InvalidOperationException("Unrecognized object type: " + (obj != null ? obj.GetType() : null)), "UnknownObjectType", ErrorCategory.ParserError, obj)); } }
private object FindItemByPath(string path, bool preferFs, bool readOnly) { FileAccess fileAccess = readOnly ? FileAccess.Read : FileAccess.ReadWrite; string diskPath; string relPath; int mountSepIdx = path.IndexOf('!'); if (mountSepIdx < 0) { diskPath = path; relPath = ""; } else { diskPath = path.Substring(0, mountSepIdx); relPath = path.Substring(mountSepIdx + 1); } VirtualDisk disk = Disk; if (disk == null) { OnDemandVirtualDisk odvd = new OnDemandVirtualDisk(Utilities.DenormalizePath(diskPath), fileAccess); if (odvd.IsValid) { disk = odvd; ShowSlowDiskWarning(); } else { return(null); } } List <string> pathElems = new List <string>(relPath.Split(new string[] { @"\" }, StringSplitOptions.RemoveEmptyEntries)); if (pathElems.Count == 0) { return(disk); } VolumeInfo volInfo = null; VolumeManager volMgr = DriveInfo != null ? DriveInfo.VolumeManager : new VolumeManager(disk); LogicalVolumeInfo[] volumes = volMgr.GetLogicalVolumes(); string volNumStr = pathElems[0].StartsWith("Volume", StringComparison.OrdinalIgnoreCase) ? pathElems[0].Substring(6) : null; int volNum; if (int.TryParse(volNumStr, out volNum) || volNum < 0 || volNum >= volumes.Length) { volInfo = volumes[volNum]; } else { volInfo = volMgr.GetVolume(Utilities.DenormalizePath(pathElems[0])); } pathElems.RemoveAt(0); if (volInfo == null || (pathElems.Count == 0 && !preferFs)) { return(volInfo); } bool disposeFs; DiscFileSystem fs = GetFileSystem(volInfo, out disposeFs); try { if (fs == null) { return(null); } // Special marker in the path - disambiguates the root folder from the volume // containing it. By this point it's done it's job (we didn't return volInfo), // so we just remove it. if (pathElems.Count > 0 && pathElems[0] == "$Root") { pathElems.RemoveAt(0); } string fsPath = string.Join(@"\", pathElems.ToArray()); if (fs.DirectoryExists(fsPath)) { return(fs.GetDirectoryInfo(fsPath)); } else if (fs.FileExists(fsPath)) { return(fs.GetFileInfo(fsPath)); } } finally { if (disposeFs && fs != null) { fs.Dispose(); } } return(null); }