123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- //------------------------------------------------------------
- // Game Framework
- // Copyright © 2013-2021 loyalsoft. All rights reserved.
- // Homepage: http://www.game7000.com/
- // Feedback: http://www.game7000.com/
- //------------------------------------------------------------
- using GameFramework;
- using GameFramework.Resource;
- using System;
- using System.IO;
- using System.Text;
- namespace UnityGameFramework.Runtime
- {
- /// <summary>
- /// 内置版本资源列表序列化器。
- /// </summary>
- public static partial class BuiltinVersionListSerializer
- {
- /// <summary>
- /// 序列化本地版本资源列表(版本 0)回调函数。
- /// </summary>
- /// <param name="stream">目标流。</param>
- /// <param name="versionList">要序列化的本地版本资源列表(版本 0)。</param>
- /// <returns>是否序列化本地版本资源列表(版本 0)成功。</returns>
- public static bool LocalVersionListSerializeCallback_V0(Stream stream, LocalVersionList versionList)
- {
- if (!versionList.IsValid)
- {
- return false;
- }
- Utility.Random.GetRandomBytes(s_CachedHashBytes);
- using (BinaryWriter binaryWriter = new BinaryWriter(stream, Encoding.UTF8))
- {
- binaryWriter.Write(s_CachedHashBytes);
- LocalVersionList.Resource[] resources = versionList.GetResources();
- binaryWriter.Write(resources.Length);
- foreach (LocalVersionList.Resource resource in resources)
- {
- binaryWriter.WriteEncryptedString(resource.Name, s_CachedHashBytes);
- binaryWriter.WriteEncryptedString(resource.Variant, s_CachedHashBytes);
- binaryWriter.Write(resource.LoadType);
- binaryWriter.Write(resource.Length);
- binaryWriter.Write(resource.HashCode);
- }
- }
- Array.Clear(s_CachedHashBytes, 0, CachedHashBytesLength);
- return true;
- }
- /// <summary>
- /// 序列化本地版本资源列表(版本 1)回调函数。
- /// </summary>
- /// <param name="stream">目标流。</param>
- /// <param name="versionList">要序列化的本地版本资源列表(版本 1)。</param>
- /// <returns>是否序列化本地版本资源列表(版本 1)成功。</returns>
- public static bool LocalVersionListSerializeCallback_V1(Stream stream, LocalVersionList versionList)
- {
- if (!versionList.IsValid)
- {
- return false;
- }
- Utility.Random.GetRandomBytes(s_CachedHashBytes);
- using (BinaryWriter binaryWriter = new BinaryWriter(stream, Encoding.UTF8))
- {
- binaryWriter.Write(s_CachedHashBytes);
- LocalVersionList.Resource[] resources = versionList.GetResources();
- binaryWriter.Write7BitEncodedInt32(resources.Length);
- foreach (LocalVersionList.Resource resource in resources)
- {
- binaryWriter.WriteEncryptedString(resource.Name, s_CachedHashBytes);
- binaryWriter.WriteEncryptedString(resource.Variant, s_CachedHashBytes);
- binaryWriter.WriteEncryptedString(resource.Extension != DefaultExtension ? resource.Extension : null, s_CachedHashBytes);
- binaryWriter.Write(resource.LoadType);
- binaryWriter.Write7BitEncodedInt32(resource.Length);
- binaryWriter.Write(resource.HashCode);
- }
- }
- Array.Clear(s_CachedHashBytes, 0, CachedHashBytesLength);
- return true;
- }
- /// <summary>
- /// 序列化本地版本资源列表(版本 2)回调函数。
- /// </summary>
- /// <param name="stream">目标流。</param>
- /// <param name="versionList">要序列化的本地版本资源列表(版本 2)。</param>
- /// <returns>是否序列化本地版本资源列表(版本 2)成功。</returns>
- public static bool LocalVersionListSerializeCallback_V2(Stream stream, LocalVersionList versionList)
- {
- if (!versionList.IsValid)
- {
- return false;
- }
- Utility.Random.GetRandomBytes(s_CachedHashBytes);
- using (BinaryWriter binaryWriter = new BinaryWriter(stream, Encoding.UTF8))
- {
- binaryWriter.Write(s_CachedHashBytes);
- LocalVersionList.Resource[] resources = versionList.GetResources();
- binaryWriter.Write7BitEncodedInt32(resources.Length);
- foreach (LocalVersionList.Resource resource in resources)
- {
- binaryWriter.WriteEncryptedString(resource.Name, s_CachedHashBytes);
- binaryWriter.WriteEncryptedString(resource.Variant, s_CachedHashBytes);
- binaryWriter.WriteEncryptedString(resource.Extension != DefaultExtension ? resource.Extension : null, s_CachedHashBytes);
- binaryWriter.Write(resource.LoadType);
- binaryWriter.Write7BitEncodedInt32(resource.Length);
- binaryWriter.Write(resource.HashCode);
- }
- LocalVersionList.FileSystem[] fileSystems = versionList.GetFileSystems();
- binaryWriter.Write7BitEncodedInt32(fileSystems.Length);
- foreach (LocalVersionList.FileSystem fileSystem in fileSystems)
- {
- binaryWriter.WriteEncryptedString(fileSystem.Name, s_CachedHashBytes);
- int[] resourceIndexes = fileSystem.GetResourceIndexes();
- binaryWriter.Write7BitEncodedInt32(resourceIndexes.Length);
- foreach (int resourceIndex in resourceIndexes)
- {
- binaryWriter.Write7BitEncodedInt32(resourceIndex);
- }
- }
- }
- Array.Clear(s_CachedHashBytes, 0, CachedHashBytesLength);
- return true;
- }
- }
- }
|