Exemplo 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);
        }
Exemplo n.º 2
0
        internal static GrfItem CreateV1(GrfArchive grf, string name, int compressedLength, int compressedLengthAligned, int realLength, GrfFileFlags flags, int position)
        {
            GrfItem ret = Create(grf, name, compressedLength, compressedLengthAligned, realLength, flags, position);

            ret.m_Flags |= (CheckExtension(name) ? GrfFileFlags.Des_0x14 : GrfFileFlags.MixCrypt);
            return(ret);
        }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
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;
 }
Exemplo n.º 5
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;
        }
Exemplo n.º 6
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;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Merges another <see cref="GrfArchive"/> with this <see cref="GrfArchive"/>.
        /// </summary>
        /// <param name="grf">The <see cref="GrfArchive"/> to add the current one.</param>
        /// <exception cref="ObjectDisposedException">
        /// Thrown when the <see cref="GrfArchive"/> is closed.
        /// </exception>
        public void Merge(GrfArchive grf)
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(this.GetType().Name);
            }

            for (int i = 0; i < grf.m_Items.Count; i++)
            {
                m_Items.Add(grf.m_Items[i]);
            }
        }
Exemplo n.º 8
0
        static void AddFiles(GrfArchive grf, DirectoryInfo dir, DirectoryInfo root)
        {
            foreach (FileInfo file in dir.GetFiles())
            {
                Console.Write("Adding '{0}'... ", file.Name);
                grf.Items.AddFile(file.FullName.Substring(root.FullName.Length + 1), file.FullName);
                Console.WriteLine("added.");
            }

            foreach (DirectoryInfo d in dir.GetDirectories())
            {
                AddFiles(grf, d, root);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Opens an existing <see cref="GrfArchive"/>.
        /// </summary>
        /// <param name="filename">The path to the <see cref="GrfArchive"/>.</param>
        /// <param name="isreadonly">Wether or not to open the file as read only.</param>
        /// <returns>The opened <see cref="GrfArchive"/>.</returns>
        public static GrfArchive Open(string filename, bool isreadonly)
        {
            if (string.IsNullOrEmpty(filename))
            {
                throw new GrfException();
            }

            GrfArchive grf = new GrfArchive();

            grf.FileStream = isreadonly ? File.OpenRead(filename) : File.Open(filename, FileMode.OpenOrCreate);
            grf.ReadHeader();

            return(grf);
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            Console.Write("Please enter a filename: ");
            string name = Console.ReadLine();
            Console.Write("Please enter a folder to add the files from: ");
            string folder = Console.ReadLine();

            using (GrfArchive grf = new GrfArchive(name))
            {
                DirectoryInfo dir = new DirectoryInfo(folder);
                AddFiles(grf, dir, dir);
            }

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
Exemplo n.º 11
0
 internal static GrfItem CreateV2(GrfArchive grf, string name, int compressedLength, int compressedLengthAligned, int realLength, GrfFileFlags flags, int position)
 {
     return(Create(grf, name, compressedLength, compressedLengthAligned, realLength, flags, position));
 }
Exemplo n.º 12
0
 internal GrfItemCollection(GrfArchive grf)
 {
     m_Items = new List <GrfItem>();
     m_Grf   = grf;
 }
Exemplo n.º 13
0
        /// <summary>
        /// Merges another <see cref="GrfArchive"/> with this <see cref="GrfArchive"/>.
        /// </summary>
        /// <param name="grf">The <see cref="GrfArchive"/> to add the current one.</param>
        /// <exception cref="ObjectDisposedException">
        /// Thrown when the <see cref="GrfArchive"/> is closed.
        /// </exception>
        public void Merge(GrfArchive grf)
        {
            if (IsDisposed)
                throw new ObjectDisposedException(this.GetType().Name);

            for (int i = 0; i < grf.m_Items.Count; i++)
                m_Items.Add(grf.m_Items[i]);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Opens an existing <see cref="GrfArchive"/>.
        /// </summary>
        /// <param name="filename">The path to the <see cref="GrfArchive"/>.</param>
        /// <param name="isreadonly">Wether or not to open the file as read only.</param>
        /// <returns>The opened <see cref="GrfArchive"/>.</returns>
        public static GrfArchive Open(string filename, bool isreadonly)
        {
            if (string.IsNullOrEmpty(filename))
                throw new GrfException();

            GrfArchive grf = new GrfArchive();
            grf.FileStream = isreadonly ? File.OpenRead(filename) : File.Open(filename, FileMode.OpenOrCreate);
            grf.ReadHeader();

            return grf;
        }