コード例 #1
0
ファイル: Format.cs プロジェクト: GodLesZ/ZeusEngine
        /// <summary>
        /// Returns the file data, decompressed if needed
        /// </summary>
        /// <param name="item">The grf file</param>
        /// <param name="decompress">Should the data decompressed?</param>
        /// <returns></returns>
        public byte[] GetFileData(FileItem item, bool decompress)
        {
            byte[] buf       = null;
            bool   isUpdated = item.IsAdded || item.IsUpdated;

            if (isUpdated)
            {
                // Load data from file
                buf = File.ReadAllBytes(item.NewFilepath);
            }
            else if (item.FileData == null || item.FileData.Length != item.LengthCompressedAlign)
            {
                // Cache data
                CacheFileData(item);
                buf = item.FileData;
            }
            else
            {
                buf = item.FileData;
            }

            if (isUpdated == false && buf != null && buf.Length > 0)
            {
                // deocde, if needed
                if (item.Cycle >= 0 && Deflate.IsMagicHead(buf) == false)
                {
                    EncryptionHelper.DecryptFileData(buf, item.Cycle == 0, item.Cycle);
                }

                // Decompress data
                if (decompress)
                {
                    buf = Deflate.Decompress(buf);
                }
            }

            return(buf);
        }