private static void RemoveFileFromDirectory(Directory dir, File file, string name) { List<string> aliases = new List<string>(); DirectoryEntry dirEntry = dir.GetEntryByName(name); if (dirEntry.Details.FileNameNamespace == FileNameNamespace.Dos || dirEntry.Details.FileNameNamespace == FileNameNamespace.Win32) { foreach (var fnStream in file.GetStreams(AttributeType.FileName, null)) { var fnr = fnStream.GetContent<FileNameRecord>(); if ((fnr.FileNameNamespace == FileNameNamespace.Win32 || fnr.FileNameNamespace == FileNameNamespace.Dos) && fnr.ParentDirectory.Value == dir.MftReference.Value) { aliases.Add(fnr.FileName); } } } else { aliases.Add(name); } foreach (var alias in aliases) { DirectoryEntry de = dir.GetEntryByName(alias); dir.RemoveEntry(de); } }
private DirectoryEntry GetDirectoryEntry(Directory dir, string[] pathEntries, int pathOffset) { DirectoryEntry entry; if (pathEntries.Length == 0) { return dir.DirectoryEntry; } else { entry = dir.GetEntryByName(pathEntries[pathOffset]); if (entry != null) { if (pathOffset == pathEntries.Length - 1) { return entry; } else if ((entry.Details.FileAttributes & FileAttributes.Directory) != 0) { return GetDirectoryEntry(GetDirectory(entry.Reference), pathEntries, pathOffset + 1); } else { throw new IOException(string.Format(CultureInfo.InvariantCulture, "{0} is a file, not a directory", pathEntries[pathOffset])); } } else { return null; } } }
private void VerifyWellKnownFilesExist() { Directory rootDir = new Directory(_context, _context.Mft.GetRecord(MasterFileTable.RootDirIndex, false)); DirectoryEntry extendDirEntry = rootDir.GetEntryByName("$Extend"); if (extendDirEntry == null) { ReportError("$Extend does not exist in root directory"); Abort(); } Directory extendDir = new Directory(_context, _context.Mft.GetRecord(extendDirEntry.Reference)); DirectoryEntry objIdDirEntry = extendDir.GetEntryByName("$ObjId"); if (objIdDirEntry == null) { ReportError("$ObjId does not exist in $Extend directory"); Abort(); } // Stash ObjectIds _context.ObjectIds = new ObjectIds(new File(_context, _context.Mft.GetRecord(objIdDirEntry.Reference))); DirectoryEntry sysVolInfDirEntry = rootDir.GetEntryByName("System Volume Information"); if (sysVolInfDirEntry == null) { ReportError("'System Volume Information' does not exist in root directory"); Abort(); } ////Directory sysVolInfDir = new Directory(_context, _context.Mft.GetRecord(sysVolInfDirEntry.Reference)); }