update patch system

初始化的时候检测覆盖安装
pull/62/head
hevinci 2022-12-13 11:29:22 +08:00
parent 889000d8a8
commit d67fc31c26
2 changed files with 89 additions and 2 deletions

View File

@ -190,6 +190,7 @@ namespace YooAsset
private enum ESteps private enum ESteps
{ {
None, None,
CheckAppFootPrint,
TryLoadCacheManifest, TryLoadCacheManifest,
QueryAppPackageVersion, QueryAppPackageVersion,
CopyAppManifest, CopyAppManifest,
@ -222,13 +223,28 @@ namespace YooAsset
} }
internal override void Start() internal override void Start()
{ {
_steps = ESteps.TryLoadCacheManifest; _steps = ESteps.CheckAppFootPrint;
} }
internal override void Update() internal override void Update()
{ {
if (_steps == ESteps.None || _steps == ESteps.Done) if (_steps == ESteps.None || _steps == ESteps.Done)
return; return;
if (_steps == ESteps.CheckAppFootPrint)
{
var appFootPrint = new AppFootPrint();
appFootPrint.Load();
// 如果水印发生变化,则说明覆盖安装后首次打开游戏
if (appFootPrint.IsDirty())
{
PersistentHelper.DeleteManifestFolder();
appFootPrint.Coverage();
YooLogger.Log("Delete manifest files when application foot print dirty !");
}
_steps = ESteps.TryLoadCacheManifest;
}
if (_steps == ESteps.TryLoadCacheManifest) if (_steps == ESteps.TryLoadCacheManifest)
{ {
if (PersistentHelper.CheckCacheManifestFileExists(_packageName)) if (PersistentHelper.CheckCacheManifestFileExists(_packageName))
@ -341,6 +357,57 @@ namespace YooAsset
} }
/// <summary>
/// 应用程序水印
/// </summary>
internal class AppFootPrint
{
private string _footPrint;
/// <summary>
/// 读取应用程序水印
/// </summary>
public void Load()
{
string footPrintFilePath = PersistentHelper.GetAppFootPrintFilePath();
if (File.Exists(footPrintFilePath))
{
_footPrint = FileUtility.ReadAllText(footPrintFilePath);
}
else
{
Coverage();
}
}
/// <summary>
/// 检测水印是否发生变化
/// </summary>
public bool IsDirty()
{
#if UNITY_EDITOR
return _footPrint != Application.version;
#else
return _footPrint != Application.buildGUID;
#endif
}
/// <summary>
/// 覆盖掉水印
/// </summary>
public void Coverage()
{
#if UNITY_EDITOR
_footPrint = Application.version;
#else
_footPrint = Application.buildGUID;
#endif
string footPrintFilePath = PersistentHelper.GetAppFootPrintFilePath();
FileUtility.CreateFile(footPrintFilePath, _footPrint);
YooLogger.Log($"Save application foot print : {_footPrint}");
}
}
/// <summary> /// <summary>
/// 内置补丁清单版本查询器 /// 内置补丁清单版本查询器
/// </summary> /// </summary>

View File

@ -84,6 +84,8 @@ namespace YooAsset
internal static class PersistentHelper internal static class PersistentHelper
{ {
private const string CacheFolderName = "CacheFiles"; private const string CacheFolderName = "CacheFiles";
private const string ManifestFolderName = "ManifestFiles";
private const string AppFootPrintFileName = "ApplicationFootPrint.bytes";
/// <summary> /// <summary>
/// 删除沙盒总目录 /// 删除沙盒总目录
@ -105,6 +107,16 @@ namespace YooAsset
Directory.Delete(root, true); Directory.Delete(root, true);
} }
/// <summary>
/// 删除沙盒内的清单文件夹
/// </summary>
public static void DeleteManifestFolder()
{
string root = PathHelper.MakePersistentLoadPath(ManifestFolderName);
if (Directory.Exists(root))
Directory.Delete(root, true);
}
/// <summary> /// <summary>
/// 获取缓存文件夹路径 /// 获取缓存文件夹路径
/// </summary> /// </summary>
@ -114,6 +126,14 @@ namespace YooAsset
return $"{root}/{packageName}"; return $"{root}/{packageName}";
} }
/// <summary>
/// 获取应用程序的水印文件路径
/// </summary>
public static string GetAppFootPrintFilePath()
{
return PathHelper.MakePersistentLoadPath(AppFootPrintFileName);
}
#region 沙盒内清单相关 #region 沙盒内清单相关
/// <summary> /// <summary>
/// 获取沙盒内清单文件的路径 /// 获取沙盒内清单文件的路径
@ -121,7 +141,7 @@ namespace YooAsset
public static string GetCacheManifestFilePath(string packageName) public static string GetCacheManifestFilePath(string packageName)
{ {
string fileName = YooAssetSettingsData.GetPatchManifestFileNameWithoutVersion(packageName); string fileName = YooAssetSettingsData.GetPatchManifestFileNameWithoutVersion(packageName);
return PathHelper.MakePersistentLoadPath(fileName); return PathHelper.MakePersistentLoadPath($"{ManifestFolderName}/{fileName}");
} }
/// <summary> /// <summary>