/// <summary> /// Get the files in the given Directory entry /// </summary> /// <param name="aDir">Must be a Directory</param> /// <returns></returns> public static FilesystemEntry[] GetFiles(FilesystemEntry aDir) { // Cosmos.Debug.Debugger.SendMessage("GetFiles(FileystemEntry)", aDir.Name); if (aDir == null) { throw new ArgumentNullException("aDir in GetFiles(FilesystemEntry)"); } if (!aDir.IsDirectory) { throw new Exception("Must be a directory"); } List <FilesystemEntry> xFiles = new List <FilesystemEntry>(); foreach (FilesystemEntry xEntry in VFSManager.GetDirectoryListing(aDir)) { // Cosmos.Debug.Debugger.SendMessage("GetFiles(FileystemEntry)", "Found " + xEntry.Name); if (!xEntry.IsDirectory) { xFiles.Add(xEntry); } } return(xFiles.ToArray()); }
//[PlugMethod(Signature = "System_Void__System_IO_FileInfo__ctor_System_String_")] public static void Ctor( FileInfo aThis, [FieldAccess(Name = "$$Storage$$")] ref FilesystemEntry aStorage, String aFile ) { //Determine if aFile is relative or absolute string xFile; if (aFile.IsRelativePath()) { xFile = Directory.GetCurrentDirectory() + aFile; } else { xFile = aFile; } var xEntry = VFSManager.GetDirectoryEntry(xFile); if (!xEntry.IsDirectory) { aStorage = xEntry; } }
/// <summary> /// Retrieves all files and directories in the given directory entry. /// </summary> /// <param name="aDirectory">Must be a Directory entry.</param> /// <returns></returns> public static FilesystemEntry[] GetDirectoryListing(FilesystemEntry aDirectory) { if (!aDirectory.IsDirectory) { throw new ArgumentException("Only Directories are allowed"); } var xFS = aDirectory.Filesystem; //// Cosmos.Debug.Debugger.SendMessage("GetDirectorylisting", "ID is " + aDirectory.Id); //aDirectory. return(xFS.GetDirectoryListing(aDirectory.Id)); }
public static FilesystemEntry[] GetVolumes() { //if (aFilesystems == null) // throw new ArgumentNullException("mFilesystems has not been initialized"); //Get volumes var xResult = new FilesystemEntry[mFilesystems.Count]; for (int i = 0; i < mFilesystems.Count; i++) { xResult[i] = GetVolumeEntry(i); } return(xResult); }
public static FileInfo[] GetFiles(DirectoryInfo aThis, [FieldAccess(Name = "$$Storage$$")] ref FilesystemEntry aStorage) { List <FileInfo> xFiles = new List <FileInfo>(); var xEntries = VFSManager.GetFiles(aStorage); foreach (FilesystemEntry xEntry in xEntries) { xFiles.Add(new FileInfo(xEntry.Name)); } return(xFiles.ToArray()); //Alternative implementation //var xEntries = VFSManager.GetFiles(aStorage); //FileInfo[] files = new FileInfo[xEntries.Length]; //for (int i = 0; i < xEntries.Length; i++) //{ // files[i] = new FileInfo(xEntries[i].Name); //} //return files; }
//public static string FullName //{ // get // { // return ".FullName isn't implemented yet"; // } //} //public static string get_FullName(DirectoryInfo aThis, [FieldAccess(Name = "$$FullPath$$")] String aFullPath) //{ // //TODO: return FULL name // return aFullPath; //} public static string get_Name(DirectoryInfo aThis, [FieldAccess(Name = "$$Storage$$")] ref FilesystemEntry aStorage) { return(aStorage.Name); }
public static bool get_Exists(DirectoryInfo aThis, [FieldAccess(Name = "$$Storage$$")] ref FilesystemEntry aStorage) { //TODO: actually test if it exists return(aStorage != null); }
public override FilesystemEntry[] GetDirectoryListing(ulong aId) { var xBaseINodeNumber = (uint)aId; INode xINode; GetINode(xBaseINodeNumber, out xINode); byte[] xFSBuffer = new byte[BlockSize]; var xResult = new List <FilesystemEntry>(10); var xDirEntriesPerFSBlock = BlockSize / sizeof(DirectoryEntry); uint xBlockId = 0; while (ReadINodeBlock(ref xINode, xBlockId, xFSBuffer)) { //HW.DebugUtil.WriteBinary("Ext2", // "Directory Entry binary", // xFSBuffer, // 0, // (int)BlockSize); //HW.DebugUtil.SendNumber("Ext2", // "First byte of datablock", // xFSBuffer[0], // 8); int xIndex = 0; var xIteration = 0; while (xIndex < BlockSize) { var xINodeNumber = ToUInt32(xFSBuffer, xIndex); var xRecLength = ToUInt16(xFSBuffer, xIndex + 4); // only include used items if (xINodeNumber > 0) { // only include non ".." or "." items if (xINodeNumber != xBaseINodeNumber) { var xNameLength = xFSBuffer[xIndex + 6]; var xFileType = xFSBuffer[xIndex + 7]; if (!(xNameLength == 2 && xFSBuffer[xIndex + 8] == (byte)'.' && xFSBuffer[xIndex + 9] == (byte)'.')) { var xFSEntry = new FilesystemEntry { Id = xINodeNumber, IsDirectory = (xFileType == 2), IsReadonly = true, Filesystem = this }; //xFSEntry.Size = GetINode(xINodeNumber).Size; char[] xName = new char[xNameLength]; for (int c = 0; c < xName.Length; c++) { xName[c] = (char)xFSBuffer[xIndex + 8 + c]; } xFSEntry.Name = new string(xName); if (!xFSEntry.Name.Equals("lost+found")) { xResult.Add(xFSEntry); } } } } xIndex += xRecLength; xIteration++; if (xIteration == 5) { break; } //break; } xBlockId++; } for (int i = 0; i < xResult.Count; i++) { INode xTheINode; GetINode((uint)xResult[i].Id, out xTheINode); xResult[i].Size = xTheINode.Size; } return(xResult.ToArray()); }
// Scan a directory and collect up all of the filesystem entries. private static FilesystemEntry[] ScanDirectory (String directory, String pattern, bool derefLinks) { String[] dirs; String[] files; String[] links; FilesystemEntry[] entries; // Convert the directory name into a full pathname. directory = Path.GetFullPath(directory); // Get all sub-directories in the specified directory, // irrespective of whether they match the pattern or not. try { dirs = Directory.GetDirectories(directory); } catch(Exception) { // An error occurred while trying to scan the directory, // so return an empty list of entries. return new FilesystemEntry [0]; } // Get all files and Windows shortcut link files that match // the pattern in the directory. if(pattern == null || pattern == "*" || pattern == "*.*") { files = Directory.GetFiles(directory); links = null; } else if(!EndsInLnk(pattern) && IsWindows()) { files = Directory.GetFiles(directory, pattern); links = Directory.GetFiles(directory, pattern + ".lnk"); } else { files = Directory.GetFiles(directory, pattern); links = null; } // Combine the three lists and populate the information. entries = new FilesystemEntry [dirs.Length + files.Length + (links != null ? links.Length : 0)]; int posn = 0; FilesystemEntry entry; bool resolveSymlinks = false; foreach(String dir in dirs) { entry = new FilesystemEntry(); entry.name = Path.GetFileName(dir); entry.fullName = dir; entry.isDirectory = true; entry.isSymlink = false; entry.iconCode = IconCode_Directory; entries[posn++] = entry; } foreach(String file in files) { entry = new FilesystemEntry(); entry.name = Path.GetFileName(file); entry.fullName = file; entry.isDirectory = false; entry.iconCode = IconCode_File; #if __CSCC__ entry.isSymlink = SymbolicLinks.IsSymbolicLink(file); if(entry.isSymlink) { resolveSymlinks = true; entry.iconCode = IconCode_Link; if(EndsInLnk(file) && IsWindows()) { // Strip ".lnk" from the end of the filename. entry.name = Path.GetFileNameWithoutExtension(file); } } #else entry.isSymlink = false; #endif entries[posn++] = entry; entry.SetIconCode(); } if(links != null) { // We have an extra list of files that end in ".lnk". foreach(String link in links) { entry = new FilesystemEntry(); entry.name = Path.GetFileNameWithoutExtension(link); entry.fullName = link; entry.isDirectory = false; entry.isSymlink = true; entry.iconCode = IconCode_Link; entries[posn++] = entry; resolveSymlinks = true; } } // Resolve symbolic links to the underlying file or directory. if(resolveSymlinks && derefLinks) { for(posn = 0; posn < entries.Length; ++posn) { entry = entries[posn]; if(entry.isSymlink) { entry.ResolveSymlinks(); entry.SetIconCode(); } } } // Sort the entry list and return it. Array.Sort(entries); return entries; }
public static bool get_Exists([FieldAccess(Name = "$$Storage$$")] ref FilesystemEntry aStorage) { return(VFSManager.FileExists(aStorage.Name)); }
public static string get_Name([FieldAccess(Name = "$$Storage$$")] ref FilesystemEntry aStorage) { return("Filename" + aStorage.Name); }