mirror of https://github.com/tuyoogame/YooAsset
Update patch manifest
parent
e5c7bbdf52
commit
d0b7ae020c
|
@ -61,8 +61,7 @@ namespace YooAsset
|
|||
// 1. 从服务器或缓存中获取AssetBundle文件
|
||||
if (_steps == ESteps.LoadFile)
|
||||
{
|
||||
string hash = StringUtility.RemoveExtension(MainBundleInfo.Hash);
|
||||
_webRequest = UnityWebRequestAssetBundle.GetAssetBundle(_webURL, Hash128.Parse(hash));
|
||||
_webRequest = UnityWebRequestAssetBundle.GetAssetBundle(_webURL, Hash128.Parse(MainBundleInfo.Hash));
|
||||
_webRequest.SendWebRequest();
|
||||
_steps = ESteps.CheckFile;
|
||||
}
|
||||
|
|
|
@ -240,7 +240,7 @@ namespace YooAsset
|
|||
{
|
||||
if (DownloadSystem.CheckContentIntegrity(GetCachePath(), _bundleInfo.SizeBytes, _bundleInfo.CRC))
|
||||
{
|
||||
DownloadSystem.CacheVerifyFile(_bundleInfo.Hash, _bundleInfo.BundleName);
|
||||
DownloadSystem.CacheVerifyFile(_bundleInfo.Hash, _bundleInfo.FileName);
|
||||
_steps = ESteps.CheckAndCopyFile;
|
||||
}
|
||||
else
|
||||
|
@ -423,7 +423,7 @@ namespace YooAsset
|
|||
{
|
||||
if (DownloadSystem.CheckContentIntegrity(GetCachePath(), _bundleInfo.SizeBytes, _bundleInfo.CRC))
|
||||
{
|
||||
DownloadSystem.CacheVerifyFile(_bundleInfo.Hash, _bundleInfo.BundleName);
|
||||
DownloadSystem.CacheVerifyFile(_bundleInfo.Hash, _bundleInfo.FileName);
|
||||
_steps = ESteps.CheckAndCopyFile;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -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());
|
||||
DownloaderBase newDownloader;
|
||||
if (bundleInfo.SizeBytes >= _breakpointResumeFileSize)
|
||||
|
@ -117,16 +117,16 @@ namespace YooAsset
|
|||
{
|
||||
if (_cachedHashList.ContainsKey(hash))
|
||||
{
|
||||
string filePath = SandboxHelper.MakeCacheFilePath(hash);
|
||||
string fileName = _cachedHashList[hash];
|
||||
string filePath = SandboxHelper.MakeCacheFilePath(fileName);
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
string bundleName = _cachedHashList[hash];
|
||||
_cachedHashList.Remove(hash);
|
||||
YooLogger.Error($"Cache file is missing : {bundleName} Hash : {hash}");
|
||||
YooLogger.Error($"Cache file is missing : {fileName}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -139,12 +139,12 @@ namespace YooAsset
|
|||
/// <summary>
|
||||
/// 缓存验证过的文件
|
||||
/// </summary>
|
||||
public static void CacheVerifyFile(string hash, string bundleName)
|
||||
public static void CacheVerifyFile(string hash, string fileName)
|
||||
{
|
||||
if (_cachedHashList.ContainsKey(hash) == false)
|
||||
{
|
||||
YooLogger.Log($"Cache verify file : {bundleName} Hash : {hash}");
|
||||
_cachedHashList.Add(hash, bundleName);
|
||||
YooLogger.Log($"Cache verify file : {fileName}");
|
||||
_cachedHashList.Add(hash, fileName);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -80,8 +80,7 @@ namespace YooAsset
|
|||
// 检查文件完整性
|
||||
if (hasError == false)
|
||||
{
|
||||
// 注意:如果文件验证失败需要删除文件
|
||||
|
||||
// 注意:如果文件验证失败需要删除文件
|
||||
if (DownloadSystem.CheckContentIntegrity(_bundleInfo.GetCacheLoadPath(), _bundleInfo.SizeBytes, _bundleInfo.CRC) == false)
|
||||
{
|
||||
hasError = true;
|
||||
|
@ -92,7 +91,7 @@ namespace YooAsset
|
|||
if (hasError == false)
|
||||
{
|
||||
_steps = ESteps.Succeed;
|
||||
DownloadSystem.CacheVerifyFile(_bundleInfo.Hash, _bundleInfo.BundleName);
|
||||
DownloadSystem.CacheVerifyFile(_bundleInfo.Hash, _bundleInfo.FileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace YooAsset
|
|||
private bool _running = true;
|
||||
private string _url;
|
||||
private string _savePath;
|
||||
private string _fileHash;
|
||||
private string _fileName;
|
||||
private string _fileCRC;
|
||||
private long _fileSize;
|
||||
private int _timeout;
|
||||
|
@ -50,11 +50,11 @@ namespace YooAsset
|
|||
/// <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;
|
||||
_savePath = savePath;
|
||||
_fileHash = fileHash;
|
||||
_fileName = fileName;
|
||||
_fileCRC = fileCRC;
|
||||
_fileSize = fileSize;
|
||||
_timeout = timeout;
|
||||
|
@ -159,14 +159,14 @@ namespace YooAsset
|
|||
bool verfiyResult = DownloadSystem.CheckContentIntegrity(_savePath, _fileSize, _fileCRC);
|
||||
if (verfiyResult == false)
|
||||
{
|
||||
Error = $"Verify download content failed : {_fileHash}";
|
||||
Error = $"Verify download content failed : {_fileName}";
|
||||
if (File.Exists(_savePath))
|
||||
File.Delete(_savePath);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Error = $"Download content is incomplete : {_fileHash}";
|
||||
Error = $"Download content is incomplete : {_fileName}";
|
||||
}
|
||||
|
||||
IsDone = true;
|
||||
|
@ -197,7 +197,7 @@ namespace YooAsset
|
|||
|
||||
_requestURL = GetRequestURL();
|
||||
_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;
|
||||
}
|
||||
|
||||
|
@ -226,7 +226,7 @@ namespace YooAsset
|
|||
}
|
||||
else
|
||||
{
|
||||
DownloadSystem.CacheVerifyFile(_bundleInfo.Hash, _bundleInfo.BundleName);
|
||||
DownloadSystem.CacheVerifyFile(_bundleInfo.Hash, _bundleInfo.FileName);
|
||||
_steps = ESteps.Succeed;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,11 @@ namespace YooAsset
|
|||
/// </summary>
|
||||
public string BundleName { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 文件名称
|
||||
/// </summary>
|
||||
public string FileName { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 远端下载地址
|
||||
/// </summary>
|
||||
|
@ -51,7 +56,7 @@ namespace YooAsset
|
|||
return _patchBundle.Hash;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 校验的CRC
|
||||
/// </summary>
|
||||
|
@ -128,6 +133,7 @@ namespace YooAsset
|
|||
_patchBundle = patchBundle;
|
||||
LoadMode = loadMode;
|
||||
BundleName = patchBundle.BundleName;
|
||||
FileName = patchBundle.FileName;
|
||||
RemoteMainURL = mainURL;
|
||||
RemoteFallbackURL = fallbackURL;
|
||||
EditorAssetPath = string.Empty;
|
||||
|
@ -137,6 +143,7 @@ namespace YooAsset
|
|||
_patchBundle = patchBundle;
|
||||
LoadMode = loadMode;
|
||||
BundleName = patchBundle.BundleName;
|
||||
FileName = patchBundle.FileName;
|
||||
RemoteMainURL = string.Empty;
|
||||
RemoteFallbackURL = string.Empty;
|
||||
EditorAssetPath = editorAssetPath;
|
||||
|
@ -146,6 +153,7 @@ namespace YooAsset
|
|||
_patchBundle = patchBundle;
|
||||
LoadMode = loadMode;
|
||||
BundleName = patchBundle.BundleName;
|
||||
FileName = patchBundle.FileName;
|
||||
RemoteMainURL = string.Empty;
|
||||
RemoteFallbackURL = string.Empty;
|
||||
EditorAssetPath = string.Empty;
|
||||
|
@ -160,7 +168,7 @@ namespace YooAsset
|
|||
return string.Empty;
|
||||
|
||||
if (string.IsNullOrEmpty(_streamingPath))
|
||||
_streamingPath = PathHelper.MakeStreamingLoadPath(_patchBundle.Hash);
|
||||
_streamingPath = PathHelper.MakeStreamingLoadPath(_patchBundle.FileName);
|
||||
return _streamingPath;
|
||||
}
|
||||
|
||||
|
@ -173,7 +181,7 @@ namespace YooAsset
|
|||
return string.Empty;
|
||||
|
||||
if (string.IsNullOrEmpty(_cachePath))
|
||||
_cachePath = SandboxHelper.MakeCacheFilePath(_patchBundle.Hash);
|
||||
_cachePath = SandboxHelper.MakeCacheFilePath(_patchBundle.FileName);
|
||||
return _cachePath;
|
||||
}
|
||||
|
||||
|
|
|
@ -391,7 +391,7 @@ namespace YooAsset
|
|||
// 注意:在弱联网模式下,我们需要验证指定资源版本的所有资源完整性
|
||||
if (weaklyUpdate)
|
||||
{
|
||||
string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.Hash);
|
||||
string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.FileName);
|
||||
if (File.Exists(filePath))
|
||||
_waitingList.Add(patchBundle);
|
||||
else
|
||||
|
@ -399,7 +399,7 @@ namespace YooAsset
|
|||
}
|
||||
else
|
||||
{
|
||||
string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.Hash);
|
||||
string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.FileName);
|
||||
if (File.Exists(filePath))
|
||||
_waitingList.Add(patchBundle);
|
||||
}
|
||||
|
@ -451,7 +451,7 @@ namespace YooAsset
|
|||
|
||||
private bool RunThread(PatchBundle patchBundle)
|
||||
{
|
||||
string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.Hash);
|
||||
string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.FileName);
|
||||
ThreadInfo info = new ThreadInfo(filePath, patchBundle);
|
||||
return ThreadPool.QueueUserWorkItem(new WaitCallback(VerifyInThread), info);
|
||||
}
|
||||
|
@ -467,7 +467,7 @@ namespace YooAsset
|
|||
if (info.Result)
|
||||
{
|
||||
VerifySuccessCount++;
|
||||
DownloadSystem.CacheVerifyFile(info.Bundle.Hash, info.Bundle.BundleName);
|
||||
DownloadSystem.CacheVerifyFile(info.Bundle.Hash, info.Bundle.FileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -211,7 +211,7 @@ namespace YooAsset
|
|||
|
||||
// 注意:通过比对文件大小做快速的文件校验!
|
||||
// 注意:在初始化的时候会去做最终校验!
|
||||
string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.Hash);
|
||||
string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.FileName);
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
long fileSize = FileUtility.GetFileSize(filePath);
|
||||
|
|
|
@ -26,6 +26,11 @@ namespace YooAsset
|
|||
/// </summary>
|
||||
public long SizeBytes;
|
||||
|
||||
/// <summary>
|
||||
/// 名字样式
|
||||
/// </summary>
|
||||
public byte NameStyle;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包的分类标签
|
||||
/// </summary>
|
||||
|
@ -52,14 +57,55 @@ namespace YooAsset
|
|||
/// </summary>
|
||||
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;
|
||||
Hash = hash;
|
||||
CRC = crc;
|
||||
SizeBytes = sizeBytes;
|
||||
NameStyle = nameStyle;
|
||||
Tags = tags;
|
||||
}
|
||||
|
||||
|
|
|
@ -102,7 +102,7 @@ namespace YooAsset
|
|||
bool used = false;
|
||||
foreach (var patchBundle in LocalPatchManifest.BundleList)
|
||||
{
|
||||
if (fileInfo.Name == patchBundle.Hash)
|
||||
if (fileInfo.Name == patchBundle.FileName)
|
||||
{
|
||||
used = true;
|
||||
break;
|
||||
|
@ -333,9 +333,8 @@ namespace YooAsset
|
|||
}
|
||||
public BundleInfo ConvertToDownloadInfo(PatchBundle patchBundle)
|
||||
{
|
||||
// 注意:资源版本号只用于确定下载路径
|
||||
string remoteMainURL = GetPatchDownloadMainURL(patchBundle.Hash);
|
||||
string remoteFallbackURL = GetPatchDownloadFallbackURL(patchBundle.Hash);
|
||||
string remoteMainURL = GetPatchDownloadMainURL(patchBundle.FileName);
|
||||
string remoteFallbackURL = GetPatchDownloadFallbackURL(patchBundle.FileName);
|
||||
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromRemote, remoteMainURL, remoteFallbackURL);
|
||||
return bundleInfo;
|
||||
}
|
||||
|
@ -354,7 +353,7 @@ namespace YooAsset
|
|||
public BundleInfo ConvertToUnpackInfo(PatchBundle patchBundle)
|
||||
{
|
||||
// 注意:我们把流加载路径指定为远端下载地址
|
||||
string streamingPath = PathHelper.MakeStreamingLoadPath(patchBundle.Hash);
|
||||
string streamingPath = PathHelper.MakeStreamingLoadPath(patchBundle.FileName);
|
||||
streamingPath = PathHelper.ConvertToWWWPath(streamingPath);
|
||||
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromRemote, streamingPath, streamingPath);
|
||||
return bundleInfo;
|
||||
|
|
Loading…
Reference in New Issue