update cache system
parent
c5c6e4ae23
commit
ef0cc05f5c
|
@ -3,10 +3,34 @@ using System.IO;
|
||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
[Serializable]
|
|
||||||
internal class CacheFileInfo
|
internal class CacheFileInfo
|
||||||
{
|
{
|
||||||
public string FileCRC;
|
private static readonly BufferWriter SharedBuffer = new BufferWriter(1024);
|
||||||
public long FileSize;
|
|
||||||
|
/// <summary>
|
||||||
|
/// 写入资源包信息
|
||||||
|
/// </summary>
|
||||||
|
public static void WriteInfoToFile(string filePath, string dataFileCRC, long dataFileSize)
|
||||||
|
{
|
||||||
|
using (FileStream fs = new FileStream(filePath, FileMode.Create))
|
||||||
|
{
|
||||||
|
SharedBuffer.Clear();
|
||||||
|
SharedBuffer.WriteUTF8(dataFileCRC);
|
||||||
|
SharedBuffer.WriteInt64(dataFileSize);
|
||||||
|
SharedBuffer.WriteToStream(fs);
|
||||||
|
fs.Flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 读取资源包信息
|
||||||
|
/// </summary>
|
||||||
|
public static void ReadInfoFromFile(string filePath, out string dataFileCRC, out long dataFileSize)
|
||||||
|
{
|
||||||
|
byte[] binaryData = FileUtility.ReadAllBytes(filePath);
|
||||||
|
BufferReader buffer = new BufferReader(binaryData);
|
||||||
|
dataFileCRC = buffer.ReadUTF8();
|
||||||
|
dataFileSize = buffer.ReadInt64();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -78,10 +78,7 @@ namespace YooAsset
|
||||||
return EVerifyResult.InfoFileNotExisted;
|
return EVerifyResult.InfoFileNotExisted;
|
||||||
|
|
||||||
// 解析信息文件获取验证数据
|
// 解析信息文件获取验证数据
|
||||||
string jsonContent = FileUtility.ReadAllText(infoFilePath);
|
CacheFileInfo.ReadInfoFromFile(infoFilePath, out element.DataFileCRC, out element.DataFileSize);
|
||||||
CacheFileInfo fileInfo = UnityEngine.JsonUtility.FromJson<CacheFileInfo>(jsonContent);
|
|
||||||
element.DataFileCRC = fileInfo.FileCRC;
|
|
||||||
element.DataFileSize = fileInfo.FileSize;
|
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
|
|
@ -220,22 +220,24 @@ namespace YooAsset
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string destFilePath = _bundleInfo.Bundle.CachedDataFilePath;
|
string infoFilePath = _bundleInfo.Bundle.CachedInfoFilePath;
|
||||||
if (File.Exists(destFilePath))
|
string dataFilePath = _bundleInfo.Bundle.CachedDataFilePath;
|
||||||
File.Delete(destFilePath);
|
string dataFileCRC = _bundleInfo.Bundle.FileCRC;
|
||||||
|
long dataFileSize = _bundleInfo.Bundle.FileSize;
|
||||||
|
|
||||||
|
if (File.Exists(infoFilePath))
|
||||||
|
File.Delete(infoFilePath);
|
||||||
|
if (File.Exists(dataFilePath))
|
||||||
|
File.Delete(dataFilePath);
|
||||||
|
|
||||||
FileInfo fileInfo = new FileInfo(_tempFilePath);
|
FileInfo fileInfo = new FileInfo(_tempFilePath);
|
||||||
fileInfo.MoveTo(destFilePath);
|
fileInfo.MoveTo(dataFilePath);
|
||||||
|
|
||||||
// 写入信息文件记录验证数据
|
// 写入信息文件记录验证数据
|
||||||
CacheFileInfo cacheInfo = new CacheFileInfo();
|
CacheFileInfo.WriteInfoToFile(infoFilePath, dataFileCRC, dataFileSize);
|
||||||
cacheInfo.FileCRC = _bundleInfo.Bundle.FileCRC;
|
|
||||||
cacheInfo.FileSize = _bundleInfo.Bundle.FileSize;
|
|
||||||
string jsonContent = UnityEngine.JsonUtility.ToJson(cacheInfo);
|
|
||||||
FileUtility.CreateFile(_bundleInfo.Bundle.CachedInfoFilePath, jsonContent);
|
|
||||||
|
|
||||||
// 记录缓存文件
|
// 记录缓存文件
|
||||||
var wrapper = new PackageCache.RecordWrapper(_bundleInfo.Bundle.CachedInfoFilePath, _bundleInfo.Bundle.CachedDataFilePath, _bundleInfo.Bundle.FileCRC, _bundleInfo.Bundle.FileSize);
|
var wrapper = new PackageCache.RecordWrapper(infoFilePath, dataFilePath, dataFileCRC, dataFileSize);
|
||||||
CacheSystem.RecordFile(_bundleInfo.Bundle.PackageName, _bundleInfo.Bundle.CacheGUID, wrapper);
|
CacheSystem.RecordFile(_bundleInfo.Bundle.PackageName, _bundleInfo.Bundle.CacheGUID, wrapper);
|
||||||
|
|
||||||
_lastError = string.Empty;
|
_lastError = string.Empty;
|
||||||
|
|
|
@ -8,6 +8,8 @@ namespace YooAsset
|
||||||
{
|
{
|
||||||
internal static class PatchManifestTools
|
internal static class PatchManifestTools
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#if UNITY_EDITOR
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 序列化(JSON文件)
|
/// 序列化(JSON文件)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -151,6 +153,7 @@ namespace YooAsset
|
||||||
|
|
||||||
return manifest;
|
return manifest;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 生成Bundle文件的正式名称
|
/// 生成Bundle文件的正式名称
|
||||||
|
|
|
@ -28,6 +28,14 @@ namespace YooAsset
|
||||||
get { return _buffer.Length; }
|
get { return _buffer.Length; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 清空缓冲区
|
||||||
|
/// </summary>
|
||||||
|
public void Clear()
|
||||||
|
{
|
||||||
|
_index = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 将有效数据写入文件流
|
/// 将有效数据写入文件流
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Loading…
Reference in New Issue