Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
 internal GrfFileInfo(GrfArchive grf, string name, GrfFileFlags flags, byte[] data)
 {
     m_Grf   = grf;
     m_Flags = flags;
     m_Name  = FilenameEncoding.Encode(name);
     m_Hash  = NameHash(m_Name);
     Data    = data;
 }
Ejemplo n.º 3
0
        internal GrfDirectoryInfo(GrfArchive grf, string name, GrfFileFlags flags)
        {
            m_Grf   = grf;
            m_Flags = flags;
            m_Name  = FilenameEncoding.Encode(name);
            m_Hash  = NameHash(m_Name);

            m_AlignedCompressedLength = GRFFILE_DIR_SZFILE;
            m_CompressedLength        = GRFFILE_DIR_SZSMALL;
            m_Length   = GRFFILE_DIR_SZORIG;
            m_Position = GRFFILE_DIR_OFFSET;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a hash from a filename.
        /// </summary>
        /// <param name="name">The filename.</param>
        /// <returns>A hash from the specified filename.</returns>
        public static uint NameHash(string name)
        {
            uint tmp = 0;

            name = FilenameEncoding.Encode(name);

            for (int i = 0; i < name.Length; i++)
            {
                tmp = (tmp << 5) + tmp + name.ToUpper()[i];
            }

            return(tmp);
        }