Compare commits

...

4 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
10 changed files with 139 additions and 45 deletions

View File

@@ -2,6 +2,15 @@
All notable changes to this package will be documented in this file. 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 ## [2.3.4-preview] - 2025-03-08
### Improvements ### Improvements

View File

@@ -333,6 +333,13 @@ namespace YooAsset
{ {
return _records.Keys.ToList(); 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) public string GetTempFilePath(PackageBundle bundle)
{ {
@@ -384,10 +391,10 @@ namespace YooAsset
public EFileVerifyResult VerifyCacheFile(PackageBundle bundle) 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; 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; return result;
} }
public bool WriteCacheBundleFile(PackageBundle bundle, string copyPath) public bool WriteCacheBundleFile(PackageBundle bundle, string copyPath)
@@ -427,22 +434,10 @@ namespace YooAsset
} }
public bool DeleteCacheBundleFile(string bundleGUID) public bool DeleteCacheBundleFile(string bundleGUID)
{ {
if (_records.TryGetValue(bundleGUID, out RecordFileElement wrapper)) if (_records.TryGetValue(bundleGUID, out RecordFileElement element))
{ {
try _records.Remove(bundleGUID);
{ return element.DeleteFolder();
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;
}
} }
else else
{ {

View File

@@ -1,4 +1,6 @@
 using System;
using System.IO;
namespace YooAsset namespace YooAsset
{ {
internal class RecordFileElement internal class RecordFileElement
@@ -7,7 +9,7 @@ namespace YooAsset
public string DataFilePath { private set; get; } public string DataFilePath { private set; get; }
public string DataFileCRC { private set; get; } public string DataFileCRC { private set; get; }
public long DataFileSize { private set; get; } public long DataFileSize { private set; get; }
public RecordFileElement(string infoFilePath, string dataFilePath, string dataFileCRC, long dataFileSize) public RecordFileElement(string infoFilePath, string dataFilePath, string dataFileCRC, long dataFileSize)
{ {
InfoFilePath = infoFilePath; InfoFilePath = infoFilePath;
@@ -15,5 +17,31 @@ namespace YooAsset
DataFileCRC = dataFileCRC; DataFileCRC = dataFileCRC;
DataFileSize = dataFileSize; 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; using UnityEngine;
namespace YooAsset namespace YooAsset
@@ -260,9 +261,30 @@ namespace YooAsset
{ {
if (_fileSystem.Exists(_bundle)) 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 else
{ {

View File

@@ -7,9 +7,10 @@ namespace YooAsset
private enum ESteps private enum ESteps
{ {
None, None,
CheckManifest,
CheckArgs, CheckArgs,
GetTagsCacheFiles, GetClearCacheFiles,
ClearTagsCacheFiles, ClearFilterCacheFiles,
Done, Done,
} }
@@ -29,13 +30,27 @@ namespace YooAsset
} }
internal override void InternalStart() internal override void InternalStart()
{ {
_steps = ESteps.CheckArgs; _steps = ESteps.CheckManifest;
} }
internal override void InternalUpdate() internal override void InternalUpdate()
{ {
if (_steps == ESteps.None || _steps == ESteps.Done) if (_steps == ESteps.None || _steps == ESteps.Done)
return; 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 (_steps == ESteps.CheckArgs)
{ {
if (_clearParam == null) if (_clearParam == null)
@@ -67,17 +82,17 @@ namespace YooAsset
return; return;
} }
_steps = ESteps.GetTagsCacheFiles; _steps = ESteps.GetClearCacheFiles;
} }
if (_steps == ESteps.GetTagsCacheFiles) if (_steps == ESteps.GetClearCacheFiles)
{ {
_clearBundleGUIDs = GetTagsBundleGUIDs(); _clearBundleGUIDs = GetBundleGUIDsByTag();
_clearFileTotalCount = _clearBundleGUIDs.Count; _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--) 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(); var allBundleGUIDs = _fileSystem.GetAllCachedBundleGUIDs();
List<string> result = new List<string>(allBundleGUIDs.Count); List<string> result = new List<string>(allBundleGUIDs.Count);

View File

@@ -8,6 +8,7 @@ namespace YooAsset
private enum ESteps private enum ESteps
{ {
None, None,
CheckManifest,
GetUnusedCacheFiles, GetUnusedCacheFiles,
ClearUnusedCacheFiles, ClearUnusedCacheFiles,
Done, Done,
@@ -19,7 +20,7 @@ namespace YooAsset
private int _unusedFileTotalCount = 0; private int _unusedFileTotalCount = 0;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
internal ClearUnusedCacheBundleFilesOperation(DefaultCacheFileSystem fileSystem, PackageManifest manifest) internal ClearUnusedCacheBundleFilesOperation(DefaultCacheFileSystem fileSystem, PackageManifest manifest)
{ {
_fileSystem = fileSystem; _fileSystem = fileSystem;
@@ -27,15 +28,29 @@ namespace YooAsset
} }
internal override void InternalStart() internal override void InternalStart()
{ {
_steps = ESteps.GetUnusedCacheFiles; _steps = ESteps.CheckManifest;
} }
internal override void InternalUpdate() internal override void InternalUpdate()
{ {
if (_steps == ESteps.None || _steps == ESteps.Done) if (_steps == ESteps.None || _steps == ESteps.Done)
return; 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) if (_steps == ESteps.GetUnusedCacheFiles)
{ {
_unusedBundleGUIDs = GetUnusedBundleGUIDs(); _unusedBundleGUIDs = GetUnusedBundleGUIDs();
_unusedFileTotalCount = _unusedBundleGUIDs.Count; _unusedFileTotalCount = _unusedBundleGUIDs.Count;
_steps = ESteps.ClearUnusedCacheFiles; _steps = ESteps.ClearUnusedCacheFiles;

View File

@@ -8,6 +8,7 @@ namespace YooAsset
private enum ESteps private enum ESteps
{ {
None, None,
CheckManifest,
ClearUnusedCacheFiles, ClearUnusedCacheFiles,
Done, Done,
} }
@@ -24,13 +25,27 @@ namespace YooAsset
} }
internal override void InternalStart() internal override void InternalStart()
{ {
_steps = ESteps.ClearUnusedCacheFiles; _steps = ESteps.CheckManifest;
} }
internal override void InternalUpdate() internal override void InternalUpdate()
{ {
if (_steps == ESteps.None || _steps == ESteps.Done) if (_steps == ESteps.None || _steps == ESteps.Done)
return; 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) if (_steps == ESteps.ClearUnusedCacheFiles)
{ {
try try

View File

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

View File

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

View File

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