Пример #1
0
        // Size is UInt32 because FAT doesn't support bigger.
        // Don't change to UInt64
        public FatDirectoryEntry(
            FatFileSystem aFileSystem,
            FatDirectoryEntry aParent,
            string aName,
            uint aSize,
            ulong aFirstCluster,
            uint aEntryHeaderDataOffset,
            DirectoryEntryTypeEnum aEntryType)
            : base(aFileSystem, aParent, aName, aSize, aEntryType)
        {
            if (aFileSystem == null)
            {
                Global.mFileSystemDebugger.SendInternal($"FatDirectoryEntry.ctor : aFileSystem is null.");
                throw new ArgumentNullException(nameof(aFileSystem));
            }

            if (aName == null)
            {
                Global.mFileSystemDebugger.SendInternal($"FatDirectoryEntry.ctor : aName is null.");
                throw new ArgumentNullException(nameof(aName));
            }

            if (aFirstCluster < 2)
            {
                Global.mFileSystemDebugger.SendInternal($"FatDirectoryEntry.ctor : aFirstCluster is out of range.");
                throw new ArgumentOutOfRangeException(nameof(aFirstCluster));
            }

            Global.mFileSystemDebugger.SendInternal($"FatDirectoryEntry.ctor : aParent.Name = {aParent?.mName}, aName = {aName}, aSize = {aSize}, aFirstCluster = {aFirstCluster}, aEntryHeaderDataOffset = {aEntryHeaderDataOffset}");

            mFileSystem = aFileSystem;
            mParent = aParent;
            mFirstClusterNum = aFirstCluster;
            mEntryHeaderDataOffset = aEntryHeaderDataOffset;
        }
Пример #2
0
        // Size is UInt32 because FAT doesn't support bigger.
        // Don't change to UInt64
        public FatDirectoryEntry(
            FatFileSystem aFileSystem,
            FatDirectoryEntry aParent,
            string aName,
            uint aSize,
            ulong aFirstCluster,
            uint aEntryHeaderDataOffset,
            DirectoryEntryTypeEnum aEntryType)
            : base(aFileSystem, aParent, aName, aSize, aEntryType)
        {
            if (aFileSystem == null)
            {
                Global.mFileSystemDebugger.SendInternal($"FatDirectoryEntry.ctor : aFileSystem is null.");
                throw new ArgumentNullException(nameof(aFileSystem));
            }

            if (aName == null)
            {
                Global.mFileSystemDebugger.SendInternal($"FatDirectoryEntry.ctor : aName is null.");
                throw new ArgumentNullException(nameof(aName));
            }

            if (aFirstCluster < 2)
            {
                Global.mFileSystemDebugger.SendInternal($"FatDirectoryEntry.ctor : aFirstCluster is out of range.");
                throw new ArgumentOutOfRangeException(nameof(aFirstCluster));
            }

            Global.mFileSystemDebugger.SendInternal($"FatDirectoryEntry.ctor : aParent.Name = {aParent?.mName}, aName = {aName}, aSize = {aSize}, aFirstCluster = {aFirstCluster}, aEntryHeaderDataOffset = {aEntryHeaderDataOffset}");

            mFileSystem            = aFileSystem;
            mParent                = aParent;
            mFirstClusterNum       = aFirstCluster;
            mEntryHeaderDataOffset = aEntryHeaderDataOffset;
        }
Пример #3
0
        // Size is UInt32 because FAT doesn't support bigger.
        // Don't change to UInt64
        public FatDirectoryEntry(
            FatFileSystem aFileSystem,
            FatDirectoryEntry aParent,
            string aName,
            uint aSize,
            ulong aFirstCluster,
            uint aEntryHeaderDataOffset,
            DirectoryEntryTypeEnum aEntryType)
            : base(aFileSystem, aParent, aName, aSize, aEntryType)
        {
            if (aFileSystem == null)
            {
                FileSystemHelpers.Debug("FatDirectoryEntry.ctor", "aFileSystem is null.");
                throw new ArgumentNullException(nameof(aFileSystem));
            }

            if (aName == null)
            {
                FileSystemHelpers.Debug("FatDirectoryEntry.ctor", "aName is null.");
                throw new ArgumentNullException(nameof(aName));
            }

            if (aFirstCluster < 2)
            {
                FileSystemHelpers.Debug("FatDirectoryEntry.ctor", "aFirstCluster is out of range.");
                throw new ArgumentOutOfRangeException(nameof(aFirstCluster));
            }

            FileSystemHelpers.Debug("FatDirectoryEntry.ctor", "aParent.Name =", aParent?.mName, ", aName =", aName, ", aSize = " + aSize, ", aFirstCluster =", aFirstCluster, ", aEntryHeaderDataOffset =", aEntryHeaderDataOffset);

            mFileSystem            = aFileSystem;
            mParent                = aParent;
            mFirstClusterNum       = aFirstCluster;
            mEntryHeaderDataOffset = aEntryHeaderDataOffset;
        }
Пример #4
0
        // Size is UInt32 because FAT doesn't support bigger.
        // Don't change to UInt64
        public FatDirectoryEntry(
            FatFileSystem aFileSystem,
            FatDirectoryEntry aParent,
            string aName,
            uint aSize,
            ulong aFirstCluster,
            uint aEntryHeaderDataOffset,
            DirectoryEntryTypeEnum aEntryType)
            : base(aFileSystem, aParent, aName, aSize, aEntryType)
        {
            if (aFileSystem == null)
            {
                throw new ArgumentNullException("aFileSystem");
            }

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

            if (aFirstCluster < 2)
            {
                throw new ArgumentOutOfRangeException("aFirstCluster");
            }

            mFileSystem = aFileSystem;
            mParent = aParent;
            mFirstClusterNum = aFirstCluster;
            mEntryHeaderDataOffset = aEntryHeaderDataOffset;

            //FatHelpers.Debug(
            //    "-- FatDirectoryEntry.ctor : " + "aParent.Name = " + aParent?.mName + ", aName = " + aName + ", aSize = "
            //    + aSize + ", aFirstCluster = " + aFirstCluster + ", aEntryHeaderDataOffset = " + aEntryHeaderDataOffset
            //    + " --");
        }
Пример #5
0
        // Size is UInt32 because FAT doesn't support bigger.
        // Don't change to UInt64
        public FatDirectoryEntry(
            FatFileSystem aFileSystem,
            FatDirectoryEntry aParent,
            string aName,
            uint aSize,
            ulong aFirstCluster,
            uint aEntryHeaderDataOffset,
            DirectoryEntryTypeEnum aEntryType)
            : base(aFileSystem, aParent, aName, aSize, aEntryType)
        {
            if (aFileSystem == null)
            {
                FileSystemHelpers.Debug("FatDirectoryEntry.ctor", "aFileSystem is null.");
                throw new ArgumentNullException(nameof(aFileSystem));
            }

            if (aName == null)
            {
                FileSystemHelpers.Debug("FatDirectoryEntry.ctor", "aName is null.");
                throw new ArgumentNullException(nameof(aName));
            }

            if (aFirstCluster < 2)
            {
                FileSystemHelpers.Debug("FatDirectoryEntry.ctor", "aFirstCluster is out of range.");
                throw new ArgumentOutOfRangeException(nameof(aFirstCluster));
            }

            FileSystemHelpers.Debug("FatDirectoryEntry.ctor", "aParent.Name =", aParent?.mName, ", aName =", aName, ", aSize = " + aSize, ", aFirstCluster =", aFirstCluster, ", aEntryHeaderDataOffset =", aEntryHeaderDataOffset);

            mFileSystem = aFileSystem;
            mParent = aParent;
            mFirstClusterNum = aFirstCluster;
            mEntryHeaderDataOffset = aEntryHeaderDataOffset;
        }
Пример #6
0
        public FatDirectoryEntry AddDirectoryEntry(string aName, DirectoryEntryTypeEnum aType)
        {
            Global.mFileSystemDebugger.SendInternal("-- FatDirectoryEntry.AddDirectoryEntry --");
            Global.mFileSystemDebugger.SendInternal("aName =");
            Global.mFileSystemDebugger.SendInternal(aName);
            Global.mFileSystemDebugger.SendInternal("aType =");
            Global.mFileSystemDebugger.SendInternal((uint)aType);

            if ((aType == DirectoryEntryTypeEnum.Directory) || (aType == DirectoryEntryTypeEnum.File))
            {
                string xFullPath = Path.Combine(mFullPath, aName);
                uint xFirstCluster = ((FatFileSystem)mFileSystem).GetFat(0).GetNextUnallocatedFatEntry();
                uint xEntryHeaderDataOffset = GetNextUnallocatedDirectoryEntry();
                Global.mFileSystemDebugger.SendInternal("xFullPath =");
                Global.mFileSystemDebugger.SendInternal(xFullPath);
                Global.mFileSystemDebugger.SendInternal("xFirstCluster =");
                Global.mFileSystemDebugger.SendInternal(xFirstCluster);
                Global.mFileSystemDebugger.SendInternal("xEntryHeaderDataOffset =");
                Global.mFileSystemDebugger.SendInternal(xEntryHeaderDataOffset);

                var xNewEntry = new FatDirectoryEntry((FatFileSystem)mFileSystem, this, xFullPath, aName, 0, xFirstCluster, xEntryHeaderDataOffset, aType);
                xNewEntry.AllocateDirectoryEntry();
                return xNewEntry;
            }
            throw new ArgumentOutOfRangeException(nameof(aType), "Unknown directory entry type.");
        }
Пример #7
0
        public FatDirectoryEntry AddDirectoryEntry(string aName, DirectoryEntryTypeEnum aType)
        {
            Global.mFileSystemDebugger.SendInternal("-- FatDirectoryEntry.AddDirectoryEntry --");
            Global.mFileSystemDebugger.SendInternal("aName =");
            Global.mFileSystemDebugger.SendInternal(aName);
            Global.mFileSystemDebugger.SendInternal("aType =");
            Global.mFileSystemDebugger.SendInternal((uint)aType);

            if ((aType == DirectoryEntryTypeEnum.Directory) || (aType == DirectoryEntryTypeEnum.File))
            {
                string xFullPath              = Path.Combine(mFullPath, aName);
                uint   xFirstCluster          = ((FatFileSystem)mFileSystem).GetFat(0).GetNextUnallocatedFatEntry();
                uint   xEntryHeaderDataOffset = GetNextUnallocatedDirectoryEntry();
                Global.mFileSystemDebugger.SendInternal("xFullPath =");
                Global.mFileSystemDebugger.SendInternal(xFullPath);
                Global.mFileSystemDebugger.SendInternal("xFirstCluster =");
                Global.mFileSystemDebugger.SendInternal(xFirstCluster);
                Global.mFileSystemDebugger.SendInternal("xEntryHeaderDataOffset =");
                Global.mFileSystemDebugger.SendInternal(xEntryHeaderDataOffset);

                var xNewEntry = new FatDirectoryEntry((FatFileSystem)mFileSystem, this, xFullPath, aName, 0, xFirstCluster, xEntryHeaderDataOffset, aType);
                xNewEntry.AllocateDirectoryEntry();
                return(xNewEntry);
            }
            throw new ArgumentOutOfRangeException(nameof(aType), "Unknown directory entry type.");
        }
Пример #8
0
 protected DirectoryEntry(FileSystem aFileSystem, DirectoryEntry aParent, string aName, uint aSize, DirectoryEntryTypeEnum aEntryType)
 {
     mFileSystem = aFileSystem;
     mParent     = aParent;
     mEntryType  = aEntryType;
     mName       = aName;
     mSize       = aSize;
 }
Пример #9
0
 protected DirectoryEntry(FileSystem aFileSystem, DirectoryEntry aParent, string aName, ulong aSize, DirectoryEntryTypeEnum aEntryType)
 {
     mFileSystem = aFileSystem;
     mParent = aParent;
     mEntryType = aEntryType;
     mName = aName;
     mSize = aSize;
 }
Пример #10
0
 // Size is UInt32 because FAT doesn't support bigger.
 // Don't change to UInt64
 public FatDirectoryEntry(FatFileSystem aFileSystem, FatDirectoryEntry aParent, string aName, uint aSize, ulong aFirstClusterNum, uint aEntryHeaderDataOffset, DirectoryEntryTypeEnum aEntryType)
     : base(aFileSystem, aParent, aName, aSize, aEntryType)
 {
     FileSystem = aFileSystem;
     Parent = aParent;
     FirstClusterNum = aFirstClusterNum;
     EntryHeaderDataOffset = aEntryHeaderDataOffset;
 }
Пример #11
0
 public FatDirectoryEntry AddDirectoryEntry(string aName, DirectoryEntryTypeEnum aType)
 {
     Global.mFileSystemDebugger.SendInternal($"FatDirectoryEntry.AddDirectoryEntry : aName = {aName}, aType = {aType}");
     if ((aType == DirectoryEntryTypeEnum.Directory) || (aType == DirectoryEntryTypeEnum.File))
     {
         uint xFirstCluster          = mFileSystem.GetFat(0).GetNextUnallocatedFatEntry();
         uint xEntryHeaderDataOffset = GetNextUnallocatedEntry();
         var  xNewEntry = new FatDirectoryEntry(mFileSystem, this, aName, 0, xFirstCluster, xEntryHeaderDataOffset, aType);
         xNewEntry.AllocateDirectoryEntry();
         return(xNewEntry);
     }
     throw new ArgumentOutOfRangeException("aType", "Unknown directory entry type.");
 }
Пример #12
0
        public DirectoryEntry(DirectoryEntry aParent, string aFullPath, string aName, long aSize, DirectoryEntryTypeEnum aEntryType)
        {
            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));
            }

            mParent    = aParent;
            mEntryType = aEntryType;
            mName      = aName;
            mSize      = aSize;
            mFullPath  = aFullPath;
        }
Пример #13
0
        // Size is UInt32 because FAT doesn't support bigger.
        // Don't change to UInt64
        public FatDirectoryEntry(
            FatFileSystem aFileSystem,
            FatDirectoryEntry aParent,
            string aFullPath,
            string aName,
            uint aSize,
            ulong aFirstCluster,
            uint aEntryHeaderDataOffset,
            DirectoryEntryTypeEnum aEntryType)
            : base(aFileSystem, aParent, aFullPath, aName, aSize, aEntryType)
        {
            if (aFirstCluster < aFileSystem.RootCluster)
            {
                throw new ArgumentOutOfRangeException(nameof(aFirstCluster));
            }

            mFirstClusterNum = aFirstCluster;
            mEntryHeaderDataOffset = aEntryHeaderDataOffset;
        }
Пример #14
0
        // Size is UInt32 because FAT doesn't support bigger.
        // Don't change to UInt64
        public FatDirectoryEntry(
            FatFileSystem aFileSystem,
            FatDirectoryEntry aParent,
            string aFullPath,
            string aName,
            long aSize,
            uint aFirstCluster,
            uint aEntryHeaderDataOffset,
            DirectoryEntryTypeEnum aEntryType)
            : base(aFileSystem, aParent, aFullPath, aName, aSize, aEntryType)
        {
            if (aFirstCluster < aFileSystem.RootCluster)
            {
                throw new ArgumentOutOfRangeException(nameof(aFirstCluster));
            }

            mFirstClusterNum       = aFirstCluster;
            mEntryHeaderDataOffset = aEntryHeaderDataOffset;
        }
Пример #15
0
        // Size is UInt32 because FAT doesn't support bigger.
        // Don't change to UInt64
        public FatDirectoryEntry(
            FatFileSystem aFileSystem,
            FatDirectoryEntry aParent,
            string aFullPath,
            string aName,
            uint aSize,
            ulong aFirstCluster,
            uint aEntryHeaderDataOffset,
            DirectoryEntryTypeEnum aEntryType)
            : base(aFileSystem, aParent, aFullPath, aName, aSize, aEntryType)
        {
            Global.mFileSystemDebugger.SendInternal("FatDirectoryEntry.ctor:");

            if (aFirstCluster < 2)
            {
                Global.mFileSystemDebugger.SendInternal("aFirstCluster is out of range.");
                throw new ArgumentOutOfRangeException(nameof(aFirstCluster));
            }

            mFirstClusterNum = aFirstCluster;
            mEntryHeaderDataOffset = aEntryHeaderDataOffset;
        }
Пример #16
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;
        }
Пример #17
0
        // Size is UInt32 because FAT doesn't support bigger.
        // Don't change to UInt64
        public FatDirectoryEntry(
            FatFileSystem aFileSystem,
            FatDirectoryEntry aParent,
            string aFullPath,
            string aName,
            uint aSize,
            ulong aFirstCluster,
            uint aEntryHeaderDataOffset,
            DirectoryEntryTypeEnum aEntryType)
            : base(aFileSystem, aParent, aFullPath, aName, aSize, aEntryType)
        {
            Global.mFileSystemDebugger.SendInternal("FatDirectoryEntry.ctor:");

            if (aFirstCluster < 2)
            {
                Global.mFileSystemDebugger.SendInternal("aFirstCluster is out of range.");
                throw new ArgumentOutOfRangeException(nameof(aFirstCluster));
            }

            mFirstClusterNum       = aFirstCluster;
            mEntryHeaderDataOffset = aEntryHeaderDataOffset;
        }
Пример #18
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;
        }
Пример #19
0
 public NtfsDirectoryEntry(FileSystem aFileSystem, DirectoryEntry aParent, string aFullPath, string aName, long aSize, DirectoryEntryTypeEnum aEntryType, NtfsFileEntry entry) : base(aFileSystem, aParent, aFullPath, aName, aSize, aEntryType)
 {
     NtfsEntry = entry;
 }
Пример #20
0
 public ISO9660DirectoryEntry(ISO9660Directory internalEntry, ISO9660FileSystem aFileSystem, ISO9660DirectoryEntry aParent, string aFullPath, string aName, long aSize, DirectoryEntryTypeEnum aEntryType) : base(aFileSystem, aParent, aFullPath, aName, aSize, aEntryType)
 {
     this.internalEntry = internalEntry;
     fs = aFileSystem;
 }
Пример #21
0
        public FatDirectoryEntry AddDirectoryEntry(string aName, DirectoryEntryTypeEnum aEntryType)
        {
            Global.mFileSystemDebugger.SendInternal("-- FatDirectoryEntry.AddDirectoryEntry --");
            Global.mFileSystemDebugger.SendInternal("aName =");
            Global.mFileSystemDebugger.SendInternal(aName);
            Global.mFileSystemDebugger.SendInternal("aEntryType =");
            Global.mFileSystemDebugger.SendInternal((uint)aEntryType);

            if ((aEntryType == DirectoryEntryTypeEnum.Directory) || (aEntryType == DirectoryEntryTypeEnum.File))
            {
                string xShortName = aName;
                uint[] xDirectoryEntriesToAllocate = null;

                //Stack corruption, just delete everything from this until commented if when it's fixed
                var x1 = aEntryType == DirectoryEntryTypeEnum.File;
                var x2 = aName.Contains(".");
                var x3 = x2 ? aName.Substring(0, aName.LastIndexOf('.')).Contains(".") : false;
                var x4 = x2 ? aName.Substring(0, aName.IndexOf('.')).Length > 8 : false;
                var x5 = x2 ? aName.Substring(aName.IndexOf('.') + 1).Length > 3 : false;
                var x6 = aEntryType == DirectoryEntryTypeEnum.Directory;
                var x7 = aName.Length > 11;

                var x8 = (x3 || (x4 || x5));
                var x9 = (x2 && x8);

                var x10 = (x1 && x9) || (x6 && x7);

                //if ((aEntryType == DirectoryEntryTypeEnum.File && (aName.Contains(".") && (aName.Substring(0, aName.LastIndexOf('.')).Contains(".") || (aName.Substring(0, aName.IndexOf('.')).Length > 8 || aName.Substring(aName.IndexOf('.') + 1).Length > 3)))) ||
                //    (aEntryType == DirectoryEntryTypeEnum.Directory && aName.Length > 11))
                if (x10)
                {
                    string xLongName = aName;

                    char[] xInvalidShortNameChars = new char[] { '"', '*', '+', ',', '.', '/', ':', ';', '<', '=', '>', '?', '[', '\\', ']', '|' };

                    int xLastPeriodPosition = aName.LastIndexOf('.');

                    string xExt = "";

                    if (xLastPeriodPosition + 1 > 0 && xLastPeriodPosition + 1 < aName.Length)
                    {
                        xExt = xShortName.Substring(xLastPeriodPosition + 1);
                    }

                    for (int i = xShortName.Length - 1; i > 0; i--)
                    {
                        char xChar = xShortName[i];

                        if (char.IsWhiteSpace(xChar) || (xChar == '.' && i != xLastPeriodPosition))
                        {
                            xShortName.Remove(i, 1);
                        }
                    }

                    foreach (char xInvalidChar in xInvalidShortNameChars)
                    {
                        xShortName.Replace(xInvalidChar, '_');
                    }

                    int n = 1;
                    List<FatDirectoryEntry> xDirectoryEntries = ReadDirectoryContents(true);
                    string[] xShortFilenames = new string[xDirectoryEntries.Count];

                    for (int i = 0; i < xDirectoryEntries.Count; i++)
                    {
                        xShortFilenames[i] = xDirectoryEntries[i].mName;
                    }

                    string xNameTry = "";

                    bool xTest = false;

                    do
                    {
                        xNameTry = (xShortName.Substring(0, 7 - n.ToString().Length) + "~" + n).ToUpperInvariant();

                        if (!string.IsNullOrEmpty(xExt))
                        {
                            xNameTry += '.' + xExt.ToUpperInvariant();
                        }

                        n++;

                        xTest = false;

                        foreach (string name in xShortFilenames)
                        {
                            if (name == xNameTry)
                            {
                                xTest = true;
                                break;
                            }
                        }
                    }
                    //TODO: Array.TrySZIndexOf plug is not being recognized; to use the generic version of IndexOf, just remove the cast to Array
                    //while (Array.IndexOf((Array)xShortFilenames, xNameTry) != -1);
                    while (xTest);

                    xShortName = xNameTry;

                    uint xChecksum = CalculateChecksum(GetShortName(xShortName));

                    int xNumEntries = (int)Math.Ceiling((double)xLongName.Length / (double)13);

                    char[] xLongNameWithPad = new char[xNumEntries * 13];

                    xLongNameWithPad[xLongNameWithPad.Length - 1] = (char)0xFFFF;
                    Array.Copy(xLongName.ToCharArray(), xLongNameWithPad, xLongName.Length);

                    xDirectoryEntriesToAllocate = GetNextUnallocatedDirectoryEntries(xNumEntries + 1);

                    for (int i = xNumEntries - 1; i >= 0; i--)
                    {
                        uint xEntry = xDirectoryEntriesToAllocate[xNumEntries - i - 1];

                        SetLongFilenameEntryMetadataValue(xEntry, FatDirectoryEntryMetadata.LongFilenameEntryMetadata.SequenceNumberAndAllocationStatus, (i + 1) | (i == xNumEntries - 1 ? (1 << 6) : 0));
                        SetLongFilenameEntryMetadataValue(xEntry, FatDirectoryEntryMetadata.LongFilenameEntryMetadata.Attributes, FatDirectoryEntryAttributeConsts.LongName);
                        SetLongFilenameEntryMetadataValue(xEntry, FatDirectoryEntryMetadata.LongFilenameEntryMetadata.Checksum, xChecksum);

                        SetLongFilenameEntryMetadataValue(xEntry, FatDirectoryEntryMetadata.LongFilenameEntryMetadata.LongName1, new string(xLongNameWithPad, i * 13, 5));
                        SetLongFilenameEntryMetadataValue(xEntry, FatDirectoryEntryMetadata.LongFilenameEntryMetadata.LongName2, new string(xLongNameWithPad, i * 13 + 5, 6));
                        SetLongFilenameEntryMetadataValue(xEntry, FatDirectoryEntryMetadata.LongFilenameEntryMetadata.LongName3, new string(xLongNameWithPad, i * 13 + 11, 2));
                    }
                }

                string xFullPath = Path.Combine(mFullPath, aName);
                uint xFirstCluster = ((FatFileSystem)mFileSystem).GetFat(0).GetNextUnallocatedFatEntry();
                uint xEntryHeaderDataOffset = xDirectoryEntriesToAllocate == null ? GetNextUnallocatedDirectoryEntry() : xDirectoryEntriesToAllocate[xDirectoryEntriesToAllocate.Length - 1];

                Global.mFileSystemDebugger.SendInternal("xFullPath =");
                Global.mFileSystemDebugger.SendInternal(xFullPath);
                Global.mFileSystemDebugger.SendInternal("xFirstCluster =");
                Global.mFileSystemDebugger.SendInternal(xFirstCluster);
                Global.mFileSystemDebugger.SendInternal("xEntryHeaderDataOffset =");
                Global.mFileSystemDebugger.SendInternal(xEntryHeaderDataOffset);

                var xNewEntry = new FatDirectoryEntry((FatFileSystem)mFileSystem, this, xFullPath, aName, 0, xFirstCluster, xEntryHeaderDataOffset, aEntryType);

                xNewEntry.AllocateDirectoryEntry(xShortName);

                return xNewEntry;
            }

            throw new ArgumentOutOfRangeException(nameof(aEntryType), "Unknown directory entry type.");
        }
Пример #22
0
 public FatDirectoryEntry AddDirectoryEntry(string aName, DirectoryEntryTypeEnum aType)
 {
     FileSystemHelpers.Debug("FatDirectoryEntry.AddDirectoryEntry");
     if ((aType == DirectoryEntryTypeEnum.Directory) || (aType == DirectoryEntryTypeEnum.File))
     {
         uint xFirstCluster = mFileSystem.GetFat(0).GetNextUnallocatedFatEntry();
         uint xEntryHeaderDataOffset = GetNextUnallocatedEntry();
         var xNewEntry = new FatDirectoryEntry(mFileSystem, this, aName, 0, xFirstCluster, xEntryHeaderDataOffset, aType);
         xNewEntry.AllocateDirectoryEntry();
         return xNewEntry;
     }
     throw new ArgumentOutOfRangeException("aType", "Unknown directory entry type.");
 }
Пример #23
0
 public FatDirectoryEntry AddDirectoryEntry(string aName, DirectoryEntryTypeEnum aType)
 {
     FileSystemHelpers.Debug("FatDirectoryEntry.AddDirectoryEntry", "aName =", aName, ", aType =", aType.ToString());
     if (aType == DirectoryEntryTypeEnum.Directory)
     {
         uint xFirstCluster = mFileSystem.GetFat(0).GetNextUnallocatedFatEntry();
         uint xEntryHeaderDataOffset = GetNextUnallocatedEntry();
         var xNewEntry = new FatDirectoryEntry(
             mFileSystem,
             this,
             aName,
             0,
             xFirstCluster,
             xEntryHeaderDataOffset,
             aType);
         xNewEntry.AllocateDirectoryEntry();
         return xNewEntry;
     }
     if (aType == DirectoryEntryTypeEnum.File)
     {
         throw new NotImplementedException("Creating new files is currently not implemented.");
     }
     throw new ArgumentOutOfRangeException("aType", "Unknown directory entry type.");
 }