Update patch manifest

pull/28/head
hevinci 2022-07-25 15:46:20 +08:00
parent e5c7bbdf52
commit d0b7ae020c
10 changed files with 86 additions and 35 deletions

View File

@ -61,8 +61,7 @@ namespace YooAsset
// 1. 从服务器或缓存中获取AssetBundle文件 // 1. 从服务器或缓存中获取AssetBundle文件
if (_steps == ESteps.LoadFile) if (_steps == ESteps.LoadFile)
{ {
string hash = StringUtility.RemoveExtension(MainBundleInfo.Hash); _webRequest = UnityWebRequestAssetBundle.GetAssetBundle(_webURL, Hash128.Parse(MainBundleInfo.Hash));
_webRequest = UnityWebRequestAssetBundle.GetAssetBundle(_webURL, Hash128.Parse(hash));
_webRequest.SendWebRequest(); _webRequest.SendWebRequest();
_steps = ESteps.CheckFile; _steps = ESteps.CheckFile;
} }

View File

@ -240,7 +240,7 @@ namespace YooAsset
{ {
if (DownloadSystem.CheckContentIntegrity(GetCachePath(), _bundleInfo.SizeBytes, _bundleInfo.CRC)) if (DownloadSystem.CheckContentIntegrity(GetCachePath(), _bundleInfo.SizeBytes, _bundleInfo.CRC))
{ {
DownloadSystem.CacheVerifyFile(_bundleInfo.Hash, _bundleInfo.BundleName); DownloadSystem.CacheVerifyFile(_bundleInfo.Hash, _bundleInfo.FileName);
_steps = ESteps.CheckAndCopyFile; _steps = ESteps.CheckAndCopyFile;
} }
else else
@ -423,7 +423,7 @@ namespace YooAsset
{ {
if (DownloadSystem.CheckContentIntegrity(GetCachePath(), _bundleInfo.SizeBytes, _bundleInfo.CRC)) if (DownloadSystem.CheckContentIntegrity(GetCachePath(), _bundleInfo.SizeBytes, _bundleInfo.CRC))
{ {
DownloadSystem.CacheVerifyFile(_bundleInfo.Hash, _bundleInfo.BundleName); DownloadSystem.CacheVerifyFile(_bundleInfo.Hash, _bundleInfo.FileName);
_steps = ESteps.CheckAndCopyFile; _steps = ESteps.CheckAndCopyFile;
} }
else else

View File

@ -88,7 +88,7 @@ namespace YooAsset
// 创建新的下载器 // 创建新的下载器
{ {
YooLogger.Log($"Beginning to download file : {bundleInfo.BundleName} URL : {bundleInfo.RemoteMainURL}"); YooLogger.Log($"Beginning to download file : {bundleInfo.FileName} URL : {bundleInfo.RemoteMainURL}");
FileUtility.CreateFileDirectory(bundleInfo.GetCacheLoadPath()); FileUtility.CreateFileDirectory(bundleInfo.GetCacheLoadPath());
DownloaderBase newDownloader; DownloaderBase newDownloader;
if (bundleInfo.SizeBytes >= _breakpointResumeFileSize) if (bundleInfo.SizeBytes >= _breakpointResumeFileSize)
@ -117,16 +117,16 @@ namespace YooAsset
{ {
if (_cachedHashList.ContainsKey(hash)) if (_cachedHashList.ContainsKey(hash))
{ {
string filePath = SandboxHelper.MakeCacheFilePath(hash); string fileName = _cachedHashList[hash];
string filePath = SandboxHelper.MakeCacheFilePath(fileName);
if (File.Exists(filePath)) if (File.Exists(filePath))
{ {
return true; return true;
} }
else else
{ {
string bundleName = _cachedHashList[hash];
_cachedHashList.Remove(hash); _cachedHashList.Remove(hash);
YooLogger.Error($"Cache file is missing : {bundleName} Hash : {hash}"); YooLogger.Error($"Cache file is missing : {fileName}");
return false; return false;
} }
} }
@ -139,12 +139,12 @@ namespace YooAsset
/// <summary> /// <summary>
/// 缓存验证过的文件 /// 缓存验证过的文件
/// </summary> /// </summary>
public static void CacheVerifyFile(string hash, string bundleName) public static void CacheVerifyFile(string hash, string fileName)
{ {
if (_cachedHashList.ContainsKey(hash) == false) if (_cachedHashList.ContainsKey(hash) == false)
{ {
YooLogger.Log($"Cache verify file : {bundleName} Hash : {hash}"); YooLogger.Log($"Cache verify file : {fileName}");
_cachedHashList.Add(hash, bundleName); _cachedHashList.Add(hash, fileName);
} }
} }

View File

@ -81,7 +81,6 @@ namespace YooAsset
if (hasError == false) if (hasError == false)
{ {
// 注意:如果文件验证失败需要删除文件 // 注意:如果文件验证失败需要删除文件
if (DownloadSystem.CheckContentIntegrity(_bundleInfo.GetCacheLoadPath(), _bundleInfo.SizeBytes, _bundleInfo.CRC) == false) if (DownloadSystem.CheckContentIntegrity(_bundleInfo.GetCacheLoadPath(), _bundleInfo.SizeBytes, _bundleInfo.CRC) == false)
{ {
hasError = true; hasError = true;
@ -92,7 +91,7 @@ namespace YooAsset
if (hasError == false) if (hasError == false)
{ {
_steps = ESteps.Succeed; _steps = ESteps.Succeed;
DownloadSystem.CacheVerifyFile(_bundleInfo.Hash, _bundleInfo.BundleName); DownloadSystem.CacheVerifyFile(_bundleInfo.Hash, _bundleInfo.FileName);
} }
else else
{ {

View File

@ -21,7 +21,7 @@ namespace YooAsset
private bool _running = true; private bool _running = true;
private string _url; private string _url;
private string _savePath; private string _savePath;
private string _fileHash; private string _fileName;
private string _fileCRC; private string _fileCRC;
private long _fileSize; private long _fileSize;
private int _timeout; private int _timeout;
@ -50,11 +50,11 @@ namespace YooAsset
/// <summary> /// <summary>
/// 开始下载 /// 开始下载
/// </summary> /// </summary>
public void Run(string url, string savePath, string fileHash, string fileCRC, long fileSize, int timeout) public void Run(string url, string savePath, string fileName, string fileCRC, long fileSize, int timeout)
{ {
_url = url; _url = url;
_savePath = savePath; _savePath = savePath;
_fileHash = fileHash; _fileName = fileName;
_fileCRC = fileCRC; _fileCRC = fileCRC;
_fileSize = fileSize; _fileSize = fileSize;
_timeout = timeout; _timeout = timeout;
@ -159,14 +159,14 @@ namespace YooAsset
bool verfiyResult = DownloadSystem.CheckContentIntegrity(_savePath, _fileSize, _fileCRC); bool verfiyResult = DownloadSystem.CheckContentIntegrity(_savePath, _fileSize, _fileCRC);
if (verfiyResult == false) if (verfiyResult == false)
{ {
Error = $"Verify download content failed : {_fileHash}"; Error = $"Verify download content failed : {_fileName}";
if (File.Exists(_savePath)) if (File.Exists(_savePath))
File.Delete(_savePath); File.Delete(_savePath);
} }
} }
else else
{ {
Error = $"Download content is incomplete : {_fileHash}"; Error = $"Download content is incomplete : {_fileName}";
} }
IsDone = true; IsDone = true;
@ -197,7 +197,7 @@ namespace YooAsset
_requestURL = GetRequestURL(); _requestURL = GetRequestURL();
_threadDownloader = new ThreadDownloader(); _threadDownloader = new ThreadDownloader();
_threadDownloader.Run(_requestURL, _bundleInfo.GetCacheLoadPath(), _bundleInfo.Hash, _bundleInfo.CRC, _bundleInfo.SizeBytes, _timeout); _threadDownloader.Run(_requestURL, _bundleInfo.GetCacheLoadPath(), _bundleInfo.FileName, _bundleInfo.CRC, _bundleInfo.SizeBytes, _timeout);
_steps = ESteps.CheckDownload; _steps = ESteps.CheckDownload;
} }
@ -226,7 +226,7 @@ namespace YooAsset
} }
else else
{ {
DownloadSystem.CacheVerifyFile(_bundleInfo.Hash, _bundleInfo.BundleName); DownloadSystem.CacheVerifyFile(_bundleInfo.Hash, _bundleInfo.FileName);
_steps = ESteps.Succeed; _steps = ESteps.Succeed;
} }
} }

View File

@ -23,6 +23,11 @@ namespace YooAsset
/// </summary> /// </summary>
public string BundleName { private set; get; } public string BundleName { private set; get; }
/// <summary>
/// 文件名称
/// </summary>
public string FileName { private set; get; }
/// <summary> /// <summary>
/// 远端下载地址 /// 远端下载地址
/// </summary> /// </summary>
@ -128,6 +133,7 @@ namespace YooAsset
_patchBundle = patchBundle; _patchBundle = patchBundle;
LoadMode = loadMode; LoadMode = loadMode;
BundleName = patchBundle.BundleName; BundleName = patchBundle.BundleName;
FileName = patchBundle.FileName;
RemoteMainURL = mainURL; RemoteMainURL = mainURL;
RemoteFallbackURL = fallbackURL; RemoteFallbackURL = fallbackURL;
EditorAssetPath = string.Empty; EditorAssetPath = string.Empty;
@ -137,6 +143,7 @@ namespace YooAsset
_patchBundle = patchBundle; _patchBundle = patchBundle;
LoadMode = loadMode; LoadMode = loadMode;
BundleName = patchBundle.BundleName; BundleName = patchBundle.BundleName;
FileName = patchBundle.FileName;
RemoteMainURL = string.Empty; RemoteMainURL = string.Empty;
RemoteFallbackURL = string.Empty; RemoteFallbackURL = string.Empty;
EditorAssetPath = editorAssetPath; EditorAssetPath = editorAssetPath;
@ -146,6 +153,7 @@ namespace YooAsset
_patchBundle = patchBundle; _patchBundle = patchBundle;
LoadMode = loadMode; LoadMode = loadMode;
BundleName = patchBundle.BundleName; BundleName = patchBundle.BundleName;
FileName = patchBundle.FileName;
RemoteMainURL = string.Empty; RemoteMainURL = string.Empty;
RemoteFallbackURL = string.Empty; RemoteFallbackURL = string.Empty;
EditorAssetPath = string.Empty; EditorAssetPath = string.Empty;
@ -160,7 +168,7 @@ namespace YooAsset
return string.Empty; return string.Empty;
if (string.IsNullOrEmpty(_streamingPath)) if (string.IsNullOrEmpty(_streamingPath))
_streamingPath = PathHelper.MakeStreamingLoadPath(_patchBundle.Hash); _streamingPath = PathHelper.MakeStreamingLoadPath(_patchBundle.FileName);
return _streamingPath; return _streamingPath;
} }
@ -173,7 +181,7 @@ namespace YooAsset
return string.Empty; return string.Empty;
if (string.IsNullOrEmpty(_cachePath)) if (string.IsNullOrEmpty(_cachePath))
_cachePath = SandboxHelper.MakeCacheFilePath(_patchBundle.Hash); _cachePath = SandboxHelper.MakeCacheFilePath(_patchBundle.FileName);
return _cachePath; return _cachePath;
} }

View File

@ -391,7 +391,7 @@ namespace YooAsset
// 注意:在弱联网模式下,我们需要验证指定资源版本的所有资源完整性 // 注意:在弱联网模式下,我们需要验证指定资源版本的所有资源完整性
if (weaklyUpdate) if (weaklyUpdate)
{ {
string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.Hash); string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.FileName);
if (File.Exists(filePath)) if (File.Exists(filePath))
_waitingList.Add(patchBundle); _waitingList.Add(patchBundle);
else else
@ -399,7 +399,7 @@ namespace YooAsset
} }
else else
{ {
string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.Hash); string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.FileName);
if (File.Exists(filePath)) if (File.Exists(filePath))
_waitingList.Add(patchBundle); _waitingList.Add(patchBundle);
} }
@ -451,7 +451,7 @@ namespace YooAsset
private bool RunThread(PatchBundle patchBundle) private bool RunThread(PatchBundle patchBundle)
{ {
string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.Hash); string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.FileName);
ThreadInfo info = new ThreadInfo(filePath, patchBundle); ThreadInfo info = new ThreadInfo(filePath, patchBundle);
return ThreadPool.QueueUserWorkItem(new WaitCallback(VerifyInThread), info); return ThreadPool.QueueUserWorkItem(new WaitCallback(VerifyInThread), info);
} }
@ -467,7 +467,7 @@ namespace YooAsset
if (info.Result) if (info.Result)
{ {
VerifySuccessCount++; VerifySuccessCount++;
DownloadSystem.CacheVerifyFile(info.Bundle.Hash, info.Bundle.BundleName); DownloadSystem.CacheVerifyFile(info.Bundle.Hash, info.Bundle.FileName);
} }
else else
{ {

View File

@ -211,7 +211,7 @@ namespace YooAsset
// 注意:通过比对文件大小做快速的文件校验! // 注意:通过比对文件大小做快速的文件校验!
// 注意:在初始化的时候会去做最终校验! // 注意:在初始化的时候会去做最终校验!
string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.Hash); string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.FileName);
if (File.Exists(filePath)) if (File.Exists(filePath))
{ {
long fileSize = FileUtility.GetFileSize(filePath); long fileSize = FileUtility.GetFileSize(filePath);

View File

@ -26,6 +26,11 @@ namespace YooAsset
/// </summary> /// </summary>
public long SizeBytes; public long SizeBytes;
/// <summary>
/// 名字样式
/// </summary>
public byte NameStyle;
/// <summary> /// <summary>
/// 资源包的分类标签 /// 资源包的分类标签
/// </summary> /// </summary>
@ -52,14 +57,55 @@ namespace YooAsset
/// </summary> /// </summary>
public bool IsRawFile { private set; get; } public bool IsRawFile { private set; get; }
/// <summary>
/// 文件名称
/// </summary>
public string FileName
{
get
{
if (_fileName != null)
return _fileName;
if (NameStyle == 1)
{
_fileName = Hash;
}
else if (NameStyle == 2)
{
string tempFileExtension = System.IO.Path.GetExtension(BundleName);
_fileName = $"{Hash}{tempFileExtension}";
}
else if (NameStyle == 3)
{
string tempFileExtension = System.IO.Path.GetExtension(BundleName);
string tempBundleName = BundleName.Replace('/', '_').Replace(tempFileExtension, "");
_fileName = $"{tempBundleName}_{Hash}";
}
else if (NameStyle == 4)
{
string tempFileExtension = System.IO.Path.GetExtension(BundleName);
string tempBundleName = BundleName.Replace('/', '_').Replace(tempFileExtension, "");
_fileName = $"{tempBundleName}_{Hash}{tempFileExtension}";
}
else
{
throw new NotImplementedException();
}
return _fileName;
}
}
private string _fileName = null;
public PatchBundle(string bundleName, string hash, string crc, long sizeBytes, string[] tags) public PatchBundle(string bundleName, string hash, string crc, long sizeBytes, byte nameStyle, string[] tags)
{ {
BundleName = bundleName; BundleName = bundleName;
Hash = hash; Hash = hash;
CRC = crc; CRC = crc;
SizeBytes = sizeBytes; SizeBytes = sizeBytes;
NameStyle = nameStyle;
Tags = tags; Tags = tags;
} }

View File

@ -102,7 +102,7 @@ namespace YooAsset
bool used = false; bool used = false;
foreach (var patchBundle in LocalPatchManifest.BundleList) foreach (var patchBundle in LocalPatchManifest.BundleList)
{ {
if (fileInfo.Name == patchBundle.Hash) if (fileInfo.Name == patchBundle.FileName)
{ {
used = true; used = true;
break; break;
@ -333,9 +333,8 @@ namespace YooAsset
} }
public BundleInfo ConvertToDownloadInfo(PatchBundle patchBundle) public BundleInfo ConvertToDownloadInfo(PatchBundle patchBundle)
{ {
// 注意:资源版本号只用于确定下载路径 string remoteMainURL = GetPatchDownloadMainURL(patchBundle.FileName);
string remoteMainURL = GetPatchDownloadMainURL(patchBundle.Hash); string remoteFallbackURL = GetPatchDownloadFallbackURL(patchBundle.FileName);
string remoteFallbackURL = GetPatchDownloadFallbackURL(patchBundle.Hash);
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromRemote, remoteMainURL, remoteFallbackURL); BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromRemote, remoteMainURL, remoteFallbackURL);
return bundleInfo; return bundleInfo;
} }
@ -354,7 +353,7 @@ namespace YooAsset
public BundleInfo ConvertToUnpackInfo(PatchBundle patchBundle) public BundleInfo ConvertToUnpackInfo(PatchBundle patchBundle)
{ {
// 注意:我们把流加载路径指定为远端下载地址 // 注意:我们把流加载路径指定为远端下载地址
string streamingPath = PathHelper.MakeStreamingLoadPath(patchBundle.Hash); string streamingPath = PathHelper.MakeStreamingLoadPath(patchBundle.FileName);
streamingPath = PathHelper.ConvertToWWWPath(streamingPath); streamingPath = PathHelper.ConvertToWWWPath(streamingPath);
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromRemote, streamingPath, streamingPath); BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromRemote, streamingPath, streamingPath);
return bundleInfo; return bundleInfo;