Ejemplo n.º 1
0
        public void GenerateBin(string path, HotfixFileFormat format, int hotVersion)
        {
            HotVersion = hotVersion;

            if (FileItems == null || FileItems.Count == 0)
            {
                return;
            }

            byte[] contentBuffer;
            using (MemoryStream stream = new MemoryStream())
            {
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(stream, this);

                contentBuffer = stream.GetBuffer();
            }

            using (FileStream fileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None))
            {
                BinaryWriter br = new BinaryWriter(fileStream);
                br.Write(FileHeader);
                br.Write(FileVersion);
                br.Write((int)HotfixFileFormat);

                if (HotfixFileFormat == HotfixFileFormat.EncryptZip)
                {
                    contentBuffer = Encrypt(contentBuffer);
                }

                br.Write(contentBuffer);
                br.Close();
            }
        }
Ejemplo n.º 2
0
        public static HotfixIndexFile Deserialize(byte[] bytes)
        {
            MemoryStream stream       = new MemoryStream(bytes);
            BinaryReader binaryReader = new BinaryReader(stream);

            string header = Encoding.UTF8.GetString(binaryReader.ReadBytes(4));

            if (header.Contains(FileHeader) == false)
            {
                Debug.LogError("HotfixIndexFile: File Format Error");
                return(null);
            }

            int fileVersion         = binaryReader.ReadInt32();
            HotfixFileFormat format = (HotfixFileFormat)binaryReader.ReadInt32();

            BinaryFormatter b   = new BinaryFormatter();
            HotfixIndexFile clz = b.Deserialize(stream) as HotfixIndexFile;

            stream.Close();
            binaryReader.Close();

            return(clz);
        }