2025-01-09 11:31:04 +08:00
|
|
|
|
#if UNITY_WEBGL && WEIXINMINIGAME
|
|
|
|
|
using YooAsset;
|
|
|
|
|
|
|
|
|
|
internal class RequestWechatPackageHashOperation : AsyncOperationBase
|
|
|
|
|
{
|
|
|
|
|
private enum ESteps
|
|
|
|
|
{
|
|
|
|
|
None,
|
|
|
|
|
RequestPackageHash,
|
|
|
|
|
Done,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly WechatFileSystem _fileSystem;
|
|
|
|
|
private readonly string _packageVersion;
|
|
|
|
|
private readonly int _timeout;
|
|
|
|
|
private UnityWebTextRequestOperation _webTextRequestOp;
|
|
|
|
|
private int _requestCount = 0;
|
|
|
|
|
private ESteps _steps = ESteps.None;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 包裹哈希值
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string PackageHash { private set; get; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public RequestWechatPackageHashOperation(WechatFileSystem fileSystem, string packageVersion, int timeout)
|
|
|
|
|
{
|
|
|
|
|
_fileSystem = fileSystem;
|
|
|
|
|
_packageVersion = packageVersion;
|
|
|
|
|
_timeout = timeout;
|
|
|
|
|
}
|
2025-02-28 16:11:01 +08:00
|
|
|
|
internal override void InternalStart()
|
2025-01-09 11:31:04 +08:00
|
|
|
|
{
|
|
|
|
|
_requestCount = WebRequestCounter.GetRequestFailedCount(_fileSystem.PackageName, nameof(RequestWechatPackageHashOperation));
|
|
|
|
|
_steps = ESteps.RequestPackageHash;
|
|
|
|
|
}
|
2025-02-28 16:11:01 +08:00
|
|
|
|
internal override void InternalUpdate()
|
2025-01-09 11:31:04 +08:00
|
|
|
|
{
|
|
|
|
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (_steps == ESteps.RequestPackageHash)
|
|
|
|
|
{
|
|
|
|
|
if (_webTextRequestOp == null)
|
|
|
|
|
{
|
|
|
|
|
string fileName = YooAssetSettingsData.GetPackageHashFileName(_fileSystem.PackageName, _packageVersion);
|
|
|
|
|
string url = GetRequestURL(fileName);
|
|
|
|
|
_webTextRequestOp = new UnityWebTextRequestOperation(url, _timeout);
|
2025-02-28 16:11:01 +08:00
|
|
|
|
_webTextRequestOp.StartOperation();
|
|
|
|
|
AddChildOperation(_webTextRequestOp);
|
2025-01-09 11:31:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-02-28 16:11:01 +08:00
|
|
|
|
_webTextRequestOp.UpdateOperation();
|
2025-01-09 11:31:04 +08:00
|
|
|
|
Progress = _webTextRequestOp.Progress;
|
|
|
|
|
if (_webTextRequestOp.IsDone == false)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (_webTextRequestOp.Status == EOperationStatus.Succeed)
|
|
|
|
|
{
|
|
|
|
|
PackageHash = _webTextRequestOp.Result;
|
|
|
|
|
if (string.IsNullOrEmpty(PackageHash))
|
|
|
|
|
{
|
|
|
|
|
_steps = ESteps.Done;
|
|
|
|
|
Status = EOperationStatus.Failed;
|
|
|
|
|
Error = $"Wechat package hash file content is empty !";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_steps = ESteps.Done;
|
|
|
|
|
Status = EOperationStatus.Succeed;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_steps = ESteps.Done;
|
|
|
|
|
Status = EOperationStatus.Failed;
|
|
|
|
|
Error = _webTextRequestOp.Error;
|
|
|
|
|
WebRequestCounter.RecordRequestFailed(_fileSystem.PackageName, nameof(RequestWechatPackageHashOperation));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetRequestURL(string fileName)
|
|
|
|
|
{
|
|
|
|
|
// 轮流返回请求地址
|
|
|
|
|
if (_requestCount % 2 == 0)
|
|
|
|
|
return _fileSystem.RemoteServices.GetRemoteMainURL(fileName);
|
|
|
|
|
else
|
|
|
|
|
return _fileSystem.RemoteServices.GetRemoteFallbackURL(fileName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|