diff --git a/Assets/YooAsset/Runtime/FileSystem/CacheSystem/Interface/ICacheSystem.cs b/Assets/YooAsset/Runtime/FileSystem/CacheSystem/Interface/ICacheSystem.cs index d5e6489..47681a4 100644 --- a/Assets/YooAsset/Runtime/FileSystem/CacheSystem/Interface/ICacheSystem.cs +++ b/Assets/YooAsset/Runtime/FileSystem/CacheSystem/Interface/ICacheSystem.cs @@ -9,6 +9,21 @@ namespace YooAsset /// string GetCacheFileRoot(); + /// + /// 获取临时缓存文件路径 + /// + string GetTempFilePath(PackageBundle bundle); + + /// + /// 获取数据文件路径 + /// + string GetDataFilePath(PackageBundle bundle); + + /// + /// 获取信息文件路径 + /// + string GetInfoFilePath(PackageBundle bundle); + /// /// 获取所有缓存文件的GUID /// diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/internal/DownloadHandlerFileRange.cs b/Assets/YooAsset/Runtime/FileSystem/CacheSystem/Operation/DownloadHandlerFileRange.cs similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/internal/DownloadHandlerFileRange.cs rename to Assets/YooAsset/Runtime/FileSystem/CacheSystem/Operation/DownloadHandlerFileRange.cs diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/internal/DownloadHandlerFileRange.cs.meta b/Assets/YooAsset/Runtime/FileSystem/CacheSystem/Operation/DownloadHandlerFileRange.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/internal/DownloadHandlerFileRange.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/CacheSystem/Operation/DownloadHandlerFileRange.cs.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/CacheSystem/Operation/DownloadNormalFileOperation.cs b/Assets/YooAsset/Runtime/FileSystem/CacheSystem/Operation/DownloadNormalFileOperation.cs new file mode 100644 index 0000000..291787d --- /dev/null +++ b/Assets/YooAsset/Runtime/FileSystem/CacheSystem/Operation/DownloadNormalFileOperation.cs @@ -0,0 +1,199 @@ +using System.IO; +using UnityEngine; +using UnityEngine.Networking; + +namespace YooAsset +{ + internal sealed class DownloadNormalFileOperation : DefaultDownloadFileOperation + { + private readonly IFileSystem _fileSystem; + private readonly ICacheSystem _cacheSystem; + private VerifyTempFileOperation _verifyOperation; + private string _tempFilePath; + private ESteps _steps = ESteps.None; + + internal DownloadNormalFileOperation(IFileSystem fileSystem, ICacheSystem cacheSystem, PackageBundle bundle, DownloadParam param) : base(bundle, param) + { + _fileSystem = fileSystem; + _cacheSystem = cacheSystem; + } + internal override void InternalOnStart() + { + _tempFilePath = _cacheSystem.GetTempFilePath(Bundle); + _steps = ESteps.CheckExists; + } + internal override void InternalOnUpdate() + { + if (_steps == ESteps.None || _steps == ESteps.Done) + return; + + // 检测文件是否存在 + if (_steps == ESteps.CheckExists) + { + if (_fileSystem.Exists(Bundle)) + { + _steps = ESteps.Done; + Status = EOperationStatus.Succeed; + } + else + { + _steps = ESteps.CreateRequest; + } + } + + // 创建下载器 + if (_steps == ESteps.CreateRequest) + { + FileUtility.CreateFileDirectory(_tempFilePath); + + // 删除临时文件 + if (File.Exists(_tempFilePath)) + File.Delete(_tempFilePath); + + // 获取请求地址 + _requestURL = GetRequestURL(); + + // 重置请求 + ResetRequestFiled(); + + // 创建下载器 + CreateWebRequest(); + + _steps = ESteps.CheckRequest; + } + + // 检测下载结果 + if (_steps == ESteps.CheckRequest) + { + DownloadProgress = _webRequest.downloadProgress; + DownloadedBytes = (long)_webRequest.downloadedBytes; + Progress = DownloadProgress; + if (_webRequest.isDone == false) + { + CheckRequestTimeout(); + return; + } + + // 检查网络错误 + if (CheckRequestResult()) + _steps = ESteps.VerifyTempFile; + else + _steps = ESteps.TryAgain; + + // 注意:最终释放请求器 + DisposeWebRequest(); + } + + // 验证下载文件 + if (_steps == ESteps.VerifyTempFile) + { + var element = new TempFileElement(_tempFilePath, Bundle.FileCRC, Bundle.FileSize); + _verifyOperation = new VerifyTempFileOperation(element); + OperationSystem.StartOperation(_fileSystem.PackageName, _verifyOperation); + _steps = ESteps.CheckVerifyTempFile; + } + + // 等待验证完成 + if (_steps == ESteps.CheckVerifyTempFile) + { + if (IsWaitForAsyncComplete) + _verifyOperation.WaitForAsyncComplete(); + + if (_verifyOperation.IsDone == false) + return; + + if (_verifyOperation.Status == EOperationStatus.Succeed) + { + if (_cacheSystem.WriteCacheFile(Bundle, _tempFilePath)) + { + _steps = ESteps.Done; + Status = EOperationStatus.Succeed; + } + else + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = $"{_fileSystem.GetType().FullName} failed to write file !"; + YooLogger.Error(Error); + } + } + else + { + _steps = ESteps.TryAgain; + Error = _verifyOperation.Error; + } + + // 注意:验证完成后直接删除文件 + if (File.Exists(_tempFilePath)) + File.Delete(_tempFilePath); + } + + // 重新尝试下载 + if (_steps == ESteps.TryAgain) + { + if (FailedTryAgain <= 0) + { + Status = EOperationStatus.Failed; + _steps = ESteps.Done; + YooLogger.Error(Error); + return; + } + + _tryAgainTimer += Time.unscaledDeltaTime; + if (_tryAgainTimer > 1f) + { + FailedTryAgain--; + _steps = ESteps.CreateRequest; + YooLogger.Warning(Error); + } + } + } + internal override void InternalOnAbort() + { + _steps = ESteps.Done; + DisposeWebRequest(); + } + internal override void InternalWaitForAsyncComplete() + { + bool isReuqestLocalFile = IsRequestLocalFile(); + + while (true) + { + // 注意:如果是导入或解压本地文件,执行等待完毕 + if (isReuqestLocalFile) + { + InternalOnUpdate(); + if (IsDone) + break; + } + else + { + if (ExecuteWhileDone()) + { + _steps = ESteps.Done; + break; + } + } + } + } + + private void CreateWebRequest() + { + _webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL); + DownloadHandlerFile handler = new DownloadHandlerFile(_tempFilePath); + handler.removeFileOnAbort = true; + _webRequest.downloadHandler = handler; + _webRequest.disposeDownloadHandlerOnDispose = true; + _webRequest.SendWebRequest(); + } + private void DisposeWebRequest() + { + if (_webRequest != null) + { + //注意:引擎底层会自动调用Abort方法 + _webRequest.Dispose(); + _webRequest = null; + } + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSDownloadFileOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/CacheSystem/Operation/DownloadNormalFileOperation.cs.meta similarity index 83% rename from Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSDownloadFileOperation.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/CacheSystem/Operation/DownloadNormalFileOperation.cs.meta index 39eda64..2ca0d68 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSDownloadFileOperation.cs.meta +++ b/Assets/YooAsset/Runtime/FileSystem/CacheSystem/Operation/DownloadNormalFileOperation.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: d6f813e2460f55e4ba3f54527e6999e3 +guid: 759967d543776a0469b625eff171d235 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSDownloadFileOperation.cs b/Assets/YooAsset/Runtime/FileSystem/CacheSystem/Operation/DownloadResumeFileOperation.cs similarity index 51% rename from Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSDownloadFileOperation.cs rename to Assets/YooAsset/Runtime/FileSystem/CacheSystem/Operation/DownloadResumeFileOperation.cs index 1ba0226..f45b8fe 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSDownloadFileOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/CacheSystem/Operation/DownloadResumeFileOperation.cs @@ -1,203 +1,15 @@ -using System.IO; +using System.Collections.Generic; +using System.IO; using UnityEngine; using UnityEngine.Networking; namespace YooAsset { - internal sealed class DCFSDownloadNormalFileOperation : DefaultDownloadFileOperation + internal sealed class DownloadResumeFileOperation : DefaultDownloadFileOperation { - private readonly DefaultCacheFileSystem _fileSystem; - private VerifyTempFileOperation _verifyOperation; - private string _tempFilePath; - private ESteps _steps = ESteps.None; - - internal DCFSDownloadNormalFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle, DownloadParam param) : base(bundle, param) - { - _fileSystem = fileSystem; - } - internal override void InternalOnStart() - { - _tempFilePath = _fileSystem.GetTempFilePath(Bundle); - _steps = ESteps.CheckExists; - } - internal override void InternalOnUpdate() - { - if (_steps == ESteps.None || _steps == ESteps.Done) - return; - - // 检测文件是否存在 - if (_steps == ESteps.CheckExists) - { - if (_fileSystem.Exists(Bundle)) - { - _steps = ESteps.Done; - Status = EOperationStatus.Succeed; - } - else - { - _steps = ESteps.CreateRequest; - } - } - - // 创建下载器 - if (_steps == ESteps.CreateRequest) - { - FileUtility.CreateFileDirectory(_tempFilePath); - - // 删除临时文件 - if (File.Exists(_tempFilePath)) - File.Delete(_tempFilePath); - - // 获取请求地址 - _requestURL = GetRequestURL(); - - // 重置请求 - ResetRequestFiled(); - - // 创建下载器 - CreateWebRequest(); - - _steps = ESteps.CheckRequest; - } - - // 检测下载结果 - if (_steps == ESteps.CheckRequest) - { - DownloadProgress = _webRequest.downloadProgress; - DownloadedBytes = (long)_webRequest.downloadedBytes; - Progress = DownloadProgress; - if (_webRequest.isDone == false) - { - CheckRequestTimeout(); - return; - } - - // 检查网络错误 - if (CheckRequestResult()) - _steps = ESteps.VerifyTempFile; - else - _steps = ESteps.TryAgain; - - // 注意:最终释放请求器 - DisposeWebRequest(); - } - - // 验证下载文件 - if (_steps == ESteps.VerifyTempFile) - { - var element = new TempFileElement(_tempFilePath, Bundle.FileCRC, Bundle.FileSize); - _verifyOperation = new VerifyTempFileOperation(element); - OperationSystem.StartOperation(_fileSystem.PackageName, _verifyOperation); - _steps = ESteps.CheckVerifyTempFile; - } - - // 等待验证完成 - if (_steps == ESteps.CheckVerifyTempFile) - { - if (IsWaitForAsyncComplete) - _verifyOperation.WaitForAsyncComplete(); - - if (_verifyOperation.IsDone == false) - return; - - if (_verifyOperation.Status == EOperationStatus.Succeed) - { - if (_fileSystem.WriteCacheFile(Bundle, _tempFilePath)) - { - _steps = ESteps.Done; - Status = EOperationStatus.Succeed; - } - else - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = $"{_fileSystem.GetType().FullName} failed to write file !"; - YooLogger.Error(Error); - } - } - else - { - _steps = ESteps.TryAgain; - Error = _verifyOperation.Error; - } - - // 注意:验证完成后直接删除文件 - if (File.Exists(_tempFilePath)) - File.Delete(_tempFilePath); - } - - // 重新尝试下载 - if (_steps == ESteps.TryAgain) - { - if (FailedTryAgain <= 0) - { - Status = EOperationStatus.Failed; - _steps = ESteps.Done; - YooLogger.Error(Error); - return; - } - - _tryAgainTimer += Time.unscaledDeltaTime; - if (_tryAgainTimer > 1f) - { - FailedTryAgain--; - _steps = ESteps.CreateRequest; - YooLogger.Warning(Error); - } - } - } - internal override void InternalOnAbort() - { - _steps = ESteps.Done; - DisposeWebRequest(); - } - internal override void InternalWaitForAsyncComplete() - { - bool isReuqestLocalFile = IsRequestLocalFile(); - - while (true) - { - // 注意:如果是导入或解压本地文件,执行等待完毕 - if (isReuqestLocalFile) - { - InternalOnUpdate(); - if (IsDone) - break; - } - else - { - if (ExecuteWhileDone()) - { - _steps = ESteps.Done; - break; - } - } - } - } - - private void CreateWebRequest() - { - _webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL); - DownloadHandlerFile handler = new DownloadHandlerFile(_tempFilePath); - handler.removeFileOnAbort = true; - _webRequest.downloadHandler = handler; - _webRequest.disposeDownloadHandlerOnDispose = true; - _webRequest.SendWebRequest(); - } - private void DisposeWebRequest() - { - if (_webRequest != null) - { - //注意:引擎底层会自动调用Abort方法 - _webRequest.Dispose(); - _webRequest = null; - } - } - } - - internal sealed class DCFSDownloadResumeFileOperation : DefaultDownloadFileOperation - { - private readonly DefaultCacheFileSystem _fileSystem; + private readonly IFileSystem _fileSystem; + private readonly ICacheSystem _cacheSystem; + private readonly List _responseCodes; private DownloadHandlerFileRange _downloadHandle; private VerifyTempFileOperation _verifyOperation; private long _fileOriginLength = 0; @@ -205,13 +17,15 @@ namespace YooAsset private ESteps _steps = ESteps.None; - internal DCFSDownloadResumeFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle, DownloadParam param) : base(bundle, param) + internal DownloadResumeFileOperation(IFileSystem fileSystem, ICacheSystem cacheSystem, PackageBundle bundle, DownloadParam param, List responseCodes) : base(bundle, param) { _fileSystem = fileSystem; + _cacheSystem = cacheSystem; + _responseCodes = responseCodes; } internal override void InternalOnStart() { - _tempFilePath = _fileSystem.GetTempFilePath(Bundle); + _tempFilePath = _cacheSystem.GetTempFilePath(Bundle); _steps = ESteps.CheckExists; } internal override void InternalOnUpdate() @@ -313,7 +127,7 @@ namespace YooAsset if (_verifyOperation.Status == EOperationStatus.Succeed) { - if (_fileSystem.WriteCacheFile(Bundle, _tempFilePath)) + if (_cacheSystem.WriteCacheFile(Bundle, _tempFilePath)) { Status = EOperationStatus.Succeed; _steps = ESteps.Done; @@ -418,11 +232,11 @@ namespace YooAsset } private void ClearTempFileWhenError() { - if (_fileSystem.ResumeDownloadResponseCodes == null) + if (_responseCodes == null) return; //说明:如果遇到以下错误返回码,验证失败直接删除文件 - if (_fileSystem.ResumeDownloadResponseCodes.Contains(HttpCode)) + if (_responseCodes.Contains(HttpCode)) { if (File.Exists(_tempFilePath)) File.Delete(_tempFilePath); diff --git a/Assets/YooAsset/Runtime/FileSystem/CacheSystem/Operation/DownloadResumeFileOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/CacheSystem/Operation/DownloadResumeFileOperation.cs.meta new file mode 100644 index 0000000..d23cbe7 --- /dev/null +++ b/Assets/YooAsset/Runtime/FileSystem/CacheSystem/Operation/DownloadResumeFileOperation.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9bfb785912326f942a31dc77762eb16a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/DefaultBuildinFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/DefaultBuildinFileSystem.cs index 2db0e01..a995cc5 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/DefaultBuildinFileSystem.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/DefaultBuildinFileSystem.cs @@ -10,36 +10,6 @@ namespace YooAsset /// internal class DefaultBuildinFileSystem : IFileSystem { - private class UnpackRemoteServices : IRemoteServices - { - private readonly string _buildinPackageRoot; - protected readonly Dictionary _mapping = new Dictionary(10000); - - public UnpackRemoteServices(string buildinPackRoot) - { - _buildinPackageRoot = buildinPackRoot; - } - string IRemoteServices.GetRemoteMainURL(string fileName) - { - return GetFileLoadURL(fileName); - } - string IRemoteServices.GetRemoteFallbackURL(string fileName) - { - return GetFileLoadURL(fileName); - } - - private string GetFileLoadURL(string fileName) - { - if (_mapping.TryGetValue(fileName, out string url) == false) - { - string filePath = PathUtility.Combine(_buildinPackageRoot, fileName); - url = DownloadSystemHelper.ConvertToWWWPath(filePath); - _mapping.Add(fileName, url); - } - return url; - } - } - public class FileWrapper { public string FileName { private set; get; } @@ -220,7 +190,7 @@ namespace YooAsset _packageRoot = PathUtility.Combine(rootDirectory, packageName); // 创建解压文件系统 - var remoteServices = new UnpackRemoteServices(_packageRoot); + var remoteServices = new DefaultUnpackRemoteServices(_packageRoot); _unpackFileSystem = new DefaultUnpackFileSystem(); _unpackFileSystem.SetParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices); _unpackFileSystem.SetParameter(FileSystemParametersDefine.FILE_VERIFY_LEVEL, FileVerifyLevel); @@ -231,6 +201,7 @@ namespace YooAsset } public virtual void OnUpdate() { + _unpackFileSystem.OnUpdate(); } public virtual bool Belong(PackageBundle bundle) diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/DefaultCacheFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/DefaultCacheFileSystem.cs index b719952..5267449 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/DefaultCacheFileSystem.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/DefaultCacheFileSystem.cs @@ -12,13 +12,14 @@ namespace YooAsset /// internal class DefaultCacheFileSystem : IFileSystem, ICacheSystem { - protected readonly Dictionary _downloaders = new Dictionary(1000); protected readonly Dictionary _wrappers = new Dictionary(10000); protected readonly Dictionary _loadedStream = new Dictionary(10000); protected readonly Dictionary _dataFilePaths = new Dictionary(10000); protected readonly Dictionary _infoFilePaths = new Dictionary(10000); protected readonly Dictionary _tempFilePaths = new Dictionary(10000); + protected readonly Dictionary _downloaders = new Dictionary(1000); protected readonly List _removeList = new List(1000); + protected string _packageRoot; protected string _cacheFileRoot; protected string _tempFileRoot; @@ -147,7 +148,7 @@ namespace YooAsset if (bundle.FileSize >= ResumeDownloadMinimumSize) { - var newDownloader = new DCFSDownloadResumeFileOperation(this, bundle, param); + var newDownloader = new DownloadResumeFileOperation(this, this, bundle, param, ResumeDownloadResponseCodes); newDownloader.Reference(); _downloaders.Add(bundle.BundleGUID, newDownloader); OperationSystem.StartOperation(PackageName, newDownloader); @@ -155,7 +156,7 @@ namespace YooAsset } else { - var newDownloader = new DCFSDownloadNormalFileOperation(this, bundle, param); + var newDownloader = new DownloadNormalFileOperation(this, this, bundle, param); newDownloader.Reference(); _downloaders.Add(bundle.BundleGUID, newDownloader); OperationSystem.StartOperation(PackageName, newDownloader); @@ -361,6 +362,37 @@ namespace YooAsset { return _cacheFileRoot; } + public string GetTempFilePath(PackageBundle bundle) + { + if (_tempFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false) + { + filePath = PathUtility.Combine(_tempFileRoot, bundle.BundleGUID); + _tempFilePaths.Add(bundle.BundleGUID, filePath); + } + return filePath; + } + public string GetDataFilePath(PackageBundle bundle) + { + if (_dataFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false) + { + string folderName = bundle.FileHash.Substring(0, 2); + filePath = PathUtility.Combine(_cacheFileRoot, folderName, bundle.BundleGUID, DefaultCacheFileSystemDefine.SaveBundleDataFileName); + if (AppendFileExtension) + filePath += bundle.FileExtension; + _dataFilePaths.Add(bundle.BundleGUID, filePath); + } + return filePath; + } + public string GetInfoFilePath(PackageBundle bundle) + { + if (_infoFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false) + { + string folderName = bundle.FileHash.Substring(0, 2); + filePath = PathUtility.Combine(_cacheFileRoot, folderName, bundle.BundleGUID, DefaultCacheFileSystemDefine.SaveBundleInfoFileName); + _infoFilePaths.Add(bundle.BundleGUID, filePath); + } + return filePath; + } public List GetAllCachedBundleGUIDs() { return _wrappers.Keys.ToList(); @@ -472,37 +504,6 @@ namespace YooAsset #endregion #region 内部方法 - protected string GetDataFilePath(PackageBundle bundle) - { - if (_dataFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false) - { - string folderName = bundle.FileHash.Substring(0, 2); - filePath = PathUtility.Combine(_cacheFileRoot, folderName, bundle.BundleGUID, DefaultCacheFileSystemDefine.SaveBundleDataFileName); - if (AppendFileExtension) - filePath += bundle.FileExtension; - _dataFilePaths.Add(bundle.BundleGUID, filePath); - } - return filePath; - } - protected string GetInfoFilePath(PackageBundle bundle) - { - if (_infoFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false) - { - string folderName = bundle.FileHash.Substring(0, 2); - filePath = PathUtility.Combine(_cacheFileRoot, folderName, bundle.BundleGUID, DefaultCacheFileSystemDefine.SaveBundleInfoFileName); - _infoFilePaths.Add(bundle.BundleGUID, filePath); - } - return filePath; - } - public string GetTempFilePath(PackageBundle bundle) - { - if (_tempFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false) - { - filePath = PathUtility.Combine(_tempFileRoot, bundle.BundleGUID); - _tempFilePaths.Add(bundle.BundleGUID, filePath); - } - return filePath; - } public string GetCacheFileLoadPath(PackageBundle bundle) { return GetDataFilePath(bundle); diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSInitializeOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSInitializeOperation.cs index e4ba18b..bd6dab3 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSInitializeOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSInitializeOperation.cs @@ -12,7 +12,7 @@ namespace YooAsset Done, } - private readonly DefaultCacheFileSystem _fileSytem; + private readonly DefaultCacheFileSystem _fileSystem; private SearchCacheFilesOperation _searchCacheFilesOp; private VerifyCacheFilesOperation _verifyCacheFilesOp; private ESteps _steps = ESteps.None; @@ -20,7 +20,7 @@ namespace YooAsset internal DCFSInitializeOperation(DefaultCacheFileSystem fileSystem) { - _fileSytem = fileSystem; + _fileSystem = fileSystem; } internal override void InternalOnStart() { @@ -39,14 +39,14 @@ namespace YooAsset if (_steps == ESteps.CheckAppFootPrint) { - var appFootPrint = new ApplicationFootPrint(_fileSytem); - appFootPrint.Load(_fileSytem.PackageName); + var appFootPrint = new ApplicationFootPrint(_fileSystem); + appFootPrint.Load(_fileSystem.PackageName); // 如果水印发生变化,则说明覆盖安装后首次打开游戏 if (appFootPrint.IsDirty()) { - _fileSytem.DeleteAllManifestFiles(); - appFootPrint.Coverage(_fileSytem.PackageName); + _fileSystem.DeleteAllManifestFiles(); + appFootPrint.Coverage(_fileSystem.PackageName); YooLogger.Warning("Delete manifest files when application foot print dirty !"); } @@ -57,8 +57,8 @@ namespace YooAsset { if (_searchCacheFilesOp == null) { - _searchCacheFilesOp = new SearchCacheFilesOperation(_fileSytem, _fileSytem.PackageName, _fileSytem.AppendFileExtension); - OperationSystem.StartOperation(_fileSytem.PackageName, _searchCacheFilesOp); + _searchCacheFilesOp = new SearchCacheFilesOperation(_fileSystem, _fileSystem.PackageName, _fileSystem.AppendFileExtension); + OperationSystem.StartOperation(_fileSystem.PackageName, _searchCacheFilesOp); } Progress = _searchCacheFilesOp.Progress; @@ -72,8 +72,8 @@ namespace YooAsset { if (_verifyCacheFilesOp == null) { - _verifyCacheFilesOp = new VerifyCacheFilesOperation(_fileSytem, _fileSytem.FileVerifyLevel, _searchCacheFilesOp.Result); - OperationSystem.StartOperation(_fileSytem.PackageName, _verifyCacheFilesOp); + _verifyCacheFilesOp = new VerifyCacheFilesOperation(_fileSystem, _fileSystem.FileVerifyLevel, _searchCacheFilesOp.Result); + OperationSystem.StartOperation(_fileSystem.PackageName, _verifyCacheFilesOp); } Progress = _verifyCacheFilesOp.Progress; @@ -84,7 +84,7 @@ namespace YooAsset { _steps = ESteps.Done; Status = EOperationStatus.Succeed; - YooLogger.Log($"Package '{_fileSytem.PackageName}' cached files count : {_fileSytem.FileCount}"); + YooLogger.Log($"Package '{_fileSystem.PackageName}' cached files count : {_fileSystem.FileCount}"); } else { diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultUnpackFileSystem/DefaultUnpackFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultUnpackFileSystem/DefaultUnpackFileSystem.cs index edc3ad1..8349d53 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultUnpackFileSystem/DefaultUnpackFileSystem.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultUnpackFileSystem/DefaultUnpackFileSystem.cs @@ -14,7 +14,7 @@ namespace YooAsset base.OnCreate(packageName, rootDirectory); // 注意:重写保存根目录和临时目录 - _saveFileRoot = PathUtility.Combine(_packageRoot, DefaultUnpackFileSystemDefine.SaveFilesFolderName); + _cacheFileRoot = PathUtility.Combine(_packageRoot, DefaultUnpackFileSystemDefine.SaveFilesFolderName); _tempFileRoot = PathUtility.Combine(_packageRoot, DefaultUnpackFileSystemDefine.TempFilesFolderName); } } diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultUnpackFileSystem/DefaultUnpackRemoteServices.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultUnpackFileSystem/DefaultUnpackRemoteServices.cs new file mode 100644 index 0000000..519db3a --- /dev/null +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultUnpackFileSystem/DefaultUnpackRemoteServices.cs @@ -0,0 +1,34 @@ +using System.Collections.Generic; + +namespace YooAsset +{ + internal class DefaultUnpackRemoteServices : IRemoteServices + { + private readonly string _buildinPackageRoot; + protected readonly Dictionary _mapping = new Dictionary(10000); + + public DefaultUnpackRemoteServices(string buildinPackRoot) + { + _buildinPackageRoot = buildinPackRoot; + } + string IRemoteServices.GetRemoteMainURL(string fileName) + { + return GetFileLoadURL(fileName); + } + string IRemoteServices.GetRemoteFallbackURL(string fileName) + { + return GetFileLoadURL(fileName); + } + + private string GetFileLoadURL(string fileName) + { + if (_mapping.TryGetValue(fileName, out string url) == false) + { + string filePath = PathUtility.Combine(_buildinPackageRoot, fileName); + url = DownloadSystemHelper.ConvertToWWWPath(filePath); + _mapping.Add(fileName, url); + } + return url; + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultUnpackFileSystem/DefaultUnpackRemoteServices.cs.meta b/Assets/YooAsset/Runtime/FileSystem/DefaultUnpackFileSystem/DefaultUnpackRemoteServices.cs.meta new file mode 100644 index 0000000..8cc2f82 --- /dev/null +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultUnpackFileSystem/DefaultUnpackRemoteServices.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 32c355598c9dff847af87f4a867a2d5c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/FileSystem/CacheSystem/FileVerifyHelper.cs b/Assets/YooAsset/Runtime/FileSystem/FileVerifyHelper.cs similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/CacheSystem/FileVerifyHelper.cs rename to Assets/YooAsset/Runtime/FileSystem/FileVerifyHelper.cs diff --git a/Assets/YooAsset/Runtime/FileSystem/CacheSystem/FileVerifyHelper.cs.meta b/Assets/YooAsset/Runtime/FileSystem/FileVerifyHelper.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/CacheSystem/FileVerifyHelper.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/FileVerifyHelper.cs.meta