예제 #1
0
        private static GrfItem Create
        (
            GrfArchive grf,
            string name,
            int compressedLength,
            int compressedLengthAligned,
            int realLength,
            GrfFileFlags flags,
            int position
        )
        {
            GrfItem ret;

            if (IsDirectory(compressedLength, compressedLengthAligned, realLength, flags, position))
            {
                ret = new GrfDirectoryInfo();
            }
            else
            {
                ret = new GrfFileInfo();
            }

            ret.m_Grf  = grf;
            ret.m_Name = FilenameEncoding.Encode(name);
            ret.m_AlignedCompressedLength = compressedLengthAligned;
            ret.m_CompressedLength        = compressedLength;
            ret.m_Length   = realLength;
            ret.m_Flags    = flags;
            ret.m_Position = position;
            ret.m_Hash     = NameHash(ret.m_Name);

            return(ret);
        }
예제 #2
0
        /// <summary>
        /// Adds a new <see cref="GrfItem"/> to the <see cref="GrfArchive"/>.
        /// </summary>
        /// <param name="grfname">The filename inside the <see cref="GrfArchive"/>.</param>
        /// <param name="flags">The <see cref="GrfFileFlags"/> for this entry.</param>
        /// <param name="data">The data of the file, or null if the <see cref="GrfItem"/> is a folder.</param>
        /// <exception cref="ObjectDisposedException">
        /// Thrown when the <see cref="GrfArchive"/> is closed.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// Thrown when the grfname is null or empty, or when the flags indicate a file and the data is null.
        /// </exception>
        /// <exception cref="AccessViolationException">
        /// Thrown when the <see cref="GrfArchive"/> is read-only.
        /// </exception>
        private void Add(string grfname, GrfFileFlags flags, byte[] data)
        {
            if (m_Grf.IsDisposed)
            {
                throw new ObjectDisposedException(m_Grf.GetType().Name);
            }

            if (m_Grf.IsReadOnly)
            {
                throw new AccessViolationException("The GrfArchive is read-only");
            }

            if (string.IsNullOrEmpty(grfname))
            {
                throw new ArgumentNullException("filename");
            }

            if ((flags & GrfFileFlags.File) == GrfFileFlags.File && data == null)
            {
                throw new ArgumentNullException("data");
            }

            GrfItem add;
            int     i = IndexOf(grfname);

            if ((flags & GrfFileFlags.File) == GrfFileFlags.None || data == null)
            {
                add = new GrfDirectoryInfo(m_Grf, grfname, flags);
            }
            else
            {
                add = new GrfFileInfo(m_Grf, grfname, flags, data);
            }

            if (i >= 0)
            {
                m_Items[i] = add;
            }
            else
            {
                m_Items.Add(add);
            }

            m_Grf.Modified = true;
        }
예제 #3
0
        /// <summary>
        /// Adds a <see cref="GrfItem"/> to the <see cref="GrfArchive"/>.
        /// </summary>
        /// <param name="item">The <see cref="GrfItem"/> to add.</param>
        /// <exception cref="ObjectDisposedException">
        /// Thrown when the <see cref="GrfArchive"/> is closed.
        /// </exception>
        /// <exception cref="AccessViolationException">
        /// Thrown when the <see cref="GrfArchive"/> is read-only.
        /// </exception>
        public void Add(GrfItem item)
        {
            if (m_Grf.IsDisposed)
            {
                throw new ObjectDisposedException(m_Grf.GetType().Name);
            }

            if (m_Grf.IsReadOnly)
            {
                throw new AccessViolationException("The GrfArchive is read-only");
            }

            int i = IndexOf(item.Name);

            if (item is GrfDirectoryInfo)
            {
                GrfDirectoryInfo add = new GrfDirectoryInfo(m_Grf, item.Name, item.Flags);
                if (i < 0)
                {
                    GrfAdd(add);
                }
                else
                {
                    m_Items[i] = add;
                }
            }
            else if (item is GrfFileInfo)
            {
                GrfFileInfo add, file = (GrfFileInfo)item;

                add = new GrfFileInfo(m_Grf, item.Name, item.Flags, file.Data);

                if (i < 0)
                {
                    GrfAdd(add);
                }
                else
                {
                    m_Items[i] = add;
                }
            }
        }