/// <summary> /// Initializes a new base listing. /// </summary> /// <param name="aFileSystem">The file system to which the listing belongs.</param> /// <param name="parent">The parent directory of the listing.</param> /// <param name="aName">The name of the listing.</param> /// <param name="isDirectory">Whether the listing is a directory or not.</param> protected Base(FileSystem aFileSystem, Directory parent, FOS_System.String aName, bool isDirectory) { TheFileSystem = aFileSystem; Name = aName; IsDirectory = isDirectory; Parent = parent; }
/// <summary> /// Copies the specified directory. /// </summary> /// <param name="srcDir">The directory to copy.</param> /// <param name="dst">The path to copy to.</param> private void CopyDirectory(Directory srcDir, FOS_System.String dst) { //If source directory is null, it means it wasn't found by the caller (or some // other error but we will assume not found since that is the expected use // case from the other overload of CopyDirectory). if (srcDir == null) { console.WriteLine("Source directory not found!"); return; } //Add a trailing "/" to the destination path name if(!dst.EndsWith(FileSystemManager.PathDelimiter)) { dst += FileSystemManager.PathDelimiter; } //Creates the entire directory tree as required or returns // the existing directory. Directory dstDir = NewDirectory(dst); //For explanation of this, see CopyFile FOS_System.String srcFullPath = srcDir.GetFullPath(); FOS_System.String dstFullPath = dstDir.GetFullPath(); if (srcFullPath == dstFullPath) { console.WriteLine("Atempted to copy a directory to itself! (" + srcFullPath + ")"); return; } else { console.WriteLine("Copying " + srcFullPath + " to " + dstFullPath); } //Copy listings // This causes CopyDirectory to be a recursive, self-calling method // which could potentially overflow. It has the benefit though that // the entire sub-directory/sub-file tree will be copied. List listings = srcDir.GetListings(); for(int i = 0; i < listings.Count; i++) { Base listing = (Base)listings[i]; if(listing.IsDirectory) { if (listing.Name != "." && listing.Name != "..") { CopyDirectory((Directory)listing, dst + listing.Name + FileSystemManager.PathDelimiter); } } else { CopyFile((File)listing, dst + listing.Name); } } }
/// <summary> /// Initializes a new file. /// </summary> /// <param name="aFileSystem">The file system to which the file belongs.</param> /// <param name="parent">The parent directory of the file.</param> /// <param name="aName">The name of the file.</param> /// <param name="aSize">The exact size of the file in bytes.</param> public File(FileSystem aFileSystem, Directory parent, FOS_System.String aName, UInt64 aSize) : base(aFileSystem, parent, aName, false) { mSize = aSize; }
/// <summary> /// Creates a new directory within the file system. /// </summary> /// <param name="name">The name of the directory to create.</param> /// <param name="parent">The parent directory of the new directory.</param> /// <returns>The new directory listing.</returns> public abstract Directory NewDirectory(FOS_System.String name, Directory parent);
/// <summary> /// Creates a new file within the file system. /// </summary> /// <param name="name">The name of the file to create.</param> /// <param name="parent">The parent directory of the new file.</param> /// <returns>The new file listing.</returns> public abstract File NewFile(FOS_System.String name, Directory parent);
/// <summary> /// Gets a specific listing from the specified list of listings. Performs a recursive /// search down the file system tree. /// </summary> /// <param name="nameParts">The parts of the full path of the listing to get.</param> /// <param name="parent">The parent directory of the directory from which the listings were taken.</param> /// <param name="listings">The listings to search through.</param> /// <returns>The listing or null if not found.</returns> public Base GetListingFromListings(List nameParts, Directory parent, List listings) { // ".." means "parent directory" if (((FOS_System.String)nameParts[0]) == "..") { nameParts.RemoveAt(0); if (nameParts.Count == 0) { return parent; } return parent.GetListing(nameParts); } for (int i = 0; i < listings.Count; i++) { Base aListing = (Base)listings[i]; if (aListing.Name == (FOS_System.String)nameParts[0]) { nameParts.RemoveAt(0); if (nameParts.Count == 0) { return aListing; } else if (aListing.IsDirectory) { return ((Directory)aListing).GetListing(nameParts); } } } return null; }
/// <summary> /// Initializes a new directory listing. /// </summary> /// <param name="aFileSystem">The file system to which the directory belongs.</param> /// <param name="parent">The parent directory of the directory.</param> /// <param name="aName">The name of the directory.</param> public Directory(FileSystem aFileSystem, Directory parent, FOS_System.String aName) : base(aFileSystem, parent, aName, true) { }