Beispiel #1
0
        private static FileType CheckFileType(EndianBinaryReader reader)
        {
            //去除新版前8个空字节
            bool haveNullByte = false;
            var  b            = reader.PeekChar();

            if (b == 0)
            {
                reader.ReadBytes(8);
                haveNullByte = true;
            }

            var signature = reader.ReadStringToNull(20);

            if (!haveNullByte)
            {
                reader.Position = 0;
            }
            else
            {
                reader.Position = 8;
            }

            switch (signature)
            {
            case "UnityWeb":
            case "UnityRaw":
            case "\xFA\xFA\xFA\xFA\xFA\xFA\xFA\xFA":
            case "UnityFS":
                return(FileType.BundleFile);

            case "UnityWebData1.0":
                return(FileType.WebFile);

            default:
            {
                var magic = reader.ReadBytes(2);
                reader.Position = 0;
                if (WebFile.gzipMagic.SequenceEqual(magic))
                {
                    return(FileType.WebFile);
                }
                reader.Position = 0x20;
                magic           = reader.ReadBytes(6);
                reader.Position = 0;
                if (WebFile.brotliMagic.SequenceEqual(magic))
                {
                    return(FileType.WebFile);
                }
                return(FileType.AssetsFile);
            }
            }
        }