update runtime code

重构了PersistentTools类
This commit is contained in:
hevinci
2023-07-05 15:14:21 +08:00
parent c5314c72f0
commit 2643ab81ed
15 changed files with 246 additions and 216 deletions
@@ -217,13 +217,13 @@ namespace YooAsset
if (_steps == ESteps.CheckAppFootPrint)
{
var appFootPrint = new AppFootPrint();
appFootPrint.Load();
appFootPrint.Load(_packageName);
// 如果水印发生变化,则说明覆盖安装后首次打开游戏
if (appFootPrint.IsDirty())
{
PersistentTools.DeleteManifestFolder();
appFootPrint.Coverage();
PersistentTools.GetPersistent(_packageName).DeleteSandboxManifestFilesFolder();
appFootPrint.Coverage(_packageName);
YooLogger.Log("Delete manifest files when application foot print dirty !");
}
_steps = ESteps.QueryCachePackageVersion;
@@ -374,16 +374,16 @@ namespace YooAsset
/// <summary>
/// 读取应用程序水印
/// </summary>
public void Load()
public void Load(string packageName)
{
string footPrintFilePath = PersistentTools.GetAppFootPrintFilePath();
string footPrintFilePath = PersistentTools.GetPersistent(packageName).SandboxAppFootPrintFilePath;
if (File.Exists(footPrintFilePath))
{
_footPrint = FileUtility.ReadAllText(footPrintFilePath);
}
else
{
Coverage();
Coverage(packageName);
}
}
@@ -402,14 +402,14 @@ namespace YooAsset
/// <summary>
/// 覆盖掉水印
/// </summary>
public void Coverage()
public void Coverage(string packageName)
{
#if UNITY_EDITOR
_footPrint = Application.version;
#else
_footPrint = Application.buildGUID;
#endif
string footPrintFilePath = PersistentTools.GetAppFootPrintFilePath();
string footPrintFilePath = PersistentTools.GetPersistent(packageName).SandboxAppFootPrintFilePath;
FileUtility.WriteAllText(footPrintFilePath, _footPrint);
YooLogger.Log($"Save application foot print : {_footPrint}");
}
@@ -41,7 +41,7 @@ namespace YooAsset
{
if (_downloader1 == null)
{
string savePath = PersistentTools.GetCachePackageHashFilePath(_packageName, _packageVersion);
string savePath = PersistentTools.GetPersistent(_packageName).GetSandboxPackageHashFilePath(_packageVersion);
string fileName = YooAssetSettingsData.GetPackageHashFileName(_packageName, _packageVersion);
string webURL = GetDownloadRequestURL(fileName);
YooLogger.Log($"Beginning to download package hash file : {webURL}");
@@ -71,7 +71,7 @@ namespace YooAsset
{
if (_downloader2 == null)
{
string savePath = PersistentTools.GetCacheManifestFilePath(_packageName, _packageVersion);
string savePath = PersistentTools.GetPersistent(_packageName).GetSandboxPackageManifestFilePath(_packageVersion);
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, _packageVersion);
string webURL = GetDownloadRequestURL(fileName);
YooLogger.Log($"Beginning to download manifest file : {webURL}");
@@ -41,8 +41,7 @@ namespace YooAsset
{
if (_downloader == null)
{
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_buildinPackageName, _buildinPackageVersion);
string filePath = PersistentTools.MakeStreamingLoadPath(fileName);
string filePath = PersistentTools.GetPersistent(_buildinPackageName).GetBuildinPackageManifestFilePath(_buildinPackageVersion);
string url = PersistentTools.ConvertToWWWPath(filePath);
_downloader = new UnityWebDataRequester();
_downloader.SendRequest(url);
@@ -67,7 +67,7 @@ namespace YooAsset
if (_steps == ESteps.VerifyFileHash)
{
_manifestFilePath = PersistentTools.GetCacheManifestFilePath(_packageName, _packageVersion);
_manifestFilePath = PersistentTools.GetPersistent(_packageName).GetSandboxPackageManifestFilePath(_packageVersion);
if (File.Exists(_manifestFilePath) == false)
{
_steps = ESteps.Done;
@@ -131,7 +131,7 @@ namespace YooAsset
File.Delete(_manifestFilePath);
}
string hashFilePath = PersistentTools.GetCachePackageHashFilePath(_packageName, _packageVersion);
string hashFilePath = PersistentTools.GetPersistent(_packageName).GetSandboxPackageHashFilePath(_packageVersion);
if (File.Exists(hashFilePath))
{
File.Delete(hashFilePath);
@@ -37,8 +37,7 @@ namespace YooAsset
{
if (_downloader == null)
{
string fileName = YooAssetSettingsData.GetPackageVersionFileName(_packageName);
string filePath = PersistentTools.MakeStreamingLoadPath(fileName);
string filePath = PersistentTools.GetPersistent(_packageName).GetBuildinPackageVersionFilePath();
string url = PersistentTools.ConvertToWWWPath(filePath);
_downloader = new UnityWebDataRequester();
_downloader.SendRequest(url);
@@ -37,7 +37,7 @@ namespace YooAsset
if (_steps == ESteps.LoadCachePackageHashFile)
{
string filePath = PersistentTools.GetCachePackageHashFilePath(_packageName, _packageVersion);
string filePath = PersistentTools.GetPersistent(_packageName).GetSandboxPackageHashFilePath(_packageVersion);
if (File.Exists(filePath) == false)
{
_steps = ESteps.Done;
@@ -35,7 +35,7 @@ namespace YooAsset
if (_steps == ESteps.LoadCachePackageVersionFile)
{
string filePath = PersistentTools.GetCachePackageVersionFilePath(_packageName);
string filePath = PersistentTools.GetPersistent(_packageName).GetSandboxPackageVersionFilePath();
if (File.Exists(filePath) == false)
{
_steps = ESteps.Done;
@@ -31,13 +31,13 @@ namespace YooAsset
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if(_steps == ESteps.UnpackManifestHashFile)
if (_steps == ESteps.UnpackManifestHashFile)
{
if (_downloader1 == null)
{
string savePath = PersistentTools.GetCachePackageHashFilePath(_buildinPackageName, _buildinPackageVersion);
string fileName = YooAssetSettingsData.GetPackageHashFileName(_buildinPackageName, _buildinPackageVersion);
string filePath = PersistentTools.MakeStreamingLoadPath(fileName);
var persistent = PersistentTools.GetPersistent(_buildinPackageName);
string savePath = persistent.GetSandboxPackageHashFilePath(_buildinPackageVersion);
string filePath = persistent.GetBuildinPackageHashFilePath(_buildinPackageVersion);
string url = PersistentTools.ConvertToWWWPath(filePath);
_downloader1 = new UnityWebFileRequester();
_downloader1.SendRequest(url, savePath);
@@ -64,9 +64,9 @@ namespace YooAsset
{
if (_downloader2 == null)
{
string savePath = PersistentTools.GetCacheManifestFilePath(_buildinPackageName, _buildinPackageVersion);
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_buildinPackageName, _buildinPackageVersion);
string filePath = PersistentTools.MakeStreamingLoadPath(fileName);
var persistent = PersistentTools.GetPersistent(_buildinPackageName);
string savePath = persistent.GetSandboxPackageManifestFilePath(_buildinPackageVersion);
string filePath = persistent.GetBuildinPackageManifestFilePath(_buildinPackageVersion);
string url = PersistentTools.ConvertToWWWPath(filePath);
_downloader2 = new UnityWebFileRequester();
_downloader2.SendRequest(url, savePath);
@@ -74,13 +74,13 @@ namespace YooAsset
string folderName = FileHash.Substring(0, 2);
if (IsRawFile)
{
string cacheRoot = PersistentTools.GetCachedRawFileFolderPath(PackageName);
string cacheRoot = PersistentTools.GetPersistent(PackageName).SandboxCacheRawFilesRoot;
_cachedDataFilePath = PathUtility.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleDataFileName);
_cachedDataFilePath += _fileExtension;
}
else
{
string cacheRoot = PersistentTools.GetCachedBundleFileFolderPath(PackageName);
string cacheRoot = PersistentTools.GetPersistent(PackageName).SandboxCacheBundleFilesRoot;
_cachedDataFilePath = PathUtility.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleDataFileName);
}
return _cachedDataFilePath;
@@ -101,12 +101,12 @@ namespace YooAsset
string folderName = FileHash.Substring(0, 2);
if (IsRawFile)
{
string cacheRoot = PersistentTools.GetCachedRawFileFolderPath(PackageName);
string cacheRoot = PersistentTools.GetPersistent(PackageName).SandboxCacheRawFilesRoot;
_cachedInfoFilePath = PathUtility.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleInfoFileName);
}
else
{
string cacheRoot = PersistentTools.GetCachedBundleFileFolderPath(PackageName);
string cacheRoot = PersistentTools.GetPersistent(PackageName).SandboxCacheBundleFilesRoot;
_cachedInfoFilePath = PathUtility.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleInfoFileName);
}
return _cachedInfoFilePath;
@@ -140,7 +140,8 @@ namespace YooAsset
if (string.IsNullOrEmpty(_streamingFilePath) == false)
return _streamingFilePath;
_streamingFilePath = PersistentTools.MakeStreamingLoadPath(FileName);
string root = PersistentTools.GetPersistent(PackageName).BuildinPackageRoot;
_streamingFilePath = PathUtility.Combine(root, FileName);
return _streamingFilePath;
}
}
@@ -74,7 +74,9 @@ namespace YooAsset
public void FlushManifestVersionFile()
{
if (_activeManifest != null)
PersistentTools.SaveCachePackageVersionFile(_packageName, _activeManifest.PackageVersion);
{
PersistentTools.GetPersistent(_packageName).SaveSandboxPackageVersionFile(_activeManifest.PackageVersion);
}
}
private bool IsBuildinPackageBundle(PackageBundle packageBundle)