Compare commits

..

No commits in common. "31a0017351fd07a50740784e173b8e38d9204c8d" and "e925d9892f98ec34890700709bf0217c465a129b" have entirely different histories.

37 changed files with 263 additions and 559 deletions

View File

@ -373,7 +373,7 @@ namespace YooAsset
{ {
if (_wrappers.ContainsKey(bundleGUID)) if (_wrappers.ContainsKey(bundleGUID))
{ {
YooLogger.Error($"{nameof(DefaultCacheFileSystem)} has element : {bundleGUID}"); YooLogger.Error($"{nameof(DefaultCacheFileSystem)} has record file element : {bundleGUID}");
return false; return false;
} }

View File

@ -1,17 +1,15 @@
#if UNITY_WEBGL && DOUYINMINIGAME #if UNITY_WEBGL && BYTEMINIGAME
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using YooAsset; using YooAsset;
using TTSDK; using StarkSDKSpace;
using System.Linq;
using System;
public static class TiktokFileSystemCreater public static class ByteGameFileSystemCreater
{ {
public static FileSystemParameters CreateByteGameFileSystemParameters(IRemoteServices remoteServices, string packageRoot) public static FileSystemParameters CreateByteGameFileSystemParameters(IRemoteServices remoteServices)
{ {
string fileSystemClass = $"{nameof(TiktokFileSystem)},YooAsset.RuntimeExtension"; string fileSystemClass = $"{nameof(ByteGameFileSystem)},YooAsset.RuntimeExtension";
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot); var fileSystemParams = new FileSystemParameters(fileSystemClass, null);
fileSystemParams.AddParameter("REMOTE_SERVICES", remoteServices); fileSystemParams.AddParameter("REMOTE_SERVICES", remoteServices);
return fileSystemParams; return fileSystemParams;
} }
@ -21,7 +19,7 @@ public static class TiktokFileSystemCreater
/// 抖音小游戏文件系统 /// 抖音小游戏文件系统
/// 参考https://developer.open-douyin.com/docs/resource/zh-CN/mini-game/develop/guide/know /// 参考https://developer.open-douyin.com/docs/resource/zh-CN/mini-game/develop/guide/know
/// </summary> /// </summary>
internal class TiktokFileSystem : IFileSystem internal class ByteGameFileSystem : IFileSystem
{ {
private class WebRemoteServices : IRemoteServices private class WebRemoteServices : IRemoteServices
{ {
@ -53,10 +51,8 @@ internal class TiktokFileSystem : IFileSystem
} }
} }
private readonly HashSet<string> _recorders = new HashSet<string>();
private readonly Dictionary<string, string> _cacheFilePaths = new Dictionary<string, string>(10000); private readonly Dictionary<string, string> _cacheFilePaths = new Dictionary<string, string>(10000);
private TTFileSystemManager _fileSystemMgr; private StarkFileSystemManager _fileSystemManager;
private string _ttCacheRoot = string.Empty;
/// <summary> /// <summary>
/// 包裹名称 /// 包裹名称
@ -70,7 +66,7 @@ internal class TiktokFileSystem : IFileSystem
{ {
get get
{ {
return _ttCacheRoot; return string.Empty;
} }
} }
@ -81,7 +77,7 @@ internal class TiktokFileSystem : IFileSystem
{ {
get get
{ {
return _recorders.Count; return 0;
} }
} }
@ -93,24 +89,24 @@ internal class TiktokFileSystem : IFileSystem
#endregion #endregion
public TiktokFileSystem() public ByteGameFileSystem()
{ {
} }
public virtual FSInitializeFileSystemOperation InitializeFileSystemAsync() public virtual FSInitializeFileSystemOperation InitializeFileSystemAsync()
{ {
var operation = new TTFSInitializeOperation(this); var operation = new BGFSInitializeOperation(this);
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
} }
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout) public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout)
{ {
var operation = new TTFSLoadPackageManifestOperation(this, packageVersion, timeout); var operation = new BGFSLoadPackageManifestOperation(this, packageVersion, timeout);
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
} }
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks, int timeout) public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks, int timeout)
{ {
var operation = new TTFSRequestPackageVersionOperation(this, timeout); var operation = new BGFSRequestPackageVersionOperation(this, timeout);
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
} }
@ -124,7 +120,7 @@ internal class TiktokFileSystem : IFileSystem
{ {
param.MainURL = RemoteServices.GetRemoteMainURL(bundle.FileName); param.MainURL = RemoteServices.GetRemoteMainURL(bundle.FileName);
param.FallbackURL = RemoteServices.GetRemoteFallbackURL(bundle.FileName); param.FallbackURL = RemoteServices.GetRemoteFallbackURL(bundle.FileName);
var operation = new TTFSDownloadFileOperation(this, bundle, param); var operation = new BGFSDownloadFileOperation(this, bundle, param);
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
} }
@ -132,13 +128,13 @@ internal class TiktokFileSystem : IFileSystem
{ {
if (bundle.BundleType == (int)EBuildBundleType.AssetBundle) if (bundle.BundleType == (int)EBuildBundleType.AssetBundle)
{ {
var operation = new TTFSLoadBundleOperation(this, bundle); var operation = new BGFSLoadBundleOperation(this, bundle);
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
} }
else else
{ {
string error = $"{nameof(TiktokFileSystem)} not support load bundle type : {bundle.BundleType}"; string error = $"{nameof(ByteGameFileSystem)} not support load bundle type : {bundle.BundleType}";
var operation = new FSLoadBundleCompleteOperation(error); var operation = new FSLoadBundleCompleteOperation(error);
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
@ -159,12 +155,6 @@ internal class TiktokFileSystem : IFileSystem
public virtual void OnCreate(string packageName, string rootDirectory) public virtual void OnCreate(string packageName, string rootDirectory)
{ {
PackageName = packageName; PackageName = packageName;
_ttCacheRoot = rootDirectory;
if (string.IsNullOrEmpty(_ttCacheRoot))
{
throw new System.Exception("请配置抖音小游戏的缓存根目录!");
}
// 注意CDN服务未启用的情况下使用抖音WEB服务器 // 注意CDN服务未启用的情况下使用抖音WEB服务器
if (RemoteServices == null) if (RemoteServices == null)
@ -173,7 +163,7 @@ internal class TiktokFileSystem : IFileSystem
RemoteServices = new WebRemoteServices(webRoot); RemoteServices = new WebRemoteServices(webRoot);
} }
_fileSystemMgr = TT.GetFileSystemManager(); _fileSystemManager = StarkSDK.API.GetStarkFileSystemManager();
} }
public virtual void OnUpdate() public virtual void OnUpdate()
{ {
@ -186,7 +176,7 @@ internal class TiktokFileSystem : IFileSystem
public virtual bool Exists(PackageBundle bundle) public virtual bool Exists(PackageBundle bundle)
{ {
string filePath = GetCacheFileLoadPath(bundle); string filePath = GetCacheFileLoadPath(bundle);
return _recorders.Contains(filePath); return _fileSystemManager.AccessSync(filePath);
} }
public virtual bool NeedDownload(PackageBundle bundle) public virtual bool NeedDownload(PackageBundle bundle)
{ {
@ -206,80 +196,27 @@ internal class TiktokFileSystem : IFileSystem
public virtual string GetBundleFilePath(PackageBundle bundle) public virtual string GetBundleFilePath(PackageBundle bundle)
{ {
return GetCacheFileLoadPath(bundle); throw new System.NotImplementedException();
} }
public virtual byte[] ReadBundleFileData(PackageBundle bundle) public virtual byte[] ReadBundleFileData(PackageBundle bundle)
{ {
string filePath = GetCacheFileLoadPath(bundle); throw new System.NotImplementedException();
if (CheckCacheFileExist(filePath))
return _fileSystemMgr.ReadFileSync(filePath);
else
return Array.Empty<byte>();
} }
public virtual string ReadBundleFileText(PackageBundle bundle) public virtual string ReadBundleFileText(PackageBundle bundle)
{ {
string filePath = GetCacheFileLoadPath(bundle); throw new System.NotImplementedException();
if (CheckCacheFileExist(filePath))
return _fileSystemMgr.ReadFileSync(filePath, "utf8");
else
return string.Empty;
} }
#region 内部方法 #region 内部方法
public TTFileSystemManager GetFileSystemMgr()
{
return _fileSystemMgr;
}
public bool CheckCacheFileExist(string filePath)
{
return _fileSystemMgr.AccessSync(filePath);
}
private string GetCacheFileLoadPath(PackageBundle bundle) private string GetCacheFileLoadPath(PackageBundle bundle)
{ {
if (_cacheFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false) if (_cacheFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false)
{ {
filePath = _fileSystemMgr.GetLocalCachedPathForUrl(bundle.FileName); filePath = _fileSystemManager.GetLocalCachedPathForUrl(bundle.FileName);
_cacheFilePaths.Add(bundle.BundleGUID, filePath); _cacheFilePaths.Add(bundle.BundleGUID, filePath);
} }
return filePath; return filePath;
} }
#endregion #endregion
#region 本地记录
public List<string> GetAllRecords()
{
return _recorders.ToList();
}
public bool RecordBundleFile(string filePath)
{
if (_recorders.Contains(filePath))
{
YooLogger.Error($"{nameof(TiktokFileSystem)} has element : {filePath}");
return false;
}
_recorders.Add(filePath);
return true;
}
public void TryRecordBundle(PackageBundle bundle)
{
string filePath = GetCacheFileLoadPath(bundle);
if (_recorders.Contains(filePath) == false)
{
_recorders.Add(filePath);
}
}
public void ClearAllRecords()
{
_recorders.Clear();
}
public void ClearRecord(string filePath)
{
if (_recorders.Contains(filePath))
{
_recorders.Remove(filePath);
}
}
#endregion
} }
#endif #endif

View File

@ -1,14 +1,15 @@
#if UNITY_WEBGL && DOUYINMINIGAME #if UNITY_WEBGL && BYTEMINIGAME
using UnityEngine; using UnityEngine;
using UnityEngine.Networking; using UnityEngine.Networking;
using YooAsset; using YooAsset;
using StarkSDKSpace;
internal class TTFSDownloadFileOperation : DefaultDownloadFileOperation internal class BGFSDownloadFileOperation : DefaultDownloadFileOperation
{ {
private TiktokFileSystem _fileSystem; private ByteGameFileSystem _fileSystem;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
internal TTFSDownloadFileOperation(TiktokFileSystem fileSystem, PackageBundle bundle, DownloadParam param) : base(bundle, param) internal BGFSDownloadFileOperation(ByteGameFileSystem fileSystem, PackageBundle bundle, DownloadParam param) : base(bundle, param)
{ {
_fileSystem = fileSystem; _fileSystem = fileSystem;
} }

View File

@ -0,0 +1,20 @@
#if UNITY_WEBGL && BYTEMINIGAME
using YooAsset;
internal partial class BGFSInitializeOperation : FSInitializeFileSystemOperation
{
private readonly ByteGameFileSystem _fileSystem;
public BGFSInitializeOperation(ByteGameFileSystem fileSystem)
{
_fileSystem = fileSystem;
}
internal override void InternalOnStart()
{
Status = EOperationStatus.Succeed;
}
internal override void InternalOnUpdate()
{
}
}
#endif

View File

@ -1,10 +1,10 @@
#if UNITY_WEBGL && DOUYINMINIGAME #if UNITY_WEBGL && BYTEMINIGAME
using UnityEngine; using UnityEngine;
using UnityEngine.Networking; using UnityEngine.Networking;
using YooAsset; using YooAsset;
using TTSDK; using StarkSDKSpace;
internal class TTFSLoadBundleOperation : FSLoadBundleOperation internal class BGFSLoadBundleOperation : FSLoadBundleOperation
{ {
private enum ESteps private enum ESteps
{ {
@ -13,12 +13,12 @@ internal class TTFSLoadBundleOperation : FSLoadBundleOperation
Done, Done,
} }
private readonly TiktokFileSystem _fileSystem; private readonly ByteGameFileSystem _fileSystem;
private readonly PackageBundle _bundle; private readonly PackageBundle _bundle;
private UnityWebRequest _webRequest; private UnityWebRequest _webRequest;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
internal TTFSLoadBundleOperation(TiktokFileSystem fileSystem, PackageBundle bundle) internal BGFSLoadBundleOperation(ByteGameFileSystem fileSystem, PackageBundle bundle)
{ {
_fileSystem = fileSystem; _fileSystem = fileSystem;
_bundle = bundle; _bundle = bundle;

View File

@ -0,0 +1,88 @@
#if UNITY_WEBGL && BYTEMINIGAME
using YooAsset;
internal class BGFSLoadPackageManifestOperation : FSLoadPackageManifestOperation
{
private enum ESteps
{
None,
RequestRemotePackageHash,
LoadRemotePackageManifest,
Done,
}
private readonly ByteGameFileSystem _fileSystem;
private readonly string _packageVersion;
private readonly int _timeout;
private RequestByteGamePackageHashOperation _requestRemotePackageHashOp;
private LoadByteGamePackageManifestOperation _loadRemotePackageManifestOp;
private ESteps _steps = ESteps.None;
public BGFSLoadPackageManifestOperation(ByteGameFileSystem fileSystem, string packageVersion, int timeout)
{
_fileSystem = fileSystem;
_packageVersion = packageVersion;
_timeout = timeout;
}
internal override void InternalOnStart()
{
_steps = ESteps.RequestRemotePackageHash;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.RequestRemotePackageHash)
{
if (_requestRemotePackageHashOp == null)
{
_requestRemotePackageHashOp = new RequestByteGamePackageHashOperation(_fileSystem, _packageVersion, _timeout);
OperationSystem.StartOperation(_fileSystem.PackageName, _requestRemotePackageHashOp);
}
if (_requestRemotePackageHashOp.IsDone == false)
return;
if (_requestRemotePackageHashOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.LoadRemotePackageManifest;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _requestRemotePackageHashOp.Error;
}
}
if (_steps == ESteps.LoadRemotePackageManifest)
{
if (_loadRemotePackageManifestOp == null)
{
string packageHash = _requestRemotePackageHashOp.PackageHash;
_loadRemotePackageManifestOp = new LoadByteGamePackageManifestOperation(_fileSystem, _packageVersion, packageHash, _timeout);
OperationSystem.StartOperation(_fileSystem.PackageName, _loadRemotePackageManifestOp);
}
Progress = _loadRemotePackageManifestOp.Progress;
if (_loadRemotePackageManifestOp.IsDone == false)
return;
if (_loadRemotePackageManifestOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
Manifest = _loadRemotePackageManifestOp.Manifest;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _loadRemotePackageManifestOp.Error;
}
}
}
}
#endif

View File

@ -1,7 +1,7 @@
#if UNITY_WEBGL && DOUYINMINIGAME #if UNITY_WEBGL && BYTEMINIGAME
using YooAsset; using YooAsset;
internal class TTFSRequestPackageVersionOperation : FSRequestPackageVersionOperation internal class BGFSRequestPackageVersionOperation : FSRequestPackageVersionOperation
{ {
private enum ESteps private enum ESteps
{ {
@ -10,13 +10,13 @@ internal class TTFSRequestPackageVersionOperation : FSRequestPackageVersionOpera
Done, Done,
} }
private readonly TiktokFileSystem _fileSystem; private readonly ByteGameFileSystem _fileSystem;
private readonly int _timeout; private readonly int _timeout;
private RequestTiktokPackageVersionOperation _requestPackageVersionOp; private RequestByteGamePackageVersionOperation _requestWebPackageVersionOp;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
internal TTFSRequestPackageVersionOperation(TiktokFileSystem fileSystem, int timeout) internal BGFSRequestPackageVersionOperation(ByteGameFileSystem fileSystem, int timeout)
{ {
_fileSystem = fileSystem; _fileSystem = fileSystem;
_timeout = timeout; _timeout = timeout;
@ -32,27 +32,27 @@ internal class TTFSRequestPackageVersionOperation : FSRequestPackageVersionOpera
if (_steps == ESteps.RequestPackageVersion) if (_steps == ESteps.RequestPackageVersion)
{ {
if (_requestPackageVersionOp == null) if (_requestWebPackageVersionOp == null)
{ {
_requestPackageVersionOp = new RequestTiktokPackageVersionOperation(_fileSystem, _timeout); _requestWebPackageVersionOp = new RequestByteGamePackageVersionOperation(_fileSystem, _timeout);
OperationSystem.StartOperation(_fileSystem.PackageName, _requestPackageVersionOp); OperationSystem.StartOperation(_fileSystem.PackageName, _requestWebPackageVersionOp);
} }
Progress = _requestPackageVersionOp.Progress; Progress = _requestWebPackageVersionOp.Progress;
if (_requestPackageVersionOp.IsDone == false) if (_requestWebPackageVersionOp.IsDone == false)
return; return;
if (_requestPackageVersionOp.Status == EOperationStatus.Succeed) if (_requestWebPackageVersionOp.Status == EOperationStatus.Succeed)
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
PackageVersion = _requestPackageVersionOp.PackageVersion; PackageVersion = _requestWebPackageVersionOp.PackageVersion;
Status = EOperationStatus.Succeed; Status = EOperationStatus.Succeed;
} }
else else
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = _requestPackageVersionOp.Error; Error = _requestWebPackageVersionOp.Error;
} }
} }
} }

View File

@ -1,7 +1,7 @@
#if UNITY_WEBGL && DOUYINMINIGAME #if UNITY_WEBGL && BYTEMINIGAME
using YooAsset; using YooAsset;
internal class LoadTiktokPackageManifestOperation : AsyncOperationBase internal class LoadByteGamePackageManifestOperation : AsyncOperationBase
{ {
private enum ESteps private enum ESteps
{ {
@ -12,7 +12,7 @@ internal class LoadTiktokPackageManifestOperation : AsyncOperationBase
Done, Done,
} }
private readonly TiktokFileSystem _fileSystem; private readonly ByteGameFileSystem _fileSystem;
private readonly string _packageVersion; private readonly string _packageVersion;
private readonly string _packageHash; private readonly string _packageHash;
private readonly int _timeout; private readonly int _timeout;
@ -27,7 +27,7 @@ internal class LoadTiktokPackageManifestOperation : AsyncOperationBase
public PackageManifest Manifest { private set; get; } public PackageManifest Manifest { private set; get; }
internal LoadTiktokPackageManifestOperation(TiktokFileSystem fileSystem, string packageVersion, string packageHash, int timeout) internal LoadByteGamePackageManifestOperation(ByteGameFileSystem fileSystem, string packageVersion, string packageHash, int timeout)
{ {
_fileSystem = fileSystem; _fileSystem = fileSystem;
_packageVersion = packageVersion; _packageVersion = packageVersion;
@ -36,7 +36,7 @@ internal class LoadTiktokPackageManifestOperation : AsyncOperationBase
} }
internal override void InternalOnStart() internal override void InternalOnStart()
{ {
_requestCount = WebRequestCounter.GetRequestFailedCount(_fileSystem.PackageName, nameof(LoadTiktokPackageManifestOperation)); _requestCount = WebRequestCounter.GetRequestFailedCount(_fileSystem.PackageName, nameof(LoadByteGamePackageManifestOperation));
_steps = ESteps.RequestFileData; _steps = ESteps.RequestFileData;
} }
internal override void InternalOnUpdate() internal override void InternalOnUpdate()
@ -67,7 +67,7 @@ internal class LoadTiktokPackageManifestOperation : AsyncOperationBase
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = _webDataRequestOp.Error; Error = _webDataRequestOp.Error;
WebRequestCounter.RecordRequestFailed(_fileSystem.PackageName, nameof(LoadTiktokPackageManifestOperation)); WebRequestCounter.RecordRequestFailed(_fileSystem.PackageName, nameof(LoadByteGamePackageManifestOperation));
} }
} }

View File

@ -1,7 +1,7 @@
#if UNITY_WEBGL && DOUYINMINIGAME #if UNITY_WEBGL && BYTEMINIGAME
using YooAsset; using YooAsset;
internal class RequestTiktokPackageHashOperation : AsyncOperationBase internal class RequestByteGamePackageHashOperation : AsyncOperationBase
{ {
private enum ESteps private enum ESteps
{ {
@ -10,7 +10,7 @@ internal class RequestTiktokPackageHashOperation : AsyncOperationBase
Done, Done,
} }
private readonly TiktokFileSystem _fileSystem; private readonly ByteGameFileSystem _fileSystem;
private readonly string _packageVersion; private readonly string _packageVersion;
private readonly int _timeout; private readonly int _timeout;
private UnityWebTextRequestOperation _webTextRequestOp; private UnityWebTextRequestOperation _webTextRequestOp;
@ -23,7 +23,7 @@ internal class RequestTiktokPackageHashOperation : AsyncOperationBase
public string PackageHash { private set; get; } public string PackageHash { private set; get; }
public RequestTiktokPackageHashOperation(TiktokFileSystem fileSystem, string packageVersion, int timeout) public RequestByteGamePackageHashOperation(ByteGameFileSystem fileSystem, string packageVersion, int timeout)
{ {
_fileSystem = fileSystem; _fileSystem = fileSystem;
_packageVersion = packageVersion; _packageVersion = packageVersion;
@ -31,7 +31,7 @@ internal class RequestTiktokPackageHashOperation : AsyncOperationBase
} }
internal override void InternalOnStart() internal override void InternalOnStart()
{ {
_requestCount = WebRequestCounter.GetRequestFailedCount(_fileSystem.PackageName, nameof(RequestTiktokPackageHashOperation)); _requestCount = WebRequestCounter.GetRequestFailedCount(_fileSystem.PackageName, nameof(RequestByteGamePackageHashOperation));
_steps = ESteps.RequestPackageHash; _steps = ESteps.RequestPackageHash;
} }
internal override void InternalOnUpdate() internal override void InternalOnUpdate()
@ -73,7 +73,7 @@ internal class RequestTiktokPackageHashOperation : AsyncOperationBase
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = _webTextRequestOp.Error; Error = _webTextRequestOp.Error;
WebRequestCounter.RecordRequestFailed(_fileSystem.PackageName, nameof(RequestTiktokPackageHashOperation)); WebRequestCounter.RecordRequestFailed(_fileSystem.PackageName, nameof(RequestByteGamePackageHashOperation));
} }
} }
} }

View File

@ -1,7 +1,7 @@
#if UNITY_WEBGL && DOUYINMINIGAME #if UNITY_WEBGL && BYTEMINIGAME
using YooAsset; using YooAsset;
internal class RequestTiktokPackageVersionOperation : AsyncOperationBase internal class RequestByteGamePackageVersionOperation : AsyncOperationBase
{ {
private enum ESteps private enum ESteps
{ {
@ -10,7 +10,7 @@ internal class RequestTiktokPackageVersionOperation : AsyncOperationBase
Done, Done,
} }
private readonly TiktokFileSystem _fileSystem; private readonly ByteGameFileSystem _fileSystem;
private readonly int _timeout; private readonly int _timeout;
private UnityWebTextRequestOperation _webTextRequestOp; private UnityWebTextRequestOperation _webTextRequestOp;
private int _requestCount = 0; private int _requestCount = 0;
@ -22,14 +22,14 @@ internal class RequestTiktokPackageVersionOperation : AsyncOperationBase
public string PackageVersion { private set; get; } public string PackageVersion { private set; get; }
public RequestTiktokPackageVersionOperation(TiktokFileSystem fileSystem, int timeout) public RequestByteGamePackageVersionOperation(ByteGameFileSystem fileSystem, int timeout)
{ {
_fileSystem = fileSystem; _fileSystem = fileSystem;
_timeout = timeout; _timeout = timeout;
} }
internal override void InternalOnStart() internal override void InternalOnStart()
{ {
_requestCount = WebRequestCounter.GetRequestFailedCount(_fileSystem.PackageName, nameof(RequestTiktokPackageVersionOperation)); _requestCount = WebRequestCounter.GetRequestFailedCount(_fileSystem.PackageName, nameof(RequestByteGamePackageVersionOperation));
_steps = ESteps.RequestPackageVersion; _steps = ESteps.RequestPackageVersion;
} }
internal override void InternalOnUpdate() internal override void InternalOnUpdate()
@ -71,7 +71,7 @@ internal class RequestTiktokPackageVersionOperation : AsyncOperationBase
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = _webTextRequestOp.Error; Error = _webTextRequestOp.Error;
WebRequestCounter.RecordRequestFailed(_fileSystem.PackageName, nameof(RequestTiktokPackageVersionOperation)); WebRequestCounter.RecordRequestFailed(_fileSystem.PackageName, nameof(RequestByteGamePackageVersionOperation));
} }
} }
} }

View File

@ -1,55 +0,0 @@
#if UNITY_WEBGL && DOUYINMINIGAME
using YooAsset;
internal partial class TTFSInitializeOperation : FSInitializeFileSystemOperation
{
private enum ESteps
{
None,
RecordCacheFiles,
Done,
}
private readonly TiktokFileSystem _fileSystem;
private RecordTiktokCacheFilesOperation _recordTiktokCacheFilesOp;
private ESteps _steps = ESteps.None;
public TTFSInitializeOperation(TiktokFileSystem fileSystem)
{
_fileSystem = fileSystem;
}
internal override void InternalOnStart()
{
_steps = ESteps.RecordCacheFiles;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.RecordCacheFiles)
{
if (_recordTiktokCacheFilesOp == null)
{
_recordTiktokCacheFilesOp = new RecordTiktokCacheFilesOperation(_fileSystem);
OperationSystem.StartOperation(_fileSystem.PackageName, _recordTiktokCacheFilesOp);
}
if (_recordTiktokCacheFilesOp.IsDone == false)
return;
if (_recordTiktokCacheFilesOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _recordTiktokCacheFilesOp.Error;
}
}
}
}
#endif

View File

@ -1,88 +0,0 @@
#if UNITY_WEBGL && DOUYINMINIGAME
using YooAsset;
internal class TTFSLoadPackageManifestOperation : FSLoadPackageManifestOperation
{
private enum ESteps
{
None,
RequestPackageHash,
LoadPackageManifest,
Done,
}
private readonly TiktokFileSystem _fileSystem;
private readonly string _packageVersion;
private readonly int _timeout;
private RequestTiktokPackageHashOperation _requestPackageHashOp;
private LoadTiktokPackageManifestOperation _loadPackageManifestOp;
private ESteps _steps = ESteps.None;
public TTFSLoadPackageManifestOperation(TiktokFileSystem fileSystem, string packageVersion, int timeout)
{
_fileSystem = fileSystem;
_packageVersion = packageVersion;
_timeout = timeout;
}
internal override void InternalOnStart()
{
_steps = ESteps.RequestPackageHash;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.RequestPackageHash)
{
if (_requestPackageHashOp == null)
{
_requestPackageHashOp = new RequestTiktokPackageHashOperation(_fileSystem, _packageVersion, _timeout);
OperationSystem.StartOperation(_fileSystem.PackageName, _requestPackageHashOp);
}
if (_requestPackageHashOp.IsDone == false)
return;
if (_requestPackageHashOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.LoadPackageManifest;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _requestPackageHashOp.Error;
}
}
if (_steps == ESteps.LoadPackageManifest)
{
if (_loadPackageManifestOp == null)
{
string packageHash = _requestPackageHashOp.PackageHash;
_loadPackageManifestOp = new LoadTiktokPackageManifestOperation(_fileSystem, _packageVersion, packageHash, _timeout);
OperationSystem.StartOperation(_fileSystem.PackageName, _loadPackageManifestOp);
}
Progress = _loadPackageManifestOp.Progress;
if (_loadPackageManifestOp.IsDone == false)
return;
if (_loadPackageManifestOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
Manifest = _loadPackageManifestOp.Manifest;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _loadPackageManifestOp.Error;
}
}
}
}
#endif

View File

@ -1,57 +0,0 @@
#if UNITY_WEBGL && DOUYINMINIGAME
using YooAsset;
using TTSDK;
internal class RecordTiktokCacheFilesOperation : AsyncOperationBase
{
private enum ESteps
{
None,
RecordCacheFiles,
WaitResponse,
Done,
}
private readonly TiktokFileSystem _fileSystem;
private ESteps _steps = ESteps.None;
public RecordTiktokCacheFilesOperation(TiktokFileSystem fileSystem)
{
_fileSystem = fileSystem;
}
internal override void InternalOnStart()
{
_steps = ESteps.RecordCacheFiles;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.RecordCacheFiles)
{
_steps = ESteps.WaitResponse;
var fileSystemMgr = _fileSystem.GetFileSystemMgr();
var getSavedFileListParam = new GetSavedFileListParam();
getSavedFileListParam.success = (TTGetSavedFileListResponse response) =>
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
foreach (var fileInfo in response.fileList)
{
//TODO 需要确认存储文件为Bundle文件
_fileSystem.RecordBundleFile(fileInfo.filePath);
}
};
getSavedFileListParam.fail = (TTGetSavedFileListResponse response) =>
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = response.errMsg;
};
fileSystemMgr.GetSavedFileList(getSavedFileListParam);
}
}
}
#endif

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: e4420bd73f37dec468a9b23425be68f2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -11,13 +11,13 @@ internal class WXFSClearAllBundleFilesOperation : FSClearCacheFilesOperation
{ {
None, None,
ClearAllCacheFiles, ClearAllCacheFiles,
WaitResult,
Done, Done,
} }
private readonly WechatFileSystem _fileSystem; private readonly WechatFileSystem _fileSystem;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
internal WXFSClearAllBundleFilesOperation(WechatFileSystem fileSystem) internal WXFSClearAllBundleFilesOperation(WechatFileSystem fileSystem)
{ {
_fileSystem = fileSystem; _fileSystem = fileSystem;
@ -33,25 +33,16 @@ internal class WXFSClearAllBundleFilesOperation : FSClearCacheFilesOperation
if (_steps == ESteps.ClearAllCacheFiles) if (_steps == ESteps.ClearAllCacheFiles)
{ {
_steps = ESteps.WaitResult;
WX.CleanAllFileCache((bool isOk) => WX.CleanAllFileCache((bool isOk) =>
{ {
if (isOk) if (isOk)
{
YooLogger.Log("微信缓存清理成功!"); YooLogger.Log("微信缓存清理成功!");
else
YooLogger.Log("微信缓存清理失败!");
});
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Succeed; Status = EOperationStatus.Succeed;
_fileSystem.ClearAllRecords();
}
else
{
YooLogger.Log("微信缓存清理失败!");
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "微信缓存清理失败!";
}
});
} }
} }
} }

View File

@ -5,11 +5,14 @@ using UnityEngine;
using YooAsset; using YooAsset;
using WeChatWASM; using WeChatWASM;
internal class WXFSClearUnusedBundleFilesAsync : FSClearCacheFilesOperation internal class WXFSClearUnusedBundleFilesAsync : FSClearCacheFilesOperation
{ {
private enum ESteps private enum ESteps
{ {
None, None,
GetAllCacheFiles,
WaitResult,
GetUnusedCacheFiles, GetUnusedCacheFiles,
ClearUnusedCacheFiles, ClearUnusedCacheFiles,
Done, Done,
@ -19,6 +22,7 @@ internal class WXFSClearUnusedBundleFilesAsync : FSClearCacheFilesOperation
private readonly PackageManifest _manifest; private readonly PackageManifest _manifest;
private List<string> _unusedCacheFiles; private List<string> _unusedCacheFiles;
private int _unusedFileTotalCount = 0; private int _unusedFileTotalCount = 0;
private GetSavedFileListSuccessCallbackResult _result;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
internal WXFSClearUnusedBundleFilesAsync(WechatFileSystem fileSystem, PackageManifest manifest) internal WXFSClearUnusedBundleFilesAsync(WechatFileSystem fileSystem, PackageManifest manifest)
@ -28,13 +32,38 @@ internal class WXFSClearUnusedBundleFilesAsync : FSClearCacheFilesOperation
} }
internal override void InternalOnStart() internal override void InternalOnStart()
{ {
_steps = ESteps.GetUnusedCacheFiles; _steps = ESteps.GetAllCacheFiles;
} }
internal override void InternalOnUpdate() internal override void InternalOnUpdate()
{ {
if (_steps == ESteps.None || _steps == ESteps.Done) if (_steps == ESteps.None || _steps == ESteps.Done)
return; return;
if (_steps == ESteps.GetAllCacheFiles)
{
_steps = ESteps.WaitResult;
var fileSystemMgr = WX.GetFileSystemManager();
var option = new GetSavedFileListOption();
fileSystemMgr.GetSavedFileList(option);
option.fail += (FileError error) =>
{
_steps = ESteps.Done;
Error = error.errMsg;
Status = EOperationStatus.Failed;
};
option.success += (GetSavedFileListSuccessCallbackResult result) =>
{
_result = result;
_steps = ESteps.GetUnusedCacheFiles;
};
}
if (_steps == ESteps.WaitResult)
{
return;
}
if (_steps == ESteps.GetUnusedCacheFiles) if (_steps == ESteps.GetUnusedCacheFiles)
{ {
_unusedCacheFiles = GetUnusedCacheFiles(); _unusedCacheFiles = GetUnusedCacheFiles();
@ -47,10 +76,9 @@ internal class WXFSClearUnusedBundleFilesAsync : FSClearCacheFilesOperation
{ {
for (int i = _unusedCacheFiles.Count - 1; i >= 0; i--) for (int i = _unusedCacheFiles.Count - 1; i >= 0; i--)
{ {
string clearFilePath = _unusedCacheFiles[i]; string cacheFilePath = _unusedCacheFiles[i];
WX.RemoveFile(cacheFilePath, null);
_unusedCacheFiles.RemoveAt(i); _unusedCacheFiles.RemoveAt(i);
_fileSystem.ClearRecord(clearFilePath);
WX.RemoveFile(clearFilePath, null);
if (OperationSystem.IsBusy) if (OperationSystem.IsBusy)
break; break;
@ -71,23 +99,22 @@ internal class WXFSClearUnusedBundleFilesAsync : FSClearCacheFilesOperation
private List<string> GetUnusedCacheFiles() private List<string> GetUnusedCacheFiles()
{ {
var allRecords = _fileSystem.GetAllRecords(); List<string> result = new List<string>(_result.fileList.Length);
List<string> result = new List<string>(allRecords.Count); foreach (var fileInfo in _result.fileList)
foreach (var filePath in allRecords)
{ {
// 如果存储文件名是按照Bundle文件哈希值存储 // 如果存储文件名是按照Bundle文件哈希值存储
string bundleGUID = Path.GetFileNameWithoutExtension(filePath); string bundleGUID = Path.GetFileNameWithoutExtension(fileInfo.filePath);
if (_manifest.TryGetPackageBundleByBundleGUID(bundleGUID, out PackageBundle value) == false) if (_manifest.TryGetPackageBundleByBundleGUID(bundleGUID, out PackageBundle value) == false)
{ {
result.Add(filePath); result.Add(fileInfo.filePath);
} }
// 如果存储文件名是按照Bundle文件名称存储 // 如果存储文件名是按照Bundle文件名称存储
/* /*
string bundleName = Path.GetFileNameWithoutExtension(filePath); string bundleName = Path.GetFileNameWithoutExtension(fileInfo.filePath);
if (_manifest.TryGetPackageBundleByBundleName(bundleName, out PackageBundle value) == false) if (_manifest.TryGetPackageBundleByBundleName(bundleName, out PackageBundle value) == false)
{ {
result.Add(filePath); result.Add(fileInfo.filePath);
} }
*/ */
} }

View File

@ -51,7 +51,6 @@ internal class WXFSDownloadFileOperation : DefaultDownloadFileOperation
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Succeed; Status = EOperationStatus.Succeed;
_fileSystem.TryRecordBundle(Bundle); //记录下载文件
} }
else else
{ {

View File

@ -3,16 +3,7 @@ using YooAsset;
internal partial class WXFSInitializeOperation : FSInitializeFileSystemOperation internal partial class WXFSInitializeOperation : FSInitializeFileSystemOperation
{ {
private enum ESteps
{
None,
RecordCacheFiles,
Done,
}
private readonly WechatFileSystem _fileSystem; private readonly WechatFileSystem _fileSystem;
private RecordWechatCacheFilesOperation _recordWechatCacheFilesOp;
private ESteps _steps = ESteps.None;
public WXFSInitializeOperation(WechatFileSystem fileSystem) public WXFSInitializeOperation(WechatFileSystem fileSystem)
{ {
@ -20,36 +11,10 @@ internal partial class WXFSInitializeOperation : FSInitializeFileSystemOperation
} }
internal override void InternalOnStart() internal override void InternalOnStart()
{ {
_steps = ESteps.RecordCacheFiles; Status = EOperationStatus.Succeed;
} }
internal override void InternalOnUpdate() internal override void InternalOnUpdate()
{ {
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.RecordCacheFiles)
{
if (_recordWechatCacheFilesOp == null)
{
_recordWechatCacheFilesOp = new RecordWechatCacheFilesOperation(_fileSystem);
OperationSystem.StartOperation(_fileSystem.PackageName, _recordWechatCacheFilesOp);
}
if (_recordWechatCacheFilesOp.IsDone == false)
return;
if (_recordWechatCacheFilesOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _recordWechatCacheFilesOp.Error;
}
}
} }
} }
#endif #endif

View File

@ -61,7 +61,6 @@ internal class WXFSLoadBundleOperation : FSLoadBundleOperation
_steps = ESteps.Done; _steps = ESteps.Done;
Result = new WXAssetBundleResult(_fileSystem, _bundle, assetBundle); Result = new WXAssetBundleResult(_fileSystem, _bundle, assetBundle);
Status = EOperationStatus.Succeed; Status = EOperationStatus.Succeed;
_fileSystem.TryRecordBundle(_bundle); //记录下载文件
} }
} }
else else

View File

@ -6,16 +6,16 @@ internal class WXFSLoadPackageManifestOperation : FSLoadPackageManifestOperation
private enum ESteps private enum ESteps
{ {
None, None,
RequestPackageHash, RequestRemotePackageHash,
LoadPackageManifest, LoadRemotePackageManifest,
Done, Done,
} }
private readonly WechatFileSystem _fileSystem; private readonly WechatFileSystem _fileSystem;
private readonly string _packageVersion; private readonly string _packageVersion;
private readonly int _timeout; private readonly int _timeout;
private RequestWechatPackageHashOperation _requestPackageHashOp; private RequestWechatPackageHashOperation _requestRemotePackageHashOp;
private LoadWechatPackageManifestOperation _loadPackageManifestOp; private LoadWechatPackageManifestOperation _loadRemotePackageManifestOp;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
@ -27,60 +27,60 @@ internal class WXFSLoadPackageManifestOperation : FSLoadPackageManifestOperation
} }
internal override void InternalOnStart() internal override void InternalOnStart()
{ {
_steps = ESteps.RequestPackageHash; _steps = ESteps.RequestRemotePackageHash;
} }
internal override void InternalOnUpdate() internal override void InternalOnUpdate()
{ {
if (_steps == ESteps.None || _steps == ESteps.Done) if (_steps == ESteps.None || _steps == ESteps.Done)
return; return;
if (_steps == ESteps.RequestPackageHash) if (_steps == ESteps.RequestRemotePackageHash)
{ {
if (_requestPackageHashOp == null) if (_requestRemotePackageHashOp == null)
{ {
_requestPackageHashOp = new RequestWechatPackageHashOperation(_fileSystem, _packageVersion, _timeout); _requestRemotePackageHashOp = new RequestWechatPackageHashOperation(_fileSystem, _packageVersion, _timeout);
OperationSystem.StartOperation(_fileSystem.PackageName, _requestPackageHashOp); OperationSystem.StartOperation(_fileSystem.PackageName, _requestRemotePackageHashOp);
} }
if (_requestPackageHashOp.IsDone == false) if (_requestRemotePackageHashOp.IsDone == false)
return; return;
if (_requestPackageHashOp.Status == EOperationStatus.Succeed) if (_requestRemotePackageHashOp.Status == EOperationStatus.Succeed)
{ {
_steps = ESteps.LoadPackageManifest; _steps = ESteps.LoadRemotePackageManifest;
} }
else else
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = _requestPackageHashOp.Error; Error = _requestRemotePackageHashOp.Error;
} }
} }
if (_steps == ESteps.LoadPackageManifest) if (_steps == ESteps.LoadRemotePackageManifest)
{ {
if (_loadPackageManifestOp == null) if (_loadRemotePackageManifestOp == null)
{ {
string packageHash = _requestPackageHashOp.PackageHash; string packageHash = _requestRemotePackageHashOp.PackageHash;
_loadPackageManifestOp = new LoadWechatPackageManifestOperation(_fileSystem, _packageVersion, packageHash, _timeout); _loadRemotePackageManifestOp = new LoadWechatPackageManifestOperation(_fileSystem, _packageVersion, packageHash, _timeout);
OperationSystem.StartOperation(_fileSystem.PackageName, _loadPackageManifestOp); OperationSystem.StartOperation(_fileSystem.PackageName, _loadRemotePackageManifestOp);
} }
Progress = _loadPackageManifestOp.Progress; Progress = _loadRemotePackageManifestOp.Progress;
if (_loadPackageManifestOp.IsDone == false) if (_loadRemotePackageManifestOp.IsDone == false)
return; return;
if (_loadPackageManifestOp.Status == EOperationStatus.Succeed) if (_loadRemotePackageManifestOp.Status == EOperationStatus.Succeed)
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Manifest = _loadPackageManifestOp.Manifest; Manifest = _loadRemotePackageManifestOp.Manifest;
Status = EOperationStatus.Succeed; Status = EOperationStatus.Succeed;
} }
else else
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = _loadPackageManifestOp.Error; Error = _loadRemotePackageManifestOp.Error;
} }
} }
} }

View File

@ -1,58 +0,0 @@
#if UNITY_WEBGL && WEIXINMINIGAME
using YooAsset;
using WeChatWASM;
using System.IO;
internal class RecordWechatCacheFilesOperation : AsyncOperationBase
{
private enum ESteps
{
None,
RecordCacheFiles,
WaitResponse,
Done,
}
private readonly WechatFileSystem _fileSystem;
private ESteps _steps = ESteps.None;
public RecordWechatCacheFilesOperation(WechatFileSystem fileSystem)
{
_fileSystem = fileSystem;
}
internal override void InternalOnStart()
{
_steps = ESteps.RecordCacheFiles;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.RecordCacheFiles)
{
_steps = ESteps.WaitResponse;
var fileSystemMgr = _fileSystem.GetFileSystemMgr();
var getSavedFileListOption = new GetSavedFileListOption();
getSavedFileListOption.success = (GetSavedFileListSuccessCallbackResult response) =>
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
foreach (var fileInfo in response.fileList)
{
//TODO 需要确认存储文件为Bundle文件
_fileSystem.RecordBundleFile(fileInfo.filePath);
}
};
getSavedFileListOption.fail = (FileError fileError) =>
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = fileError.errMsg;
};
fileSystemMgr.GetSavedFileList(getSavedFileListOption);
}
}
}
#endif

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 640ec7bd883b8314db53b508278aea6e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,17 +1,16 @@
#if UNITY_WEBGL && WEIXINMINIGAME #if UNITY_WEBGL && WEIXINMINIGAME
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using UnityEngine; using UnityEngine;
using YooAsset; using YooAsset;
using WeChatWASM; using WeChatWASM;
public static class WechatFileSystemCreater public static class WechatFileSystemCreater
{ {
public static FileSystemParameters CreateWechatFileSystemParameters(IRemoteServices remoteServices, string packageRoot) public static FileSystemParameters CreateWechatFileSystemParameters(IRemoteServices remoteServices)
{ {
string fileSystemClass = $"{nameof(WechatFileSystem)},YooAsset.RuntimeExtension"; string fileSystemClass = $"{nameof(WechatFileSystem)},YooAsset.RuntimeExtension";
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot); var fileSystemParams = new FileSystemParameters(fileSystemClass, null);
fileSystemParams.AddParameter("REMOTE_SERVICES", remoteServices); fileSystemParams.AddParameter("REMOTE_SERVICES", remoteServices);
return fileSystemParams; return fileSystemParams;
} }
@ -53,10 +52,12 @@ internal class WechatFileSystem : IFileSystem
} }
} }
private readonly HashSet<string> _recorders = new HashSet<string>(); /// <summary>
/// Key:资源包GUID Value:缓存路径
/// </summary>
private readonly Dictionary<string, string> _cacheFilePaths = new Dictionary<string, string>(10000); private readonly Dictionary<string, string> _cacheFilePaths = new Dictionary<string, string>(10000);
private WXFileSystemManager _fileSystemMgr; private WXFileSystemManager _wxFileSystemMgr;
private string _wxCacheRoot = string.Empty; private string _fileCacheRoot = string.Empty;
/// <summary> /// <summary>
/// 包裹名称 /// 包裹名称
@ -70,7 +71,7 @@ internal class WechatFileSystem : IFileSystem
{ {
get get
{ {
return _wxCacheRoot; return _fileCacheRoot;
} }
} }
@ -81,7 +82,7 @@ internal class WechatFileSystem : IFileSystem
{ {
get get
{ {
return _recorders.Count; return 0;
} }
} }
@ -175,12 +176,6 @@ internal class WechatFileSystem : IFileSystem
public virtual void OnCreate(string packageName, string rootDirectory) public virtual void OnCreate(string packageName, string rootDirectory)
{ {
PackageName = packageName; PackageName = packageName;
_wxCacheRoot = rootDirectory;
if (string.IsNullOrEmpty(_wxCacheRoot))
{
throw new System.Exception("请配置微信小游戏缓存根目录!");
}
// 注意CDN服务未启用的情况下使用微信WEB服务器 // 注意CDN服务未启用的情况下使用微信WEB服务器
if (RemoteServices == null) if (RemoteServices == null)
@ -189,7 +184,10 @@ internal class WechatFileSystem : IFileSystem
RemoteServices = new WebRemoteServices(webRoot); RemoteServices = new WebRemoteServices(webRoot);
} }
_fileSystemMgr = WX.GetFileSystemManager(); _wxFileSystemMgr = WX.GetFileSystemManager();
_fileCacheRoot = $"{WX.env.USER_DATA_PATH}/__GAME_FILE_CACHE";
//_fileCacheRoot = $"{WX.env.USER_DATA_PATH}/__GAME_FILE_CACHE/子目录"; //注意:如果有子目录,请修改此处!
//_fileCacheRoot = PathUtility.Combine(WX.PluginCachePath, $"StreamingAssets/WebGL");
} }
public virtual void OnUpdate() public virtual void OnUpdate()
{ {
@ -202,7 +200,7 @@ internal class WechatFileSystem : IFileSystem
public virtual bool Exists(PackageBundle bundle) public virtual bool Exists(PackageBundle bundle)
{ {
string filePath = GetCacheFileLoadPath(bundle); string filePath = GetCacheFileLoadPath(bundle);
return _recorders.Contains(filePath); return CheckCacheFileExist(filePath);
} }
public virtual bool NeedDownload(PackageBundle bundle) public virtual bool NeedDownload(PackageBundle bundle)
{ {
@ -228,7 +226,7 @@ internal class WechatFileSystem : IFileSystem
{ {
string filePath = GetCacheFileLoadPath(bundle); string filePath = GetCacheFileLoadPath(bundle);
if (CheckCacheFileExist(filePath)) if (CheckCacheFileExist(filePath))
return _fileSystemMgr.ReadFileSync(filePath); return _wxFileSystemMgr.ReadFileSync(filePath);
else else
return Array.Empty<byte>(); return Array.Empty<byte>();
} }
@ -236,67 +234,26 @@ internal class WechatFileSystem : IFileSystem
{ {
string filePath = GetCacheFileLoadPath(bundle); string filePath = GetCacheFileLoadPath(bundle);
if (CheckCacheFileExist(filePath)) if (CheckCacheFileExist(filePath))
return _fileSystemMgr.ReadFileSync(filePath, "utf8"); return _wxFileSystemMgr.ReadFileSync(filePath, "utf8");
else else
return string.Empty; return string.Empty;
} }
#region 内部方法 #region 内部方法
public WXFileSystemManager GetFileSystemMgr()
{
return _fileSystemMgr;
}
public bool CheckCacheFileExist(string filePath) public bool CheckCacheFileExist(string filePath)
{ {
string result = _fileSystemMgr.AccessSync(filePath); string result = _wxFileSystemMgr.AccessSync(filePath);
return result.Equals("access:ok"); return result.Equals("access:ok");
} }
public string GetCacheFileLoadPath(PackageBundle bundle) public string GetCacheFileLoadPath(PackageBundle bundle)
{ {
if (_cacheFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false) if (_cacheFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false)
{ {
filePath = PathUtility.Combine(_wxCacheRoot, bundle.FileName); filePath = PathUtility.Combine(_fileCacheRoot, bundle.FileName);
_cacheFilePaths.Add(bundle.BundleGUID, filePath); _cacheFilePaths.Add(bundle.BundleGUID, filePath);
} }
return filePath; return filePath;
} }
#endregion #endregion
#region 本地记录
public List<string> GetAllRecords()
{
return _recorders.ToList();
}
public bool RecordBundleFile(string filePath)
{
if (_recorders.Contains(filePath))
{
YooLogger.Error($"{nameof(WechatFileSystem)} has element : {filePath}");
return false;
}
_recorders.Add(filePath);
return true;
}
public void TryRecordBundle(PackageBundle bundle)
{
string filePath = GetCacheFileLoadPath(bundle);
if (_recorders.Contains(filePath) == false)
{
_recorders.Add(filePath);
}
}
public void ClearAllRecords()
{
_recorders.Clear();
}
public void ClearRecord(string filePath)
{
if (_recorders.Contains(filePath))
{
_recorders.Remove(filePath);
}
}
#endregion
} }
#endif #endif

View File

@ -129,13 +129,13 @@ public class CopyBuildinManifestOperation : GameAsyncOperation
{ {
string fileRoot = GetBuildinYooRoot(); string fileRoot = GetBuildinYooRoot();
string fileName = YooAssetSettingsData.GetPackageHashFileName(_packageName, _packageVersion); string fileName = YooAssetSettingsData.GetPackageHashFileName(_packageName, _packageVersion);
return PathUtility.Combine(fileRoot, _packageName, fileName); return PathUtility.Combine(fileRoot, fileName);
} }
private string GetBuildinManifestFilePath() private string GetBuildinManifestFilePath()
{ {
string fileRoot = GetBuildinYooRoot(); string fileRoot = GetBuildinYooRoot();
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, _packageVersion); string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, _packageVersion);
return PathUtility.Combine(fileRoot, _packageName, fileName); return PathUtility.Combine(fileRoot, fileName);
} }
private string GetCacheYooRoot() private string GetCacheYooRoot()
@ -146,12 +146,12 @@ public class CopyBuildinManifestOperation : GameAsyncOperation
{ {
string fileRoot = GetCacheYooRoot(); string fileRoot = GetCacheYooRoot();
string fileName = YooAssetSettingsData.GetPackageHashFileName(_packageName, _packageVersion); string fileName = YooAssetSettingsData.GetPackageHashFileName(_packageName, _packageVersion);
return PathUtility.Combine(fileRoot, _packageName, fileName); return PathUtility.Combine(fileRoot, fileName);
} }
private string GetCacheManifestFilePath() private string GetCacheManifestFilePath()
{ {
string fileRoot = GetCacheYooRoot(); string fileRoot = GetCacheYooRoot();
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, _packageVersion); string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, _packageVersion);
return PathUtility.Combine(fileRoot, _packageName, fileName); return PathUtility.Combine(fileRoot, fileName);
} }
} }

View File

@ -4,7 +4,7 @@
"references": [ "references": [
"GUID:e34a5702dd353724aa315fb8011f08c3", "GUID:e34a5702dd353724aa315fb8011f08c3",
"GUID:5efd170ecd8084500bed5692932fe14e", "GUID:5efd170ecd8084500bed5692932fe14e",
"GUID:bb21d6197862c4c3e863390dec9859a7" "GUID:0f8df04a5a494444eb8fa0504f6fb965"
], ],
"includePlatforms": [], "includePlatforms": [],
"excludePlatforms": [], "excludePlatforms": [],