Update YooAsset
This commit is contained in:
@@ -86,7 +86,7 @@ namespace YooAsset
|
||||
{
|
||||
if (_cachedHashList.ContainsKey(hash))
|
||||
{
|
||||
string filePath = PatchHelper.MakeSandboxCacheFilePath(hash);
|
||||
string filePath = SandboxHelper.MakeSandboxCacheFilePath(hash);
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
return true;
|
||||
@@ -124,7 +124,7 @@ namespace YooAsset
|
||||
}
|
||||
public static bool CheckContentIntegrity(PatchBundle patchBundle)
|
||||
{
|
||||
string filePath = PatchHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
|
||||
string filePath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
|
||||
return CheckContentIntegrity(filePath, patchBundle.SizeBytes, patchBundle.CRC);
|
||||
}
|
||||
public static bool CheckContentIntegrity(string filePath, long size, string crc)
|
||||
|
||||
@@ -59,8 +59,8 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.LoadAppManifest)
|
||||
{
|
||||
string filePath = AssetPathHelper.MakeStreamingLoadPath(ResourceSettingData.Setting.PatchManifestFileName);
|
||||
_downloadURL = AssetPathHelper.ConvertToWWWPath(filePath);
|
||||
string filePath = PathHelper.MakeStreamingLoadPath(ResourceSettingData.Setting.PatchManifestFileName);
|
||||
_downloadURL = PathHelper.ConvertToWWWPath(filePath);
|
||||
_downloader = new UnityWebRequester();
|
||||
_downloader.SendRequest(_downloadURL);
|
||||
_steps = ESteps.CheckAppManifest;
|
||||
@@ -134,11 +134,11 @@ namespace YooAsset
|
||||
if (_impl.ClearCacheWhenDirty)
|
||||
{
|
||||
YooLogger.Warning("Clear cache files.");
|
||||
PatchHelper.DeleteSandboxCacheFolder();
|
||||
SandboxHelper.DeleteSandboxCacheFolder();
|
||||
}
|
||||
|
||||
// 删除清单文件
|
||||
PatchHelper.DeleteSandboxPatchManifestFile();
|
||||
SandboxHelper.DeleteSandboxPatchManifestFile();
|
||||
// 更新缓存文件
|
||||
PatchCache.UpdateCache();
|
||||
}
|
||||
@@ -149,8 +149,8 @@ namespace YooAsset
|
||||
{
|
||||
// 加载APP内的补丁清单
|
||||
YooLogger.Log($"Load application patch manifest.");
|
||||
string filePath = AssetPathHelper.MakeStreamingLoadPath(ResourceSettingData.Setting.PatchManifestFileName);
|
||||
_downloadURL = AssetPathHelper.ConvertToWWWPath(filePath);
|
||||
string filePath = PathHelper.MakeStreamingLoadPath(ResourceSettingData.Setting.PatchManifestFileName);
|
||||
_downloadURL = PathHelper.ConvertToWWWPath(filePath);
|
||||
_downloader = new UnityWebRequester();
|
||||
_downloader.SendRequest(_downloadURL);
|
||||
_steps = ESteps.CheckAppManifest;
|
||||
@@ -181,10 +181,10 @@ namespace YooAsset
|
||||
if (_steps == ESteps.LoadSandboxManifest)
|
||||
{
|
||||
// 加载沙盒内的补丁清单
|
||||
if (PatchHelper.CheckSandboxPatchManifestFileExist())
|
||||
if (SandboxHelper.CheckSandboxPatchManifestFileExist())
|
||||
{
|
||||
YooLogger.Log($"Load sandbox patch manifest.");
|
||||
string filePath = AssetPathHelper.MakePersistentLoadPath(ResourceSettingData.Setting.PatchManifestFileName);
|
||||
string filePath = PathHelper.MakePersistentLoadPath(ResourceSettingData.Setting.PatchManifestFileName);
|
||||
string jsonData = File.ReadAllText(filePath);
|
||||
_impl.LocalPatchManifest = PatchManifest.Deserialize(jsonData);
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ namespace YooAsset
|
||||
_downloaderHash.Dispose();
|
||||
|
||||
// 如果补丁清单文件的哈希值相同
|
||||
string currentFileHash = PatchHelper.GetSandboxPatchManifestFileHash();
|
||||
string currentFileHash = SandboxHelper.GetSandboxPatchManifestFileHash();
|
||||
if (currentFileHash == webManifestHash)
|
||||
{
|
||||
YooLogger.Log($"Patch manifest file hash is not change : {webManifestHash}");
|
||||
@@ -206,7 +206,7 @@ namespace YooAsset
|
||||
|
||||
// 注意:这里会覆盖掉沙盒内的补丁清单文件
|
||||
YooLogger.Log("Save remote patch manifest file.");
|
||||
string savePath = AssetPathHelper.MakePersistentLoadPath(ResourceSettingData.Setting.PatchManifestFileName);
|
||||
string savePath = PathHelper.MakePersistentLoadPath(ResourceSettingData.Setting.PatchManifestFileName);
|
||||
PatchManifest.Serialize(savePath, _impl.LocalPatchManifest);
|
||||
}
|
||||
|
||||
@@ -246,7 +246,7 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
// 查看文件是否存在
|
||||
string filePath = PatchHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
|
||||
string filePath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
|
||||
if (File.Exists(filePath) == false)
|
||||
continue;
|
||||
|
||||
@@ -285,7 +285,7 @@ namespace YooAsset
|
||||
}
|
||||
private bool RunThread(PatchBundle patchBundle)
|
||||
{
|
||||
string filePath = PatchHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
|
||||
string filePath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
|
||||
ThreadInfo info = new ThreadInfo(filePath, patchBundle);
|
||||
return ThreadPool.QueueUserWorkItem(new WaitCallback(VerifyFile), info);
|
||||
}
|
||||
|
||||
@@ -19,10 +19,10 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public static PatchCache LoadCache()
|
||||
{
|
||||
if (PatchHelper.CheckSandboxCacheFileExist())
|
||||
if (SandboxHelper.CheckSandboxCacheFileExist())
|
||||
{
|
||||
YooLogger.Log("Load patch cache from disk.");
|
||||
string filePath = PatchHelper.GetSandboxCacheFilePath();
|
||||
string filePath = SandboxHelper.GetSandboxCacheFilePath();
|
||||
string jsonData = FileUtility.ReadFile(filePath);
|
||||
return JsonUtility.FromJson<PatchCache>(jsonData);
|
||||
}
|
||||
@@ -31,7 +31,7 @@ namespace YooAsset
|
||||
YooLogger.Log($"Create patch cache to disk : {Application.version}");
|
||||
PatchCache cache = new PatchCache();
|
||||
cache.CacheAppVersion = Application.version;
|
||||
string filePath = PatchHelper.GetSandboxCacheFilePath();
|
||||
string filePath = SandboxHelper.GetSandboxCacheFilePath();
|
||||
string jsonData = JsonUtility.ToJson(cache);
|
||||
FileUtility.CreateFile(filePath, jsonData);
|
||||
return cache;
|
||||
@@ -46,7 +46,7 @@ namespace YooAsset
|
||||
YooLogger.Log($"Update patch cache to disk : {Application.version}");
|
||||
PatchCache cache = new PatchCache();
|
||||
cache.CacheAppVersion = Application.version;
|
||||
string filePath = PatchHelper.GetSandboxCacheFilePath();
|
||||
string filePath = SandboxHelper.GetSandboxCacheFilePath();
|
||||
string jsonData = JsonUtility.ToJson(cache);
|
||||
FileUtility.CreateFile(filePath, jsonData);
|
||||
}
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal static class PatchHelper
|
||||
{
|
||||
private const string StrCacheFileName = "Cache.bytes";
|
||||
private const string StrCacheFolderName = "CacheFiles";
|
||||
|
||||
/// <summary>
|
||||
/// 清空沙盒目录
|
||||
/// </summary>
|
||||
public static void ClearSandbox()
|
||||
{
|
||||
string directoryPath = AssetPathHelper.MakePersistentLoadPath(string.Empty);
|
||||
if (Directory.Exists(directoryPath))
|
||||
Directory.Delete(directoryPath, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除沙盒内补丁清单文件
|
||||
/// </summary>
|
||||
public static void DeleteSandboxPatchManifestFile()
|
||||
{
|
||||
string filePath = AssetPathHelper.MakePersistentLoadPath(ResourceSettingData.Setting.PatchManifestFileName);
|
||||
if (File.Exists(filePath))
|
||||
File.Delete(filePath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除沙盒内的缓存文件
|
||||
/// </summary>
|
||||
public static void DeleteSandboxCacheFile()
|
||||
{
|
||||
string filePath = GetSandboxCacheFilePath();
|
||||
if (File.Exists(filePath))
|
||||
File.Delete(filePath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除沙盒内的缓存文件夹
|
||||
/// </summary>
|
||||
public static void DeleteSandboxCacheFolder()
|
||||
{
|
||||
string directoryPath = AssetPathHelper.MakePersistentLoadPath(StrCacheFolderName);
|
||||
if (Directory.Exists(directoryPath))
|
||||
Directory.Delete(directoryPath, true);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取沙盒内缓存文件的路径
|
||||
/// </summary>
|
||||
public static string GetSandboxCacheFilePath()
|
||||
{
|
||||
return AssetPathHelper.MakePersistentLoadPath(StrCacheFileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检测沙盒内缓存文件是否存在
|
||||
/// </summary>
|
||||
public static bool CheckSandboxCacheFileExist()
|
||||
{
|
||||
string filePath = GetSandboxCacheFilePath();
|
||||
return File.Exists(filePath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检测沙盒内补丁清单文件是否存在
|
||||
/// </summary>
|
||||
public static bool CheckSandboxPatchManifestFileExist()
|
||||
{
|
||||
string filePath = AssetPathHelper.MakePersistentLoadPath(ResourceSettingData.Setting.PatchManifestFileName);
|
||||
return File.Exists(filePath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取沙盒内补丁清单文件的哈希值
|
||||
/// 注意:如果沙盒内补丁清单文件不存在,返回空字符串
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string GetSandboxPatchManifestFileHash()
|
||||
{
|
||||
string filePath = AssetPathHelper.MakePersistentLoadPath(ResourceSettingData.Setting.PatchManifestFileName);
|
||||
if (File.Exists(filePath))
|
||||
return HashUtility.FileMD5(filePath);
|
||||
else
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取缓存文件的存储路径
|
||||
/// </summary>
|
||||
public static string MakeSandboxCacheFilePath(string fileName)
|
||||
{
|
||||
return AssetPathHelper.MakePersistentLoadPath($"{StrCacheFolderName}/{fileName}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 887179b2bb92ca04988d1091b3b8f8e2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -170,7 +170,7 @@ namespace YooAsset
|
||||
foreach (var patchBundle in AppPatchManifest.BundleList)
|
||||
{
|
||||
// 如果已经在沙盒内
|
||||
string filePath = PatchHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
|
||||
string filePath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
|
||||
if (System.IO.File.Exists(filePath))
|
||||
continue;
|
||||
|
||||
@@ -216,7 +216,7 @@ namespace YooAsset
|
||||
private BundleInfo ConvertToDownloadInfo(PatchBundle patchBundle)
|
||||
{
|
||||
// 注意:资源版本号只用于确定下载路径
|
||||
string sandboxPath = PatchHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
|
||||
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);
|
||||
@@ -236,8 +236,8 @@ namespace YooAsset
|
||||
// 解压相关
|
||||
private BundleInfo ConvertToUnpackInfo(PatchBundle patchBundle)
|
||||
{
|
||||
string sandboxPath = PatchHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
|
||||
string streamingLoadPath = AssetPathHelper.MakeStreamingLoadPath(patchBundle.Hash);
|
||||
string sandboxPath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
|
||||
string streamingLoadPath = PathHelper.MakeStreamingLoadPath(patchBundle.Hash);
|
||||
BundleInfo bundleInfo = new BundleInfo(patchBundle, sandboxPath, streamingLoadPath, streamingLoadPath);
|
||||
return bundleInfo;
|
||||
}
|
||||
@@ -265,7 +265,7 @@ namespace YooAsset
|
||||
{
|
||||
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
|
||||
{
|
||||
string appLoadPath = AssetPathHelper.MakeStreamingLoadPath(appPatchBundle.Hash);
|
||||
string appLoadPath = PathHelper.MakeStreamingLoadPath(appPatchBundle.Hash);
|
||||
BundleInfo bundleInfo = new BundleInfo(appPatchBundle, appLoadPath);
|
||||
return bundleInfo;
|
||||
}
|
||||
@@ -274,7 +274,7 @@ namespace YooAsset
|
||||
// 查询沙盒资源
|
||||
if (DownloadSystem.ContainsVerifyFile(patchBundle.Hash))
|
||||
{
|
||||
string sandboxLoadPath = PatchHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
|
||||
string sandboxLoadPath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
|
||||
BundleInfo bundleInfo = new BundleInfo(patchBundle, sandboxLoadPath);
|
||||
return bundleInfo;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace YooAsset
|
||||
|
||||
if (AppPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle patchBundle))
|
||||
{
|
||||
string localPath = AssetPathHelper.MakeStreamingLoadPath(patchBundle.Hash);
|
||||
string localPath = PathHelper.MakeStreamingLoadPath(patchBundle.Hash);
|
||||
BundleInfo bundleInfo = new BundleInfo(patchBundle, localPath);
|
||||
return bundleInfo;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user