diff --git a/Assets/YooAsset.zip b/Assets/YooAsset.zip deleted file mode 100644 index d2578faa..00000000 Binary files a/Assets/YooAsset.zip and /dev/null differ diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderSetting.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderSetting.cs index 3bb0ad7b..5f23c2c2 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderSetting.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderSetting.cs @@ -83,7 +83,7 @@ namespace YooAsset.Editor public static string GetPackageManifestProcessServicesClassName(string packageName, string buildPipeline) { string key = $"{Application.productName}_{packageName}_{buildPipeline}_ManifestProcessServicesClassName"; - return EditorPrefs.GetString(key, $"{typeof(ManifestProcessNone).FullName}"); + return EditorPrefs.GetString(key, $"{typeof(ManifestEncryptorNone).FullName}"); } public static void SetPackageManifestProcessServicesClassName(string packageName, string buildPipeline, string encyptionClassName) { @@ -95,7 +95,7 @@ namespace YooAsset.Editor public static string GetPackageManifestRestoreServicesClassName(string packageName, string buildPipeline) { string key = $"{Application.productName}_{packageName}_{buildPipeline}_ManifestRestoreServicesClassName"; - return EditorPrefs.GetString(key, $"{typeof(ManifestRestoreNone).FullName}"); + return EditorPrefs.GetString(key, $"{typeof(ManifestDecryptorNone).FullName}"); } public static void SetPackageManifestRestoreServicesClassName(string packageName, string buildPipeline, string encyptionClassName) { diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParameters.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParameters.cs index 673567d3..98c3bc68 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParameters.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParameters.cs @@ -94,19 +94,19 @@ namespace YooAsset.Editor public string BuildinFileCopyParams; /// - /// 资源包加密服务类 + /// 资源包加密器 /// - public IBundleEncryptionServices EncryptionServices; + public IBundleEncryptor BundleEncryptor; /// - /// 资源清单加密服务类 + /// 资源清单加密器 /// - public IManifestProcessServices ManifestProcessServices; + public IManifestEncryptor ManifestEncryptor; /// - /// 资源清单解密服务类 + /// 资源清单解密器 /// - public IManifestRestoreServices ManifestRestoreServices; + public IManifestDecryptor ManifestDecryptor; private string _pipelineOutputDirectory = string.Empty; private string _packageOutputDirectory = string.Empty; diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateCatalog.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateCatalog.cs index aa39abf7..910a625a 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateCatalog.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateCatalog.cs @@ -14,7 +14,7 @@ namespace YooAsset.Editor { string buildinRootDirectory = buildParametersContext.GetBuildinRootDirectory(); string buildPackageName = buildParametersContext.Parameters.PackageName; - var manifestServices = buildParametersContext.Parameters.ManifestRestoreServices; + var manifestServices = buildParametersContext.Parameters.ManifestDecryptor; BuiltinFileCatalogTools.CreateFile(manifestServices, buildPackageName, buildinRootDirectory); // 刷新目录 diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateManifest.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateManifest.cs index 65ccc4b3..ca505253 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateManifest.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateManifest.cs @@ -81,7 +81,7 @@ namespace YooAsset.Editor { string fileName = YooAssetSettingsData.GetManifestBinaryFileName(buildParameters.PackageName, buildParameters.PackageVersion); packagePath = $"{packageOutputDirectory}/{fileName}"; - PackageManifestTools.SerializeManifestToBinary(packagePath, manifest, buildParameters.ManifestProcessServices); + PackageManifestTools.SerializeManifestToBinary(packagePath, manifest, buildParameters.ManifestEncryptor); packageHash = HashUtility.ComputeFileCRC32(packagePath); BuildLogger.Log($"Create package manifest file: {packagePath}"); } @@ -106,7 +106,7 @@ namespace YooAsset.Editor { ManifestContext manifestContext = new ManifestContext(); byte[] bytesData = FileUtility.ReadAllBytes(packagePath); - manifestContext.Manifest = PackageManifestTools.DeserializeManifestFromBinary(bytesData, buildParameters.ManifestRestoreServices); + manifestContext.Manifest = PackageManifestTools.DeserializeManifestFromBinary(bytesData, buildParameters.ManifestDecryptor); context.SetContextObject(manifestContext); } } diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateReport.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateReport.cs index ceade7ce..284810ce 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateReport.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateReport.cs @@ -44,9 +44,9 @@ namespace YooAsset.Editor buildReport.Summary.EnableSharePackRule = buildParameters.EnableSharePackRule; buildReport.Summary.SingleReferencedPackAlone = buildParameters.SingleReferencedPackAlone; buildReport.Summary.FileNameStyle = buildParameters.FileNameStyle; - buildReport.Summary.EncryptionServicesClassName = buildParameters.EncryptionServices == null ? "null" : buildParameters.EncryptionServices.GetType().FullName; - buildReport.Summary.ManifestProcessServicesClassName = buildParameters.ManifestProcessServices == null ? "null" : buildParameters.ManifestProcessServices.GetType().FullName; - buildReport.Summary.ManifestRestoreServicesClassName = buildParameters.ManifestRestoreServices == null ? "null" : buildParameters.ManifestRestoreServices.GetType().FullName; + buildReport.Summary.EncryptionServicesClassName = buildParameters.BundleEncryptor == null ? "null" : buildParameters.BundleEncryptor.GetType().FullName; + buildReport.Summary.ManifestProcessServicesClassName = buildParameters.ManifestEncryptor == null ? "null" : buildParameters.ManifestEncryptor.GetType().FullName; + buildReport.Summary.ManifestRestoreServicesClassName = buildParameters.ManifestDecryptor == null ? "null" : buildParameters.ManifestDecryptor.GetType().FullName; if (buildParameters is BuiltinBuildParameters) { diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskEncryption.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskEncryption.cs index 051bb09f..2ad777e6 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskEncryption.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskEncryption.cs @@ -13,7 +13,7 @@ namespace YooAsset.Editor /// public void EncryptingBundleFiles(BuildParametersContext buildParametersContext, BuildMapContext buildMapContext) { - var encryptionServices = buildParametersContext.Parameters.EncryptionServices; + var encryptionServices = buildParametersContext.Parameters.BundleEncryptor; if (encryptionServices == null) return; @@ -24,14 +24,14 @@ namespace YooAsset.Editor string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory(); foreach (var bundleInfo in buildMapContext.Collection) { - BundleEncryptionContext fileInfo = new BundleEncryptionContext(); - fileInfo.BundleName = bundleInfo.BundleName; - fileInfo.FileLoadPath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}"; - var encryptResult = encryptionServices.Encrypt(fileInfo); + BundleEncryptArgs args = new BundleEncryptArgs(); + args.BundleName = bundleInfo.BundleName; + args.FilePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}"; + var encryptResult = encryptionServices.Encrypt(args); if (encryptResult.Encrypted) { string filePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}.encrypt"; - FileUtility.WriteAllBytes(filePath, encryptResult.EncryptedData); + FileUtility.WriteAllBytes(filePath, encryptResult.EncryptedFileData); bundleInfo.EncryptedFilePath = filePath; bundleInfo.Encrypted = true; BuildLogger.Log($"Bundle file encryption complete: {filePath}"); diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/DefaultEncryptionServices.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/DefaultEncryptionServices.cs index 049a2988..badc8ed0 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/DefaultEncryptionServices.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/DefaultEncryptionServices.cs @@ -1,9 +1,9 @@  namespace YooAsset.Editor { - public class EncryptionNone : IBundleEncryptionServices + public class EncryptionNone : IBundleEncryptor { - public BundleEncryptionResult Encrypt(BundleEncryptionContext fileInfo) + public BundleEncryptResult Encrypt(BundleEncryptArgs fileInfo) { throw new System.NotImplementedException(); } diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/DefaultManifestServices.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/DefaultManifestServices.cs index e423d246..bf12105e 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/DefaultManifestServices.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/DefaultManifestServices.cs @@ -1,17 +1,17 @@  namespace YooAsset.Editor { - public class ManifestProcessNone : IManifestProcessServices + public class ManifestEncryptorNone : IManifestEncryptor { - byte[] IManifestProcessServices.ProcessManifest(byte[] fileData) + byte[] IManifestEncryptor.Encrypt(byte[] fileData) { return fileData; } } - public class ManifestRestoreNone : IManifestRestoreServices + public class ManifestDecryptorNone : IManifestDecryptor { - byte[] IManifestRestoreServices.RestoreManifest(byte[] fileData) + byte[] IManifestDecryptor.Decrypt(byte[] fileData) { return fileData; } diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/VisualViewers/BuildPipelineViewerBase.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/VisualViewers/BuildPipelineViewerBase.cs index 3c105b00..22c78d24 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/VisualViewers/BuildPipelineViewerBase.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/VisualViewers/BuildPipelineViewerBase.cs @@ -44,43 +44,43 @@ namespace YooAsset.Editor } /// - /// 创建资源包加密服务类实例 + /// 创建资源包加密器实例 /// - protected IBundleEncryptionServices CreateEncryptionServicesInstance() + protected IBundleEncryptor CreateBundleEncryptorInstance() { var className = AssetBundleBuilderSetting.GetPackageEncyptionServicesClassName(PackageName, PipelineName); - var classTypes = EditorTools.GetAssignableTypes(typeof(IBundleEncryptionServices)); + var classTypes = EditorTools.GetAssignableTypes(typeof(IBundleEncryptor)); var classType = classTypes.Find(x => x.FullName.Equals(className)); if (classType != null) - return (IBundleEncryptionServices)Activator.CreateInstance(classType); + return (IBundleEncryptor)Activator.CreateInstance(classType); else return null; } /// - /// 创建资源清单加密服务类实例 + /// 创建资源清单加密器实例 /// - protected IManifestProcessServices CreateManifestProcessServicesInstance() + protected IManifestEncryptor CreateManifestEncryptorInstance() { var className = AssetBundleBuilderSetting.GetPackageManifestProcessServicesClassName(PackageName, PipelineName); - var classTypes = EditorTools.GetAssignableTypes(typeof(IManifestProcessServices)); + var classTypes = EditorTools.GetAssignableTypes(typeof(IManifestEncryptor)); var classType = classTypes.Find(x => x.FullName.Equals(className)); if (classType != null) - return (IManifestProcessServices)Activator.CreateInstance(classType); + return (IManifestEncryptor)Activator.CreateInstance(classType); else return null; } /// - /// 创建资源清单解密服务类实例 + /// 创建资源清单解密器实例 /// - protected IManifestRestoreServices CreateManifestRestoreServicesInstance() + protected IManifestDecryptor CreateManifestDecryptorInstance() { var className = AssetBundleBuilderSetting.GetPackageManifestRestoreServicesClassName(PackageName, PipelineName); - var classTypes = EditorTools.GetAssignableTypes(typeof(IManifestRestoreServices)); + var classTypes = EditorTools.GetAssignableTypes(typeof(IManifestDecryptor)); var classType = classTypes.Find(x => x.FullName.Equals(className)); if (classType != null) - return (IManifestRestoreServices)Activator.CreateInstance(classType); + return (IManifestDecryptor)Activator.CreateInstance(classType); else return null; } @@ -184,7 +184,7 @@ namespace YooAsset.Editor protected PopupField CreateEncryptionServicesField(VisualElement container) { // 资源包加密服务类 - var classTypes = EditorTools.GetAssignableTypes(typeof(IBundleEncryptionServices)); + var classTypes = EditorTools.GetAssignableTypes(typeof(IBundleEncryptor)); if (classTypes.Count > 0) { var className = AssetBundleBuilderSetting.GetPackageEncyptionServicesClassName(PackageName, PipelineName); @@ -215,7 +215,7 @@ namespace YooAsset.Editor protected PopupField CreateManifestProcessServicesField(VisualElement container) { // 资源清单加密服务类 - var classTypes = EditorTools.GetAssignableTypes(typeof(IManifestProcessServices)); + var classTypes = EditorTools.GetAssignableTypes(typeof(IManifestEncryptor)); if (classTypes.Count > 0) { var className = AssetBundleBuilderSetting.GetPackageManifestProcessServicesClassName(PackageName, PipelineName); @@ -246,7 +246,7 @@ namespace YooAsset.Editor protected PopupField CreateManifestRestoreServicesField(VisualElement container) { // 资源清单加密服务类 - var classTypes = EditorTools.GetAssignableTypes(typeof(IManifestRestoreServices)); + var classTypes = EditorTools.GetAssignableTypes(typeof(IManifestDecryptor)); if (classTypes.Count > 0) { var className = AssetBundleBuilderSetting.GetPackageManifestRestoreServicesClassName(PackageName, PipelineName); diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/VisualViewers/BuiltinBuildPipeline/BuiltinBuildPipelineViewer.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/VisualViewers/BuiltinBuildPipeline/BuiltinBuildPipelineViewer.cs index 62a447f8..29f6f23b 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/VisualViewers/BuiltinBuildPipeline/BuiltinBuildPipelineViewer.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/VisualViewers/BuiltinBuildPipeline/BuiltinBuildPipelineViewer.cs @@ -121,9 +121,9 @@ namespace YooAsset.Editor buildParameters.CompressOption = compressOption; buildParameters.ClearBuildCacheFiles = clearBuildCache; buildParameters.UseAssetDependencyDB = useAssetDependencyDB; - buildParameters.EncryptionServices = CreateEncryptionServicesInstance(); - buildParameters.ManifestProcessServices = CreateManifestProcessServicesInstance(); - buildParameters.ManifestRestoreServices = CreateManifestRestoreServicesInstance(); + buildParameters.BundleEncryptor = CreateBundleEncryptorInstance(); + buildParameters.ManifestEncryptor = CreateManifestEncryptorInstance(); + buildParameters.ManifestDecryptor = CreateManifestDecryptorInstance(); BuiltinBuildPipeline pipeline = new BuiltinBuildPipeline(); var buildResult = pipeline.Run(buildParameters, true); diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/VisualViewers/RawfileBuildpipeline/RawfileBuildPipelineViewer.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/VisualViewers/RawfileBuildpipeline/RawfileBuildPipelineViewer.cs index dd78c58d..bf720ff1 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/VisualViewers/RawfileBuildpipeline/RawfileBuildPipelineViewer.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/VisualViewers/RawfileBuildpipeline/RawfileBuildPipelineViewer.cs @@ -113,9 +113,9 @@ namespace YooAsset.Editor buildParameters.BuildinFileCopyParams = buildinFileCopyParams; buildParameters.ClearBuildCacheFiles = clearBuildCache; buildParameters.UseAssetDependencyDB = useAssetDependencyDB; - buildParameters.EncryptionServices = CreateEncryptionServicesInstance(); - buildParameters.ManifestProcessServices = CreateManifestProcessServicesInstance(); - buildParameters.ManifestRestoreServices = CreateManifestRestoreServicesInstance(); + buildParameters.BundleEncryptor = CreateBundleEncryptorInstance(); + buildParameters.ManifestEncryptor = CreateManifestEncryptorInstance(); + buildParameters.ManifestDecryptor = CreateManifestDecryptorInstance(); RawFileBuildPipeline pipeline = new RawFileBuildPipeline(); var buildResult = pipeline.Run(buildParameters, true); diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/VisualViewers/ScriptableBuildPipeline/ScriptableBuildPipelineViewer.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/VisualViewers/ScriptableBuildPipeline/ScriptableBuildPipelineViewer.cs index e3be3b05..0980a59e 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/VisualViewers/ScriptableBuildPipeline/ScriptableBuildPipelineViewer.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/VisualViewers/ScriptableBuildPipeline/ScriptableBuildPipelineViewer.cs @@ -121,9 +121,9 @@ namespace YooAsset.Editor buildParameters.CompressOption = compressOption; buildParameters.ClearBuildCacheFiles = clearBuildCache; buildParameters.UseAssetDependencyDB = useAssetDependencyDB; - buildParameters.EncryptionServices = CreateEncryptionServicesInstance(); - buildParameters.ManifestProcessServices = CreateManifestProcessServicesInstance(); - buildParameters.ManifestRestoreServices = CreateManifestRestoreServicesInstance(); + buildParameters.BundleEncryptor = CreateBundleEncryptorInstance(); + buildParameters.ManifestEncryptor = CreateManifestEncryptorInstance(); + buildParameters.ManifestDecryptor = CreateManifestDecryptorInstance(); buildParameters.BuiltinShadersBundleName = GetBuiltinShaderBundleName(); ScriptableBuildPipeline pipeline = new ScriptableBuildPipeline(); diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebGameFileSystem.meta b/Assets/YooAsset/Runtime/FileCache/Operations/Internal.meta similarity index 77% rename from Assets/YooAsset/Runtime/FileSystem/Services/WebGameFileSystem.meta rename to Assets/YooAsset/Runtime/FileCache/Operations/Internal.meta index c0881227..75b07687 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/WebGameFileSystem.meta +++ b/Assets/YooAsset/Runtime/FileCache/Operations/Internal.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 1ca8ffceab2965e4c8892f62efa86e90 +guid: c40f1ef3e0cc72f49903ce3b3a68d0cb folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalAssetBundleOperation.cs b/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalAssetBundleOperation.cs new file mode 100644 index 00000000..b0f503be --- /dev/null +++ b/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalAssetBundleOperation.cs @@ -0,0 +1,162 @@ +using System.IO; +using UnityEngine; + +namespace YooAsset +{ + internal class LoadLocalAssetBundleOperation : FCLoadBundleOperation + { + private enum ESteps + { + None, + LoadBundle, + CheckResult, + Done, + } + + private readonly PackageBundle _bundle; + private readonly LoadLocalAssetBundleOptions _options; + private AssetBundleCreateRequest _createRequest; + private AssetBundle _assetBundle; + private Stream _loadStream; + private ESteps _steps = ESteps.None; + + public bool UnityEngineLoadFailed = false; + + public LoadLocalAssetBundleOperation(LoadLocalAssetBundleOptions options) + { + _options = options; + } + internal override void InternalStart() + { + _steps = ESteps.LoadBundle; + } + internal override void InternalUpdate() + { + if (_steps == ESteps.None || _steps == ESteps.Done) + return; + + if (_steps == ESteps.LoadBundle) + { + if (_bundle.IsEncrypted == false) + { + LoadFromFile(); + } + else + { + var decryptor = _options.Decryptor; + if (decryptor == null) + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = $"{_options.CacheName} decryptor is null."; + return; + } + + if (decryptor is IBundleOffsetDecryptor offsetDecryptor) + { + LoadFromFileWithOffset(offsetDecryptor); + } + else if (decryptor is IBundleMemoryDecryptor memoryDecryptor) + { + LoadFromMemory(memoryDecryptor); + } + else if (decryptor is IBundleStreamDecryptor streamDecryptor) + { + LoadFromStream(streamDecryptor); + } + else + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = $"{_options.CacheName} not support {decryptor.GetType().Name}"; + return; + } + } + + _steps = ESteps.CheckResult; + } + + if (_steps == ESteps.CheckResult) + { + if (_createRequest != null) + { + if (IsWaitForCompletion) + { + // ǿƹ̣߳ע⣺òܺʱ + YooLogger.Warning("Suspend the main thread to load unity bundle."); + _assetBundle = _createRequest.assetBundle; + } + else + { + if (_createRequest.isDone == false) + return; + _assetBundle = _createRequest.assetBundle; + } + } + + if (_assetBundle == null) + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = "Unity engine load failed."; + UnityEngineLoadFailed = true; + } + else + { + _steps = ESteps.Done; + Status = EOperationStatus.Succeeded; + BundleResult = new AssetBundleResult(_options.FilePath, _options.Bundle, _assetBundle, _loadStream); + } + } + } + internal override void InternalWaitForCompletion() + { + ExecuteBatch(); + } + + private void LoadFromFile() + { + if (IsWaitForCompletion) + _assetBundle = AssetBundle.LoadFromFile(_options.FilePath); + else + _createRequest = AssetBundle.LoadFromFileAsync(_options.FilePath); + } + private void LoadFromFileWithOffset(IBundleOffsetDecryptor decryptor) + { + var args = new BundleDecryptArgs(); + args.Bundle = _bundle; + args.FilePath = _options.FilePath; + uint offset = decryptor.GetFileOffset(args); + + if (IsWaitForCompletion) + _assetBundle = AssetBundle.LoadFromFile(_options.FilePath, 0, offset); + else + _createRequest = AssetBundle.LoadFromFileAsync(_options.FilePath, 0, offset); + } + private void LoadFromMemory(IBundleMemoryDecryptor decryptor) + { + var args = new BundleDecryptArgs(); + args.Bundle = _bundle; + args.FilePath = _options.FilePath; + var binaryData = decryptor.GetDecryptData(args); + + if (IsWaitForCompletion) + _assetBundle = AssetBundle.LoadFromMemory(binaryData); + else + _createRequest = AssetBundle.LoadFromMemoryAsync(binaryData); + } + private void LoadFromStream(IBundleStreamDecryptor decryptor) + { + var args = new BundleDecryptArgs(); + args.Bundle = _bundle; + args.FilePath = _options.FilePath; + uint bufferSize = decryptor.GetReadBufferSize(args); + _loadStream = decryptor.GetDecryptStream(args); + + if (IsWaitForCompletion) + _assetBundle = AssetBundle.LoadFromStream(_loadStream, 0, bufferSize); + else + _createRequest = AssetBundle.LoadFromStreamAsync(_loadStream, 0, bufferSize); + } + } +} diff --git a/Assets/YooAsset/Runtime/FileCache/Services/LoadAssetBundleOperation.cs.meta b/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalAssetBundleOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/LoadAssetBundleOperation.cs.meta rename to Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalAssetBundleOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalAssetBundleOptions.cs b/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalAssetBundleOptions.cs new file mode 100644 index 00000000..0d5df967 --- /dev/null +++ b/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalAssetBundleOptions.cs @@ -0,0 +1,30 @@ + +namespace YooAsset +{ + /// + /// 加载 AssetBundle 的上下文信息 + /// + internal struct LoadLocalAssetBundleOptions + { + /// + /// 文件缓存名称 + /// + public string CacheName { get; set; } + + /// + /// 资源包信息 + /// + public PackageBundle Bundle { get; set; } + + /// + /// 文件加载路径 + /// + public string FilePath { get; set; } + + /// + /// 解密接口 + /// + public IBundleDecryptor Decryptor { get; set; } + } +} + diff --git a/Assets/YooAsset/Runtime/FileCache/Services/LoadAssetBundleOptions.cs.meta b/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalAssetBundleOptions.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/LoadAssetBundleOptions.cs.meta rename to Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalAssetBundleOptions.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalRawBundleOperation.cs b/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalRawBundleOperation.cs new file mode 100644 index 00000000..0c7f8077 --- /dev/null +++ b/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalRawBundleOperation.cs @@ -0,0 +1,111 @@ +using System; +using System.IO; + +namespace YooAsset +{ + internal class LoadLocalRawBundleOperation : FCLoadBundleOperation + { + private enum ESteps + { + None, + LoadBundle, + CheckResult, + Done, + } + + protected readonly LoadLocalRawBundleOptions _options; + private RawBundle _rawBundle; + private ESteps _steps = ESteps.None; + + public LoadLocalRawBundleOperation(LoadLocalRawBundleOptions options) + { + _options = options; + } + internal override void InternalStart() + { + _steps = ESteps.LoadBundle; + } + internal override void InternalUpdate() + { + if (_steps == ESteps.None || _steps == ESteps.Done) + return; + + if (_steps == ESteps.LoadBundle) + { + if (_options.Bundle.IsEncrypted == false) + { + if (IsSupportFileIO(_options.FilePath) == false) + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = $"FileIO not supported for builtin path : {_options.FilePath}"; + return; + } + + LoadFromFile(); + } + else + { + var decryptor = _options.Decryptor; + if (decryptor == null) + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = $"{_options.CacheName} decryptor is null."; + return; + } + + if (decryptor is IBundleMemoryDecryptor memoryDecryptor) + { + LoadFromMemory(memoryDecryptor); + } + else + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = $"{_options.CacheName} not support {decryptor.GetType().Name}"; + return; + } + } + + _steps = ESteps.CheckResult; + } + + if (_steps == ESteps.CheckResult) + { + if (_rawBundle == null) + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = $"Loaded raw bundle is null."; + } + else + { + _steps = ESteps.Done; + Status = EOperationStatus.Succeeded; + BundleResult = new RawBundleResult(_options.FilePath, _options.Bundle, _rawBundle); + } + } + } + internal override void InternalWaitForCompletion() + { + ExecuteBatch(); + } + + private void LoadFromFile() + { + byte[] data = File.ReadAllBytes(_options.FilePath); + if (data != null) + _rawBundle = new RawBundle(data); + } + private void LoadFromMemory(IBundleMemoryDecryptor decryptor) + { + var args = new BundleDecryptArgs(); + args.Bundle = _options.Bundle; + args.FilePath = _options.FilePath; + var binaryData = decryptor.GetDecryptData(args); + if (binaryData != null) + _rawBundle = new RawBundle(binaryData); + } + } +} diff --git a/Assets/YooAsset/Runtime/FileCache/Services/LoadRawBundleFileOperation.cs.meta b/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalRawBundleOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/LoadRawBundleFileOperation.cs.meta rename to Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalRawBundleOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalRawBundleOptions.cs b/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalRawBundleOptions.cs new file mode 100644 index 00000000..28cbc77c --- /dev/null +++ b/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalRawBundleOptions.cs @@ -0,0 +1,29 @@ + +namespace YooAsset +{ + /// + /// 加载 RawBundle 的上下文信息 + /// + internal struct LoadLocalRawBundleOptions + { + /// + /// 文件缓存名称 + /// + public string CacheName { get; set; } + + /// + /// 资源包信息 + /// + public PackageBundle Bundle { get; set; } + + /// + /// 文件加载路径 + /// + public string FilePath { get; set; } + + /// + /// 解密接口 + /// + public IBundleDecryptor Decryptor { get; set; } + } +} diff --git a/Assets/YooAsset/Runtime/FileCache/Services/LoadRawBundleFileOptions.cs.meta b/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalRawBundleOptions.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/LoadRawBundleFileOptions.cs.meta rename to Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadLocalRawBundleOptions.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadWebAssetBundleOperation.cs b/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadWebAssetBundleOperation.cs new file mode 100644 index 00000000..b94c55ff --- /dev/null +++ b/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadWebAssetBundleOperation.cs @@ -0,0 +1,252 @@ +using UnityEngine; + +namespace YooAsset +{ + internal abstract class LoadWebAssetBundleOperation : FCLoadBundleOperation + { + } + + internal class LoadWebNormalAssetBundleOperation : LoadWebAssetBundleOperation + { + private enum ESteps + { + None, + DownloadBundle, + CheckResult, + TryAgain, + Done, + } + + protected readonly LoadWebAssetBundleOptions _options; + private IDownloadAssetBundleRequest _downloadAssetBundleRequest; + private ESteps _steps = ESteps.None; + + // ʧ + private int _requestCount = 0; + private float _tryAgainTimer = 0; + private int _failedTryAgain; + + public LoadWebNormalAssetBundleOperation(LoadWebAssetBundleOptions options) + { + _options = options; + _failedTryAgain = int.MaxValue; //ע⣺ԭʧܺ³ֱɹ + } + internal override void InternalStart() + { + _steps = ESteps.DownloadBundle; + } + internal override void InternalUpdate() + { + if (_steps == ESteps.None || _steps == ESteps.Done) + return; + + if (_steps == ESteps.DownloadBundle) + { + string url = GetRequestURL(); + var args = new DownloadAssetBundleRequestArgs(url, 0, _options.WatchdogTimeout, _options.DisableUnityWebCache, _options.Bundle.FileHash, _options.Bundle.UnityCRC); + _downloadAssetBundleRequest = _options.DownloadBackend.CreateAssetBundleRequest(args); + _downloadAssetBundleRequest.SendRequest(); + _steps = ESteps.CheckResult; + } + + if (_steps == ESteps.CheckResult) + { + Progress = _downloadAssetBundleRequest.DownloadProgress; + if (_downloadAssetBundleRequest.IsDone == false) + return; + + if (_downloadAssetBundleRequest.Status == EDownloadRequestStatus.Succeeded) + { + var assetBundle = _downloadAssetBundleRequest.Result; + if (assetBundle == null) + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = $"Fatal error: dwonload asset bundle is null."; + } + else + { + _steps = ESteps.Done; + Status = EOperationStatus.Succeeded; + BundleResult = new AssetBundleResult(_downloadAssetBundleRequest.Url, _options.Bundle, assetBundle, null); + } + } + else + { + if (_failedTryAgain > 0) + { + _steps = ESteps.TryAgain; + } + else + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = _downloadAssetBundleRequest.Error; + } + } + + // ͷ + _downloadAssetBundleRequest.Dispose(); + } + + if (_steps == ESteps.TryAgain) + { + _tryAgainTimer += UnityEngine.Time.unscaledDeltaTime; + if (_tryAgainTimer > 1f) + { + _tryAgainTimer = 0f; + _failedTryAgain--; + Progress = 0f; + _steps = ESteps.DownloadBundle; + } + } + } + + private string GetRequestURL() + { + // ַ + _requestCount++; + if (_requestCount % 2 == 0) + return _options.FallbackURL; + else + return _options.MainURL; + } + } + + internal class LoadWebEncryptedAssetBundleOperation : LoadWebAssetBundleOperation + { + private enum ESteps + { + None, + DownloadData, + CheckResult, + TryAgain, + Done, + } + + protected readonly LoadWebAssetBundleOptions _options; + private IDownloadBytesRequest _downloadBytesRequest; + private IBundleMemoryDecryptor _decryptor; + private ESteps _steps = ESteps.None; + + // ʧ + private int _requestCount = 0; + private float _tryAgainTimer = 0; + private int _failedTryAgain; + + public LoadWebEncryptedAssetBundleOperation(LoadWebAssetBundleOptions options) + { + _options = options; + _failedTryAgain = int.MaxValue; //ע⣺ԭʧܺ³ֱɹ + } + internal override void InternalStart() + { + _steps = ESteps.DownloadData; + } + internal override void InternalUpdate() + { + if (_steps == ESteps.None || _steps == ESteps.Done) + return; + + if (_steps == ESteps.DownloadData) + { + var decryptor = _options.Decryptor; + if (decryptor == null) + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = $"{_options.CacheName} decryptor is null."; + return; + } + + if (decryptor is IBundleMemoryDecryptor) + { + string url = GetRequestURL(); + _decryptor = decryptor as IBundleMemoryDecryptor; + var args = new DownloadDataRequestArgs(url, 0, _options.WatchdogTimeout); + _downloadBytesRequest = _options.DownloadBackend.CreateBytesRequest(args); + _downloadBytesRequest.SendRequest(); + _steps = ESteps.CheckResult; + } + else + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = $"{_options.CacheName} not support {decryptor.GetType().Name}"; + return; + } + } + + if (_steps == ESteps.CheckResult) + { + Progress = _downloadBytesRequest.DownloadProgress; + if (_downloadBytesRequest.IsDone == false) + return; + + // + if (_downloadBytesRequest.Status == EDownloadRequestStatus.Succeeded) + { + var assetBundle = LoadFromMemory(_decryptor, _downloadBytesRequest.Result); + if (assetBundle == null) + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = "Unity engine load failed."; + } + else + { + _steps = ESteps.Done; + Status = EOperationStatus.Succeeded; + BundleResult = new AssetBundleResult(_downloadBytesRequest.Url, _options.Bundle, assetBundle, null); + } + } + else + { + if (_failedTryAgain > 0) + { + _steps = ESteps.TryAgain; + } + else + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = _downloadBytesRequest.Error; + } + } + + // ͷ + _downloadBytesRequest.Dispose(); + } + + if (_steps == ESteps.TryAgain) + { + _tryAgainTimer += Time.unscaledDeltaTime; + if (_tryAgainTimer > 1f) + { + _tryAgainTimer = 0f; + _failedTryAgain--; + Progress = 0f; + _steps = ESteps.DownloadData; + } + } + } + + private AssetBundle LoadFromMemory(IBundleMemoryDecryptor decryptor, byte[] fileData) + { + var args = new BundleDecryptArgs(); + args.Bundle = _options.Bundle; + args.FileData = fileData; + var binaryData = decryptor.GetDecryptData(args); + return AssetBundle.LoadFromMemory(binaryData); + } + private string GetRequestURL() + { + // ַ + _requestCount++; + if (_requestCount % 2 == 0) + return _options.FallbackURL; + else + return _options.MainURL; + } + } +} diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebGameFileSystem/Operations/LoadWebAssetBundleOperation.cs.meta b/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadWebAssetBundleOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/Services/WebGameFileSystem/Operations/LoadWebAssetBundleOperation.cs.meta rename to Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadWebAssetBundleOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadWebAssetBundleOptions.cs b/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadWebAssetBundleOptions.cs new file mode 100644 index 00000000..47805439 --- /dev/null +++ b/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadWebAssetBundleOptions.cs @@ -0,0 +1,49 @@ + +namespace YooAsset +{ + /// + /// 加载 AssetBundle 的上下文信息 + /// + internal struct LoadWebAssetBundleOptions + { + /// + /// 文件缓存名称 + /// + public string CacheName { get; set; } + + /// + /// 资源包信息 + /// + public PackageBundle Bundle { get; set; } + + /// + /// 请求地址 + /// + public string MainURL { get; set; } + + /// + /// 请求地址 + /// + public string FallbackURL { get; set; } + + /// + /// 解密接口 + /// + public IBundleDecryptor Decryptor { get; set; } + + /// + /// 下载后台接口 + /// + public IDownloadBackend DownloadBackend { get; set; } + + /// + /// 看门狗超时时间 + /// + public int WatchdogTimeout { get; set; } + + /// + /// 禁用Unity的网络缓存 + /// + public bool DisableUnityWebCache { get; set; } + } +} diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebGameFileSystem/Operations/LoadWebAssetBundleOptions.cs.meta b/Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadWebAssetBundleOptions.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/Services/WebGameFileSystem/Operations/LoadWebAssetBundleOptions.cs.meta rename to Assets/YooAsset/Runtime/FileCache/Operations/Internal/LoadWebAssetBundleOptions.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCache.cs b/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCache.cs index 448d4c22..a7d526c1 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCache.cs +++ b/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCache.cs @@ -7,6 +7,19 @@ namespace YooAsset { internal struct CacheConfig { + /// + /// AssetBundle 解密器 + /// + public IBundleDecryptor AssetBundleDecryptor { get; set; } + + /// + /// RawBundle 解密器 + /// + public IBundleDecryptor RawBundleDecryptor { get; set; } + + /// + /// 下载后台接口 + /// public IDownloadBackend DownloadBackend { get; set; } } diff --git a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCatalogTools.cs b/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCatalogTools.cs index 5b4636f9..75beb29d 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCatalogTools.cs +++ b/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/BuiltinFileCatalogTools.cs @@ -12,7 +12,7 @@ namespace YooAsset /// 生成包裹的内置资源目录文件 /// 说明:根据指定目录下的文件生成清单文件。 /// - public static bool CreateFile(IManifestRestoreServices services, string packageName, string packageDirectory) + public static bool CreateFile(IManifestDecryptor decryptor, string packageName, string packageDirectory) { // 获取资源清单版本 string packageVersion; @@ -40,7 +40,7 @@ namespace YooAsset } var binaryData = FileUtility.ReadAllBytes(manifestFilePath); - packageManifest = PackageManifestTools.DeserializeManifestFromBinary(binaryData, services); + packageManifest = PackageManifestTools.DeserializeManifestFromBinary(binaryData, decryptor); } // 获取文件名映射关系 diff --git a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/Operations/BFCLoadBundleOperation.cs b/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/Operations/BFCLoadBundleOperation.cs index 5bf97d24..bc45ba6f 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/Operations/BFCLoadBundleOperation.cs +++ b/Assets/YooAsset/Runtime/FileCache/Services/BuiltinFileCache/Operations/BFCLoadBundleOperation.cs @@ -1,7 +1,4 @@ -using System; -using System.IO; -using UnityEngine; - + namespace YooAsset { internal class BFCLoadAssetBundleOperation : FCLoadBundleOperation @@ -9,16 +6,15 @@ namespace YooAsset private enum ESteps { None, - LoadAssetBundle, - CheckResult, + GetEntry, + LoadBundle, Done, } private readonly BuiltinFileCache _fileCache; private readonly PackageBundle _bundle; - private AssetBundleCreateRequest _createRequest; - private AssetBundle _assetBundle; - private string _filePath; + private LoadLocalAssetBundleOperation _loadLocalAssetBundleOp; + private BuiltinFileCacheEntry _cacheEntry; private ESteps _steps = ESteps.None; public BFCLoadAssetBundleOperation(BuiltinFileCache fileCache, PackageBundle bundle) @@ -28,62 +24,63 @@ namespace YooAsset } internal override void InternalStart() { - _steps = ESteps.LoadAssetBundle; + _steps = ESteps.GetEntry; } internal override void InternalUpdate() { if (_steps == ESteps.None || _steps == ESteps.Done) return; - if (_steps == ESteps.LoadAssetBundle) + if (_steps == ESteps.GetEntry) { - var entry = _fileCache.GetEntry(_bundle.BundleGUID); - if (entry == null) + _cacheEntry = _fileCache.GetEntry(_bundle.BundleGUID); + if (_cacheEntry == null) { _steps = ESteps.Done; Status = EOperationStatus.Failed; Error = $"Not found file cache entry: {_bundle.BundleGUID}"; - return; } - - _filePath = entry.FilePath; - if (IsWaitForCompletion) - _assetBundle = AssetBundle.LoadFromFile(_filePath); else - _createRequest = AssetBundle.LoadFromFileAsync(_filePath); - - _steps = ESteps.CheckResult; + { + _steps = ESteps.LoadBundle; + } } - if (_steps == ESteps.CheckResult) + if (_steps == ESteps.LoadBundle) { - if (_createRequest != null) + if (_loadLocalAssetBundleOp == null) { - if (IsWaitForCompletion) - { - // 强制挂起主线程(注意:该操作会很耗时) - YooLogger.Warning("Suspend the main thread to load unity bundle."); - _assetBundle = _createRequest.assetBundle; - } - else - { - if (_createRequest.isDone == false) - return; - _assetBundle = _createRequest.assetBundle; - } + var options = new LoadLocalAssetBundleOptions(); + options.CacheName = _fileCache.GetType().Name; + options.Bundle = _bundle; + options.FilePath = _cacheEntry.FilePath; + options.Decryptor = _fileCache.Config.AssetBundleDecryptor; + _loadLocalAssetBundleOp = new LoadLocalAssetBundleOperation(options); + _loadLocalAssetBundleOp.StartOperation(); + AddChildOperation(_loadLocalAssetBundleOp); } - if (_assetBundle == null) + if (IsWaitForCompletion) + _loadLocalAssetBundleOp.WaitForCompletion(); + + _loadLocalAssetBundleOp.UpdateOperation(); + if (_loadLocalAssetBundleOp.IsDone == false) + return; + + if (_loadLocalAssetBundleOp.Status == EOperationStatus.Succeeded) + { + if (_loadLocalAssetBundleOp.BundleResult == null) + throw new YooInternalException("Loaded asset bundle result is null."); + + _steps = ESteps.Done; + Status = EOperationStatus.Succeeded; + BundleResult = _loadLocalAssetBundleOp.BundleResult; + } + else { _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = $"Failed to load asset bundle : {_bundle.BundleName}"; - } - else - { - _steps = ESteps.Done; - Status = EOperationStatus.Succeeded; - BundleResult = new AssetBundleResult(_filePath, _bundle, _assetBundle, null); + Error = _loadLocalAssetBundleOp.Error; } } } @@ -98,12 +95,15 @@ namespace YooAsset private enum ESteps { None, - LoadRawBundle, + GetEntry, + LoadBundle, Done, } private readonly BuiltinFileCache _fileCache; private readonly PackageBundle _bundle; + private LoadLocalRawBundleOperation _loadLocalRawBundleOp; + private BuiltinFileCacheEntry _cacheEntry; private ESteps _steps = ESteps.None; public BFCLoadRawBundleOperation(BuiltinFileCache fileCache, PackageBundle bundle) @@ -113,48 +113,61 @@ namespace YooAsset } internal override void InternalStart() { - _steps = ESteps.LoadRawBundle; + _steps = ESteps.GetEntry; } internal override void InternalUpdate() { if (_steps == ESteps.None || _steps == ESteps.Done) return; - if (_steps == ESteps.LoadRawBundle) + if (_steps == ESteps.GetEntry) { - var entry = _fileCache.GetEntry(_bundle.BundleGUID); - if (entry == null) + _cacheEntry = _fileCache.GetEntry(_bundle.BundleGUID); + if (_cacheEntry == null) { _steps = ESteps.Done; Status = EOperationStatus.Failed; Error = $"Not found file cache entry: {_bundle.BundleGUID}"; - return; - } - - string filePath = entry.FilePath; - if (IsSupportFileIO(filePath) == false) - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = $"FileIO not supported for builtin path : {filePath}"; } else { - if (File.Exists(filePath)) - { - _steps = ESteps.Done; - Status = EOperationStatus.Succeeded; + _steps = ESteps.LoadBundle; + } + } - byte[] data = File.ReadAllBytes(filePath); - var rawBundle = new RawBundle(data); - BundleResult = new RawBundleResult(filePath, _bundle, rawBundle); - } - else - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = $"Can not found raw bundle file : {filePath}"; - } + if (_steps == ESteps.LoadBundle) + { + if(_loadLocalRawBundleOp == null) + { + var options = new LoadLocalRawBundleOptions(); + options.CacheName = _fileCache.GetType().Name; + options.Bundle = _bundle; + options.FilePath = _cacheEntry.FilePath; + options.Decryptor = _fileCache.Config.AssetBundleDecryptor; + _loadLocalRawBundleOp = new LoadLocalRawBundleOperation(options); + _loadLocalRawBundleOp.StartOperation(); + AddChildOperation(_loadLocalRawBundleOp); + } + + if (IsWaitForCompletion) + _loadLocalRawBundleOp.WaitForCompletion(); + + _loadLocalRawBundleOp.UpdateOperation(); + if (_loadLocalRawBundleOp.IsDone == false) + return; + + if(_loadLocalRawBundleOp.Status == EOperationStatus.Succeeded) + { + if (_loadLocalRawBundleOp.BundleResult == null) + throw new YooInternalException("Loaded raw bundle result is null."); + + BundleResult = _loadLocalRawBundleOp.BundleResult; + } + else + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = _loadLocalRawBundleOp.Error; } } } @@ -163,16 +176,4 @@ namespace YooAsset ExecuteBatch(); } } - - internal abstract class BFCLoadAssetBundleFromOperation : FCLoadBundleOperation - { - internal abstract AssetBundle LoadFromOffset(); - internal abstract AssetBundleCreateRequest LoadFromOffsetAsync(); - - internal abstract AssetBundle LoadFromMemory(); - internal abstract AssetBundleCreateRequest LoadFromMemoryAsync(); - - internal abstract AssetBundle LoadFromStream(); - internal abstract AssetBundleCreateRequest LoadFromStreamAsync(); - } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/EditorFileCache.cs b/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/EditorFileCache.cs index 80b90723..7897e1d0 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/EditorFileCache.cs +++ b/Assets/YooAsset/Runtime/FileCache/Services/EditorFileCache/EditorFileCache.cs @@ -84,8 +84,17 @@ namespace YooAsset } public virtual FCLoadBundleOperation LoadBundleAsync(LoadBundleOptions options) { - var operation = new EFCLoadVirtualBundleOperation(this, options.Bundle); - return operation; + if (options.Bundle.BundleType == (int)EBundleType.VirtualBundle) + { + var operation = new EFCLoadVirtualBundleOperation(this, options.Bundle); + return operation; + } + else + { + string error = $"{nameof(EditorFileCache)} not support load bundle type : {options.Bundle.BundleType}"; + var operation = new FCLoadBundleErrorOperation(error); + return operation; + } } public virtual bool IsCached(string bundleGUID) { diff --git a/Assets/YooAsset/Runtime/FileCache/Services/LoadAssetBundleOperation.cs b/Assets/YooAsset/Runtime/FileCache/Services/LoadAssetBundleOperation.cs deleted file mode 100644 index 3b7829d9..00000000 --- a/Assets/YooAsset/Runtime/FileCache/Services/LoadAssetBundleOperation.cs +++ /dev/null @@ -1,75 +0,0 @@ -using System.IO; -using UnityEngine; - -namespace YooAsset -{ - /// - /// 加载 AssetBundle 的抽象基类 - /// 用户可继承此类实现自定义加载逻辑(如加密解密) - /// - public abstract class LoadAssetBundleOperation : AsyncOperationBase - { - protected readonly LoadAssetBundleOptions _options; - - /// - /// 加载结果:AssetBundle 对象 - /// - public AssetBundle Result { get; protected set; } - - /// - /// 托管流对象(如果使用流加载) - /// 注意:流对象在资源包对象释放的时候会自动释放 - /// - public Stream ManagedStream { get; protected set; } - - public LoadAssetBundleOperation(LoadAssetBundleOptions options) - { - _options = options; - } - - /// - /// 后备加载方法:从内存加载 AssetBundle - /// 当主加载方式失败时,FileSystem 会调用此方法作为后备机制 - /// - /// 加载成功返回 AssetBundle 对象,失败返回 null - public abstract AssetBundle LoadFromMemory(); - - /// - /// 检查文件路径是否支持 FileIO 读取 - /// - protected static bool IsSupportFileIO(string filePath) - { - if (string.IsNullOrEmpty(filePath)) - return true; - if (filePath.StartsWith("jar:") || filePath.StartsWith("content:")) - return false; - return true; - } - } - - /// - /// 立即完成(失败)的 AssetBundle 加载操作 - /// 用途:当 Factory 判定某种场景不支持(例如默认实现不支持加密包)时,返回该 Operation - /// - public sealed class LoadAssetBundleCompleteOperation : LoadAssetBundleOperation - { - private readonly string _error; - - public LoadAssetBundleCompleteOperation(string error, LoadAssetBundleOptions options) : base(options) - { - _error = error; - } - internal override void InternalStart() - { - Status = EOperationStatus.Failed; - Error = _error; - } - internal override void InternalUpdate() - { - } - public override AssetBundle LoadFromMemory() - { - return null; - } - } -} diff --git a/Assets/YooAsset/Runtime/FileCache/Services/LoadAssetBundleOptions.cs b/Assets/YooAsset/Runtime/FileCache/Services/LoadAssetBundleOptions.cs deleted file mode 100644 index a90807cc..00000000 --- a/Assets/YooAsset/Runtime/FileCache/Services/LoadAssetBundleOptions.cs +++ /dev/null @@ -1,19 +0,0 @@ - -namespace YooAsset -{ - /// - /// 加载 AssetBundle 的上下文信息 - /// - public struct LoadAssetBundleOptions - { - /// - /// 文件加载路径 - /// - internal string FileLoadPath { get; set; } - - /// - /// 资源包信息 - /// - internal PackageBundle Bundle { get; set; } - } -} diff --git a/Assets/YooAsset/Runtime/FileCache/Services/LoadRawBundleFileOperation.cs b/Assets/YooAsset/Runtime/FileCache/Services/LoadRawBundleFileOperation.cs deleted file mode 100644 index 9715fec5..00000000 --- a/Assets/YooAsset/Runtime/FileCache/Services/LoadRawBundleFileOperation.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System.Text; - -namespace YooAsset -{ - /// - /// 加载 RawBundle 的抽象基类 - /// 用户可继承此类实现自定义加载逻辑(如加密解密) - /// - public abstract class LoadRawBundleOperation : AsyncOperationBase - { - protected readonly LoadRawBundleOptions _options; - - /// - /// 加载结果:RawBundle 对象 - /// - public RawBundle Result { get; protected set; } - - public LoadRawBundleOperation(LoadRawBundleOptions options) - { - _options = options; - } - - /// - /// 检查文件路径是否支持 FileIO 读取 - /// - protected static bool IsSupportFileIO(string filePath) - { - if (string.IsNullOrEmpty(filePath)) - return true; - if (filePath.StartsWith("jar:") || filePath.StartsWith("content:")) - return false; - return true; - } - } - - /// - /// 立即完成(失败)的 RawBundle 加载操作 - /// 用途:当 Factory 判定某种场景不支持(例如默认实现不支持加密包)时,返回该 Operation - /// - public sealed class LoadRawBundleCompleteOperation : LoadRawBundleOperation - { - private readonly string _error; - - public LoadRawBundleCompleteOperation(string error, LoadRawBundleOptions options) : base(options) - { - _error = error; - } - internal override void InternalStart() - { - Status = EOperationStatus.Failed; - Error = _error; - } - internal override void InternalUpdate() - { - } - } -} diff --git a/Assets/YooAsset/Runtime/FileCache/Services/LoadRawBundleFileOptions.cs b/Assets/YooAsset/Runtime/FileCache/Services/LoadRawBundleFileOptions.cs deleted file mode 100644 index 00c8e31f..00000000 --- a/Assets/YooAsset/Runtime/FileCache/Services/LoadRawBundleFileOptions.cs +++ /dev/null @@ -1,19 +0,0 @@ - -namespace YooAsset -{ - /// - /// 加载 RawBundle 的上下文信息 - /// - public struct LoadRawBundleOptions - { - /// - /// 文件加载路径 - /// - internal string FileLoadPath { get; set; } - - /// - /// 资源包信息 - /// - internal PackageBundle Bundle { get; set; } - } -} diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCLoadBundleOperation.cs b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCLoadBundleOperation.cs index 016ee6ff..2003575b 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCLoadBundleOperation.cs +++ b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/Operations/SFCLoadBundleOperation.cs @@ -9,18 +9,18 @@ namespace YooAsset private enum ESteps { None, - LoadAssetBundle, - CheckResult, + GetEntry, + LoadBundle, + VerifyFile, TryFallback, Done, } private readonly SandboxFileCache _fileCache; private readonly PackageBundle _bundle; + private LoadLocalAssetBundleOperation _loadLocalAssetBundleOp; private FCVerifyCacheOperation _verifyCacheOp; - private AssetBundleCreateRequest _createRequest; - private AssetBundle _assetBundle; - private string _filePath; + private SandboxFileCacheEntry _cacheEntry; private ESteps _steps = ESteps.None; public SFCLoadAssetBundleOperation(SandboxFileCache fileCache, PackageBundle bundle) @@ -30,64 +30,75 @@ namespace YooAsset } internal override void InternalStart() { - _steps = ESteps.LoadAssetBundle; + _steps = ESteps.GetEntry; } internal override void InternalUpdate() { if (_steps == ESteps.None || _steps == ESteps.Done) return; - if (_steps == ESteps.LoadAssetBundle) + if (_steps == ESteps.GetEntry) { - var entry = _fileCache.GetEntry(_bundle.BundleGUID); - if (entry == null) + _cacheEntry = _fileCache.GetEntry(_bundle.BundleGUID); + if (_cacheEntry == null) { _steps = ESteps.Done; Status = EOperationStatus.Failed; Error = $"Not found file cache entry: {_bundle.BundleGUID}"; - return; } - - _filePath = entry.DataFilePath; - if (IsWaitForCompletion) - _assetBundle = AssetBundle.LoadFromFile(_filePath); else - _createRequest = AssetBundle.LoadFromFileAsync(_filePath); - - _steps = ESteps.CheckResult; + { + _steps = ESteps.LoadBundle; + } } - if (_steps == ESteps.CheckResult) + if (_steps == ESteps.LoadBundle) { - if (_createRequest != null) + if (_loadLocalAssetBundleOp == null) { - if (IsWaitForCompletion) + var options = new LoadLocalAssetBundleOptions(); + options.CacheName = _fileCache.GetType().Name; + options.Bundle = _bundle; + options.FilePath = _cacheEntry.DataFilePath; + options.Decryptor = _fileCache.Config.AssetBundleDecryptor; + _loadLocalAssetBundleOp = new LoadLocalAssetBundleOperation(options); + _loadLocalAssetBundleOp.StartOperation(); + AddChildOperation(_loadLocalAssetBundleOp); + } + + if (IsWaitForCompletion) + _loadLocalAssetBundleOp.WaitForCompletion(); + + _loadLocalAssetBundleOp.UpdateOperation(); + if (_loadLocalAssetBundleOp.IsDone == false) + return; + + if (_loadLocalAssetBundleOp.Status == EOperationStatus.Succeeded) + { + if (_loadLocalAssetBundleOp.BundleResult == null) + throw new YooInternalException("Loaded asset bundle result is null."); + + _steps = ESteps.Done; + Status = EOperationStatus.Succeeded; + BundleResult = _loadLocalAssetBundleOp.BundleResult; + } + else + { + // 注意:如果引擎加载失败,需要重新验证文件 + if (_loadLocalAssetBundleOp.UnityEngineLoadFailed) { - // 强制挂起主线程(注意:该操作会很耗时) - YooLogger.Warning("Suspend the main thread to load unity bundle."); - _assetBundle = _createRequest.assetBundle; + _steps = ESteps.VerifyFile; } else { - if (_createRequest.isDone == false) - return; - _assetBundle = _createRequest.assetBundle; + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = _loadLocalAssetBundleOp.Error; } } - - if (_assetBundle == null) - { - _steps = ESteps.TryFallback; - } - else - { - _steps = ESteps.Done; - Status = EOperationStatus.Succeeded; - BundleResult = new AssetBundleResult(_filePath, _bundle, _assetBundle, null); - } } - if (_steps == ESteps.TryFallback) + if (_steps == ESteps.VerifyFile) { // 注意:当缓存文件的校验等级为Low的时候,并不能保证缓存文件的完整性。 // 说明:在AssetBundle文件加载失败的情况下,我们需要重新验证文件的完整性! @@ -110,22 +121,7 @@ namespace YooAsset if (_verifyCacheOp.Status == EOperationStatus.Succeeded) { - // 调用后备加载方法 - // 注意:在安卓移动平台,华为和三星真机上有极小概率加载资源包失败。 - // 说明:大多数情况在首次安装下载资源到沙盒内,游戏过程中切换到后台再回到游戏内有很大概率触发! - AssetBundle assetBundle = LoadFromMemory(); - if (assetBundle != null) - { - _steps = ESteps.Done; - Status = EOperationStatus.Succeeded; - BundleResult = new AssetBundleResult(_filePath, _bundle, assetBundle, null); - } - else - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = $"Failed to load asset bundle from memory : {_bundle.BundleName}"; - } + _steps = ESteps.TryFallback; } else { @@ -134,19 +130,70 @@ namespace YooAsset Error = _verifyCacheOp.Error; } } + + if (_steps == ESteps.TryFallback) + { + // 调用后备加载方法 + // 注意:在安卓移动平台,华为和三星真机上有极小概率加载资源包失败。 + // 说明:大多数情况在首次安装下载资源到沙盒内,游戏过程中切换到后台再回到游戏内有很大概率触发! + AssetBundle assetBundle; + if (_bundle.IsEncrypted) + { + if (_fileCache.Config.AssetBundleFallbackDecryptor == null) + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = $"{nameof(SandboxFileCache)} fallback decryptor is null."; + return; + } + + assetBundle = FallbackLoadDecryptAssetBundle(_fileCache.Config.AssetBundleFallbackDecryptor); + if (assetBundle == null) + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = $"Failed fallback load encrypted asset bundle: {_bundle.BundleName}"; + } + } + else + { + assetBundle = FallbackLoadAssetBundle(); + if (assetBundle == null) + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = $"Failed fallback load asset bundle: {_bundle.BundleName}"; + } + } + + if (assetBundle != null) + { + _steps = ESteps.Done; + Status = EOperationStatus.Succeeded; + BundleResult = new AssetBundleResult(_cacheEntry.DataFilePath, _bundle, assetBundle, null); + } + } } internal override void InternalWaitForCompletion() { ExecuteBatch(); } - private AssetBundle LoadFromMemory() + private AssetBundle FallbackLoadAssetBundle() { - byte[] fileData = FileUtility.ReadAllBytes(_filePath); + byte[] fileData = FileUtility.ReadAllBytes(_cacheEntry.DataFilePath); if (fileData == null || fileData.Length == 0) return null; return AssetBundle.LoadFromMemory(fileData); } + private AssetBundle FallbackLoadDecryptAssetBundle(IBundleMemoryDecryptor decryptor) + { + var args = new BundleDecryptArgs(); + args.Bundle = _bundle; + args.FilePath = _cacheEntry.DataFilePath; + var binaryData = decryptor.GetDecryptData(args); + return AssetBundle.LoadFromMemory(binaryData); + } } internal class SFCLoadRawBundleOperation : FCLoadBundleOperation @@ -154,12 +201,16 @@ namespace YooAsset private enum ESteps { None, - LoadRawBundle, + GetEntry, + LoadBundle, Done, } private readonly SandboxFileCache _fileCache; private readonly PackageBundle _bundle; + private LoadLocalRawBundleOperation _loadLocalRawBundleOp; + private SandboxFileCacheEntry _cacheEntry; + private ESteps _steps = ESteps.None; public SFCLoadRawBundleOperation(SandboxFileCache fileCache, PackageBundle bundle) @@ -169,39 +220,61 @@ namespace YooAsset } internal override void InternalStart() { - _steps = ESteps.LoadRawBundle; + _steps = ESteps.GetEntry; } internal override void InternalUpdate() { if (_steps == ESteps.None || _steps == ESteps.Done) return; - if (_steps == ESteps.LoadRawBundle) + if (_steps == ESteps.GetEntry) { - var entry = _fileCache.GetEntry(_bundle.BundleGUID); - if (entry == null) + _cacheEntry = _fileCache.GetEntry(_bundle.BundleGUID); + if (_cacheEntry == null) { _steps = ESteps.Done; Status = EOperationStatus.Failed; Error = $"Not found file cache entry: {_bundle.BundleGUID}"; - return; + } + else + { + _steps = ESteps.LoadBundle; + } + } + + if (_steps == ESteps.LoadBundle) + { + if (_loadLocalRawBundleOp == null) + { + var options = new LoadLocalRawBundleOptions(); + options.CacheName = _fileCache.GetType().Name; + options.Bundle = _bundle; + options.FilePath = _cacheEntry.DataFilePath; + options.Decryptor = _fileCache.Config.AssetBundleDecryptor; + _loadLocalRawBundleOp = new LoadLocalRawBundleOperation(options); + _loadLocalRawBundleOp.StartOperation(); + AddChildOperation(_loadLocalRawBundleOp); } - string filePath = entry.DataFilePath; - if (File.Exists(filePath)) - { - _steps = ESteps.Done; - Status = EOperationStatus.Succeeded; + if (IsWaitForCompletion) + _loadLocalRawBundleOp.WaitForCompletion(); - byte[] data = File.ReadAllBytes(filePath); - var rawBundle = new RawBundle(data); - BundleResult = new RawBundleResult(filePath, _bundle, rawBundle); + _loadLocalRawBundleOp.UpdateOperation(); + if (_loadLocalRawBundleOp.IsDone == false) + return; + + if (_loadLocalRawBundleOp.Status == EOperationStatus.Succeeded) + { + if (_loadLocalRawBundleOp.BundleResult == null) + throw new YooInternalException("Loaded raw bundle result is null."); + + BundleResult = _loadLocalRawBundleOp.BundleResult; } else { _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = $"Can not found raw bundle file : {filePath}"; + Error = _loadLocalRawBundleOp.Error; } } } @@ -210,16 +283,4 @@ namespace YooAsset ExecuteBatch(); } } - - internal abstract class SFCLoadAssetBundleFromOperation : FCLoadBundleOperation - { - internal abstract AssetBundle LoadFromOffset(); - internal abstract AssetBundleCreateRequest LoadFromOffsetAsync(); - - internal abstract AssetBundle LoadFromMemory(); - internal abstract AssetBundleCreateRequest LoadFromMemoryAsync(); - - internal abstract AssetBundle LoadFromStream(); - internal abstract AssetBundleCreateRequest LoadFromStreamAsync(); - } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SandboxFileCache.cs b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SandboxFileCache.cs index 0971fc43..529c3c14 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SandboxFileCache.cs +++ b/Assets/YooAsset/Runtime/FileCache/Services/SandboxFileCache/SandboxFileCache.cs @@ -16,6 +16,21 @@ namespace YooAsset /// 文件校验级别 /// public EFileVerifyLevel FileVerifyLevel { get; set; } + + /// + /// AssetBundle 解密器 + /// + public IBundleDecryptor AssetBundleDecryptor { get; set; } + + /// + /// RawBundle 解密器 + /// + public IBundleDecryptor RawBundleDecryptor { get; set; } + + /// + /// AssetBundle 备用解密器 + /// + public IBundleMemoryDecryptor AssetBundleFallbackDecryptor { get; set; } } private const int HashFolderLength = 2; diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/Operations/WRFCLoadBundleOperation.cs b/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/Operations/WRFCLoadBundleOperation.cs index dfd18939..ec4f4fcf 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/Operations/WRFCLoadBundleOperation.cs +++ b/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/Operations/WRFCLoadBundleOperation.cs @@ -6,121 +6,89 @@ namespace YooAsset private enum ESteps { None, - CreateRequest, - CheckRequest, - TryAgain, + GetEntry, + LoadBundle, Done, } private readonly WebRemoteFileCache _fileCache; private readonly LoadBundleOptions _options; - private IDownloadAssetBundleRequest _downloadAssetBundleRequest; + private LoadWebAssetBundleOperation _loadWebAssetBundleOp; + private WebRemoteFileCacheEntry _cacheEntry; private ESteps _steps = ESteps.None; - // 失败重试 - private int _requestCount = 0; - private float _tryAgainTimer = 0; - private int _failedTryAgain; - public WRFCLoadAssetBundleOperation(WebRemoteFileCache fileCache, LoadBundleOptions options) { _fileCache = fileCache; _options = options; - _failedTryAgain = fileCache.Config.RetryCount; } internal override void InternalStart() { - _steps = ESteps.CreateRequest; + _steps = ESteps.GetEntry; } internal override void InternalUpdate() { if (_steps == ESteps.None || _steps == ESteps.Done) return; - if (_steps == ESteps.CreateRequest) + if (_steps == ESteps.GetEntry) { - var entry = _fileCache.GetEntry(_options.Bundle); - if(entry == null) + _cacheEntry = _fileCache.GetEntry(_options.Bundle); + if (_cacheEntry == null) { _steps = ESteps.Done; Status = EOperationStatus.Failed; Error = $"Not found file cache entry: {_options.Bundle.BundleGUID}"; - return; - } - - string url = GetRequestURL(entry); - var args = new DownloadAssetBundleRequestArgs(url, 0, _fileCache.Config.WatchdogTimeout, _fileCache.Config.DisableUnityWebCache, _options.Bundle.FileHash, _options.Bundle.UnityCRC); - _downloadAssetBundleRequest = _fileCache.Config.DownloadBackend.CreateAssetBundleRequest(args); - _downloadAssetBundleRequest.SendRequest(); - _steps = ESteps.CheckRequest; - } - - if (_steps == ESteps.CheckRequest) - { - Progress = _downloadAssetBundleRequest.DownloadProgress; - if (_downloadAssetBundleRequest.IsDone == false) - return; - - if (_downloadAssetBundleRequest.Status == EDownloadRequestStatus.Succeeded) - { - var assetBundle = _downloadAssetBundleRequest.Result; - if (assetBundle == null) - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = $"Failed to load asset bundle : {_options.Bundle.BundleName}"; - } - else - { - _steps = ESteps.Done; - Status = EOperationStatus.Succeeded; - BundleResult = new AssetBundleResult(null, _options.Bundle, assetBundle, null); - } } else { - if (_failedTryAgain > 0) - { - _steps = ESteps.TryAgain; - YooLogger.Warning($"Failed download : {_downloadAssetBundleRequest.Url} Try again."); - } - else - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = _downloadAssetBundleRequest.Error; - YooLogger.Error(Error); - } + _steps = ESteps.LoadBundle; } - - // 最终释放请求器 - _downloadAssetBundleRequest.Dispose(); } - if (_steps == ESteps.TryAgain) + if (_steps == ESteps.LoadBundle) { - _tryAgainTimer += UnityEngine.Time.unscaledDeltaTime; - if (_tryAgainTimer > 1f) + if (_loadWebAssetBundleOp == null) { - _tryAgainTimer = 0f; - _failedTryAgain--; - Progress = 0f; - _steps = ESteps.CreateRequest; + var options = new LoadWebAssetBundleOptions(); + options.CacheName = _fileCache.GetType().Name; + options.Bundle = _options.Bundle; + options.MainURL = _cacheEntry.MainURL; + options.FallbackURL = _cacheEntry.FallbackURL; + options.Decryptor = _fileCache.Config.AssetBundleDecryptor; + options.DownloadBackend = _fileCache.Config.DownloadBackend; + options.WatchdogTimeout = _fileCache.Config.WatchdogTimeout; + options.DisableUnityWebCache = _fileCache.Config.DisableUnityWebCache; + + if (_options.Bundle.IsEncrypted) + _loadWebAssetBundleOp = new LoadWebEncryptedAssetBundleOperation(options); + else + _loadWebAssetBundleOp = new LoadWebNormalAssetBundleOperation(options); + + _loadWebAssetBundleOp.StartOperation(); + AddChildOperation(_loadWebAssetBundleOp); + } + + _loadWebAssetBundleOp.UpdateOperation(); + if (_loadWebAssetBundleOp.IsDone == false) + return; + + if (_loadWebAssetBundleOp.Status == EOperationStatus.Succeeded) + { + if (_loadWebAssetBundleOp.BundleResult == null) + throw new YooInternalException("Loaded asset bundle result is null."); + + _steps = ESteps.Done; + Status = EOperationStatus.Succeeded; + BundleResult = _loadWebAssetBundleOp.BundleResult; + } + else + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = _loadWebAssetBundleOp.Error; } } } - - /// - /// 获取网络请求地址 - /// - protected string GetRequestURL(WebRemoteFileCacheEntry entry) - { - // 轮流返回请求地址 - _requestCount++; - if (_requestCount % 2 == 0) - return entry.FallbackURL; - else - return entry.MainURL; - } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/WebRemoteFileCache.cs b/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/WebRemoteFileCache.cs index 8ab7b6fc..18ea86bc 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/WebRemoteFileCache.cs +++ b/Assets/YooAsset/Runtime/FileCache/Services/WebRemoteFileCache/WebRemoteFileCache.cs @@ -7,27 +7,30 @@ namespace YooAsset { internal struct CacheConfig { + /// + /// 看门狗超时时间 + /// + public int WatchdogTimeout { get; set; } + /// /// 禁用Unity的网络缓存 /// public bool DisableUnityWebCache { get; set; } + /// + /// AssetBundle 解密器 + /// + public IBundleDecryptor AssetBundleDecryptor { get; set; } + + /// + /// 远程服务接口 + /// public IRemoteServices RemoteServices { get; set; } /// /// 下载后台接口 /// public IDownloadBackend DownloadBackend { get; set; } - - /// - /// 看门狗超时时间 - /// - public int WatchdogTimeout { get; set; } - - /// - /// 失败后重试次数 - /// - public int RetryCount { get; set; } } private readonly Dictionary _caches = new Dictionary(10000); @@ -101,8 +104,17 @@ namespace YooAsset } public virtual FCLoadBundleOperation LoadBundleAsync(LoadBundleOptions options) { - var operation = new WRFCLoadAssetBundleOperation(this, options); - return operation; + if (options.Bundle.BundleType == (int)EBundleType.AssetBundle) + { + var operation = new WRFCLoadAssetBundleOperation(this, options); + return operation; + } + else + { + string error = $"{nameof(WebServerFileCache)} not support load bundle type : {options.Bundle.BundleType}"; + var operation = new FCLoadBundleErrorOperation(error); + return operation; + } } public virtual bool IsCached(string bundleGUID) { diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/Operations/WSFCLoadBundleOperation.cs b/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/Operations/WSFCLoadBundleOperation.cs index a0edc3ac..cf2bcf22 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/Operations/WSFCLoadBundleOperation.cs +++ b/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/Operations/WSFCLoadBundleOperation.cs @@ -1,110 +1,93 @@  namespace YooAsset { - internal class WFCLoadAssetBundleOperation : FCLoadBundleOperation + internal class WSFCLoadAssetBundleOperation : FCLoadBundleOperation { private enum ESteps { None, - CreateRequest, - CheckRequest, - TryAgain, + GetEntry, + LoadBundle, Done, } private readonly WebServerFileCache _fileCache; private readonly LoadBundleOptions _options; - private IDownloadAssetBundleRequest _downloadAssetBundleRequest; + private LoadWebAssetBundleOperation _loadWebAssetBundleOp; + private WebServerFileCacheEntry _cacheEntry; private ESteps _steps = ESteps.None; - // 失败重试 - private float _tryAgainTimer = 0; - private int _failedTryAgain; - - public WFCLoadAssetBundleOperation(WebServerFileCache fileCache, LoadBundleOptions options) + public WSFCLoadAssetBundleOperation(WebServerFileCache fileCache, LoadBundleOptions options) { _fileCache = fileCache; _options = options; - _failedTryAgain = fileCache.Config.RetryCount; } internal override void InternalStart() { - _steps = ESteps.CreateRequest; + _steps = ESteps.GetEntry; } internal override void InternalUpdate() { if (_steps == ESteps.None || _steps == ESteps.Done) return; - if (_steps == ESteps.CreateRequest) + if (_steps == ESteps.GetEntry) { - var entry = _fileCache.GetEntry(_options.Bundle.BundleGUID); - if (entry == null) + _cacheEntry = _fileCache.GetEntry(_options.Bundle.BundleGUID); + if (_cacheEntry == null) { _steps = ESteps.Done; Status = EOperationStatus.Failed; Error = $"Not found file cache entry: {_options.Bundle.BundleGUID}"; - return; - } - - string url = DownloadSystemTools.ToLocalUrl(entry.FilePath); - var args = new DownloadAssetBundleRequestArgs(url, 0, _fileCache.Config.WatchdogTimeout, _fileCache.Config.DisableUnityWebCache, _options.Bundle.FileHash, _options.Bundle.UnityCRC); - _downloadAssetBundleRequest = _fileCache.Config.DownloadBackend.CreateAssetBundleRequest(args); - _downloadAssetBundleRequest.SendRequest(); - _steps = ESteps.CheckRequest; - } - - if (_steps == ESteps.CheckRequest) - { - Progress = _downloadAssetBundleRequest.DownloadProgress; - if (_downloadAssetBundleRequest.IsDone == false) - return; - - if (_downloadAssetBundleRequest.Status == EDownloadRequestStatus.Succeeded) - { - var assetBundle = _downloadAssetBundleRequest.Result; - if (assetBundle == null) - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = $"Failed to load asset bundle : {_options.Bundle.BundleName}"; - } - else - { - _steps = ESteps.Done; - Status = EOperationStatus.Succeeded; - BundleResult = new AssetBundleResult(null, _options.Bundle, assetBundle, null); - } } else { - if (_failedTryAgain > 0) - { - _steps = ESteps.TryAgain; - YooLogger.Warning($"Failed download : {_downloadAssetBundleRequest.Url} Try again."); - } - else - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = _downloadAssetBundleRequest.Error; - YooLogger.Error(Error); - } + _steps = ESteps.LoadBundle; } - - // 最终释放请求器 - _downloadAssetBundleRequest.Dispose(); } - if (_steps == ESteps.TryAgain) + if (_steps == ESteps.LoadBundle) { - _tryAgainTimer += UnityEngine.Time.unscaledDeltaTime; - if (_tryAgainTimer > 1f) + if (_loadWebAssetBundleOp == null) { - _tryAgainTimer = 0f; - _failedTryAgain--; - Progress = 0f; - _steps = ESteps.CreateRequest; + string url = DownloadSystemTools.ToLocalUrl(_cacheEntry.FilePath); + var options = new LoadWebAssetBundleOptions(); + options.CacheName = _fileCache.GetType().Name; + options.Bundle = _options.Bundle; + options.MainURL = url; + options.FallbackURL = url; + options.Decryptor = _fileCache.Config.AssetBundleDecryptor; + options.DownloadBackend = _fileCache.Config.DownloadBackend; + options.WatchdogTimeout = _fileCache.Config.WatchdogTimeout; + options.DisableUnityWebCache = _fileCache.Config.DisableUnityWebCache; + + if (_options.Bundle.IsEncrypted) + _loadWebAssetBundleOp = new LoadWebEncryptedAssetBundleOperation(options); + else + _loadWebAssetBundleOp = new LoadWebNormalAssetBundleOperation(options); + + _loadWebAssetBundleOp.StartOperation(); + AddChildOperation(_loadWebAssetBundleOp); + } + + _loadWebAssetBundleOp.UpdateOperation(); + if (_loadWebAssetBundleOp.IsDone == false) + return; + + if (_loadWebAssetBundleOp.Status == EOperationStatus.Succeeded) + { + if (_loadWebAssetBundleOp.BundleResult == null) + throw new YooInternalException("Loaded asset bundle result is null."); + + _steps = ESteps.Done; + Status = EOperationStatus.Succeeded; + BundleResult = _loadWebAssetBundleOp.BundleResult; + } + else + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = _loadWebAssetBundleOp.Error; } } } diff --git a/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/WebServerFileCache.cs b/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/WebServerFileCache.cs index 0b8002f1..caef84c3 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/WebServerFileCache.cs +++ b/Assets/YooAsset/Runtime/FileCache/Services/WebServerFileCache/WebServerFileCache.cs @@ -7,25 +7,25 @@ namespace YooAsset { internal struct CacheConfig { - /// - /// 禁用Unity的网络缓存 - /// - public bool DisableUnityWebCache { get; set; } - - /// - /// 下载后台接口 - /// - public IDownloadBackend DownloadBackend { get; set; } - /// /// 看门狗超时时间 /// public int WatchdogTimeout { get; set; } /// - /// 失败后重试次数 + /// 禁用Unity的网络缓存 /// - public int RetryCount { get; set; } + public bool DisableUnityWebCache { get; set; } + + /// + /// AssetBundle 解密器 + /// + public IBundleDecryptor AssetBundleDecryptor { get; set; } + + /// + /// 下载后台接口 + /// + public IDownloadBackend DownloadBackend { get; set; } } private readonly Dictionary _caches = new Dictionary(10000); @@ -99,8 +99,17 @@ namespace YooAsset } public virtual FCLoadBundleOperation LoadBundleAsync(LoadBundleOptions options) { - var operation = new WFCLoadAssetBundleOperation(this, options); - return operation; + if (options.Bundle.BundleType == (int)EBundleType.AssetBundle) + { + var operation = new WSFCLoadAssetBundleOperation(this, options); + return operation; + } + else + { + string error = $"{nameof(WebServerFileCache)} not support load bundle type : {options.Bundle.BundleType}"; + var operation = new FCLoadBundleErrorOperation(error); + return operation; + } } public virtual bool IsCached(string bundleGUID) { diff --git a/Assets/YooAsset/Runtime/FileCache/Services/DefaultLoadAssetBundleOperation.cs b/Assets/YooAsset/Runtime/FileCache/Services/XXXDefaultLoadAssetBundleOperation.cs similarity index 57% rename from Assets/YooAsset/Runtime/FileCache/Services/DefaultLoadAssetBundleOperation.cs rename to Assets/YooAsset/Runtime/FileCache/Services/XXXDefaultLoadAssetBundleOperation.cs index 0df3df7e..9e19d9bd 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/DefaultLoadAssetBundleOperation.cs +++ b/Assets/YooAsset/Runtime/FileCache/Services/XXXDefaultLoadAssetBundleOperation.cs @@ -2,6 +2,7 @@ using System; using System.IO; using UnityEngine; +/* namespace YooAsset { /// @@ -96,72 +97,8 @@ namespace YooAsset /// public abstract class DefaultLoadAssetBundleFromOffsetOperation : LoadAssetBundleOperation { - private enum ESteps + protected DefaultLoadAssetBundleFromOffsetOperation(LoadAssetBundleOptions options) : base(options) { - None, - LoadAssetBundle, - CheckResult, - Done, - } - - private AssetBundleCreateRequest _createRequest; - private ESteps _steps = ESteps.None; - - public DefaultLoadAssetBundleFromOffsetOperation(LoadAssetBundleOptions options) : base(options) { } - internal override void InternalStart() - { - _steps = ESteps.LoadAssetBundle; - } - internal override void InternalUpdate() - { - if (_steps == ESteps.None || _steps == ESteps.Done) - return; - - if (_steps == ESteps.LoadAssetBundle) - { - ulong offset = GetFileOffset(); - if (IsWaitForCompletion) - Result = AssetBundle.LoadFromFile(_options.FileLoadPath, 0, offset); - else - _createRequest = AssetBundle.LoadFromFileAsync(_options.FileLoadPath, 0, offset); - - _steps = ESteps.CheckResult; - } - - if (_steps == ESteps.CheckResult) - { - if (_createRequest != null) - { - if (IsWaitForCompletion) - { - // 强制挂起主线程(注意:该操作会很耗时) - YooLogger.Warning("Suspend the main thread to load unity bundle."); - Result = _createRequest.assetBundle; - } - else - { - if (_createRequest.isDone == false) - return; - Result = _createRequest.assetBundle; - } - } - - if (Result == null) - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = $"Failed to load asset bundle file : {_options.Bundle.BundleName}"; - } - else - { - _steps = ESteps.Done; - Status = EOperationStatus.Succeeded; - } - } - } - internal override void InternalWaitForCompletion() - { - ExecuteBatch(); } /// @@ -209,9 +146,6 @@ namespace YooAsset } internal override void InternalUpdate() { - if (_steps == ESteps.None || _steps == ESteps.Done) - return; - if (_steps == ESteps.CheckFilePath) { string filePath = _options.FileLoadPath; @@ -246,41 +180,6 @@ namespace YooAsset _steps = ESteps.CheckResult; } - - if (_steps == ESteps.CheckResult) - { - if (_createRequest != null) - { - if (IsWaitForCompletion) - { - // 强制挂起主线程(注意:该操作会很耗时) - YooLogger.Warning("Suspend the main thread to load unity bundle."); - Result = _createRequest.assetBundle; - } - else - { - if (_createRequest.isDone == false) - return; - Result = _createRequest.assetBundle; - } - } - - if (Result == null) - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = $"Failed to load asset bundle file : {_options.Bundle.BundleName}"; - } - else - { - _steps = ESteps.Done; - Status = EOperationStatus.Succeeded; - } - } - } - internal override void InternalWaitForCompletion() - { - ExecuteBatch(); } /// @@ -313,20 +212,13 @@ namespace YooAsset CheckResult, Done, } - - private AssetBundleCreateRequest _createRequest; private ESteps _steps = ESteps.None; - - public DefaultLoadAssetBundleFromStreamOperation(LoadAssetBundleOptions options) : base(options) { } - internal override void InternalStart() + protected DefaultLoadAssetBundleFromStreamOperation(LoadAssetBundleOptions options) : base(options) { - _steps = ESteps.CheckFilePath; } + internal override void InternalUpdate() { - if (_steps == ESteps.None || _steps == ESteps.Done) - return; - if (_steps == ESteps.CheckFilePath) { string filePath = _options.FileLoadPath; @@ -341,65 +233,7 @@ namespace YooAsset _steps = ESteps.LoadAssetBundle; } } - - if (_steps == ESteps.LoadAssetBundle) - { - ManagedStream = CreateManagedFileStream(); - uint bufferSize = GetManagedReadBufferSize(); - - if (IsWaitForCompletion) - Result = AssetBundle.LoadFromStream(ManagedStream, 0, bufferSize); - else - _createRequest = AssetBundle.LoadFromStreamAsync(ManagedStream, 0, bufferSize); - - _steps = ESteps.CheckResult; - } - - if (_steps == ESteps.CheckResult) - { - if (_createRequest != null) - { - if (IsWaitForCompletion) - { - // 强制挂起主线程(注意:该操作会很耗时) - YooLogger.Warning("Suspend the main thread to load unity bundle."); - Result = _createRequest.assetBundle; - } - else - { - if (_createRequest.isDone == false) - return; - Result = _createRequest.assetBundle; - } - } - - if (Result == null) - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = $"Failed to load asset bundle file : {_options.Bundle.BundleName}"; - } - else - { - _steps = ESteps.Done; - Status = EOperationStatus.Succeeded; - } - } } - internal override void InternalWaitForCompletion() - { - ExecuteBatch(); - } - - /// - /// 获取文件流 - /// - protected abstract FileStream CreateManagedFileStream(); - - /// - /// 获取缓冲池大小 - /// - protected abstract uint GetManagedReadBufferSize(); /// /// 文件数据解密 @@ -416,4 +250,5 @@ namespace YooAsset return AssetBundle.LoadFromMemory(rawData); } } -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/FileCache/Services/DefaultLoadAssetBundleOperation.cs.meta b/Assets/YooAsset/Runtime/FileCache/Services/XXXDefaultLoadAssetBundleOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/DefaultLoadAssetBundleOperation.cs.meta rename to Assets/YooAsset/Runtime/FileCache/Services/XXXDefaultLoadAssetBundleOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/DefaultLoadRawBundleOperation.cs b/Assets/YooAsset/Runtime/FileCache/Services/XXXDefaultLoadRawBundleOperation.cs similarity index 70% rename from Assets/YooAsset/Runtime/FileCache/Services/DefaultLoadRawBundleOperation.cs rename to Assets/YooAsset/Runtime/FileCache/Services/XXXDefaultLoadRawBundleOperation.cs index ac72ec6d..61071a59 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/DefaultLoadRawBundleOperation.cs +++ b/Assets/YooAsset/Runtime/FileCache/Services/XXXDefaultLoadRawBundleOperation.cs @@ -1,5 +1,6 @@ using System.IO; +/* namespace YooAsset { /// @@ -25,24 +26,6 @@ namespace YooAsset } internal override void InternalUpdate() { - if (_steps == ESteps.None || _steps == ESteps.Done) - return; - - if (_steps == ESteps.CheckFilePath) - { - string filePath = _options.FileLoadPath; - if (IsSupportFileIO(filePath) == false) - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = $"FileIO not supported for builtin path : {filePath}"; - } - else - { - _steps = ESteps.LoadRawBundle; - } - } - if (_steps == ESteps.LoadRawBundle) { string filePath = _options.FileLoadPath; @@ -61,10 +44,6 @@ namespace YooAsset } } } - internal override void InternalWaitForCompletion() - { - ExecuteBatch(); - } } /// @@ -90,24 +69,6 @@ namespace YooAsset } internal override void InternalUpdate() { - if (_steps == ESteps.None || _steps == ESteps.Done) - return; - - if (_steps == ESteps.CheckFilePath) - { - string filePath = _options.FileLoadPath; - if (IsSupportFileIO(filePath) == false) - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = $"FileIO not supported for builtin path : {filePath}"; - } - else - { - _steps = ESteps.LoadRawBundle; - } - } - if (_steps == ESteps.LoadRawBundle) { string filePath = _options.FileLoadPath; @@ -136,10 +97,6 @@ namespace YooAsset } } } - internal override void InternalWaitForCompletion() - { - ExecuteBatch(); - } /// /// 文件数据解密 @@ -147,3 +104,4 @@ namespace YooAsset protected abstract byte[] DecryptData(byte[] data); } } +*/ \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/FileCache/Services/DefaultLoadRawBundleOperation.cs.meta b/Assets/YooAsset/Runtime/FileCache/Services/XXXDefaultLoadRawBundleOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/DefaultLoadRawBundleOperation.cs.meta rename to Assets/YooAsset/Runtime/FileCache/Services/XXXDefaultLoadRawBundleOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileCache/Services/DefaultLoadWebAssetBundleOperation.cs b/Assets/YooAsset/Runtime/FileCache/Services/XXXDefaultLoadWebAssetBundleOperation.cs similarity index 99% rename from Assets/YooAsset/Runtime/FileCache/Services/DefaultLoadWebAssetBundleOperation.cs rename to Assets/YooAsset/Runtime/FileCache/Services/XXXDefaultLoadWebAssetBundleOperation.cs index 9cc2a73a..6480ec6a 100644 --- a/Assets/YooAsset/Runtime/FileCache/Services/DefaultLoadWebAssetBundleOperation.cs +++ b/Assets/YooAsset/Runtime/FileCache/Services/XXXDefaultLoadWebAssetBundleOperation.cs @@ -1,5 +1,6 @@ using UnityEngine; +/* namespace YooAsset { /// @@ -247,3 +248,4 @@ namespace YooAsset } } } +*/ \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/FileCache/Services/DefaultLoadWebAssetBundleOperation.cs.meta b/Assets/YooAsset/Runtime/FileCache/Services/XXXDefaultLoadWebAssetBundleOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileCache/Services/DefaultLoadWebAssetBundleOperation.cs.meta rename to Assets/YooAsset/Runtime/FileCache/Services/XXXDefaultLoadWebAssetBundleOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/FileSystemParameters.cs b/Assets/YooAsset/Runtime/FileSystem/FileSystemParameters.cs index 881c763c..5e593adf 100644 --- a/Assets/YooAsset/Runtime/FileSystem/FileSystemParameters.cs +++ b/Assets/YooAsset/Runtime/FileSystem/FileSystemParameters.cs @@ -96,7 +96,7 @@ namespace YooAsset /// 文件系统的根目录 public static FileSystemParameters CreateDefaultCacheFileSystemParameters(IRemoteServices remoteServices, string packageRoot = null) { - string fileSystemClass = typeof(CacheFileSystem).FullName; + string fileSystemClass = typeof(SandboxFileSystem).FullName; var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot); fileSystemParams.AddParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices); return fileSystemParams; diff --git a/Assets/YooAsset/Runtime/FileSystem/FileSystemParametersDefine.cs b/Assets/YooAsset/Runtime/FileSystem/FileSystemParametersDefine.cs index c726aa1f..6b95fa52 100644 --- a/Assets/YooAsset/Runtime/FileSystem/FileSystemParametersDefine.cs +++ b/Assets/YooAsset/Runtime/FileSystem/FileSystemParametersDefine.cs @@ -24,25 +24,25 @@ namespace YooAsset public const string REMOTE_SERVICES = "REMOTE_SERVICES"; /// - /// 资源清单服务类 + /// AssetBundle 解密器 /// - public const string MANIFEST_RESTORE_SERVICES = "MANIFEST_RESTORE_SERVICES"; + public const string ASSETBUNDLE_DECRYPTOR = "ASSETBUNDLE_DECRYPTOR"; /// /// 禁用Unity的网络缓存 /// public const string DISABLE_UNITY_WEB_CACHE = "DISABLE_UNITY_WEB_CACHE"; - /// - /// 禁用边玩边下机制 - /// - public const string DISABLE_ONDEMAND_DOWNLOAD = "DISABLE_ONDEMAND_DOWNLOAD"; - /// /// UnityWebRequest 创建委托 /// public const string UNITY_WEB_REQUEST_CREATOR = "UNITY_WEB_REQUEST_CREATOR"; + /// + /// 禁用边玩边下机制 + /// + public const string DOWNLOAD_DISABLE_ONDEMAND = "DOWNLOAD_DISABLE_ONDEMAND"; + /// /// 下载后台接口 /// @@ -66,12 +66,12 @@ namespace YooAsset /// /// 启用断点续传的最小尺寸 /// - public const string RESUME_DOWNLOAD_MINMUM_SIZE = "RESUME_DOWNLOAD_MINMUM_SIZE"; + public const string DOWNLOAD_RESUME_MINMUM_SIZE = "DOWNLOAD_RESUME_MINMUM_SIZE"; /// /// 断点续传下载器关注的错误码 > /// - public const string RESUME_DOWNLOAD_RESPONSE_CODES = "RESUME_DOWNLOAD_RESPONSE_CODES"; + public const string DOWNLOAD_RESUME_RESPONSE_CODES = "DOWNLOAD_RESUME_RESPONSE_CODES"; /// /// 模拟WebGL平台模式 @@ -112,5 +112,20 @@ namespace YooAsset /// 解压文件系统的根目录 /// public const string UNPACK_FILE_SYSTEM_ROOT = "UNPACK_FILE_SYSTEM_ROOT"; + + /// + /// RawBundle 解密器 + /// + public const string RAWBUNDLE_DECRYPTOR = "RAWBUNDLE_DECRYPTOR"; + + /// + /// AssetBundle 备用解密器 + /// + public const string ASSETBUNDLE_FALLBACK_DECRYPTOR = "ASSETBUNDLE_FALLBACK_DECRYPTOR"; + + /// + /// 资源清单解密器 + /// + public const string MANIFEST_DECRYPTOR = "MANIFEST_DECRYPTOR"; } } diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/BuiltinFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/BuiltinFileSystem.cs index abd66e68..89186a44 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/BuiltinFileSystem.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/BuiltinFileSystem.cs @@ -93,9 +93,24 @@ namespace YooAsset public int UnpackMaxRequestPerFrame { private set; get; } /// - /// 自定义参数:资源清单服务类 + /// 自定义参数:AssetBundle 解密器 /// - public IManifestRestoreServices ManifestRestoreServices { private set; get; } + public IBundleDecryptor AssetBundleDecryptor { get; set; } + + /// + /// 自定义参数:RawBundle 解密器 + /// + public IBundleDecryptor RawBundleDecryptor { get; set; } + + /// + /// 自定义参数:AssetBundle 备用解密器 + /// + public IBundleMemoryDecryptor AssetBundleFallbackDecryptor { get; set; } + + /// + /// 自定义参数:资源清单解密器 + /// + public IManifestDecryptor ManifestDecryptor { private set; get; } #endregion @@ -190,9 +205,21 @@ namespace YooAsset // 限制在合理范围内:1-32 UnpackMaxRequestPerFrame = Mathf.Clamp(convertValue, 1, 32); } - else if (name == FileSystemParametersDefine.MANIFEST_RESTORE_SERVICES) + else if (name == FileSystemParametersDefine.ASSETBUNDLE_DECRYPTOR) { - ManifestRestoreServices = (IManifestRestoreServices)value; + AssetBundleDecryptor = (IBundleDecryptor)value; + } + else if (name == FileSystemParametersDefine.RAWBUNDLE_DECRYPTOR) + { + RawBundleDecryptor = (IBundleDecryptor)value; + } + else if (name == FileSystemParametersDefine.ASSETBUNDLE_FALLBACK_DECRYPTOR) + { + AssetBundleFallbackDecryptor = (IBundleMemoryDecryptor)value; + } + else if (name == FileSystemParametersDefine.MANIFEST_DECRYPTOR) + { + ManifestDecryptor = (IManifestDecryptor)value; } else { @@ -218,13 +245,15 @@ namespace YooAsset unpackRoot = GetDefaultUnpackCacheRoot(packageName); else unpackRoot = UnpackFileSystemRoot; - _unpackManifestFilesRoot = PathUtility.Combine(unpackRoot, BuiltinFileSystemConstants.UnpackManifestFilesFolderName); - _unpackBundleFilesRoot = PathUtility.Combine(unpackRoot, BuiltinFileSystemConstants.UnpackBundleFilesFolderName); - _unpackTempFilesRoot = PathUtility.Combine(unpackRoot, BuiltinFileSystemConstants.UnpackTempFilesFolderName); + _unpackManifestFilesRoot = PathUtility.Combine(unpackRoot, BuiltinFileSystemDefine.UnpackManifestFilesFolderName); + _unpackBundleFilesRoot = PathUtility.Combine(unpackRoot, BuiltinFileSystemDefine.UnpackBundleFilesFolderName); + _unpackTempFilesRoot = PathUtility.Combine(unpackRoot, BuiltinFileSystemDefine.UnpackTempFilesFolderName); // 创建内置缓存对象 { var cacheConfig = new BuiltinFileCache.CacheConfig(); + cacheConfig.AssetBundleDecryptor = AssetBundleDecryptor; + cacheConfig.RawBundleDecryptor = RawBundleDecryptor; cacheConfig.DownloadBackend = DownloadBackend; BuiltinFileCache = new BuiltinFileCache(packageName, _packageRoot, cacheConfig); } @@ -232,8 +261,11 @@ namespace YooAsset // 创建沙盒缓存对象 { var cacheConfig = new SandboxFileCache.CacheConfig(); - cacheConfig.FileVerifyLevel = FileVerifyLevel; cacheConfig.FileVerifyMaxConcurrency = FileVerifyMaxConcurrency; + cacheConfig.FileVerifyLevel = FileVerifyLevel; + cacheConfig.AssetBundleDecryptor = AssetBundleDecryptor; + cacheConfig.RawBundleDecryptor = RawBundleDecryptor; + cacheConfig.AssetBundleFallbackDecryptor = AssetBundleFallbackDecryptor; UnpackFileCache = new SandboxFileCache(packageName, _unpackBundleFilesRoot, cacheConfig); } } @@ -341,7 +373,7 @@ namespace YooAsset } public string GetSandboxAppFootPrintFilePath() { - return PathUtility.Combine(_unpackManifestFilesRoot, DefaultCacheFileSystemDefine.AppFootPrintFileName); + return PathUtility.Combine(_unpackManifestFilesRoot, SandboxFileSystemDefine.AppFootPrintFileName); } /// diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/BuiltinFileSystemDefine.cs b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/BuiltinFileSystemDefine.cs index 4e2f8dae..10012505 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/BuiltinFileSystemDefine.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/BuiltinFileSystemDefine.cs @@ -1,7 +1,7 @@ namespace YooAsset { - internal class BuiltinFileSystemConstants + internal class BuiltinFileSystemDefine { /// /// 解压清单文件的文件夹名称 diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSInitializeOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSInitializeOperation.cs index 3463b7f3..f15ba5f7 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSInitializeOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSInitializeOperation.cs @@ -1,4 +1,4 @@ - + namespace YooAsset { internal class BFSInitializeOperation : FSInitializeOperation @@ -45,7 +45,7 @@ namespace YooAsset var appFootprint = new ApplicationFootprint(footprintFilePath); appFootprint.Load(_fileSystem.PackageName); - // ˮӡ仯˵ǰװ״δϷ + // 如果水印发生变化,则说明覆盖安装后首次打开游戏 if (appFootprint.IsDirty()) { if (_fileSystem.InstallClearMode == EInstallCleanupMode.None) @@ -163,8 +163,8 @@ namespace YooAsset if (_steps == ESteps.CreateScheduler) { - // ע: صһֹʼʧܺ - // ע: صΪУ + // 注意: 下载调度中心在最后一步创建,防止初始化失败后残留任务。 + // 注意: 下载调度中心作为独立任务运行! if (_fileSystem.UnpackScheduler == null) { var schedulerConfig = new DownloadSchedulerOperation.SchedulerConfig(); diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/CopyBuiltinFileOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/CopyBuiltinFileOperation.cs index b131b97f..8fa25428 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/CopyBuiltinFileOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/CopyBuiltinFileOperation.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; namespace YooAsset @@ -77,7 +77,7 @@ namespace YooAsset { if (_webFileRequestOp == null) { - //TODO Ž棬ijЩ׿ͣףͨUnityWebRequestļСʧܣҪʽļ + //TODO 团结引擎,在某些安卓机型(红米),通过UnityWebRequest拷贝包内文件会小概率失败!需要借助其它方式来拷贝包内文件。 string url = DownloadSystemTools.ToLocalUrl(_sourceFilePath); var args = new DownloadFileRequestArgs(url, _destFilePath, 60, 0); _webFileRequestOp = _fileSystem.DownloadBackend.CreateFileRequest(args); @@ -102,7 +102,7 @@ namespace YooAsset } internal override void InternalWaitForCompletion() { - //TODO ȴѹļϣọ̀߳ + //TODO 等待解压本地文件完毕,该操作会挂起主线程! ExecuteUntilComplete(); } } diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/CopyBuiltinPackageManifest.cs b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/CopyBuiltinPackageManifest.cs index eafa7199..07529125 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/CopyBuiltinPackageManifest.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/CopyBuiltinPackageManifest.cs @@ -120,7 +120,7 @@ namespace YooAsset if (string.IsNullOrEmpty(destRoot)) { string defaultCacheRoot = YooAssetSettingsData.GetYooDefaultCacheRoot(); - destRoot = PathUtility.Combine(defaultCacheRoot, _fileSystem.PackageName, DefaultCacheFileSystemDefine.ManifestFilesFolderName); + destRoot = PathUtility.Combine(defaultCacheRoot, _fileSystem.PackageName, SandboxFileSystemDefine.ManifestFilesFolderName); } return destRoot; } diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/LoadBuiltinPackageManifestOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/LoadBuiltinPackageManifestOperation.cs index 9053b925..e901aa0b 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/LoadBuiltinPackageManifestOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/internal/LoadBuiltinPackageManifestOperation.cs @@ -102,7 +102,7 @@ namespace YooAsset { if (_deserializer == null) { - _deserializer = new DeserializeManifestOperation(_fileSystem.ManifestRestoreServices, _fileData); + _deserializer = new DeserializeManifestOperation(_fileSystem.ManifestDecryptor, _fileData); _deserializer.StartOperation(); AddChildOperation(_deserializer); } diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem.meta b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem.meta rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/ApplicationFootprint.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/ApplicationFootprint.cs similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/ApplicationFootprint.cs rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/ApplicationFootprint.cs diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/ApplicationFootprint.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/ApplicationFootprint.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/ApplicationFootprint.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/ApplicationFootprint.cs.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/EInstallCleanupMode.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/EInstallCleanupMode.cs similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/EInstallCleanupMode.cs rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/EInstallCleanupMode.cs diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/EInstallCleanupMode.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/EInstallCleanupMode.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/EInstallCleanupMode.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/EInstallCleanupMode.cs.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/EManifestClearMode.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/EManifestClearMode.cs similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/EManifestClearMode.cs rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/EManifestClearMode.cs diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/EManifestClearMode.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/EManifestClearMode.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/EManifestClearMode.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/EManifestClearMode.cs.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations.meta b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations.meta rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal.meta b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal.meta rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/DownloadAndCacheFileOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/DownloadAndCacheFileOperation.cs similarity index 97% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/DownloadAndCacheFileOperation.cs rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/DownloadAndCacheFileOperation.cs index a0766e2d..3d19fd7f 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/DownloadAndCacheFileOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/DownloadAndCacheFileOperation.cs @@ -13,7 +13,7 @@ namespace YooAsset Done, } - private readonly CacheFileSystem _fileSystem; + private readonly SandboxFileSystem _fileSystem; private readonly string _tempFilePath; private bool _enableResume = false; private long _fileOriginLength = 0; @@ -21,7 +21,7 @@ namespace YooAsset private FCWriteCacheOperation _writeCacheOp; private ESteps _steps = ESteps.None; - internal DownloadAndCacheFileOperation(CacheFileSystem fileSystem, PackageBundle bundle, string url) : base(bundle, url) + internal DownloadAndCacheFileOperation(SandboxFileSystem fileSystem, PackageBundle bundle, string url) : base(bundle, url) { _fileSystem = fileSystem; _tempFilePath = _fileSystem.GetTempFilePath(bundle); diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/DownloadAndCacheFileOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/DownloadAndCacheFileOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/DownloadAndCacheFileOperation.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/DownloadAndCacheFileOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/DownloadPackageHashOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/DownloadPackageHashOperation.cs similarity index 95% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/DownloadPackageHashOperation.cs rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/DownloadPackageHashOperation.cs index de2f4b81..f4e9dbf6 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/DownloadPackageHashOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/DownloadPackageHashOperation.cs @@ -12,7 +12,7 @@ namespace YooAsset Done, } - private readonly CacheFileSystem _fileSystem; + private readonly SandboxFileSystem _fileSystem; private readonly string _packageVersion; private readonly int _timeout; private IDownloadFileRequest _webFileRequestOp; @@ -20,7 +20,7 @@ namespace YooAsset private ESteps _steps = ESteps.None; - internal DownloadPackageHashOperation(CacheFileSystem fileSystem, string packageVersion, int timeout) + internal DownloadPackageHashOperation(SandboxFileSystem fileSystem, string packageVersion, int timeout) { _fileSystem = fileSystem; _packageVersion = packageVersion; diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/DownloadPackageHashOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/DownloadPackageHashOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/DownloadPackageHashOperation.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/DownloadPackageHashOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/DownloadPackageManifestOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/DownloadPackageManifestOperation.cs similarity index 94% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/DownloadPackageManifestOperation.cs rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/DownloadPackageManifestOperation.cs index 44b12974..72869c6a 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/DownloadPackageManifestOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/DownloadPackageManifestOperation.cs @@ -12,7 +12,7 @@ namespace YooAsset Done, } - private readonly CacheFileSystem _fileSystem; + private readonly SandboxFileSystem _fileSystem; private readonly string _packageVersion; private readonly int _timeout; private IDownloadFileRequest _webFileRequestOp; @@ -20,7 +20,7 @@ namespace YooAsset private ESteps _steps = ESteps.None; - internal DownloadPackageManifestOperation(CacheFileSystem fileSystem, string packageVersion, int timeout) + internal DownloadPackageManifestOperation(SandboxFileSystem fileSystem, string packageVersion, int timeout) { _fileSystem = fileSystem; _packageVersion = packageVersion; diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/DownloadPackageManifestOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/DownloadPackageManifestOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/DownloadPackageManifestOperation.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/DownloadPackageManifestOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/ImportAndCacheFileOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/ImportAndCacheFileOperation.cs similarity index 94% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/ImportAndCacheFileOperation.cs rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/ImportAndCacheFileOperation.cs index f73ea2ae..70e1ee07 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/ImportAndCacheFileOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/ImportAndCacheFileOperation.cs @@ -13,13 +13,13 @@ namespace YooAsset Done, } - private readonly CacheFileSystem _fileSystem; + private readonly SandboxFileSystem _fileSystem; private readonly string _sourceFilePath; private readonly string _tempFilePath; private FCWriteCacheOperation _bundleCacheOp; private ESteps _steps = ESteps.None; - internal ImportAndCacheFileOperation(CacheFileSystem fileSystem, PackageBundle bundle, string sourceFilePath) : base(bundle, sourceFilePath) + internal ImportAndCacheFileOperation(SandboxFileSystem fileSystem, PackageBundle bundle, string sourceFilePath) : base(bundle, sourceFilePath) { _fileSystem = fileSystem; _sourceFilePath = sourceFilePath; diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/ImportAndCacheFileOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/ImportAndCacheFileOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/ImportAndCacheFileOperation.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/ImportAndCacheFileOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/LoadCachePackageHashOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/LoadCachePackageHashOperation.cs similarity index 91% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/LoadCachePackageHashOperation.cs rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/LoadCachePackageHashOperation.cs index b8405abb..2dd1566d 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/LoadCachePackageHashOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/LoadCachePackageHashOperation.cs @@ -11,7 +11,7 @@ namespace YooAsset Done, } - private readonly CacheFileSystem _fileSystem; + private readonly SandboxFileSystem _fileSystem; private readonly string _packageVersion; private ESteps _steps = ESteps.None; @@ -21,7 +21,7 @@ namespace YooAsset public string PackageHash { private set; get; } - internal LoadCachePackageHashOperation(CacheFileSystem fileSystem, string packageVersion) + internal LoadCachePackageHashOperation(SandboxFileSystem fileSystem, string packageVersion) { _fileSystem = fileSystem; _packageVersion = packageVersion; diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/LoadCachePackageHashOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/LoadCachePackageHashOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/LoadCachePackageHashOperation.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/LoadCachePackageHashOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/LoadCachePackageManifestOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/LoadCachePackageManifestOperation.cs similarity index 93% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/LoadCachePackageManifestOperation.cs rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/LoadCachePackageManifestOperation.cs index 04c299b9..a35442c9 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/LoadCachePackageManifestOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/LoadCachePackageManifestOperation.cs @@ -13,7 +13,7 @@ namespace YooAsset Done, } - private readonly CacheFileSystem _fileSystem; + private readonly SandboxFileSystem _fileSystem; private readonly string _packageVersion; private readonly string _packageHash; private DeserializeManifestOperation _deserializer; @@ -26,7 +26,7 @@ namespace YooAsset public PackageManifest Manifest { private set; get; } - internal LoadCachePackageManifestOperation(CacheFileSystem fileSystem, string packageVersion, string packageHash) + internal LoadCachePackageManifestOperation(SandboxFileSystem fileSystem, string packageVersion, string packageHash) { _fileSystem = fileSystem; _packageVersion = packageVersion; @@ -75,7 +75,7 @@ namespace YooAsset { if (_deserializer == null) { - _deserializer = new DeserializeManifestOperation(_fileSystem.ManifestRestoreServices, _fileData); + _deserializer = new DeserializeManifestOperation(_fileSystem.ManifestDecryptor, _fileData); _deserializer.StartOperation(); AddChildOperation(_deserializer); } diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/LoadCachePackageManifestOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/LoadCachePackageManifestOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/LoadCachePackageManifestOperation.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/LoadCachePackageManifestOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/RequestRemotePackageVersionOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/RequestRemotePackageVersionOperation.cs similarity index 95% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/RequestRemotePackageVersionOperation.cs rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/RequestRemotePackageVersionOperation.cs index 0c1b36c1..4468fa8c 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/RequestRemotePackageVersionOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/RequestRemotePackageVersionOperation.cs @@ -10,7 +10,7 @@ namespace YooAsset Done, } - private readonly CacheFileSystem _fileSystem; + private readonly SandboxFileSystem _fileSystem; private readonly bool _appendTimeTicks; private readonly int _timeout; private IDownloadTextRequest _webTextRequestOp; @@ -23,7 +23,7 @@ namespace YooAsset internal string PackageVersion { set; get; } - internal RequestRemotePackageVersionOperation(CacheFileSystem fileSystem, bool appendTimeTicks, int timeout) + internal RequestRemotePackageVersionOperation(SandboxFileSystem fileSystem, bool appendTimeTicks, int timeout) { _fileSystem = fileSystem; _appendTimeTicks = appendTimeTicks; diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/RequestRemotePackageVersionOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/RequestRemotePackageVersionOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/internal/RequestRemotePackageVersionOperation.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/Internal/RequestRemotePackageVersionOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/CFSClearCacheOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSClearCacheOperation.cs similarity index 89% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/CFSClearCacheOperation.cs rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSClearCacheOperation.cs index 7acd1553..45839d78 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/CFSClearCacheOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSClearCacheOperation.cs @@ -3,7 +3,7 @@ using System.IO; namespace YooAsset { - internal class CFSClearCacheOperation : FSClearCacheOperation + internal class SFSClearCacheOperation : FSClearCacheOperation { private enum ESteps { @@ -12,12 +12,12 @@ namespace YooAsset Done, } - private readonly CacheFileSystem _fileSystem; + private readonly SandboxFileSystem _fileSystem; private readonly ClearCacheOptions _options; private FCClearCacheOperation _clearCacheOp; private ESteps _steps = ESteps.None; - internal CFSClearCacheOperation(CacheFileSystem fileSystem, ClearCacheOptions options) + internal SFSClearCacheOperation(SandboxFileSystem fileSystem, ClearCacheOptions options) { _fileSystem = fileSystem; _options = options; @@ -68,10 +68,10 @@ namespace YooAsset Done, } - private readonly CacheFileSystem _fileSystem; + private readonly SandboxFileSystem _fileSystem; private ESteps _steps = ESteps.None; - internal CFSClearAllCacheManifestOperation(CacheFileSystem fileSystem) + internal CFSClearAllCacheManifestOperation(SandboxFileSystem fileSystem) { _fileSystem = fileSystem; } @@ -96,7 +96,7 @@ namespace YooAsset foreach (FileInfo fileInfo in directoryInfo.GetFiles()) { string fileName = fileInfo.Name; - if (fileName == DefaultCacheFileSystemDefine.AppFootPrintFileName) + if (fileName == SandboxFileSystemDefine.AppFootPrintFileName) continue; fileInfo.Delete(); @@ -126,11 +126,11 @@ namespace YooAsset Done, } - private readonly CacheFileSystem _fileSystem; + private readonly SandboxFileSystem _fileSystem; private readonly PackageManifest _manifest; private ESteps _steps = ESteps.None; - internal CFSClearUnusedCacheManifestOperation(CacheFileSystem fileSystem, PackageManifest manifest) + internal CFSClearUnusedCacheManifestOperation(SandboxFileSystem fileSystem, PackageManifest manifest) { _fileSystem = fileSystem; _manifest = manifest; @@ -173,7 +173,7 @@ namespace YooAsset foreach (FileInfo fileInfo in directoryInfo.GetFiles()) { string fileName = fileInfo.Name; - if (fileName == DefaultCacheFileSystemDefine.AppFootPrintFileName) + if (fileName == SandboxFileSystemDefine.AppFootPrintFileName) continue; if (fileName == activeManifestFileName || fileName == activeHashFileName) continue; diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/CFSClearCacheOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSClearCacheOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/CFSClearCacheOperation.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSClearCacheOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/CFSDownloadFileOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSDownloadFileOperation.cs similarity index 95% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/CFSDownloadFileOperation.cs rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSDownloadFileOperation.cs index 73bfd1b9..03d6dd0c 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/CFSDownloadFileOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSDownloadFileOperation.cs @@ -2,7 +2,7 @@ using UnityEngine; namespace YooAsset { - internal class CFSDownloadFileOperation : FSDownloadFileOperation + internal class SFSDownloadFileOperation : FSDownloadFileOperation { protected enum ESteps { @@ -13,7 +13,7 @@ namespace YooAsset Done, } - private readonly CacheFileSystem _fileSystem; + private readonly SandboxFileSystem _fileSystem; private readonly DownloadFileOptions _options; private DownloadFileBaseOperation _downloadFileOp; private ESteps _steps = ESteps.None; @@ -23,7 +23,7 @@ namespace YooAsset private float _tryAgainTimer = 0; private int _failedTryAgain; - internal CFSDownloadFileOperation(CacheFileSystem fileSystem, DownloadFileOptions options) : base(options.Bundle) + internal SFSDownloadFileOperation(SandboxFileSystem fileSystem, DownloadFileOptions options) : base(options.Bundle) { _fileSystem = fileSystem; _options = options; diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/CFSDownloadFileOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSDownloadFileOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/CFSDownloadFileOperation.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSDownloadFileOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/CFSInitializeOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSInitializeOperation.cs similarity index 87% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/CFSInitializeOperation.cs rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSInitializeOperation.cs index b77c36ee..ac6397e9 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/CFSInitializeOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSInitializeOperation.cs @@ -1,7 +1,7 @@ namespace YooAsset { - internal class CFSInitializeOperation : FSInitializeOperation + internal class SFSInitializeOperation : FSInitializeOperation { private enum ESteps { @@ -12,12 +12,12 @@ namespace YooAsset Done, } - private readonly CacheFileSystem _fileSystem; + private readonly SandboxFileSystem _fileSystem; private FCInitializeOperation _initializeFileCacheOp; private ESteps _steps = ESteps.None; - internal CFSInitializeOperation(CacheFileSystem fileSystem) + internal SFSInitializeOperation(SandboxFileSystem fileSystem) { _fileSystem = fileSystem; } @@ -45,29 +45,29 @@ namespace YooAsset // 如果水印发生变化,则说明覆盖安装后首次打开游戏 if (appFootprint.IsDirty()) { - if (_fileSystem.InstallClearMode == EInstallCleanupMode.None) + if (_fileSystem.InstallCleanupMode == EInstallCleanupMode.None) { YooLogger.Warning("Do nothing when overwrite install application."); } - else if (_fileSystem.InstallClearMode == EInstallCleanupMode.ClearAllCacheFiles) + else if (_fileSystem.InstallCleanupMode == EInstallCleanupMode.ClearAllCacheFiles) { _fileSystem.DeleteAllBundleFiles(); _fileSystem.DeleteAllManifestFiles(); YooLogger.Warning("Delete all cache files when overwrite install application."); } - else if (_fileSystem.InstallClearMode == EInstallCleanupMode.ClearAllBundleFiles) + else if (_fileSystem.InstallCleanupMode == EInstallCleanupMode.ClearAllBundleFiles) { _fileSystem.DeleteAllBundleFiles(); YooLogger.Warning("Delete all bundle files when overwrite install application."); } - else if (_fileSystem.InstallClearMode == EInstallCleanupMode.ClearAllManifestFiles) + else if (_fileSystem.InstallCleanupMode == EInstallCleanupMode.ClearAllManifestFiles) { _fileSystem.DeleteAllManifestFiles(); YooLogger.Warning("Delete all manifest files when overwrite install application."); } else { - throw new System.NotImplementedException(_fileSystem.InstallClearMode.ToString()); + throw new System.NotImplementedException(_fileSystem.InstallCleanupMode.ToString()); } appFootprint.Coverage(_fileSystem.PackageName); diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/CFSInitializeOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSInitializeOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/CFSInitializeOperation.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSInitializeOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/CFSLoadBundleOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSLoadBundleOperation.cs similarity index 94% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/CFSLoadBundleOperation.cs rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSLoadBundleOperation.cs index bd38f4d8..73717eb8 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/CFSLoadBundleOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSLoadBundleOperation.cs @@ -1,7 +1,7 @@ namespace YooAsset { - internal class CFSLoadBundleOperation : FSLoadBundleOperation + internal class SFSLoadBundleOperation : FSLoadBundleOperation { private enum ESteps { @@ -14,13 +14,13 @@ namespace YooAsset Done, } - private readonly CacheFileSystem _fileSystem; + private readonly SandboxFileSystem _fileSystem; private readonly LoadBundleOptions _options; private FSDownloadFileOperation _downloadFileOp; private FCLoadBundleOperation _loadBundleOp; private ESteps _steps = ESteps.None; - internal CFSLoadBundleOperation(CacheFileSystem fileSystem, LoadBundleOptions options) + internal SFSLoadBundleOperation(SandboxFileSystem fileSystem, LoadBundleOptions options) { _fileSystem = fileSystem; _options = options; @@ -139,7 +139,7 @@ namespace YooAsset { _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = "Loaded bundle result is null."; + Error = "Fatal error: loaded bundle result is null."; YooLogger.Error(Error); } else diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/CFSLoadBundleOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSLoadBundleOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/CFSLoadBundleOperation.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSLoadBundleOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/CFSLoadManifestOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSLoadManifestOperation.cs similarity index 96% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/CFSLoadManifestOperation.cs rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSLoadManifestOperation.cs index e6dee325..e175838e 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/CFSLoadManifestOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSLoadManifestOperation.cs @@ -2,7 +2,7 @@ namespace YooAsset { - internal class CFSLoadPackageManifestOperation : FSLoadManifestOperation + internal class SFSLoadPackageManifestOperation : FSLoadManifestOperation { private enum ESteps { @@ -14,7 +14,7 @@ namespace YooAsset Done, } - private readonly CacheFileSystem _fileSystem; + private readonly SandboxFileSystem _fileSystem; private readonly string _packageVersion; private readonly int _timeout; private DownloadPackageHashOperation _downloadPackageHashOp; @@ -24,7 +24,7 @@ namespace YooAsset private ESteps _steps = ESteps.None; - internal CFSLoadPackageManifestOperation(CacheFileSystem fileSystem, string packageVersion, int timeout) + internal SFSLoadPackageManifestOperation(SandboxFileSystem fileSystem, string packageVersion, int timeout) { _fileSystem = fileSystem; _packageVersion = packageVersion; diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/CFSLoadManifestOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSLoadManifestOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/CFSLoadManifestOperation.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSLoadManifestOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/CFSRequestVersionOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSRequestVersionOperation.cs similarity index 89% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/CFSRequestVersionOperation.cs rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSRequestVersionOperation.cs index 4bf2df42..776ebbc9 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/CFSRequestVersionOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSRequestVersionOperation.cs @@ -1,7 +1,7 @@  namespace YooAsset { - internal class CFSRequestPackageVersionOperation : FSRequestVersionOperation + internal class SFSRequestPackageVersionOperation : FSRequestVersionOperation { private enum ESteps { @@ -10,14 +10,14 @@ namespace YooAsset Done, } - private readonly CacheFileSystem _fileSystem; + private readonly SandboxFileSystem _fileSystem; private readonly bool _appendTimeTicks; private readonly int _timeout; private RequestRemotePackageVersionOperation _requestRemotePackageVersionOp; private ESteps _steps = ESteps.None; - internal CFSRequestPackageVersionOperation(CacheFileSystem fileSystem, bool appendTimeTicks, int timeout) + internal SFSRequestPackageVersionOperation(SandboxFileSystem fileSystem, bool appendTimeTicks, int timeout) { _fileSystem = fileSystem; _appendTimeTicks = appendTimeTicks; diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/CFSRequestVersionOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSRequestVersionOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/Operations/CFSRequestVersionOperation.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSRequestVersionOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/CacheFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/SandboxFileSystem.cs similarity index 82% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/CacheFileSystem.cs rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/SandboxFileSystem.cs index ceaba2e4..dc5202e2 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/CacheFileSystem.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/SandboxFileSystem.cs @@ -7,10 +7,9 @@ using UnityEngine; namespace YooAsset { /// - /// 缓存文件系统 - /// 说明:正在进行的下载器会在ResourcePackage销毁的时候执行Abort操作! + /// 沙盒文件系统 /// - internal class CacheFileSystem : IFileSystem + internal class SandboxFileSystem : IFileSystem { protected readonly Dictionary _tempFilePathMapping = new Dictionary(10000); protected string _packageRoot; @@ -52,12 +51,12 @@ namespace YooAsset /// /// 自定义参数:覆盖安装缓存清理模式 /// - public EInstallCleanupMode InstallClearMode { private set; get; } = EInstallCleanupMode.ClearAllManifestFiles; + public EInstallCleanupMode InstallCleanupMode { private set; get; } = EInstallCleanupMode.None; /// /// 自定义参数:初始化的时候缓存文件校验级别 /// - public EFileVerifyLevel FileVerifyLevel { private set; get; } = EFileVerifyLevel.Middle; + public EFileVerifyLevel FileVerifyLevel { private set; get; } = EFileVerifyLevel.Low; /// /// 自定义参数:初始化的时候缓存文件校验最大并发数 @@ -101,27 +100,42 @@ namespace YooAsset public List ResumeDownloadResponseCodes { private set; get; } = null; /// - /// 自定义参数:资源清单服务类 + /// 自定义参数:AssetBundle 解密器 /// - public IManifestRestoreServices ManifestRestoreServices { private set; get; } + public IBundleDecryptor AssetBundleDecryptor { get; set; } + + /// + /// 自定义参数:RawBundle 解密器 + /// + public IBundleDecryptor RawBundleDecryptor { get; set; } + + /// + /// 自定义参数:AssetBundle 备用解密器 + /// + public IBundleMemoryDecryptor AssetBundleFallbackDecryptor { get; set; } + + /// + /// 自定义参数:资源清单解密器 + /// + public IManifestDecryptor ManifestDecryptor { private set; get; } #endregion - public CacheFileSystem() + public SandboxFileSystem() { } public virtual FSInitializeOperation InitializeAsync() { - var operation = new CFSInitializeOperation(this); + var operation = new SFSInitializeOperation(this); return operation; } public virtual FSRequestVersionOperation RequestVersionAsync(RequestVersionOptions options) { - var operation = new CFSRequestPackageVersionOperation(this, options.AppendTimeTicks, options.Timeout); + var operation = new SFSRequestPackageVersionOperation(this, options.AppendTimeTicks, options.Timeout); return operation; } public virtual FSLoadManifestOperation LoadManifestAsync(LoadManifestOptions options) { - var operation = new CFSLoadPackageManifestOperation(this, options.PackageVersion, options.Timeout); + var operation = new SFSLoadPackageManifestOperation(this, options.PackageVersion, options.Timeout); return operation; } public virtual FSClearCacheOperation ClearCacheAsync(ClearCacheOptions options) @@ -138,18 +152,18 @@ namespace YooAsset } else { - var operation = new CFSClearCacheOperation(this, options); + var operation = new SFSClearCacheOperation(this, options); return operation; } } public virtual FSDownloadFileOperation DownloadFileAsync(DownloadFileOptions options) { - var downloader = new CFSDownloadFileOperation(this, options); + var downloader = new SFSDownloadFileOperation(this, options); return downloader; } public virtual FSLoadBundleOperation LoadBundleAsync(LoadBundleOptions options) { - var operation = new CFSLoadBundleOperation(this, options); + var operation = new SFSLoadBundleOperation(this, options); return operation; } @@ -169,7 +183,7 @@ namespace YooAsset } else if (name == FileSystemParametersDefine.INSTALL_CLEAR_MODE) { - InstallClearMode = (EInstallCleanupMode)value; + InstallCleanupMode = (EInstallCleanupMode)value; } else if (name == FileSystemParametersDefine.FILE_VERIFY_LEVEL) { @@ -186,7 +200,7 @@ namespace YooAsset // 限制在合理范围内:1-32 FileVerifyMaxConcurrency = Mathf.Clamp(convertValue, 1, 32); } - else if (name == FileSystemParametersDefine.DISABLE_ONDEMAND_DOWNLOAD) + else if (name == FileSystemParametersDefine.DOWNLOAD_DISABLE_ONDEMAND) { DisableOnDemandDownload = Convert.ToBoolean(value); } @@ -217,17 +231,29 @@ namespace YooAsset int convertValue = Convert.ToInt32(value); DownloadWatchDogTimeout = Mathf.Clamp(convertValue, 0, int.MaxValue); } - else if (name == FileSystemParametersDefine.RESUME_DOWNLOAD_MINMUM_SIZE) + else if (name == FileSystemParametersDefine.DOWNLOAD_RESUME_MINMUM_SIZE) { ResumeDownloadMinimumSize = Convert.ToInt64(value); } - else if (name == FileSystemParametersDefine.RESUME_DOWNLOAD_RESPONSE_CODES) + else if (name == FileSystemParametersDefine.DOWNLOAD_RESUME_RESPONSE_CODES) { ResumeDownloadResponseCodes = (List)value; } - else if (name == FileSystemParametersDefine.MANIFEST_RESTORE_SERVICES) + else if (name == FileSystemParametersDefine.ASSETBUNDLE_DECRYPTOR) { - ManifestRestoreServices = (IManifestRestoreServices)value; + AssetBundleDecryptor = (IBundleDecryptor)value; + } + else if (name == FileSystemParametersDefine.RAWBUNDLE_DECRYPTOR) + { + RawBundleDecryptor = (IBundleDecryptor)value; + } + else if (name == FileSystemParametersDefine.ASSETBUNDLE_FALLBACK_DECRYPTOR) + { + AssetBundleFallbackDecryptor = (IBundleMemoryDecryptor)value; + } + else if (name == FileSystemParametersDefine.MANIFEST_DECRYPTOR) + { + ManifestDecryptor = (IManifestDecryptor)value; } else { @@ -243,15 +269,18 @@ namespace YooAsset else _packageRoot = packageRoot; - _cacheBundleFilesRoot = PathUtility.Combine(_packageRoot, DefaultCacheFileSystemDefine.BundleFilesFolderName); - _cacheManifestFilesRoot = PathUtility.Combine(_packageRoot, DefaultCacheFileSystemDefine.ManifestFilesFolderName); - _tempFilesRoot = PathUtility.Combine(_packageRoot, DefaultCacheFileSystemDefine.TempFilesFolderName); + _cacheBundleFilesRoot = PathUtility.Combine(_packageRoot, SandboxFileSystemDefine.BundleFilesFolderName); + _cacheManifestFilesRoot = PathUtility.Combine(_packageRoot, SandboxFileSystemDefine.ManifestFilesFolderName); + _tempFilesRoot = PathUtility.Combine(_packageRoot, SandboxFileSystemDefine.TempFilesFolderName); // 创建文件缓存系统 { var cacheConfig = new SandboxFileCache.CacheConfig(); - cacheConfig.FileVerifyLevel = FileVerifyLevel; cacheConfig.FileVerifyMaxConcurrency = FileVerifyMaxConcurrency; + cacheConfig.FileVerifyLevel = FileVerifyLevel; + cacheConfig.AssetBundleDecryptor = AssetBundleDecryptor; + cacheConfig.RawBundleDecryptor = RawBundleDecryptor; + cacheConfig.AssetBundleFallbackDecryptor = AssetBundleFallbackDecryptor; FileCache = new SandboxFileCache(PackageName, _cacheBundleFilesRoot, cacheConfig); } @@ -326,7 +355,7 @@ namespace YooAsset } public string GetSandboxAppFootPrintFilePath() { - return PathUtility.Combine(_cacheManifestFilesRoot, DefaultCacheFileSystemDefine.AppFootPrintFileName); + return PathUtility.Combine(_cacheManifestFilesRoot, SandboxFileSystemDefine.AppFootPrintFileName); } public string GetTempFilePath(PackageBundle bundle) { diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/CacheFileSystem.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/SandboxFileSystem.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/CacheFileSystem.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/SandboxFileSystem.cs.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/CacheFileSystemDefine.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/SandboxFileSystemDefine.cs similarity index 93% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/CacheFileSystemDefine.cs rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/SandboxFileSystemDefine.cs index 2074edff..5cd1a62d 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/CacheFileSystemDefine.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/SandboxFileSystemDefine.cs @@ -1,7 +1,7 @@  namespace YooAsset { - internal class DefaultCacheFileSystemDefine + internal class SandboxFileSystemDefine { /// /// 记录应用程序版本的文件名称 diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/CacheFileSystemDefine.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/SandboxFileSystemDefine.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/Services/CacheFileSystem/CacheFileSystemDefine.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/SandboxFileSystemDefine.cs.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebGameFileSystem/Operations/LoadWebAssetBundleOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebGameFileSystem/Operations/LoadWebAssetBundleOperation.cs deleted file mode 100644 index 0debfd7c..00000000 --- a/Assets/YooAsset/Runtime/FileSystem/Services/WebGameFileSystem/Operations/LoadWebAssetBundleOperation.cs +++ /dev/null @@ -1,55 +0,0 @@ -using UnityEngine; - -namespace YooAsset -{ - /// - /// 加载 AssetBundle 的抽象基类 - /// 用户可继承此类实现自定义加载逻辑(如加密解密) - /// - public abstract class LoadWebAssetBundleOperation : AsyncOperationBase - { - protected readonly LoadWebAssetBundleOptions _options; - - /// - /// 加载结果:AssetBundle 对象 - /// - public AssetBundle Result { get; protected set; } - - /// - /// 下载进度 - /// - public float DownloadProgress { protected set; get; } - - /// - /// 下载大小 - /// - public long DownloadedBytes { protected set; get; } - - public LoadWebAssetBundleOperation(LoadWebAssetBundleOptions options) - { - _options = options; - } - } - - /// - /// 立即完成(失败)的 AssetBundle 加载操作 - /// 用途:当 Factory 判定某种场景不支持(例如默认实现不支持加密包)时,返回该 Operation - /// - public sealed class LoadWebAssetBundleCompleteOperation : LoadWebAssetBundleOperation - { - private readonly string _error; - - public LoadWebAssetBundleCompleteOperation(string error, LoadWebAssetBundleOptions options) : base(options) - { - _error = error; - } - internal override void InternalStart() - { - Status = EOperationStatus.Failed; - Error = _error; - } - internal override void InternalUpdate() - { - } - } -} diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebGameFileSystem/Operations/LoadWebAssetBundleOptions.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebGameFileSystem/Operations/LoadWebAssetBundleOptions.cs deleted file mode 100644 index b33b8e74..00000000 --- a/Assets/YooAsset/Runtime/FileSystem/Services/WebGameFileSystem/Operations/LoadWebAssetBundleOptions.cs +++ /dev/null @@ -1,44 +0,0 @@ - -namespace YooAsset -{ - /// - /// 加载 AssetBundle 的上下文信息 - /// - public struct LoadWebAssetBundleOptions - { - /// - /// 资源包信息 - /// - internal PackageBundle Bundle { get; set; } - - /// - /// 失败后重试次数 - /// - internal int RetryCount { get; set; } - - /// - /// 看门狗超时时间 - /// - internal int WatchdogTimeout { get; set; } - - /// - /// 下载后台接口 - /// - internal IDownloadBackend DownloadBackend { get; set; } - - /// - /// 禁用Unity的网络缓存 - /// - internal bool DisableUnityWebCache { get; set; } - - /// - /// 主资源地址 - /// - internal string MainURL { get; set; } - - /// - /// 备用资源地址 - /// - internal string FallbackURL { get; set; } - } -} diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebGameFileSystem/Operations.meta b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/Internal.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/Services/WebGameFileSystem/Operations.meta rename to Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/Internal.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebGameFileSystem/Operations/LoadWebPackageManifestOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/Internal/LoadWebPackageManifestOperation.cs similarity index 93% rename from Assets/YooAsset/Runtime/FileSystem/Services/WebGameFileSystem/Operations/LoadWebPackageManifestOperation.cs rename to Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/Internal/LoadWebPackageManifestOperation.cs index 8ad69073..e0c1fe11 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/WebGameFileSystem/Operations/LoadWebPackageManifestOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/Internal/LoadWebPackageManifestOperation.cs @@ -11,7 +11,7 @@ internal class LoadWebPackageManifestOperation : AsyncOperationBase Done, } - private readonly IManifestRestoreServices _manifestServices; + private readonly IManifestDecryptor _manifestDecryptor; private readonly IRemoteServices _remoteServices; private readonly IDownloadBackend _downloadBackend; private readonly string _packageName; @@ -29,10 +29,10 @@ internal class LoadWebPackageManifestOperation : AsyncOperationBase public PackageManifest Manifest { private set; get; } - internal LoadWebPackageManifestOperation(IManifestRestoreServices manifestServices, IRemoteServices remoteServices, IDownloadBackend downloadBackend, + internal LoadWebPackageManifestOperation(IManifestDecryptor manifestDecryptor, IRemoteServices remoteServices, IDownloadBackend downloadBackend, string packageName, string packageVersion, string packageHash, int timeout) { - _manifestServices = manifestServices; + _manifestDecryptor = manifestDecryptor; _remoteServices = remoteServices; _downloadBackend = downloadBackend; _packageName = packageName; @@ -96,7 +96,7 @@ internal class LoadWebPackageManifestOperation : AsyncOperationBase { if (_deserializer == null) { - _deserializer = new DeserializeManifestOperation(_manifestServices, _webDataRequestOp.Result); + _deserializer = new DeserializeManifestOperation(_manifestDecryptor, _webDataRequestOp.Result); _deserializer.StartOperation(); AddChildOperation(_deserializer); } diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebGameFileSystem/Operations/LoadWebPackageManifestOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/Internal/LoadWebPackageManifestOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/Services/WebGameFileSystem/Operations/LoadWebPackageManifestOperation.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/Internal/LoadWebPackageManifestOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebGameFileSystem/Operations/RequestWebPackageHashOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/Internal/RequestWebPackageHashOperation.cs similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/Services/WebGameFileSystem/Operations/RequestWebPackageHashOperation.cs rename to Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/Internal/RequestWebPackageHashOperation.cs diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebGameFileSystem/Operations/RequestWebPackageHashOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/Internal/RequestWebPackageHashOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/Services/WebGameFileSystem/Operations/RequestWebPackageHashOperation.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/Internal/RequestWebPackageHashOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebGameFileSystem/Operations/RequestWebPackageVersionOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/Internal/RequestWebPackageVersionOperation.cs similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/Services/WebGameFileSystem/Operations/RequestWebPackageVersionOperation.cs rename to Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/Internal/RequestWebPackageVersionOperation.cs diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebGameFileSystem/Operations/RequestWebPackageVersionOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/Internal/RequestWebPackageVersionOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/Services/WebGameFileSystem/Operations/RequestWebPackageVersionOperation.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/Internal/RequestWebPackageVersionOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/WRFSLoadBundleOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/WRFSLoadBundleOperation.cs index c62586da..03caccaf 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/WRFSLoadBundleOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/WRFSLoadBundleOperation.cs @@ -15,7 +15,6 @@ namespace YooAsset private FCLoadBundleOperation _loadBundleOp; private ESteps _steps = ESteps.None; - internal WRFSLoadBundleOperation(WebRemoteFileSystem fileSystem, LoadBundleOptions options) { _fileSystem = fileSystem; diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/WRFSLoadManifestOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/WRFSLoadManifestOperation.cs index 6ae1a085..baad040d 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/WRFSLoadManifestOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/Operations/WRFSLoadManifestOperation.cs @@ -65,7 +65,7 @@ namespace YooAsset { string packageHash = _requestWebPackageHashOp.PackageHash; string packageName = _fileSystem.PackageName; - var manifestServices = _fileSystem.ManifestRestoreServices; + var manifestServices = _fileSystem.ManifestDecryptor; var remoteServices = _fileSystem.RemoteServices; var downloadBackend = _fileSystem.DownloadBackend; _loadWebPackageManifestOp = new LoadWebPackageManifestOperation(manifestServices, remoteServices, downloadBackend, packageName, _packageVersion, packageHash, _timeout); diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/WebRemoteFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/WebRemoteFileSystem.cs index 4547342a..d4b69ef6 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/WebRemoteFileSystem.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/WebRemoteFileSystem.cs @@ -47,9 +47,14 @@ namespace YooAsset public IRemoteServices RemoteServices { private set; get; } /// - /// 自定义参数:资源清单服务类 + /// 自定义参数:AssetBundle 解密器 /// - public IManifestRestoreServices ManifestRestoreServices { private set; get; } + public IBundleDecryptor AssetBundleDecryptor { get; set; } + + /// + /// 自定义参数:资源清单解密器 + /// + public IManifestDecryptor ManifestDecryptor { private set; get; } #endregion @@ -109,9 +114,13 @@ namespace YooAsset { RemoteServices = (IRemoteServices)value; } - else if (name == FileSystemParametersDefine.MANIFEST_RESTORE_SERVICES) + else if (name == FileSystemParametersDefine.ASSETBUNDLE_DECRYPTOR) { - ManifestRestoreServices = (IManifestRestoreServices)value; + AssetBundleDecryptor = (IBundleDecryptor)value; + } + else if (name == FileSystemParametersDefine.MANIFEST_DECRYPTOR) + { + ManifestDecryptor = (IManifestDecryptor)value; } else { @@ -128,11 +137,11 @@ namespace YooAsset // 创建Web文件缓存系统 var cacheConfig = new WebRemoteFileCache.CacheConfig(); + cacheConfig.WatchdogTimeout = DownloadWatchDogTimeout; cacheConfig.DisableUnityWebCache = DisableUnityWebCache; + cacheConfig.AssetBundleDecryptor = AssetBundleDecryptor; cacheConfig.RemoteServices = RemoteServices; cacheConfig.DownloadBackend = DownloadBackend; - cacheConfig.WatchdogTimeout = DownloadWatchDogTimeout; - cacheConfig.RetryCount = int.MaxValue; FileCache = new WebRemoteFileCache(packageName, packageRoot, cacheConfig); } public virtual void OnDestroy() diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/WSFSLoadBundleOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/WSFSLoadBundleOperation.cs index bcb386aa..b94b5d57 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/WSFSLoadBundleOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/WSFSLoadBundleOperation.cs @@ -15,7 +15,6 @@ namespace YooAsset private FCLoadBundleOperation _loadBundleOp; private ESteps _steps = ESteps.None; - internal WSFSLoadAssetBundleOperation(WebServerFileSystem fileSystem, LoadBundleOptions options) { _fileSystem = fileSystem; diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/internal/LoadWebServerPackageManifestOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/internal/LoadWebServerPackageManifestOperation.cs index ac86e566..6ff921d3 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/internal/LoadWebServerPackageManifestOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/Operations/internal/LoadWebServerPackageManifestOperation.cs @@ -86,7 +86,7 @@ namespace YooAsset { if (_deserializer == null) { - _deserializer = new DeserializeManifestOperation(_fileSystem.ManifestRestoreServices, _webDataRequestOp.Result); + _deserializer = new DeserializeManifestOperation(_fileSystem.ManifestDecryptor, _webDataRequestOp.Result); _deserializer.StartOperation(); AddChildOperation(_deserializer); } diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/WebServerFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/WebServerFileSystem.cs index 7e799b6c..e4388762 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/WebServerFileSystem.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/WebServerFileSystem.cs @@ -45,9 +45,14 @@ namespace YooAsset public int DownloadWatchDogTimeout { private set; get; } = 0; /// - /// 自定义参数:资源清单服务类 + /// 自定义参数:AssetBundle 解密器 /// - public IManifestRestoreServices ManifestRestoreServices { private set; get; } + public IBundleDecryptor AssetBundleDecryptor { get; set; } + + /// + /// 自定义参数:资源清单解密器 + /// + public IManifestDecryptor ManifestDecryptor { private set; get; } #endregion @@ -103,9 +108,13 @@ namespace YooAsset int convertValue = Convert.ToInt32(value); DownloadWatchDogTimeout = Mathf.Clamp(convertValue, 0, int.MaxValue); } - else if (name == FileSystemParametersDefine.MANIFEST_RESTORE_SERVICES) + else if (name == FileSystemParametersDefine.ASSETBUNDLE_DECRYPTOR) { - ManifestRestoreServices = (IManifestRestoreServices)value; + AssetBundleDecryptor = (IBundleDecryptor)value; + } + else if (name == FileSystemParametersDefine.MANIFEST_DECRYPTOR) + { + ManifestDecryptor = (IManifestDecryptor)value; } else { @@ -127,10 +136,10 @@ namespace YooAsset // 创建Web文件缓存系统 var cacheConfig = new WebServerFileCache.CacheConfig(); + cacheConfig.WatchdogTimeout = DownloadWatchDogTimeout; cacheConfig.DisableUnityWebCache = DisableUnityWebCache; cacheConfig.DownloadBackend = DownloadBackend; - cacheConfig.WatchdogTimeout = DownloadWatchDogTimeout; - cacheConfig.RetryCount = int.MaxValue; + cacheConfig.AssetBundleDecryptor = AssetBundleDecryptor; FileCache = new WebServerFileCache(packageName, _packageRoot, cacheConfig); } public virtual void OnDestroy() diff --git a/Assets/YooAsset/Runtime/Interfaces/IBundleDecryptor.cs b/Assets/YooAsset/Runtime/Interfaces/IBundleDecryptor.cs new file mode 100644 index 00000000..aab5ce13 --- /dev/null +++ b/Assets/YooAsset/Runtime/Interfaces/IBundleDecryptor.cs @@ -0,0 +1,29 @@ +using System; +using System.IO; + +namespace YooAsset +{ + public struct BundleDecryptArgs + { + internal PackageBundle Bundle { get; set; } + public byte[] FileData { get; set; } + public string FilePath { get; set; } + } + + public interface IBundleDecryptor + { + } + public interface IBundleOffsetDecryptor : IBundleDecryptor + { + uint GetFileOffset(BundleDecryptArgs args); + } + public interface IBundleMemoryDecryptor : IBundleDecryptor + { + byte[] GetDecryptData(BundleDecryptArgs args); + } + public interface IBundleStreamDecryptor : IBundleDecryptor + { + uint GetReadBufferSize(BundleDecryptArgs args); + Stream GetDecryptStream(BundleDecryptArgs args); + } +} diff --git a/Assets/YooAsset/Runtime/Interfaces/IBundleDecryptor.cs.meta b/Assets/YooAsset/Runtime/Interfaces/IBundleDecryptor.cs.meta new file mode 100644 index 00000000..1b043f13 --- /dev/null +++ b/Assets/YooAsset/Runtime/Interfaces/IBundleDecryptor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 57f045994206fd54bbe7c29b1bf9a1a6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/Interfaces/IBundleEncryptionServices.cs b/Assets/YooAsset/Runtime/Interfaces/IBundleEncryptor.cs similarity index 55% rename from Assets/YooAsset/Runtime/Interfaces/IBundleEncryptionServices.cs rename to Assets/YooAsset/Runtime/Interfaces/IBundleEncryptor.cs index c7d705ac..b7489197 100644 --- a/Assets/YooAsset/Runtime/Interfaces/IBundleEncryptionServices.cs +++ b/Assets/YooAsset/Runtime/Interfaces/IBundleEncryptor.cs @@ -1,19 +1,20 @@  namespace YooAsset { - public struct BundleEncryptionContext + public struct BundleEncryptArgs { /// /// 资源包名称 /// - public string BundleName; + internal string BundleName; /// /// 文件路径 /// - public string FileLoadPath; + public string FilePath; } - public struct BundleEncryptionResult + + public struct BundleEncryptResult { /// /// 文件是否加密 @@ -23,10 +24,11 @@ namespace YooAsset /// /// 加密后的文件数据 /// - public byte[] EncryptedData; + public byte[] EncryptedFileData; } - public interface IBundleEncryptionServices + + public interface IBundleEncryptor { - BundleEncryptionResult Encrypt(BundleEncryptionContext bundleInfo); + BundleEncryptResult Encrypt(BundleEncryptArgs args); } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/Interfaces/IBundleEncryptionServices.cs.meta b/Assets/YooAsset/Runtime/Interfaces/IBundleEncryptor.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/Interfaces/IBundleEncryptionServices.cs.meta rename to Assets/YooAsset/Runtime/Interfaces/IBundleEncryptor.cs.meta diff --git a/Assets/YooAsset/Runtime/Interfaces/IManifestDecryptor.cs b/Assets/YooAsset/Runtime/Interfaces/IManifestDecryptor.cs new file mode 100644 index 00000000..0d83ea16 --- /dev/null +++ b/Assets/YooAsset/Runtime/Interfaces/IManifestDecryptor.cs @@ -0,0 +1,11 @@ + +namespace YooAsset +{ + /// + /// 资源清单解密器 + /// + public interface IManifestDecryptor + { + byte[] Decrypt(byte[] fileData); + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/Interfaces/IManifestRestoreServices.cs.meta b/Assets/YooAsset/Runtime/Interfaces/IManifestDecryptor.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/Interfaces/IManifestRestoreServices.cs.meta rename to Assets/YooAsset/Runtime/Interfaces/IManifestDecryptor.cs.meta diff --git a/Assets/YooAsset/Runtime/Interfaces/IManifestEncryptor.cs b/Assets/YooAsset/Runtime/Interfaces/IManifestEncryptor.cs new file mode 100644 index 00000000..bbdcaadc --- /dev/null +++ b/Assets/YooAsset/Runtime/Interfaces/IManifestEncryptor.cs @@ -0,0 +1,11 @@ + +namespace YooAsset +{ + /// + /// 资源清单加密器 + /// + public interface IManifestEncryptor + { + byte[] Encrypt(byte[] fileData); + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/Interfaces/IManifestProcessServices.cs.meta b/Assets/YooAsset/Runtime/Interfaces/IManifestEncryptor.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/Interfaces/IManifestProcessServices.cs.meta rename to Assets/YooAsset/Runtime/Interfaces/IManifestEncryptor.cs.meta diff --git a/Assets/YooAsset/Runtime/Interfaces/IManifestProcessServices.cs b/Assets/YooAsset/Runtime/Interfaces/IManifestProcessServices.cs deleted file mode 100644 index 76fd42ac..00000000 --- a/Assets/YooAsset/Runtime/Interfaces/IManifestProcessServices.cs +++ /dev/null @@ -1,14 +0,0 @@ - -namespace YooAsset -{ - /// - /// 资源清单文件处理服务接口 - /// - public interface IManifestProcessServices - { - /// - /// 处理资源清单(压缩或加密) - /// - byte[] ProcessManifest(byte[] fileData); - } -} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/Interfaces/IManifestRestoreServices.cs b/Assets/YooAsset/Runtime/Interfaces/IManifestRestoreServices.cs deleted file mode 100644 index 4fc3599e..00000000 --- a/Assets/YooAsset/Runtime/Interfaces/IManifestRestoreServices.cs +++ /dev/null @@ -1,14 +0,0 @@ - -namespace YooAsset -{ - /// - /// 资源清单文件处理服务接口 - /// - public interface IManifestRestoreServices - { - /// - /// 还原资源清单(解压或解密) - /// - byte[] RestoreManifest(byte[] fileData); - } -} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Operations/Internal/DeserializeManifestOperation.cs b/Assets/YooAsset/Runtime/ResourcePackage/Operations/Internal/DeserializeManifestOperation.cs index a6677822..2af8483f 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/Operations/Internal/DeserializeManifestOperation.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/Operations/Internal/DeserializeManifestOperation.cs @@ -23,7 +23,7 @@ namespace YooAsset Done, } - private readonly IManifestRestoreServices _services; + private readonly IManifestDecryptor _decryptor; private byte[] _sourceData; private BufferReader _buffer; private int _packageAssetCount; @@ -36,9 +36,9 @@ namespace YooAsset /// public PackageManifest Manifest { get; private set; } - public DeserializeManifestOperation(IManifestRestoreServices services, byte[] binaryData) + public DeserializeManifestOperation(IManifestDecryptor decryptor, byte[] binaryData) { - _services = services; + _decryptor = decryptor; _sourceData = binaryData; } internal override void InternalStart() @@ -52,9 +52,9 @@ namespace YooAsset if (_steps == ESteps.RestoreFileData) { - if (_services != null) + if (_decryptor != null) { - var resultData = _services.RestoreManifest(_sourceData); + var resultData = _decryptor.Decrypt(_sourceData); if (resultData != null) _sourceData = resultData; } diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PackageManifestTools.cs b/Assets/YooAsset/Runtime/ResourcePackage/PackageManifestTools.cs index 1e342f3b..ce224aa1 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/PackageManifestTools.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/PackageManifestTools.cs @@ -56,7 +56,7 @@ namespace YooAsset /// 保存路径 /// 清单对象 /// 清单处理服务(可为null) - public static void SerializeManifestToBinary(string savePath, PackageManifest manifest, IManifestProcessServices services) + public static void SerializeManifestToBinary(string savePath, PackageManifest manifest, IManifestEncryptor services) { using (FileStream fs = new FileStream(savePath, FileMode.Create)) { @@ -114,7 +114,7 @@ namespace YooAsset if (services != null) { var tempBytes = buffer.GetBytes(); - var resultBytes = services.ProcessManifest(tempBytes); + var resultBytes = services.Encrypt(tempBytes); fs.Write(resultBytes, 0, resultBytes.Length); fs.Flush(); } @@ -154,9 +154,9 @@ namespace YooAsset /// 二进制数据 /// 清单恢复服务(可为null) /// 返回反序列化后的清单对象 - public static PackageManifest DeserializeManifestFromBinary(byte[] binaryData, IManifestRestoreServices services) + public static PackageManifest DeserializeManifestFromBinary(byte[] binaryData, IManifestDecryptor decryptor) { - DeserializeManifestOperation operation = new DeserializeManifestOperation(services, binaryData); + DeserializeManifestOperation operation = new DeserializeManifestOperation(decryptor, binaryData); operation.StartOperation(); operation.WaitForCompletion(); return operation.Manifest; diff --git a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/GetCacheBundleSizeOperation.cs b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/GetCacheBundleSizeOperation.cs index 295e851f..a835604c 100644 --- a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/GetCacheBundleSizeOperation.cs +++ b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/GetCacheBundleSizeOperation.cs @@ -62,6 +62,6 @@ public class GetCacheBundleSizeOperation : AsyncOperationBase { string rootDirectory = YooAssetSettingsData.GetYooDefaultCacheRoot(); string packageRoot = PathUtility.Combine(rootDirectory, _packageName); - return PathUtility.Combine(packageRoot, DefaultCacheFileSystemDefine.BundleFilesFolderName); + return PathUtility.Combine(packageRoot, SandboxFileSystemDefine.BundleFilesFolderName); } } \ No newline at end of file diff --git a/Assets/YooAsset/Samples~/Mini Game/Runtime/AlipayFileSystem/AlipayFileSystem.cs b/Assets/YooAsset/Samples~/Mini Game/Runtime/AlipayFileSystem/AlipayFileSystem.cs index dcb47c6a..864cab77 100644 --- a/Assets/YooAsset/Samples~/Mini Game/Runtime/AlipayFileSystem/AlipayFileSystem.cs +++ b/Assets/YooAsset/Samples~/Mini Game/Runtime/AlipayFileSystem/AlipayFileSystem.cs @@ -104,7 +104,7 @@ internal class AlipayFileSystem : IFileSystem public IWebDecryptionServices DecryptionServices { private set; get; } /// - /// 自定义参数:资源清单服务类 + /// 自定义参数:资源清单解密器 /// public IManifestRestoreServices ManifestServices { private set; get; } #endregion diff --git a/Assets/YooAsset/Samples~/Mini Game/Runtime/TaptapFileSystem/TaptapFileSystem.cs b/Assets/YooAsset/Samples~/Mini Game/Runtime/TaptapFileSystem/TaptapFileSystem.cs index 177055da..d4a525fb 100644 --- a/Assets/YooAsset/Samples~/Mini Game/Runtime/TaptapFileSystem/TaptapFileSystem.cs +++ b/Assets/YooAsset/Samples~/Mini Game/Runtime/TaptapFileSystem/TaptapFileSystem.cs @@ -105,7 +105,7 @@ internal class TaptapFileSystem : IFileSystem public IWebDecryptionServices DecryptionServices { private set; get; } /// - /// 自定义参数:资源清单服务类 + /// 自定义参数:资源清单解密器 /// public IManifestRestoreServices ManifestServices { private set; get; } #endregion diff --git a/Assets/YooAsset/Samples~/Mini Game/Runtime/TiktokFileSystem/TiktokFileSystem.cs b/Assets/YooAsset/Samples~/Mini Game/Runtime/TiktokFileSystem/TiktokFileSystem.cs index d91b8feb..e24fc4d7 100644 --- a/Assets/YooAsset/Samples~/Mini Game/Runtime/TiktokFileSystem/TiktokFileSystem.cs +++ b/Assets/YooAsset/Samples~/Mini Game/Runtime/TiktokFileSystem/TiktokFileSystem.cs @@ -104,7 +104,7 @@ internal class TiktokFileSystem : IFileSystem public IWebDecryptionServices DecryptionServices { private set; get; } /// - /// 自定义参数:资源清单服务类 + /// 自定义参数:资源清单解密器 /// public IManifestRestoreServices ManifestServices { private set; get; } #endregion diff --git a/Assets/YooAsset/Samples~/Mini Game/Runtime/WechatFileSystem/WechatFileSystem.cs b/Assets/YooAsset/Samples~/Mini Game/Runtime/WechatFileSystem/WechatFileSystem.cs index a02a4e9b..36ea35ab 100644 --- a/Assets/YooAsset/Samples~/Mini Game/Runtime/WechatFileSystem/WechatFileSystem.cs +++ b/Assets/YooAsset/Samples~/Mini Game/Runtime/WechatFileSystem/WechatFileSystem.cs @@ -104,7 +104,7 @@ internal class WechatFileSystem : IFileSystem public IWebDecryptionServices DecryptionServices { private set; get; } /// - /// 自定义参数:资源清单服务类 + /// 自定义参数:资源清单解密器 /// public IManifestRestoreServices ManifestServices { private set; get; } #endregion diff --git a/Assets/YooAsset/Samples~/Test Sample/Editor/TestPackageBuilder.cs b/Assets/YooAsset/Samples~/Test Sample/Editor/TestPackageBuilder.cs index 8fedc1db..0129dff9 100644 --- a/Assets/YooAsset/Samples~/Test Sample/Editor/TestPackageBuilder.cs +++ b/Assets/YooAsset/Samples~/Test Sample/Editor/TestPackageBuilder.cs @@ -71,9 +71,9 @@ public static class TestPackageBuilder buildParameters.ClearBuildCacheFiles = true; buildParameters.UseAssetDependencyDB = true; buildParameters.BuiltinShadersBundleName = builtinShaderBundleName; - buildParameters.EncryptionServices = new TestFileStreamEncryption(); - buildParameters.ManifestProcessServices = new TestProcessManifest(); - buildParameters.ManifestRestoreServices = new TestRestoreManifest(); + buildParameters.BundleEncryptor = new TestFileStreamEncryption(); + buildParameters.ManifestEncryptor = new TestManifestEncryptor(); + buildParameters.ManifestDecryptor = new TestManifestDecryptor(); var pipeline = new ScriptableBuildPipeline(); BuildResult buildResult = pipeline.Run(buildParameters, false); @@ -110,9 +110,9 @@ public static class TestPackageBuilder buildParameters.CompressOption = ECompressOption.LZ4; buildParameters.ClearBuildCacheFiles = true; buildParameters.UseAssetDependencyDB = true; - buildParameters.EncryptionServices = new TestFileStreamEncryption(); - buildParameters.ManifestProcessServices = new TestProcessManifest(); - buildParameters.ManifestRestoreServices = new TestRestoreManifest(); + buildParameters.BundleEncryptor = new TestFileStreamEncryption(); + buildParameters.ManifestEncryptor = new TestManifestEncryptor(); + buildParameters.ManifestDecryptor = new TestManifestDecryptor(); var pipeline = new BuiltinBuildPipeline(); BuildResult buildResult = pipeline.Run(buildParameters, false); diff --git a/Assets/YooAsset/Samples~/Test Sample/Runtime/CryptoSample/TestFileEncryption.cs b/Assets/YooAsset/Samples~/Test Sample/Runtime/CryptoSample/TestFileEncryption.cs index eb6eb891..a40186e9 100644 --- a/Assets/YooAsset/Samples~/Test Sample/Runtime/CryptoSample/TestFileEncryption.cs +++ b/Assets/YooAsset/Samples~/Test Sample/Runtime/CryptoSample/TestFileEncryption.cs @@ -22,75 +22,77 @@ public class BundleStream : FileStream return index; } } -public class TestFileStreamEncryption : IBundleEncryptionServices +public class TestFileStreamEncryption : IBundleEncryptor { - public BundleEncryptionResult Encrypt(BundleEncryptionContext fileInfo) + public BundleEncryptResult Encrypt(BundleEncryptArgs fileInfo) { // 说明:对TestRes3资源目录进行加密 if (fileInfo.BundleName.Contains("_testres3_")) { - var fileData = File.ReadAllBytes(fileInfo.FileLoadPath); + var fileData = File.ReadAllBytes(fileInfo.FilePath); for (int i = 0; i < fileData.Length; i++) { fileData[i] ^= BundleStream.KEY; } - BundleEncryptionResult result = new BundleEncryptionResult(); + BundleEncryptResult result = new BundleEncryptResult(); result.Encrypted = true; - result.EncryptedData = fileData; + result.EncryptedFileData = fileData; return result; } else { - BundleEncryptionResult result = new BundleEncryptionResult(); + BundleEncryptResult result = new BundleEncryptResult(); result.Encrypted = false; return result; } } } -public class TestFileOffsetEncryption : IBundleEncryptionServices +public class TestFileOffsetEncryption : IBundleEncryptor { - public BundleEncryptionResult Encrypt(BundleEncryptionContext fileInfo) + public BundleEncryptResult Encrypt(BundleEncryptArgs fileInfo) { // 说明:对TestRes3资源目录进行加密 if (fileInfo.BundleName.Contains("_testres3_")) { int offset = 32; - byte[] fileData = File.ReadAllBytes(fileInfo.FileLoadPath); + byte[] fileData = File.ReadAllBytes(fileInfo.FilePath); var encryptedData = new byte[fileData.Length + offset]; Buffer.BlockCopy(fileData, 0, encryptedData, offset, fileData.Length); - BundleEncryptionResult result = new BundleEncryptionResult(); + BundleEncryptResult result = new BundleEncryptResult(); result.Encrypted = true; - result.EncryptedData = encryptedData; + result.EncryptedFileData = encryptedData; return result; } else { - BundleEncryptionResult result = new BundleEncryptionResult(); + BundleEncryptResult result = new BundleEncryptResult(); result.Encrypted = false; return result; } } } -public class TestLoadAssetBundleFromOffsetOperation : DefaultLoadAssetBundleFromOffsetOperation +public class TestFileOffsetDecryption : IBundleOffsetDecryptor { private const uint FILE_OFFSET = 32; - public TestLoadAssetBundleFromOffsetOperation(LoadAssetBundleOptions options) : base(options) { } - - protected override uint GetFileOffset() + uint IBundleOffsetDecryptor.GetFileOffset(BundleDecryptArgs args) { return FILE_OFFSET; } } -public class TestLoadAssetBundleFromMemoryOperation : DefaultLoadAssetBundleFromMemoryOperation +public class TestFileMemoryDecryption : IBundleMemoryDecryptor { - public TestLoadAssetBundleFromMemoryOperation(LoadAssetBundleOptions options) : base(options) { } - - protected override byte[] DecryptData(byte[] data) + byte[] IBundleMemoryDecryptor.GetDecryptData(BundleDecryptArgs args) { + byte[] data = args.FileData; + + // 注意:如果数据为空,自行加载文件数据。 + if (data == null) + data = FileUtility.ReadAllBytes(args.FilePath); + for (int i = 0; i < data.Length; i++) { data[i] ^= BundleStream.KEY; @@ -98,39 +100,16 @@ public class TestLoadAssetBundleFromMemoryOperation : DefaultLoadAssetBundleFrom return data; } } -public class TestLoadAssetBundleFromStreamOperation : DefaultLoadAssetBundleFromStreamOperation +public class TestFileStreamDecryption : IBundleStreamDecryptor { - public TestLoadAssetBundleFromStreamOperation(LoadAssetBundleOptions options) : base(options) { } - - protected override FileStream CreateManagedFileStream() + Stream IBundleStreamDecryptor.GetDecryptStream(BundleDecryptArgs args) { - var fileStream = new BundleStream(_options.FileLoadPath, FileMode.Open, FileAccess.Read, FileShare.Read); + var fileStream = new BundleStream(args.FilePath, FileMode.Open, FileAccess.Read, FileShare.Read); return fileStream; } - protected override uint GetManagedReadBufferSize() + + uint IBundleStreamDecryptor.GetReadBufferSize(BundleDecryptArgs args) { return 1024; } - protected override byte[] DecryptData(byte[] data) - { - for (int i = 0; i < data.Length; i++) - { - data[i] ^= BundleStream.KEY; - } - return data; - } -} -public class TestWebAssetBundleFromMemoryDecryption : DefaultLoadWebAssetBundleFromMemoryOperation -{ - public TestWebAssetBundleFromMemoryDecryption(LoadWebAssetBundleOptions opionts) : base(opionts) { } - - protected override byte[] Decryption(byte[] data) - { - for (int i = 0; i < data.Length; i++) - { - data[i] ^= BundleStream.KEY; - } - - return data; - } -} +} \ No newline at end of file diff --git a/Assets/YooAsset/Samples~/Test Sample/Runtime/CryptoSample/TestManifestServices.cs b/Assets/YooAsset/Samples~/Test Sample/Runtime/CryptoSample/TestManifestServices.cs index 074afd9d..33cd4eee 100644 --- a/Assets/YooAsset/Samples~/Test Sample/Runtime/CryptoSample/TestManifestServices.cs +++ b/Assets/YooAsset/Samples~/Test Sample/Runtime/CryptoSample/TestManifestServices.cs @@ -6,17 +6,17 @@ using UnityEngine; using NUnit.Framework; using YooAsset; -public class TestProcessManifest : IManifestProcessServices +public class TestManifestEncryptor : IManifestEncryptor { - byte[] IManifestProcessServices.ProcessManifest(byte[] fileData) + byte[] IManifestEncryptor.Encrypt(byte[] fileData) { return XorCrypto.Crypto(fileData, "YOO"); } } -public class TestRestoreManifest : IManifestRestoreServices +public class TestManifestDecryptor : IManifestDecryptor { - byte[] IManifestRestoreServices.RestoreManifest(byte[] fileData) + byte[] IManifestDecryptor.Decrypt(byte[] fileData) { return XorCrypto.Crypto(fileData, "YOO"); } diff --git a/Assets/YooAsset/Samples~/Test Sample/Runtime/T2_TestBuldinFileSystem/T2_TestBuldinFileSystem.cs b/Assets/YooAsset/Samples~/Test Sample/Runtime/T2_TestBuldinFileSystem/T2_TestBuldinFileSystem.cs index dd87c7fd..89d2c52e 100644 --- a/Assets/YooAsset/Samples~/Test Sample/Runtime/T2_TestBuldinFileSystem/T2_TestBuldinFileSystem.cs +++ b/Assets/YooAsset/Samples~/Test Sample/Runtime/T2_TestBuldinFileSystem/T2_TestBuldinFileSystem.cs @@ -60,9 +60,9 @@ public class T2_TestBuldinFileSystem : IPrebuildSetup, IPostBuildCleanup // 初始化资源包 var initParams = new OfflinePlayModeOptions(); - var manifestServices = new TestRestoreManifest(); + var manifestServices = new TestManifestDecryptor(); initParams.BuildinFileSystemParameters = FileSystemParameters.CreateDefaultBuildinFileSystemParameters(packageRoot); - initParams.BuildinFileSystemParameters.AddParameter(FileSystemParametersDefine.MANIFEST_RESTORE_SERVICES, manifestServices); + initParams.BuildinFileSystemParameters.AddParameter(FileSystemParametersDefine.MANIFEST_DECRYPTOR, manifestServices); var initializeOp = package.InitializePackageAsync(initParams); yield return initializeOp; if (initializeOp.Status != EOperationStatus.Succeeded) diff --git a/Assets/YooAsset/Samples~/Test Sample/Runtime/T3_TestCacheFileSystem/T3_TestCacheFileSystem.cs b/Assets/YooAsset/Samples~/Test Sample/Runtime/T3_TestCacheFileSystem/T3_TestCacheFileSystem.cs index b7a0d498..c5848f4c 100644 --- a/Assets/YooAsset/Samples~/Test Sample/Runtime/T3_TestCacheFileSystem/T3_TestCacheFileSystem.cs +++ b/Assets/YooAsset/Samples~/Test Sample/Runtime/T3_TestCacheFileSystem/T3_TestCacheFileSystem.cs @@ -45,13 +45,13 @@ public class T3_TestCacheFileSystem : IPrebuildSetup, IPostBuildCleanup // 初始化资源包 var initParams = new HostPlayModeOptions(); - var manifestServices = new TestRestoreManifest(); + var manifestServices = new TestManifestDecryptor(); string hostServerIP = "http://127.0.0.1/CDN/Android/Test/"; var remoteServices = new TestRemoteServices(hostServerIP); initParams.BuildinFileSystemParameters = null; initParams.CacheFileSystemParameters = FileSystemParameters.CreateDefaultCacheFileSystemParameters(remoteServices); - initParams.CacheFileSystemParameters.AddParameter(FileSystemParametersDefine.MANIFEST_RESTORE_SERVICES, manifestServices); + initParams.CacheFileSystemParameters.AddParameter(FileSystemParametersDefine.MANIFEST_DECRYPTOR, manifestServices); var initializeOp = package.InitializePackageAsync(initParams); yield return initializeOp; if (initializeOp.Status != EOperationStatus.Succeeded)