Exemplo n.º 1
0
 protected DirectoryEntry(FileSystem aFileSystem, DirectoryEntry aParent, string aName, ulong aSize, DirectoryEntryTypeEnum aEntryType)
 {
     mFileSystem = aFileSystem;
     mParent = aParent;
     mEntryType = aEntryType;
     mName = aName;
     mSize = aSize;
 }
Exemplo n.º 2
0
        public override List<DirectoryEntry> GetDirectoryListing(DirectoryEntry aDirectory)
        {
            DirectoryEntry xTempEntry = aDirectory;
            string xFullPath = "";
            while (xTempEntry.mParent != null)
            {
                xFullPath = Path.Combine(xTempEntry.mName, xFullPath);
                xTempEntry = xTempEntry.mParent;
            }

            return GetDirectoryListing(xFullPath);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DirectoryEntry"/> class.
        /// </summary>
        /// <param name="aFileSystem">The file system that contains the directory entry.</param>
        /// <param name="aParent">The parent directory entry or null if the current entry is the root.</param>
        /// <param name="aFullPath">The full path to the entry.</param>
        /// <param name="aName">The entry name.</param>
        /// <param name="aSize">The size of the entry.</param>
        /// <param name="aEntryType">The ype of the entry.</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentException">
        /// Argument is null or empty
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// </exception>
        protected DirectoryEntry(FileSystem aFileSystem, DirectoryEntry aParent, string aFullPath, string aName, long aSize, DirectoryEntryTypeEnum aEntryType)
        {
            if (aFileSystem == null)
            {
                throw new ArgumentNullException(nameof(aFileSystem));
            }
            if (string.IsNullOrEmpty(aFullPath))
            {
                throw new ArgumentException("Argument is null or empty", nameof(aFullPath));
            }
            if (string.IsNullOrEmpty(aName))
            {
                throw new ArgumentException("Argument is null or empty", nameof(aName));
            }

            mFileSystem = aFileSystem;
            mParent = aParent;
            mEntryType = aEntryType;
            mName = aName;
            mSize = aSize;
            mFullPath = aFullPath;
        }
Exemplo n.º 4
0
 public abstract void DeleteFile(DirectoryEntry aPath);
Exemplo n.º 5
0
        public static string GetFullPath(DirectoryEntry aEntry)
        {
            Global.mFileSystemDebugger.SendInternal("VFSManager.GetFullPath:");

            if (aEntry == null)
            {
                throw new ArgumentNullException(nameof(aEntry));
            }

            Global.mFileSystemDebugger.SendInternal("aEntry.mName =");
            Global.mFileSystemDebugger.SendInternal(aEntry.mName);

            var xParent = aEntry.mParent;
            string xPath = aEntry.mName;

            while (xParent != null)
            {
                xPath = xParent.mName + xPath;
                Global.mFileSystemDebugger.SendInternal("xPath =");
                Global.mFileSystemDebugger.SendInternal(xPath);

                xParent = xParent.mParent;
                Global.mFileSystemDebugger.SendInternal("xParent.mName =");
                Global.mFileSystemDebugger.SendInternal(xParent.mName);
            }

            Global.mFileSystemDebugger.SendInternal("xPath =");
            Global.mFileSystemDebugger.SendInternal(xPath);

            return xPath;
        }
Exemplo n.º 6
0
        public override Stream GetFileStream(DirectoryEntry fileInfo)
        {
            if (fileInfo.EntryType == DirectoryEntryTypeEnum.File)
            {
                return new FatStream((FatDirectoryEntry)fileInfo);
            }

            FatHelpers.Debug("GetFileStream only works for file entries.");
            return null;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Gets the directory listing for a directory entry.
        /// </summary>
        /// <param name="aDirectory">The directory entry.</param>
        /// <returns></returns>
        public override List<DirectoryEntry> GetDirectoryListing(DirectoryEntry aDirectory)
        {
            if (aDirectory == null || String.IsNullOrEmpty(aDirectory.mFullPath))
            {
                throw new ArgumentException("Argument is null or empty", nameof(aDirectory));
            }

            return GetDirectoryListing(aDirectory.mFullPath);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Deletes an empty directory.
        /// </summary>
        /// <param name="aPath">The full path.</param>
        /// <returns></returns>
        public override bool DeleteDirectory(DirectoryEntry aPath)
        {
            try
            {
                if (GetDirectoryListing(aPath).Count > 0)
                    throw new Exception("Directory is not empty");

                var xFS = GetFileSystemFromPath(aPath.mFullPath);
                xFS.DeleteDirectory(aPath);
                return true;
            }
            catch
            {
                return false;
            }
        }
Exemplo n.º 9
0
        public override List<DirectoryEntry> GetDirectoryListing(DirectoryEntry baseDirectory)
        {
            Global.mFileSystemDebugger.SendInternal("-- FatFileSystem.GetDirectoryListing --");

            if (baseDirectory == null)
            {
                throw new ArgumentNullException(nameof(baseDirectory));
            }

            var result = new List<DirectoryEntry>();
            var xEntry = (FatDirectoryEntry)baseDirectory;
            var fatListing = xEntry.ReadDirectoryContents();

            for (int i = 0; i < fatListing.Count; i++)
            {
                result.Add(fatListing[i]);
            }
            return result;
        }
Exemplo n.º 10
0
 public abstract DirectoryEntry CreateFile(DirectoryEntry aParentDirectory, string aNewFile);
Exemplo n.º 11
0
        public override void DeleteFile(DirectoryEntry aDirectoryEntry)
        {
            if (aDirectoryEntry == null)
            {
                throw new ArgumentNullException(nameof(aDirectoryEntry));
            }

            var xDirectoryEntry = (FatDirectoryEntry)aDirectoryEntry;

            var entries = xDirectoryEntry.GetFatTable();

            foreach (var entry in entries)
            {
                GetFat(0).ClearFatEntry(entry);
            }

            xDirectoryEntry.DeleteDirectoryEntry();
        }
Exemplo n.º 12
0
        public override void DeleteDirectory(DirectoryEntry aDirectoryEntry)
        {
            if(aDirectoryEntry == null)
            {
                throw new ArgumentNullException(nameof(aDirectoryEntry));
            }

            var xDirectoryEntry = (FatDirectoryEntry)aDirectoryEntry;

            xDirectoryEntry.DeleteDirectoryEntry();
        }
Exemplo n.º 13
0
 public abstract Stream GetFileStream(DirectoryEntry fileInfo);
Exemplo n.º 14
0
        public override DirectoryEntry CreateFile(DirectoryEntry aParentDirectory, string aNewFile)
        {
            if (aParentDirectory == null)
            {
                throw new ArgumentNullException("aParentDirectory");
            }

            if (aNewFile == null)
            {
                throw new ArgumentNullException("aNewFile");
            }

            if (string.IsNullOrWhiteSpace(aNewFile))
            {
                throw new ArgumentException("The new file must be specified.", "aNewFile");
            }

            FileSystemHelpers.Debug("FatFileSystem.CreateFile", "aParentDirectory.Name =", aParentDirectory?.mName, ", aNewFile =", aNewFile);
            var xParentDirectory = (FatDirectoryEntry)aParentDirectory;
            var xDirectoryEntryToAdd = xParentDirectory.AddDirectoryEntry(aNewFile, DirectoryEntryTypeEnum.File);
            return xDirectoryEntryToAdd;
        }
Exemplo n.º 15
0
        public override List<DirectoryEntry> GetDirectoryListing(DirectoryEntry baseDirectory)
        {
            FileSystemHelpers.Debug("FatFileSystem.GetDirectoryListing", "baseDirectory.Name =", baseDirectory?.mName);

            var result = new List<DirectoryEntry>();
            List<FatDirectoryEntry> fatListing;
            if (baseDirectory == null)
            {
                // get root folder
                var xEntry = (FatDirectoryEntry)GetRootDirectory();
                fatListing = xEntry.ReadDirectoryContents();
            }
            else
            {
                var xEntry = (FatDirectoryEntry)baseDirectory;
                fatListing = xEntry.ReadDirectoryContents();
            }

            for (int i = 0; i < fatListing.Count; i++)
            {
                result.Add(fatListing[i]);
            }
            return result;
        }
Exemplo n.º 16
0
        public static string GetFullPath(DirectoryEntry aEntry)
        {
            FatHelpers.Debug("-- VFSManager.GetFullPath --");

            DirectoryEntry xEntry = aEntry;
            string xPath = string.Empty;

            while (xEntry != null)
            {
                xPath = xEntry + xEntry.Name;
                xEntry = aEntry.Parent;
                FatHelpers.Debug("-- VFSManager.GetFullPath : xPath = " + xPath + " --");
            }

            return Path.GetFullPath(xPath);
        }
Exemplo n.º 17
0
        public static bool DirectoryExists(DirectoryEntry aEntry)
        {
            FatHelpers.Debug("-- VFSManager.DirectoryExists --");

            try
            {
                string xPath = GetFullPath(aEntry);
                return GetDirectory(xPath) != null;
            }
            catch (Exception e)
            {
                global::System.Console.Write("Exception occurred: ");
                global::System.Console.WriteLine(e.Message);
                return false;
            }
        }
Exemplo n.º 18
0
 public abstract List<DirectoryEntry> GetDirectoryListing(DirectoryEntry baseDirectory);
Exemplo n.º 19
0
 public abstract DirectoryEntry CreateDirectory(DirectoryEntry aParentDirectory, string aNewDirectory);
Exemplo n.º 20
0
        public override List<DirectoryEntry> GetDirectoryListing(DirectoryEntry baseDirectory)
        {
            Global.mFileSystemDebugger.SendInternal($"FatFileSystem.GetDirectoryListing : baseDirectory.Name = {baseDirectory?.mName}");

            var result = new List<DirectoryEntry>();
            List<FatDirectoryEntry> fatListing;
            if (baseDirectory == null)
            {
                // get root folder
                var xEntry = (FatDirectoryEntry)GetRootDirectory();
                fatListing = xEntry.ReadDirectoryContents();
            }
            else
            {
                var xEntry = (FatDirectoryEntry)baseDirectory;
                fatListing = xEntry.ReadDirectoryContents();
            }

            for (int i = 0; i < fatListing.Count; i++)
            {
                result.Add(fatListing[i]);
            }
            return result;
        }
Exemplo n.º 21
0
        public static string GetFullPath(DirectoryEntry aEntry)
        {
            FileSystemHelpers.Debug("VFSManager.GetFullPath : aEntry.mName = " + aEntry?.mName);
            var xParent = aEntry?.mParent;
            string xPath = aEntry?.mName;

            while (xParent != null)
            { 
                xPath = xParent.mName + xPath;
                FileSystemHelpers.Debug("VFSManager.GetFullPath : xPath = " + xPath);
                xParent = xParent.mParent;
            }

            FileSystemHelpers.Debug("VFSManager.GetFullPath : xPath = " + xPath);
            return xPath;
        }
Exemplo n.º 22
0
        public override DirectoryEntry CreateFile(DirectoryEntry aParentDirectory, string aNewFile)
        {
            if (aParentDirectory == null)
            {
                throw new ArgumentNullException("aParentDirectory");
            }

            if (aNewFile == null)
            {
                throw new ArgumentNullException("aNewFile");
            }

            if (string.IsNullOrWhiteSpace(aNewFile))
            {
                throw new ArgumentException("The new file must be specified.", "aNewFile");
            }

            Global.mFileSystemDebugger.SendInternal($"FatFileSystem.CreateFile : aParentDirectory.Name = {aParentDirectory?.mName},  aNewFile = {aNewFile}");
            var xParentDirectory = (FatDirectoryEntry)aParentDirectory;
            var xDirectoryEntryToAdd = xParentDirectory.AddDirectoryEntry(aNewFile, DirectoryEntryTypeEnum.File);
            return xDirectoryEntryToAdd;
        }
Exemplo n.º 23
0
        public override DirectoryEntry CreateFile(DirectoryEntry aParentDirectory, string aNewFile)
        {
            Global.mFileSystemDebugger.SendInternal("-- FatFileSystem.CreateFile --");
            Global.mFileSystemDebugger.SendInternal("aParentDirectory.Name =");
            Global.mFileSystemDebugger.SendInternal(aParentDirectory?.mName);
            Global.mFileSystemDebugger.SendInternal("aNewFile =");
            Global.mFileSystemDebugger.SendInternal(aNewFile);

            if (aParentDirectory == null)
            {
                throw new ArgumentNullException(nameof(aParentDirectory));
            }

            if (string.IsNullOrEmpty(aNewFile))
            {
                throw new ArgumentNullException(nameof(aNewFile));
            }

            var xParentDirectory = (FatDirectoryEntry)aParentDirectory;
            var xDirectoryEntryToAdd = xParentDirectory.AddDirectoryEntry(aNewFile, DirectoryEntryTypeEnum.File);
            return xDirectoryEntryToAdd;
        }
Exemplo n.º 24
0
 public abstract bool DeleteDirectory(DirectoryEntry aPath);
Exemplo n.º 25
0
 /// <summary>
 /// Deletes a file.
 /// </summary>
 /// <param name="aPath">The full path.</param>
 /// <returns></returns>
 public override bool DeleteFile(DirectoryEntry aPath)
 {
     try
     {
         var xFS = GetFileSystemFromPath(aPath.mFullPath);
         xFS.DeleteFile(aPath);
         return true;
     }
     catch
     {
         return false;
     }
 }
Exemplo n.º 26
0
        public static string GetFullPath(DirectoryEntry aEntry)
        {
            FileSystemHelpers.Debug("VFSManager.GetFullPath : aEntry.mName = " + aEntry?.mName);
            var xEntry = aEntry?.mParent;
            string xPath = aEntry?.mName;

            while (xEntry != null)
            {
                FileSystemHelpers.Debug("VFSManager.GetFullPath : xEntry is not null.");
                xPath = string.Concat(xPath, xEntry.mName);
                FileSystemHelpers.Debug("VFSManager.GetFullPath : xPath = " + xPath);
                xEntry = aEntry.mParent;
            }

            FileSystemHelpers.Debug("VFSManager.GetFullPath : xPath = " + xPath);
            return xPath;
        }
Exemplo n.º 27
0
 public static bool DirectoryExists(DirectoryEntry aEntry)
 {
     try
     {
         FileSystemHelpers.Debug("VFSManager.DirectoryExists", "aEntry.mName =", aEntry?.mName);
         string xPath = GetFullPath(aEntry);
         return GetDirectory(xPath) != null;
     }
     catch (Exception e)
     {
         global::System.Console.Write("Exception occurred: ");
         global::System.Console.WriteLine(e.Message);
         return false;
     }
 }
Exemplo n.º 28
0
        public override List<DirectoryEntry> GetDirectoryListing(DirectoryEntry baseDirectory)
        {
            List<DirectoryEntry> result = new List<DirectoryEntry>();
            List<FatDirectoryEntry> fatListing = new List<FatDirectoryEntry>();
            if (baseDirectory == null)
            {
                // get root folder
                fatListing = GetRoot();
            }
            else
            {
                fatListing = GetDirectoryContents((FatDirectoryEntry)baseDirectory);
            }

            for (int i = 0; i < fatListing.Count; i++)
            {
                result.Add(fatListing[i]);
            }
            return result;
        }
Exemplo n.º 29
0
        public static bool DirectoryExists(DirectoryEntry aEntry)
        {
            Global.mFileSystemDebugger.SendInternal("VFSManager.DirectoryExists:");

            if (aEntry == null)
            {
                throw new ArgumentNullException(nameof(aEntry));
            }

            try
            {
                Global.mFileSystemDebugger.SendInternal("aEntry.mName =");
                Global.mFileSystemDebugger.SendInternal(aEntry.mName);

                string xPath = GetFullPath(aEntry);
                Global.mFileSystemDebugger.SendInternal("After GetFullPath");
                Global.mFileSystemDebugger.SendInternal("xPath =");
                Global.mFileSystemDebugger.SendInternal(xPath);

                return GetDirectory(xPath) != null;
            }
            catch (Exception e)
            {
                global::System.Console.Write("Exception occurred: ");
                global::System.Console.WriteLine(e.Message);
                return false;
            }
        }
Exemplo n.º 30
0
        public static string GetFullPath(DirectoryEntry aEntry)
        {
            DirectoryEntry xEntry = aEntry;
            string xPath = string.Empty;

            while (xEntry != null)
            {
                xPath = xEntry + xEntry.Name;
                xEntry = aEntry.Parent;
            }

            return Path.GetFullPath(xPath);
        }