using System.IO;
using UnityEngine;
namespace YooAsset
{
///
/// 应用程序水印
///
internal class ApplicationFootPrint
{
private readonly DefaultCacheFileSystem _fileSystem;
private string _footPrint;
public ApplicationFootPrint(DefaultCacheFileSystem fileSystem)
{
_fileSystem = fileSystem;
}
///
/// 读取应用程序水印
///
public void Load(string packageName)
{
string footPrintFilePath = _fileSystem.GetSandboxAppFootPrintFilePath();
if (File.Exists(footPrintFilePath))
{
_footPrint = FileUtility.ReadAllText(footPrintFilePath);
}
else
{
Coverage(packageName);
}
}
///
/// 检测水印是否发生变化
///
public bool IsDirty()
{
#if UNITY_EDITOR
return _footPrint != Application.version;
#else
return _footPrint != Application.buildGUID;
#endif
}
///
/// 覆盖掉水印
///
public void Coverage(string packageName)
{
#if UNITY_EDITOR
_footPrint = Application.version;
#else
_footPrint = Application.buildGUID;
#endif
string footPrintFilePath = _fileSystem.GetSandboxAppFootPrintFilePath();
FileUtility.WriteAllText(footPrintFilePath, _footPrint);
YooLogger.Log($"Save application foot print : {_footPrint}");
}
}
}