コード例 #1
0
ファイル: FatLfnDirectory.cs プロジェクト: riina/fat32lib.NET
        /// <summary>
        /// Unlinks the specified entry from this directory without actually
        /// deleting it.
        /// </summary>
        /// <param name="entry">the entry to be unlinked</param>
        /// <seealso cref="LinkEntry(FatLfnDirectoryEntry)"/>
        internal void UnlinkEntry(FatLfnDirectoryEntry entry)
        {
            var sn = entry.RealEntry.GetShortName();

            if (sn.Equals(ShortName.Dot) || sn.Equals(ShortName.DotDot))
            {
                throw
                    new ArgumentException(
                        "the dot entries can not be removed");
            }

            var lowerName = entry.GetName().ToLowerInvariant();

            if (!longNameIndex.ContainsKey(lowerName))
            {
                throw new Exception();
            }
            longNameIndex.Remove(lowerName);

            if (!shortNameIndex.ContainsKey(sn))
            {
                throw new Exception();
            }
            shortNameIndex.Remove(sn);

            if (entry.IsFile())
            {
                entryToFile.Remove(entry.RealEntry);
            }
            else
            {
                entryToDirectory.Remove(entry.RealEntry);
            }
        }
コード例 #2
0
ファイル: FatLfnDirectory.cs プロジェクト: riina/fat32lib.NET
        /// <summary>
        /// According to the FAT file system specification, leading and trailing
        /// spaces in the name are ignored by this method.
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        /// <exception cref="IOException"></exception>
        public IFsDirectoryEntry AddDirectory(string name)
        {
            CheckWritable();
            CheckUniqueName(name);

            name = name.Trim();
            var sn   = MakeShortName(name, true);
            var real = Dir.CreateSub(fat);

            real.SetShortName(sn);
            var e = new FatLfnDirectoryEntry(this, real, name);

            try {
                Dir.AddEntries(e.CompactForm());
            }
            catch (IOException ex) {
                var cc = new ClusterChain(fat, real.GetStartCluster(), false);
                cc.SetChainLength(0);
                Dir.RemoveEntry(real);
                throw ex;
            }

            shortNameIndex.Add(sn, e);
            longNameIndex.Add(name.ToLowerInvariant(), e);

            GetDirectory(real);

            Flush();
            return(e);
        }
コード例 #3
0
ファイル: FatLfnDirectory.cs プロジェクト: riina/fat32lib.NET
        /// <summary>
        /// Links the specified entry to this directory, updating the entrie's
        /// short name.
        /// </summary>
        /// <param name="entry">the entry to be linked (added) to this directory</param>
        /// <seealso cref="UnlinkEntry(FatLfnDirectoryEntry)"/>
        internal void LinkEntry(FatLfnDirectoryEntry entry)
        {
            CheckUniqueName(entry.GetName());
            ShortName name;

            name = dbg.Generate83BufferNew(entry.GetName());
            entry.RealEntry.SetShortName(name);

            longNameIndex.Add(entry.GetName().ToLowerInvariant(), entry);
            shortNameIndex.Add(entry.RealEntry.GetShortName(), entry);

            UpdateLfn();
        }
コード例 #4
0
ファイル: FatLfnDirectory.cs プロジェクト: riina/fat32lib.NET
        private void ParseLfn()
        {
            var i    = 0;
            var size = Dir.GetEntryCount();

            while (i < size)
            {
                // jump over empty entries
                while (i < size && Dir.GetEntry(i) == null)
                {
                    i++;
                }

                if (i >= size)
                {
                    break;
                }

                var offset = i; // beginning of the entry
                                // check when we reach a real entry
                while (Dir.GetEntry(i).IsLfnEntry())
                {
                    i++;
                    if (i >= size)
                    {
                        // This is a cutted entry, forgive it
                        break;
                    }
                }

                if (i >= size)
                {
                    // This is a cutted entry, forgive it
                    break;
                }

                var current =
                    FatLfnDirectoryEntry.Extract(this, offset, ++i - offset);

                if (!current.RealEntry.IsDeleted() && current.IsValid())
                {
                    CheckUniqueName(current.GetName());

                    shortNameIndex.Add(current.RealEntry.GetShortName(), current);
                    longNameIndex.Add(current.GetName().ToLowerInvariant(), current);
                }
            }
        }
コード例 #5
0
ファイル: FatLfnDirectory.cs プロジェクト: riina/fat32lib.NET
        /// <summary>
        /// According to the FAT file system specification, leading and trailing
        /// spaces in the name are ignored by this method.
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        /// <exception cref="IOException"></exception>
        public IFsDirectoryEntry AddFile(string name)
        {
            CheckWritable();
            CheckUniqueName(name);

            name = name.Trim();
            var sn = MakeShortName(name, false);

            var entry = new FatLfnDirectoryEntry(name, sn, this, false);

            Dir.AddEntries(entry.CompactForm());

            shortNameIndex.Add(sn, entry);
            longNameIndex.Add(name.ToLowerInvariant(), entry);

            GetFile(entry.RealEntry);

            Dir.SetDirty();
            return(entry);
        }