mirror of https://github.com/tuyoogame/YooAsset
parent
0a85f3126f
commit
07086b68c8
|
@ -3,16 +3,7 @@ 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)
|
||||
{
|
||||
|
@ -20,36 +11,10 @@ internal partial class TTFSInitializeOperation : FSInitializeFileSystemOperation
|
|||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.RecordCacheFiles;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
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
|
|
@ -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
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e4420bd73f37dec468a9b23425be68f2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -53,8 +53,7 @@ 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> _cacheFilePathMapping = new Dictionary<string, string>(10000);
|
||||
private TTFileSystemManager _fileSystemMgr;
|
||||
private string _ttCacheRoot = string.Empty;
|
||||
|
||||
|
@ -81,7 +80,7 @@ internal class TiktokFileSystem : IFileSystem
|
|||
{
|
||||
get
|
||||
{
|
||||
return _recorders.Count;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -185,8 +184,7 @@ internal class TiktokFileSystem : IFileSystem
|
|||
}
|
||||
public virtual bool Exists(PackageBundle bundle)
|
||||
{
|
||||
string filePath = GetCacheFileLoadPath(bundle);
|
||||
return _recorders.Contains(filePath);
|
||||
return CheckCacheFileExist(bundle);
|
||||
}
|
||||
public virtual bool NeedDownload(PackageBundle bundle)
|
||||
{
|
||||
|
@ -210,19 +208,27 @@ internal class TiktokFileSystem : IFileSystem
|
|||
}
|
||||
public virtual byte[] ReadBundleFileData(PackageBundle bundle)
|
||||
{
|
||||
string filePath = GetCacheFileLoadPath(bundle);
|
||||
if (CheckCacheFileExist(filePath))
|
||||
if (CheckCacheFileExist(bundle))
|
||||
{
|
||||
string filePath = GetCacheFileLoadPath(bundle);
|
||||
return _fileSystemMgr.ReadFileSync(filePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Array.Empty<byte>();
|
||||
}
|
||||
}
|
||||
public virtual string ReadBundleFileText(PackageBundle bundle)
|
||||
{
|
||||
string filePath = GetCacheFileLoadPath(bundle);
|
||||
if (CheckCacheFileExist(filePath))
|
||||
if (CheckCacheFileExist(bundle))
|
||||
{
|
||||
string filePath = GetCacheFileLoadPath(bundle);
|
||||
return _fileSystemMgr.ReadFileSync(filePath, "utf8");
|
||||
}
|
||||
else
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
#region 内部方法
|
||||
|
@ -230,56 +236,20 @@ internal class TiktokFileSystem : IFileSystem
|
|||
{
|
||||
return _fileSystemMgr;
|
||||
}
|
||||
public bool CheckCacheFileExist(string filePath)
|
||||
public bool CheckCacheFileExist(PackageBundle bundle)
|
||||
{
|
||||
return _fileSystemMgr.AccessSync(filePath);
|
||||
string url = RemoteServices.GetRemoteMainURL(bundle.FileName);
|
||||
return _fileSystemMgr.IsUrlCached(url);
|
||||
}
|
||||
private string GetCacheFileLoadPath(PackageBundle bundle)
|
||||
{
|
||||
if (_cacheFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false)
|
||||
if (_cacheFilePathMapping.TryGetValue(bundle.BundleGUID, out string filePath) == false)
|
||||
{
|
||||
filePath = _fileSystemMgr.GetLocalCachedPathForUrl(bundle.FileName);
|
||||
_cacheFilePaths.Add(bundle.BundleGUID, filePath);
|
||||
_cacheFilePathMapping.Add(bundle.BundleGUID, filePath);
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
#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
|
Loading…
Reference in New Issue