update file system
This commit is contained in:
+1
-1
@@ -45,7 +45,7 @@ namespace YooAsset
|
||||
for (int i = _allBundleGUIDs.Count - 1; i >= 0; i--)
|
||||
{
|
||||
string bundleGUID = _allBundleGUIDs[i];
|
||||
_fileSystem.DeleteFile(bundleGUID);
|
||||
_fileSystem.DeleteCacheFile(bundleGUID);
|
||||
_allBundleGUIDs.RemoveAt(i);
|
||||
if (OperationSystem.IsBusy)
|
||||
break;
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ namespace YooAsset
|
||||
for (int i = _unusedBundleGUIDs.Count - 1; i >= 0; i--)
|
||||
{
|
||||
string bundleGUID = _unusedBundleGUIDs[i];
|
||||
_fileSystem.DeleteFile(bundleGUID);
|
||||
_fileSystem.DeleteCacheFile(bundleGUID);
|
||||
_unusedBundleGUIDs.RemoveAt(i);
|
||||
if (OperationSystem.IsBusy)
|
||||
break;
|
||||
|
||||
+21
-37
@@ -8,17 +8,18 @@ namespace YooAsset
|
||||
{
|
||||
private readonly DefaultCacheFileSystem _fileSystem;
|
||||
private VerifyTempFileOperation _verifyOperation;
|
||||
private string _fileSavePath;
|
||||
private string _tempFilePath;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal DCFSDownloadNormalFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle, string mainURL, string fallbackURL, int failedTryAgain, int timeout)
|
||||
internal DCFSDownloadNormalFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle,
|
||||
string mainURL, string fallbackURL, int failedTryAgain, int timeout)
|
||||
: base(bundle, mainURL, fallbackURL, failedTryAgain, timeout)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_fileSavePath = _fileSystem.GetTempFilePath(Bundle);
|
||||
_tempFilePath = _fileSystem.GetTempFilePath(Bundle);
|
||||
_steps = ESteps.CheckExists;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
@@ -43,26 +44,17 @@ namespace YooAsset
|
||||
// 创建下载器
|
||||
if (_steps == ESteps.CreateRequest)
|
||||
{
|
||||
FileUtility.CreateFileDirectory(_fileSavePath);
|
||||
FileUtility.CreateFileDirectory(_tempFilePath);
|
||||
|
||||
// 删除临时文件
|
||||
if (File.Exists(_tempFilePath))
|
||||
File.Delete(_tempFilePath);
|
||||
|
||||
// 获取请求地址
|
||||
_requestURL = GetRequestURL();
|
||||
|
||||
// 重置变量
|
||||
_isAbort = false;
|
||||
_latestDownloadBytes = 0;
|
||||
_latestDownloadRealtime = Time.realtimeSinceStartup;
|
||||
DownloadProgress = 0f;
|
||||
DownloadedBytes = 0;
|
||||
|
||||
// 重置计时器
|
||||
if (_tryAgainTimer > 0f)
|
||||
YooLogger.Warning($"Try again download : {_requestURL}");
|
||||
_tryAgainTimer = 0f;
|
||||
|
||||
// 删除临时文件
|
||||
if (File.Exists(_fileSavePath))
|
||||
File.Delete(_fileSavePath);
|
||||
// 重置请求
|
||||
ResetRequestFiled();
|
||||
|
||||
// 创建下载器
|
||||
CreateWebRequest();
|
||||
@@ -95,7 +87,7 @@ namespace YooAsset
|
||||
// 验证下载文件
|
||||
if (_steps == ESteps.VerifyTempFile)
|
||||
{
|
||||
var element = new TempFileElement(_fileSavePath, Bundle.FileCRC, Bundle.FileSize);
|
||||
var element = new TempFileElement(_tempFilePath, Bundle.FileCRC, Bundle.FileSize);
|
||||
_verifyOperation = new VerifyTempFileOperation(element);
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, _verifyOperation);
|
||||
_steps = ESteps.CheckVerifyTempFile;
|
||||
@@ -111,7 +103,7 @@ namespace YooAsset
|
||||
|
||||
if (_verifyOperation.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
if (_fileSystem.WriteFile(Bundle, _fileSavePath))
|
||||
if (_fileSystem.WriteCacheFile(Bundle, _tempFilePath))
|
||||
{
|
||||
Status = EOperationStatus.Succeed;
|
||||
_steps = ESteps.Done;
|
||||
@@ -131,8 +123,8 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
// 注意:验证完成后直接删除文件
|
||||
if (File.Exists(_fileSavePath))
|
||||
File.Delete(_fileSavePath);
|
||||
if (File.Exists(_tempFilePath))
|
||||
File.Delete(_tempFilePath);
|
||||
}
|
||||
|
||||
// 重新尝试下载
|
||||
@@ -183,7 +175,7 @@ namespace YooAsset
|
||||
private void CreateWebRequest()
|
||||
{
|
||||
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
||||
DownloadHandlerFile handler = new DownloadHandlerFile(_fileSavePath);
|
||||
DownloadHandlerFile handler = new DownloadHandlerFile(_tempFilePath);
|
||||
handler.removeFileOnAbort = true;
|
||||
_webRequest.downloadHandler = handler;
|
||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||
@@ -210,7 +202,8 @@ namespace YooAsset
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
internal DCFSDownloadResumeFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle, string mainURL, string fallbackURL, int failedTryAgain, int timeout)
|
||||
internal DCFSDownloadResumeFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle,
|
||||
string mainURL, string fallbackURL, int failedTryAgain, int timeout)
|
||||
: base(bundle, mainURL, fallbackURL, failedTryAgain, timeout)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
@@ -248,19 +241,10 @@ namespace YooAsset
|
||||
_requestURL = GetRequestURL();
|
||||
|
||||
// 重置变量
|
||||
_isAbort = false;
|
||||
_latestDownloadBytes = 0;
|
||||
_latestDownloadRealtime = Time.realtimeSinceStartup;
|
||||
_fileOriginLength = 0;
|
||||
DownloadProgress = 0f;
|
||||
DownloadedBytes = 0;
|
||||
|
||||
// 重置计时器
|
||||
if (_tryAgainTimer > 0f)
|
||||
YooLogger.Warning($"Try again download : {_requestURL}");
|
||||
_tryAgainTimer = 0f;
|
||||
ResetRequestFiled();
|
||||
|
||||
// 获取下载起始位置
|
||||
_fileOriginLength = 0;
|
||||
long fileBeginLength = -1;
|
||||
if (File.Exists(_fileSavePath))
|
||||
{
|
||||
@@ -325,7 +309,7 @@ namespace YooAsset
|
||||
|
||||
if (_verifyOperation.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
if (_fileSystem.WriteFile(Bundle, _fileSavePath))
|
||||
if (_fileSystem.WriteCacheFile(Bundle, _fileSavePath))
|
||||
{
|
||||
Status = EOperationStatus.Succeed;
|
||||
_steps = ESteps.Done;
|
||||
|
||||
+4
-4
@@ -29,7 +29,7 @@ namespace YooAsset
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
if (_fileSystem.CheckNeedDownload(_bundle))
|
||||
if (_fileSystem.NeedDownload(_bundle))
|
||||
{
|
||||
_steps = ESteps.DownloadFile;
|
||||
}
|
||||
@@ -112,7 +112,7 @@ namespace YooAsset
|
||||
{
|
||||
// 注意:当缓存文件的校验等级为Low的时候,并不能保证缓存文件的完整性。
|
||||
// 说明:在AssetBundle文件加载失败的情况下,我们需要重新验证文件的完整性!
|
||||
EFileVerifyResult result = _fileSystem.VerifyFile(_bundle);
|
||||
EFileVerifyResult result = _fileSystem.VerifyCacheFile(_bundle);
|
||||
if (result == EFileVerifyResult.Succeed)
|
||||
{
|
||||
// 注意:在安卓移动平台,华为和三星真机上有极小概率加载资源包失败。
|
||||
@@ -146,7 +146,7 @@ namespace YooAsset
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
_fileSystem.DeleteFile(_bundle);
|
||||
_fileSystem.DeleteCacheFile(_bundle.BundleGUID);
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Find corrupted file and delete the file : {_bundle.BundleName}";
|
||||
YooLogger.Error(Error);
|
||||
@@ -215,7 +215,7 @@ namespace YooAsset
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
if (_fileSystem.CheckNeedDownload(_bundle))
|
||||
if (_fileSystem.NeedDownload(_bundle))
|
||||
{
|
||||
_steps = ESteps.DownloadFile;
|
||||
}
|
||||
|
||||
+1
-1
@@ -81,7 +81,7 @@ namespace YooAsset
|
||||
foreach (var chidDirectory in childDirectories)
|
||||
{
|
||||
string bundleGUID = chidDirectory.Name;
|
||||
if (_fileSystem.Exists(bundleGUID))
|
||||
if (_fileSystem.IsRecordFile(bundleGUID))
|
||||
continue;
|
||||
|
||||
// 创建验证元素类
|
||||
|
||||
+1
-1
@@ -159,7 +159,7 @@ namespace YooAsset
|
||||
{
|
||||
_succeedCount++;
|
||||
var fileWrapper = new DefaultCacheFileSystem.FileWrapper(element.InfoFilePath, element.DataFilePath, element.DataFileCRC, element.DataFileSize);
|
||||
_fileSystem.Record(element.BundleGUID, fileWrapper);
|
||||
_fileSystem.RecordFile(element.BundleGUID, fileWrapper);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user