diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/DefaultCacheFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/DefaultCacheFileSystem.cs index 6e1ce5e0..9718bfe1 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/DefaultCacheFileSystem.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/DefaultCacheFileSystem.cs @@ -333,6 +333,13 @@ namespace YooAsset { return _records.Keys.ToList(); } + public RecordFileElement GetRecordFileElement(PackageBundle bundle) + { + if (_records.TryGetValue(bundle.BundleGUID, out RecordFileElement element)) + return element; + else + return null; + } public string GetTempFilePath(PackageBundle bundle) { @@ -384,10 +391,10 @@ namespace YooAsset public EFileVerifyResult VerifyCacheFile(PackageBundle bundle) { - if (_records.TryGetValue(bundle.BundleGUID, out RecordFileElement wrapper) == false) + if (_records.TryGetValue(bundle.BundleGUID, out RecordFileElement element) == false) return EFileVerifyResult.CacheNotFound; - EFileVerifyResult result = FileVerifyHelper.FileVerify(wrapper.DataFilePath, wrapper.DataFileSize, wrapper.DataFileCRC, EFileVerifyLevel.High); + EFileVerifyResult result = FileVerifyHelper.FileVerify(element.DataFilePath, element.DataFileSize, element.DataFileCRC, EFileVerifyLevel.High); return result; } public bool WriteCacheBundleFile(PackageBundle bundle, string copyPath) @@ -427,10 +434,10 @@ namespace YooAsset } public bool DeleteCacheBundleFile(string bundleGUID) { - if (_records.TryGetValue(bundleGUID, out RecordFileElement wrapper)) + if (_records.TryGetValue(bundleGUID, out RecordFileElement element)) { _records.Remove(bundleGUID); - return wrapper.DeleteFolder(); + return element.DeleteFolder(); } else { diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSLoadBundleOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSLoadBundleOperation.cs index b588e0aa..dff1153c 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSLoadBundleOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSLoadBundleOperation.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; using UnityEngine; namespace YooAsset @@ -260,9 +261,30 @@ namespace YooAsset { if (_fileSystem.Exists(_bundle)) { - DownloadProgress = 1f; - DownloadedBytes = _bundle.FileSize; - _steps = ESteps.LoadCacheRawBundle; + // 注意:缓存的原生文件的格式,可能会在业务端根据需求发生变动! + // 注意:这里需要校验文件格式,如果不一致对本地文件进行修正! + string filePath = _fileSystem.GetCacheBundleFileLoadPath(_bundle); + if (File.Exists(filePath) == false) + { + try + { + var recordFileElement = _fileSystem.GetRecordFileElement(_bundle); + File.Move(recordFileElement.DataFilePath, filePath); + _steps = ESteps.LoadCacheRawBundle; + } + catch (Exception e) + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = $"Faild rename raw data file : {e.Message}"; + } + } + else + { + DownloadProgress = 1f; + DownloadedBytes = _bundle.FileSize; + _steps = ESteps.LoadCacheRawBundle; + } } else { diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/internal/SearchCacheFilesOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/internal/SearchCacheFilesOperation.cs index 7779c73b..0be6c4dc 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/internal/SearchCacheFilesOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/internal/SearchCacheFilesOperation.cs @@ -92,12 +92,7 @@ namespace YooAsset if (_fileSystem.AppendFileExtension) { string dataFileExtension = FindDataFileExtension(chidDirectory); - if (string.IsNullOrEmpty(dataFileExtension)) - { - //注意:覆盖安装的情况下,缓存文件可能会没有后缀格式,需要删除重新下载! - dataFilePath = string.Empty; - } - else + if (string.IsNullOrEmpty(dataFileExtension) == false) { dataFilePath += dataFileExtension; }