Compare commits

..

6 Commits

Author SHA1 Message Date
何冠峰
6155256fb6 Update CHANGELOG.md 2025-03-14 14:48:16 +08:00
何冠峰
0d4f2bc893 Update package.json 2025-03-14 14:47:39 +08:00
何冠峰
600e928ab4 fix #512 2025-03-14 14:32:39 +08:00
何冠峰
4599ff098c update resource package
优化ClearCacheFilesAsync方法
2025-03-14 12:27:01 +08:00
何冠峰
4d2df5b705 Update TestBundleEncryption.cs 2025-03-13 16:29:48 +08:00
何冠峰
79a7732cfd Update InitializeParameters.cs 2025-03-13 14:00:59 +08:00
12 changed files with 151 additions and 49 deletions

View File

@@ -2,6 +2,15 @@
All notable changes to this package will be documented in this file.
## [2.3.5-preview] - 2025-03-14
### Fixed
- (#502) 修复了原生缓存文件由于文件格式变动导致的加载本地缓存文件失败的问题。
- (#504) 修复了MacOS平台Offline Play Mode模式请求本地资源清单失败的问题。
- (#506) 修复了v2.3x版本LoadAllAssets方法计算依赖Bundle不完整的问题。
- (#506) 修复了微信小游戏文件系统在启用加密算法后卸载bundle报错的问题。
## [2.3.4-preview] - 2025-03-08
### Improvements

View File

@@ -333,6 +333,13 @@ namespace YooAsset
{
return _records.Keys.ToList();
}
public RecordFileElement GetRecordFileElement(PackageBundle bundle)
{
if (_records.TryGetValue(bundle.BundleGUID, out RecordFileElement element))
return element;
else
return null;
}
public string GetTempFilePath(PackageBundle bundle)
{
@@ -384,10 +391,10 @@ namespace YooAsset
public EFileVerifyResult VerifyCacheFile(PackageBundle bundle)
{
if (_records.TryGetValue(bundle.BundleGUID, out RecordFileElement wrapper) == false)
if (_records.TryGetValue(bundle.BundleGUID, out RecordFileElement element) == false)
return EFileVerifyResult.CacheNotFound;
EFileVerifyResult result = FileVerifyHelper.FileVerify(wrapper.DataFilePath, wrapper.DataFileSize, wrapper.DataFileCRC, EFileVerifyLevel.High);
EFileVerifyResult result = FileVerifyHelper.FileVerify(element.DataFilePath, element.DataFileSize, element.DataFileCRC, EFileVerifyLevel.High);
return result;
}
public bool WriteCacheBundleFile(PackageBundle bundle, string copyPath)
@@ -427,22 +434,10 @@ namespace YooAsset
}
public bool DeleteCacheBundleFile(string bundleGUID)
{
if (_records.TryGetValue(bundleGUID, out RecordFileElement wrapper))
if (_records.TryGetValue(bundleGUID, out RecordFileElement element))
{
try
{
string dataFilePath = wrapper.DataFilePath;
FileInfo fileInfo = new FileInfo(dataFilePath);
if (fileInfo.Exists)
fileInfo.Directory.Delete(true);
_records.Remove(bundleGUID);
return true;
}
catch (Exception e)
{
YooLogger.Error($"Failed to delete cache file ! {e.Message}");
return false;
}
_records.Remove(bundleGUID);
return element.DeleteFolder();
}
else
{

View File

@@ -1,4 +1,6 @@

using System;
using System.IO;
namespace YooAsset
{
internal class RecordFileElement
@@ -7,7 +9,7 @@ namespace YooAsset
public string DataFilePath { private set; get; }
public string DataFileCRC { private set; get; }
public long DataFileSize { private set; get; }
public RecordFileElement(string infoFilePath, string dataFilePath, string dataFileCRC, long dataFileSize)
{
InfoFilePath = infoFilePath;
@@ -15,5 +17,31 @@ namespace YooAsset
DataFileCRC = dataFileCRC;
DataFileSize = dataFileSize;
}
/// <summary>
/// 删除记录文件
/// </summary>
public bool DeleteFolder()
{
try
{
string directory = Path.GetDirectoryName(InfoFilePath);
DirectoryInfo directoryInfo = new DirectoryInfo(directory);
if (directoryInfo.Exists)
{
directoryInfo.Delete(true);
return true;
}
else
{
return false;
}
}
catch (Exception e)
{
YooLogger.Error($"Failed to delete cache file ! {e.Message}");
return false;
}
}
}
}

View File

@@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using UnityEngine;
namespace YooAsset
@@ -260,9 +261,30 @@ namespace YooAsset
{
if (_fileSystem.Exists(_bundle))
{
DownloadProgress = 1f;
DownloadedBytes = _bundle.FileSize;
_steps = ESteps.LoadCacheRawBundle;
// 注意:缓存的原生文件的格式,可能会在业务端根据需求发生变动!
// 注意:这里需要校验文件格式,如果不一致对本地文件进行修正!
string filePath = _fileSystem.GetCacheBundleFileLoadPath(_bundle);
if (File.Exists(filePath) == false)
{
try
{
var recordFileElement = _fileSystem.GetRecordFileElement(_bundle);
File.Move(recordFileElement.DataFilePath, filePath);
_steps = ESteps.LoadCacheRawBundle;
}
catch (Exception e)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Faild rename raw data file : {e.Message}";
}
}
else
{
DownloadProgress = 1f;
DownloadedBytes = _bundle.FileSize;
_steps = ESteps.LoadCacheRawBundle;
}
}
else
{

View File

@@ -7,9 +7,10 @@ namespace YooAsset
private enum ESteps
{
None,
CheckManifest,
CheckArgs,
GetTagsCacheFiles,
ClearTagsCacheFiles,
GetClearCacheFiles,
ClearFilterCacheFiles,
Done,
}
@@ -29,13 +30,27 @@ namespace YooAsset
}
internal override void InternalStart()
{
_steps = ESteps.CheckArgs;
_steps = ESteps.CheckManifest;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.CheckManifest)
{
if (_manifest == null)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Can not found active package manifest !";
}
else
{
_steps = ESteps.CheckArgs;
}
}
if (_steps == ESteps.CheckArgs)
{
if (_clearParam == null)
@@ -67,17 +82,17 @@ namespace YooAsset
return;
}
_steps = ESteps.GetTagsCacheFiles;
_steps = ESteps.GetClearCacheFiles;
}
if (_steps == ESteps.GetTagsCacheFiles)
if (_steps == ESteps.GetClearCacheFiles)
{
_clearBundleGUIDs = GetTagsBundleGUIDs();
_clearBundleGUIDs = GetBundleGUIDsByTag();
_clearFileTotalCount = _clearBundleGUIDs.Count;
_steps = ESteps.ClearTagsCacheFiles;
_steps = ESteps.ClearFilterCacheFiles;
}
if (_steps == ESteps.ClearTagsCacheFiles)
if (_steps == ESteps.ClearFilterCacheFiles)
{
for (int i = _clearBundleGUIDs.Count - 1; i >= 0; i--)
{
@@ -100,7 +115,7 @@ namespace YooAsset
}
}
}
private List<string> GetTagsBundleGUIDs()
private List<string> GetBundleGUIDsByTag()
{
var allBundleGUIDs = _fileSystem.GetAllCachedBundleGUIDs();
List<string> result = new List<string>(allBundleGUIDs.Count);

View File

@@ -8,6 +8,7 @@ namespace YooAsset
private enum ESteps
{
None,
CheckManifest,
GetUnusedCacheFiles,
ClearUnusedCacheFiles,
Done,
@@ -19,7 +20,7 @@ namespace YooAsset
private int _unusedFileTotalCount = 0;
private ESteps _steps = ESteps.None;
internal ClearUnusedCacheBundleFilesOperation(DefaultCacheFileSystem fileSystem, PackageManifest manifest)
{
_fileSystem = fileSystem;
@@ -27,15 +28,29 @@ namespace YooAsset
}
internal override void InternalStart()
{
_steps = ESteps.GetUnusedCacheFiles;
_steps = ESteps.CheckManifest;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.CheckManifest)
{
if (_manifest == null)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Can not found active package manifest !";
}
else
{
_steps = ESteps.GetUnusedCacheFiles;
}
}
if (_steps == ESteps.GetUnusedCacheFiles)
{
{
_unusedBundleGUIDs = GetUnusedBundleGUIDs();
_unusedFileTotalCount = _unusedBundleGUIDs.Count;
_steps = ESteps.ClearUnusedCacheFiles;

View File

@@ -8,6 +8,7 @@ namespace YooAsset
private enum ESteps
{
None,
CheckManifest,
ClearUnusedCacheFiles,
Done,
}
@@ -24,13 +25,27 @@ namespace YooAsset
}
internal override void InternalStart()
{
_steps = ESteps.ClearUnusedCacheFiles;
_steps = ESteps.CheckManifest;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.CheckManifest)
{
if (_manifest == null)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Can not found active package manifest !";
}
else
{
_steps = ESteps.ClearUnusedCacheFiles;
}
}
if (_steps == ESteps.ClearUnusedCacheFiles)
{
try

View File

@@ -92,12 +92,7 @@ namespace YooAsset
if (_fileSystem.AppendFileExtension)
{
string dataFileExtension = FindDataFileExtension(chidDirectory);
if (string.IsNullOrEmpty(dataFileExtension))
{
//注意:覆盖安装的情况下,缓存文件可能会没有后缀格式,需要删除重新下载!
dataFilePath = string.Empty;
}
else
if (string.IsNullOrEmpty(dataFileExtension) == false)
{
dataFilePath += dataFileExtension;
}

View File

@@ -83,6 +83,6 @@ namespace YooAsset
/// 文件系统初始化参数列表
/// 注意:列表最后一个元素作为主文件系统!
/// </summary>
public List<FileSystemParameters> FileSystemParameterList;
public readonly List<FileSystemParameters> FileSystemParameterList = new List<FileSystemParameters>();
}
}

View File

@@ -263,7 +263,7 @@ namespace YooAsset
/// <param name="clearParam">执行参数</param>
public ClearCacheFilesOperation ClearCacheFilesAsync(EFileClearMode clearMode, object clearParam = null)
{
DebugCheckInitialize();
DebugCheckInitialize(false);
var operation = _playModeImpl.ClearCacheFilesAsync(clearMode.ToString(), clearParam);
OperationSystem.StartOperation(PackageName, operation);
return operation;
@@ -276,7 +276,7 @@ namespace YooAsset
/// <param name="clearParam">执行参数</param>
public ClearCacheFilesOperation ClearCacheFilesAsync(string clearMode, object clearParam = null)
{
DebugCheckInitialize();
DebugCheckInitialize(false);
var operation = _playModeImpl.ClearCacheFilesAsync(clearMode, clearParam);
OperationSystem.StartOperation(PackageName, operation);
return operation;

View File

@@ -3,9 +3,6 @@ using System.IO;
using System.Text;
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.U2D;
using UnityEngine.TestTools;
using NUnit.Framework;
using YooAsset;
@@ -231,6 +228,7 @@ public class WebFileStreamDecryption : IWebDecryptionServices
{
public WebDecryptResult LoadAssetBundle(WebDecryptFileInfo fileInfo)
{
/*
byte[] copyData = new byte[fileInfo.FileData.Length];
Buffer.BlockCopy(fileInfo.FileData, 0, copyData, 0, fileInfo.FileData.Length);
@@ -242,5 +240,15 @@ public class WebFileStreamDecryption : IWebDecryptionServices
WebDecryptResult decryptResult = new WebDecryptResult();
decryptResult.Result = AssetBundle.LoadFromMemory(copyData);
return decryptResult;
*/
for (int i = 0; i < fileInfo.FileData.Length; i++)
{
fileInfo.FileData[i] ^= BundleStream.KEY;
}
WebDecryptResult decryptResult = new WebDecryptResult();
decryptResult.Result = AssetBundle.LoadFromMemory(fileInfo.FileData);
return decryptResult;
}
}

View File

@@ -1,7 +1,7 @@
{
"name": "com.tuyoogame.yooasset",
"displayName": "YooAsset",
"version": "2.3.4-preview",
"version": "2.3.5-preview",
"unity": "2019.4",
"description": "unity3d resources management system.",
"author": {