diff --git a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/TiktokFileSystem/Operation/TTFSInitializeOperation.cs b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/TiktokFileSystem/Operation/TTFSInitializeOperation.cs index 837e6dae..92c1660a 100644 --- a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/TiktokFileSystem/Operation/TTFSInitializeOperation.cs +++ b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/TiktokFileSystem/Operation/TTFSInitializeOperation.cs @@ -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 \ No newline at end of file diff --git a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/TiktokFileSystem/Operation/internal/RecordTiktokCacheFilesOperation.cs b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/TiktokFileSystem/Operation/internal/RecordTiktokCacheFilesOperation.cs deleted file mode 100644 index d4f82e03..00000000 --- a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/TiktokFileSystem/Operation/internal/RecordTiktokCacheFilesOperation.cs +++ /dev/null @@ -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 \ No newline at end of file diff --git a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/TiktokFileSystem/Operation/internal/RecordTiktokCacheFilesOperation.cs.meta b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/TiktokFileSystem/Operation/internal/RecordTiktokCacheFilesOperation.cs.meta deleted file mode 100644 index 5ec7d443..00000000 --- a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/TiktokFileSystem/Operation/internal/RecordTiktokCacheFilesOperation.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: e4420bd73f37dec468a9b23425be68f2 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/TiktokFileSystem/TiktokFileSystem.cs b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/TiktokFileSystem/TiktokFileSystem.cs index 3fc0c8e1..29a68f57 100644 --- a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/TiktokFileSystem/TiktokFileSystem.cs +++ b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/TiktokFileSystem/TiktokFileSystem.cs @@ -53,8 +53,7 @@ internal class TiktokFileSystem : IFileSystem } } - private readonly HashSet _recorders = new HashSet(); - private readonly Dictionary _cacheFilePaths = new Dictionary(10000); + private readonly Dictionary _cacheFilePathMapping = new Dictionary(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(); + } } 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 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 \ No newline at end of file