Update PatchSystem

pull/4/head
hevinci 2022-03-25 15:02:21 +08:00
parent f9ac8ab51b
commit bcd53cf834
4 changed files with 82 additions and 63 deletions

View File

@ -160,51 +160,20 @@ namespace YooAsset
/// </summary> /// </summary>
public DownloaderOperation CreateUnpackerByTags(string[] tags, int fileUpackingMaxNumber, int failedTryAgain) public DownloaderOperation CreateUnpackerByTags(string[] tags, int fileUpackingMaxNumber, int failedTryAgain)
{ {
List<BundleInfo> unpcakList = GetUnpackListByTags(tags); List<BundleInfo> unpcakList = PatchHelper.GetUnpackListByTags(AppPatchManifest, tags);
var operation = new DownloaderOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain); var operation = new DownloaderOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain);
return operation; return operation;
} }
private List<BundleInfo> GetUnpackListByTags(string[] tags)
{
List<PatchBundle> downloadList = new List<PatchBundle>(1000);
foreach (var patchBundle in AppPatchManifest.BundleList)
{
// 如果已经在沙盒内
string filePath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
if (System.IO.File.Exists(filePath))
continue;
// 如果不是内置资源
if (patchBundle.IsBuildin == false)
continue;
// 如果是纯内置资源
if (patchBundle.IsPureBuildin())
{
downloadList.Add(patchBundle);
}
else
{
// 查询DLC资源
if (patchBundle.HasTag(tags))
{
downloadList.Add(patchBundle);
}
}
}
return ConvertToUnpackList(downloadList);
}
// WEB相关 // WEB相关
internal string GetPatchDownloadMainURL(int resourceVersion, string fileName) public string GetPatchDownloadMainURL(int resourceVersion, string fileName)
{ {
if (IgnoreResourceVersion) if (IgnoreResourceVersion)
return $"{_defaultHostServer}/{fileName}"; return $"{_defaultHostServer}/{fileName}";
else else
return $"{_defaultHostServer}/{resourceVersion}/{fileName}"; return $"{_defaultHostServer}/{resourceVersion}/{fileName}";
} }
internal string GetPatchDownloadFallbackURL(int resourceVersion, string fileName) public string GetPatchDownloadFallbackURL(int resourceVersion, string fileName)
{ {
if (IgnoreResourceVersion) if (IgnoreResourceVersion)
return $"{_fallbackHostServer}/{fileName}"; return $"{_fallbackHostServer}/{fileName}";
@ -213,15 +182,6 @@ namespace YooAsset
} }
// 下载相关 // 下载相关
private BundleInfo ConvertToDownloadInfo(PatchBundle patchBundle)
{
// 注意:资源版本号只用于确定下载路径
string sandboxPath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
string remoteMainURL = GetPatchDownloadMainURL(patchBundle.Version, patchBundle.Hash);
string remoteFallbackURL = GetPatchDownloadFallbackURL(patchBundle.Version, patchBundle.Hash);
BundleInfo bundleInfo = new BundleInfo(patchBundle, sandboxPath, remoteMainURL, remoteFallbackURL);
return bundleInfo;
}
private List<BundleInfo> ConvertToDownloadList(List<PatchBundle> downloadList) private List<BundleInfo> ConvertToDownloadList(List<PatchBundle> downloadList)
{ {
List<BundleInfo> result = new List<BundleInfo>(downloadList.Count); List<BundleInfo> result = new List<BundleInfo>(downloadList.Count);
@ -232,25 +192,15 @@ namespace YooAsset
} }
return result; return result;
} }
private BundleInfo ConvertToDownloadInfo(PatchBundle patchBundle)
// 解压相关
private BundleInfo ConvertToUnpackInfo(PatchBundle patchBundle)
{ {
// 注意:资源版本号只用于确定下载路径
string sandboxPath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash); string sandboxPath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
string streamingLoadPath = PathHelper.MakeStreamingLoadPath(patchBundle.Hash); string remoteMainURL = GetPatchDownloadMainURL(patchBundle.Version, patchBundle.Hash);
BundleInfo bundleInfo = new BundleInfo(patchBundle, sandboxPath, streamingLoadPath, streamingLoadPath); string remoteFallbackURL = GetPatchDownloadFallbackURL(patchBundle.Version, patchBundle.Hash);
BundleInfo bundleInfo = new BundleInfo(patchBundle, sandboxPath, remoteMainURL, remoteFallbackURL);
return bundleInfo; return bundleInfo;
} }
private List<BundleInfo> ConvertToUnpackList(List<PatchBundle> unpackList)
{
List<BundleInfo> result = new List<BundleInfo>(unpackList.Count);
foreach (var patchBundle in unpackList)
{
var bundleInfo = ConvertToUnpackInfo(patchBundle);
result.Add(bundleInfo);
}
return result;
}
#region IBundleServices接口 #region IBundleServices接口
BundleInfo IBundleServices.GetBundleInfo(string bundleName) BundleInfo IBundleServices.GetBundleInfo(string bundleName)

View File

@ -28,6 +28,16 @@ namespace YooAsset
return AppPatchManifest.ResourceVersion; return AppPatchManifest.ResourceVersion;
} }
/// <summary>
/// 创建解压器
/// </summary>
public DownloaderOperation CreateUnpackerByTags(string[] tags, int fileUpackingMaxNumber, int failedTryAgain)
{
List<BundleInfo> unpcakList = PatchHelper.GetUnpackListByTags(AppPatchManifest, tags);
var operation = new DownloaderOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain);
return operation;
}
#region IBundleServices接口 #region IBundleServices接口
BundleInfo IBundleServices.GetBundleInfo(string bundleName) BundleInfo IBundleServices.GetBundleInfo(string bundleName)
{ {

View File

@ -1,4 +1,5 @@
using System.IO; using System.IO;
using System.Collections.Generic;
namespace YooAsset namespace YooAsset
{ {
@ -220,4 +221,62 @@ namespace YooAsset
return PathHelper.MakePersistentLoadPath($"{StrCacheFolderName}/{fileName}"); return PathHelper.MakePersistentLoadPath($"{StrCacheFolderName}/{fileName}");
} }
} }
/// <summary>
/// 补丁包帮助类
/// </summary>
internal static class PatchHelper
{
/// <summary>
/// 获取内置资源解压列表
/// </summary>
public static List<BundleInfo> GetUnpackListByTags(PatchManifest appPatchManifest, string[] tags)
{
List<PatchBundle> downloadList = new List<PatchBundle>(1000);
foreach (var patchBundle in appPatchManifest.BundleList)
{
// 如果已经在沙盒内
string filePath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
if (System.IO.File.Exists(filePath))
continue;
// 如果不是内置资源
if (patchBundle.IsBuildin == false)
continue;
// 如果是纯内置资源
if (patchBundle.IsPureBuildin())
{
downloadList.Add(patchBundle);
}
else
{
// 查询DLC资源
if (patchBundle.HasTag(tags))
{
downloadList.Add(patchBundle);
}
}
}
return ConvertToUnpackList(downloadList);
}
private static List<BundleInfo> ConvertToUnpackList(List<PatchBundle> unpackList)
{
List<BundleInfo> result = new List<BundleInfo>(unpackList.Count);
foreach (var patchBundle in unpackList)
{
var bundleInfo = ConvertToUnpackInfo(patchBundle);
result.Add(bundleInfo);
}
return result;
}
private static BundleInfo ConvertToUnpackInfo(PatchBundle patchBundle)
{
string sandboxPath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
string streamingLoadPath = PathHelper.MakeStreamingLoadPath(patchBundle.Hash);
BundleInfo bundleInfo = new BundleInfo(patchBundle, sandboxPath, streamingLoadPath, streamingLoadPath);
return bundleInfo;
}
}
} }

View File

@ -538,9 +538,9 @@ namespace YooAsset
} }
else if (_playMode == EPlayMode.OfflinePlayMode) else if (_playMode == EPlayMode.OfflinePlayMode)
{ {
List<BundleInfo> downloadList = new List<BundleInfo>(); if (_offlinePlayModeImpl == null)
var operation = new DownloaderOperation(downloadList, unpackingMaxNumber, failedTryAgain); throw new Exception("YooAsset is not initialized.");
return operation; return _offlinePlayModeImpl.CreateUnpackerByTags(tags, unpackingMaxNumber, failedTryAgain);
} }
else if (_playMode == EPlayMode.HostPlayMode) else if (_playMode == EPlayMode.HostPlayMode)
{ {