refactor : default cache file system

pull/332/merge
何冠峰 2024-12-12 17:35:42 +08:00
parent 9607d7135b
commit 97f9a3d4b1
15 changed files with 333 additions and 277 deletions

View File

@ -9,6 +9,21 @@ namespace YooAsset
/// </summary> /// </summary>
string GetCacheFileRoot(); string GetCacheFileRoot();
/// <summary>
/// 获取临时缓存文件路径
/// </summary>
string GetTempFilePath(PackageBundle bundle);
/// <summary>
/// 获取数据文件路径
/// </summary>
string GetDataFilePath(PackageBundle bundle);
/// <summary>
/// 获取信息文件路径
/// </summary>
string GetInfoFilePath(PackageBundle bundle);
/// <summary> /// <summary>
/// 获取所有缓存文件的GUID /// 获取所有缓存文件的GUID
/// </summary> /// </summary>

View File

@ -0,0 +1,199 @@
using System.IO;
using UnityEngine;
using UnityEngine.Networking;
namespace YooAsset
{
internal sealed class DownloadNormalFileOperation : DefaultDownloadFileOperation
{
private readonly IFileSystem _fileSystem;
private readonly ICacheSystem _cacheSystem;
private VerifyTempFileOperation _verifyOperation;
private string _tempFilePath;
private ESteps _steps = ESteps.None;
internal DownloadNormalFileOperation(IFileSystem fileSystem, ICacheSystem cacheSystem, PackageBundle bundle, DownloadParam param) : base(bundle, param)
{
_fileSystem = fileSystem;
_cacheSystem = cacheSystem;
}
internal override void InternalOnStart()
{
_tempFilePath = _cacheSystem.GetTempFilePath(Bundle);
_steps = ESteps.CheckExists;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
// 检测文件是否存在
if (_steps == ESteps.CheckExists)
{
if (_fileSystem.Exists(Bundle))
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.CreateRequest;
}
}
// 创建下载器
if (_steps == ESteps.CreateRequest)
{
FileUtility.CreateFileDirectory(_tempFilePath);
// 删除临时文件
if (File.Exists(_tempFilePath))
File.Delete(_tempFilePath);
// 获取请求地址
_requestURL = GetRequestURL();
// 重置请求
ResetRequestFiled();
// 创建下载器
CreateWebRequest();
_steps = ESteps.CheckRequest;
}
// 检测下载结果
if (_steps == ESteps.CheckRequest)
{
DownloadProgress = _webRequest.downloadProgress;
DownloadedBytes = (long)_webRequest.downloadedBytes;
Progress = DownloadProgress;
if (_webRequest.isDone == false)
{
CheckRequestTimeout();
return;
}
// 检查网络错误
if (CheckRequestResult())
_steps = ESteps.VerifyTempFile;
else
_steps = ESteps.TryAgain;
// 注意:最终释放请求器
DisposeWebRequest();
}
// 验证下载文件
if (_steps == ESteps.VerifyTempFile)
{
var element = new TempFileElement(_tempFilePath, Bundle.FileCRC, Bundle.FileSize);
_verifyOperation = new VerifyTempFileOperation(element);
OperationSystem.StartOperation(_fileSystem.PackageName, _verifyOperation);
_steps = ESteps.CheckVerifyTempFile;
}
// 等待验证完成
if (_steps == ESteps.CheckVerifyTempFile)
{
if (IsWaitForAsyncComplete)
_verifyOperation.WaitForAsyncComplete();
if (_verifyOperation.IsDone == false)
return;
if (_verifyOperation.Status == EOperationStatus.Succeed)
{
if (_cacheSystem.WriteCacheFile(Bundle, _tempFilePath))
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"{_fileSystem.GetType().FullName} failed to write file !";
YooLogger.Error(Error);
}
}
else
{
_steps = ESteps.TryAgain;
Error = _verifyOperation.Error;
}
// 注意:验证完成后直接删除文件
if (File.Exists(_tempFilePath))
File.Delete(_tempFilePath);
}
// 重新尝试下载
if (_steps == ESteps.TryAgain)
{
if (FailedTryAgain <= 0)
{
Status = EOperationStatus.Failed;
_steps = ESteps.Done;
YooLogger.Error(Error);
return;
}
_tryAgainTimer += Time.unscaledDeltaTime;
if (_tryAgainTimer > 1f)
{
FailedTryAgain--;
_steps = ESteps.CreateRequest;
YooLogger.Warning(Error);
}
}
}
internal override void InternalOnAbort()
{
_steps = ESteps.Done;
DisposeWebRequest();
}
internal override void InternalWaitForAsyncComplete()
{
bool isReuqestLocalFile = IsRequestLocalFile();
while (true)
{
// 注意:如果是导入或解压本地文件,执行等待完毕
if (isReuqestLocalFile)
{
InternalOnUpdate();
if (IsDone)
break;
}
else
{
if (ExecuteWhileDone())
{
_steps = ESteps.Done;
break;
}
}
}
}
private void CreateWebRequest()
{
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
DownloadHandlerFile handler = new DownloadHandlerFile(_tempFilePath);
handler.removeFileOnAbort = true;
_webRequest.downloadHandler = handler;
_webRequest.disposeDownloadHandlerOnDispose = true;
_webRequest.SendWebRequest();
}
private void DisposeWebRequest()
{
if (_webRequest != null)
{
//注意引擎底层会自动调用Abort方法
_webRequest.Dispose();
_webRequest = null;
}
}
}
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: d6f813e2460f55e4ba3f54527e6999e3 guid: 759967d543776a0469b625eff171d235
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@ -1,203 +1,15 @@
using System.IO; using System.Collections.Generic;
using System.IO;
using UnityEngine; using UnityEngine;
using UnityEngine.Networking; using UnityEngine.Networking;
namespace YooAsset namespace YooAsset
{ {
internal sealed class DCFSDownloadNormalFileOperation : DefaultDownloadFileOperation internal sealed class DownloadResumeFileOperation : DefaultDownloadFileOperation
{ {
private readonly DefaultCacheFileSystem _fileSystem; private readonly IFileSystem _fileSystem;
private VerifyTempFileOperation _verifyOperation; private readonly ICacheSystem _cacheSystem;
private string _tempFilePath; private readonly List<long> _responseCodes;
private ESteps _steps = ESteps.None;
internal DCFSDownloadNormalFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle, DownloadParam param) : base(bundle, param)
{
_fileSystem = fileSystem;
}
internal override void InternalOnStart()
{
_tempFilePath = _fileSystem.GetTempFilePath(Bundle);
_steps = ESteps.CheckExists;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
// 检测文件是否存在
if (_steps == ESteps.CheckExists)
{
if (_fileSystem.Exists(Bundle))
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.CreateRequest;
}
}
// 创建下载器
if (_steps == ESteps.CreateRequest)
{
FileUtility.CreateFileDirectory(_tempFilePath);
// 删除临时文件
if (File.Exists(_tempFilePath))
File.Delete(_tempFilePath);
// 获取请求地址
_requestURL = GetRequestURL();
// 重置请求
ResetRequestFiled();
// 创建下载器
CreateWebRequest();
_steps = ESteps.CheckRequest;
}
// 检测下载结果
if (_steps == ESteps.CheckRequest)
{
DownloadProgress = _webRequest.downloadProgress;
DownloadedBytes = (long)_webRequest.downloadedBytes;
Progress = DownloadProgress;
if (_webRequest.isDone == false)
{
CheckRequestTimeout();
return;
}
// 检查网络错误
if (CheckRequestResult())
_steps = ESteps.VerifyTempFile;
else
_steps = ESteps.TryAgain;
// 注意:最终释放请求器
DisposeWebRequest();
}
// 验证下载文件
if (_steps == ESteps.VerifyTempFile)
{
var element = new TempFileElement(_tempFilePath, Bundle.FileCRC, Bundle.FileSize);
_verifyOperation = new VerifyTempFileOperation(element);
OperationSystem.StartOperation(_fileSystem.PackageName, _verifyOperation);
_steps = ESteps.CheckVerifyTempFile;
}
// 等待验证完成
if (_steps == ESteps.CheckVerifyTempFile)
{
if (IsWaitForAsyncComplete)
_verifyOperation.WaitForAsyncComplete();
if (_verifyOperation.IsDone == false)
return;
if (_verifyOperation.Status == EOperationStatus.Succeed)
{
if (_fileSystem.WriteCacheFile(Bundle, _tempFilePath))
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"{_fileSystem.GetType().FullName} failed to write file !";
YooLogger.Error(Error);
}
}
else
{
_steps = ESteps.TryAgain;
Error = _verifyOperation.Error;
}
// 注意:验证完成后直接删除文件
if (File.Exists(_tempFilePath))
File.Delete(_tempFilePath);
}
// 重新尝试下载
if (_steps == ESteps.TryAgain)
{
if (FailedTryAgain <= 0)
{
Status = EOperationStatus.Failed;
_steps = ESteps.Done;
YooLogger.Error(Error);
return;
}
_tryAgainTimer += Time.unscaledDeltaTime;
if (_tryAgainTimer > 1f)
{
FailedTryAgain--;
_steps = ESteps.CreateRequest;
YooLogger.Warning(Error);
}
}
}
internal override void InternalOnAbort()
{
_steps = ESteps.Done;
DisposeWebRequest();
}
internal override void InternalWaitForAsyncComplete()
{
bool isReuqestLocalFile = IsRequestLocalFile();
while (true)
{
// 注意:如果是导入或解压本地文件,执行等待完毕
if (isReuqestLocalFile)
{
InternalOnUpdate();
if (IsDone)
break;
}
else
{
if (ExecuteWhileDone())
{
_steps = ESteps.Done;
break;
}
}
}
}
private void CreateWebRequest()
{
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
DownloadHandlerFile handler = new DownloadHandlerFile(_tempFilePath);
handler.removeFileOnAbort = true;
_webRequest.downloadHandler = handler;
_webRequest.disposeDownloadHandlerOnDispose = true;
_webRequest.SendWebRequest();
}
private void DisposeWebRequest()
{
if (_webRequest != null)
{
//注意引擎底层会自动调用Abort方法
_webRequest.Dispose();
_webRequest = null;
}
}
}
internal sealed class DCFSDownloadResumeFileOperation : DefaultDownloadFileOperation
{
private readonly DefaultCacheFileSystem _fileSystem;
private DownloadHandlerFileRange _downloadHandle; private DownloadHandlerFileRange _downloadHandle;
private VerifyTempFileOperation _verifyOperation; private VerifyTempFileOperation _verifyOperation;
private long _fileOriginLength = 0; private long _fileOriginLength = 0;
@ -205,13 +17,15 @@ namespace YooAsset
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
internal DCFSDownloadResumeFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle, DownloadParam param) : base(bundle, param) internal DownloadResumeFileOperation(IFileSystem fileSystem, ICacheSystem cacheSystem, PackageBundle bundle, DownloadParam param, List<long> responseCodes) : base(bundle, param)
{ {
_fileSystem = fileSystem; _fileSystem = fileSystem;
_cacheSystem = cacheSystem;
_responseCodes = responseCodes;
} }
internal override void InternalOnStart() internal override void InternalOnStart()
{ {
_tempFilePath = _fileSystem.GetTempFilePath(Bundle); _tempFilePath = _cacheSystem.GetTempFilePath(Bundle);
_steps = ESteps.CheckExists; _steps = ESteps.CheckExists;
} }
internal override void InternalOnUpdate() internal override void InternalOnUpdate()
@ -313,7 +127,7 @@ namespace YooAsset
if (_verifyOperation.Status == EOperationStatus.Succeed) if (_verifyOperation.Status == EOperationStatus.Succeed)
{ {
if (_fileSystem.WriteCacheFile(Bundle, _tempFilePath)) if (_cacheSystem.WriteCacheFile(Bundle, _tempFilePath))
{ {
Status = EOperationStatus.Succeed; Status = EOperationStatus.Succeed;
_steps = ESteps.Done; _steps = ESteps.Done;
@ -418,11 +232,11 @@ namespace YooAsset
} }
private void ClearTempFileWhenError() private void ClearTempFileWhenError()
{ {
if (_fileSystem.ResumeDownloadResponseCodes == null) if (_responseCodes == null)
return; return;
//说明:如果遇到以下错误返回码,验证失败直接删除文件 //说明:如果遇到以下错误返回码,验证失败直接删除文件
if (_fileSystem.ResumeDownloadResponseCodes.Contains(HttpCode)) if (_responseCodes.Contains(HttpCode))
{ {
if (File.Exists(_tempFilePath)) if (File.Exists(_tempFilePath))
File.Delete(_tempFilePath); File.Delete(_tempFilePath);

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9bfb785912326f942a31dc77762eb16a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -10,36 +10,6 @@ namespace YooAsset
/// </summary> /// </summary>
internal class DefaultBuildinFileSystem : IFileSystem internal class DefaultBuildinFileSystem : IFileSystem
{ {
private class UnpackRemoteServices : IRemoteServices
{
private readonly string _buildinPackageRoot;
protected readonly Dictionary<string, string> _mapping = new Dictionary<string, string>(10000);
public UnpackRemoteServices(string buildinPackRoot)
{
_buildinPackageRoot = buildinPackRoot;
}
string IRemoteServices.GetRemoteMainURL(string fileName)
{
return GetFileLoadURL(fileName);
}
string IRemoteServices.GetRemoteFallbackURL(string fileName)
{
return GetFileLoadURL(fileName);
}
private string GetFileLoadURL(string fileName)
{
if (_mapping.TryGetValue(fileName, out string url) == false)
{
string filePath = PathUtility.Combine(_buildinPackageRoot, fileName);
url = DownloadSystemHelper.ConvertToWWWPath(filePath);
_mapping.Add(fileName, url);
}
return url;
}
}
public class FileWrapper public class FileWrapper
{ {
public string FileName { private set; get; } public string FileName { private set; get; }
@ -220,7 +190,7 @@ namespace YooAsset
_packageRoot = PathUtility.Combine(rootDirectory, packageName); _packageRoot = PathUtility.Combine(rootDirectory, packageName);
// 创建解压文件系统 // 创建解压文件系统
var remoteServices = new UnpackRemoteServices(_packageRoot); var remoteServices = new DefaultUnpackRemoteServices(_packageRoot);
_unpackFileSystem = new DefaultUnpackFileSystem(); _unpackFileSystem = new DefaultUnpackFileSystem();
_unpackFileSystem.SetParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices); _unpackFileSystem.SetParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices);
_unpackFileSystem.SetParameter(FileSystemParametersDefine.FILE_VERIFY_LEVEL, FileVerifyLevel); _unpackFileSystem.SetParameter(FileSystemParametersDefine.FILE_VERIFY_LEVEL, FileVerifyLevel);
@ -231,6 +201,7 @@ namespace YooAsset
} }
public virtual void OnUpdate() public virtual void OnUpdate()
{ {
_unpackFileSystem.OnUpdate();
} }
public virtual bool Belong(PackageBundle bundle) public virtual bool Belong(PackageBundle bundle)

View File

@ -12,13 +12,14 @@ namespace YooAsset
/// </summary> /// </summary>
internal class DefaultCacheFileSystem : IFileSystem, ICacheSystem internal class DefaultCacheFileSystem : IFileSystem, ICacheSystem
{ {
protected readonly Dictionary<string, DefaultDownloadFileOperation> _downloaders = new Dictionary<string, DefaultDownloadFileOperation>(1000);
protected readonly Dictionary<string, CacheWrapper> _wrappers = new Dictionary<string, CacheWrapper>(10000); protected readonly Dictionary<string, CacheWrapper> _wrappers = new Dictionary<string, CacheWrapper>(10000);
protected readonly Dictionary<string, Stream> _loadedStream = new Dictionary<string, Stream>(10000); protected readonly Dictionary<string, Stream> _loadedStream = new Dictionary<string, Stream>(10000);
protected readonly Dictionary<string, string> _dataFilePaths = new Dictionary<string, string>(10000); protected readonly Dictionary<string, string> _dataFilePaths = new Dictionary<string, string>(10000);
protected readonly Dictionary<string, string> _infoFilePaths = new Dictionary<string, string>(10000); protected readonly Dictionary<string, string> _infoFilePaths = new Dictionary<string, string>(10000);
protected readonly Dictionary<string, string> _tempFilePaths = new Dictionary<string, string>(10000); protected readonly Dictionary<string, string> _tempFilePaths = new Dictionary<string, string>(10000);
protected readonly Dictionary<string, DefaultDownloadFileOperation> _downloaders = new Dictionary<string, DefaultDownloadFileOperation>(1000);
protected readonly List<string> _removeList = new List<string>(1000); protected readonly List<string> _removeList = new List<string>(1000);
protected string _packageRoot; protected string _packageRoot;
protected string _cacheFileRoot; protected string _cacheFileRoot;
protected string _tempFileRoot; protected string _tempFileRoot;
@ -147,7 +148,7 @@ namespace YooAsset
if (bundle.FileSize >= ResumeDownloadMinimumSize) if (bundle.FileSize >= ResumeDownloadMinimumSize)
{ {
var newDownloader = new DCFSDownloadResumeFileOperation(this, bundle, param); var newDownloader = new DownloadResumeFileOperation(this, this, bundle, param, ResumeDownloadResponseCodes);
newDownloader.Reference(); newDownloader.Reference();
_downloaders.Add(bundle.BundleGUID, newDownloader); _downloaders.Add(bundle.BundleGUID, newDownloader);
OperationSystem.StartOperation(PackageName, newDownloader); OperationSystem.StartOperation(PackageName, newDownloader);
@ -155,7 +156,7 @@ namespace YooAsset
} }
else else
{ {
var newDownloader = new DCFSDownloadNormalFileOperation(this, bundle, param); var newDownloader = new DownloadNormalFileOperation(this, this, bundle, param);
newDownloader.Reference(); newDownloader.Reference();
_downloaders.Add(bundle.BundleGUID, newDownloader); _downloaders.Add(bundle.BundleGUID, newDownloader);
OperationSystem.StartOperation(PackageName, newDownloader); OperationSystem.StartOperation(PackageName, newDownloader);
@ -361,6 +362,37 @@ namespace YooAsset
{ {
return _cacheFileRoot; return _cacheFileRoot;
} }
public string GetTempFilePath(PackageBundle bundle)
{
if (_tempFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false)
{
filePath = PathUtility.Combine(_tempFileRoot, bundle.BundleGUID);
_tempFilePaths.Add(bundle.BundleGUID, filePath);
}
return filePath;
}
public string GetDataFilePath(PackageBundle bundle)
{
if (_dataFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false)
{
string folderName = bundle.FileHash.Substring(0, 2);
filePath = PathUtility.Combine(_cacheFileRoot, folderName, bundle.BundleGUID, DefaultCacheFileSystemDefine.SaveBundleDataFileName);
if (AppendFileExtension)
filePath += bundle.FileExtension;
_dataFilePaths.Add(bundle.BundleGUID, filePath);
}
return filePath;
}
public string GetInfoFilePath(PackageBundle bundle)
{
if (_infoFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false)
{
string folderName = bundle.FileHash.Substring(0, 2);
filePath = PathUtility.Combine(_cacheFileRoot, folderName, bundle.BundleGUID, DefaultCacheFileSystemDefine.SaveBundleInfoFileName);
_infoFilePaths.Add(bundle.BundleGUID, filePath);
}
return filePath;
}
public List<string> GetAllCachedBundleGUIDs() public List<string> GetAllCachedBundleGUIDs()
{ {
return _wrappers.Keys.ToList(); return _wrappers.Keys.ToList();
@ -472,37 +504,6 @@ namespace YooAsset
#endregion #endregion
#region 内部方法 #region 内部方法
protected string GetDataFilePath(PackageBundle bundle)
{
if (_dataFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false)
{
string folderName = bundle.FileHash.Substring(0, 2);
filePath = PathUtility.Combine(_cacheFileRoot, folderName, bundle.BundleGUID, DefaultCacheFileSystemDefine.SaveBundleDataFileName);
if (AppendFileExtension)
filePath += bundle.FileExtension;
_dataFilePaths.Add(bundle.BundleGUID, filePath);
}
return filePath;
}
protected string GetInfoFilePath(PackageBundle bundle)
{
if (_infoFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false)
{
string folderName = bundle.FileHash.Substring(0, 2);
filePath = PathUtility.Combine(_cacheFileRoot, folderName, bundle.BundleGUID, DefaultCacheFileSystemDefine.SaveBundleInfoFileName);
_infoFilePaths.Add(bundle.BundleGUID, filePath);
}
return filePath;
}
public string GetTempFilePath(PackageBundle bundle)
{
if (_tempFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false)
{
filePath = PathUtility.Combine(_tempFileRoot, bundle.BundleGUID);
_tempFilePaths.Add(bundle.BundleGUID, filePath);
}
return filePath;
}
public string GetCacheFileLoadPath(PackageBundle bundle) public string GetCacheFileLoadPath(PackageBundle bundle)
{ {
return GetDataFilePath(bundle); return GetDataFilePath(bundle);

View File

@ -12,7 +12,7 @@ namespace YooAsset
Done, Done,
} }
private readonly DefaultCacheFileSystem _fileSytem; private readonly DefaultCacheFileSystem _fileSystem;
private SearchCacheFilesOperation _searchCacheFilesOp; private SearchCacheFilesOperation _searchCacheFilesOp;
private VerifyCacheFilesOperation _verifyCacheFilesOp; private VerifyCacheFilesOperation _verifyCacheFilesOp;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
@ -20,7 +20,7 @@ namespace YooAsset
internal DCFSInitializeOperation(DefaultCacheFileSystem fileSystem) internal DCFSInitializeOperation(DefaultCacheFileSystem fileSystem)
{ {
_fileSytem = fileSystem; _fileSystem = fileSystem;
} }
internal override void InternalOnStart() internal override void InternalOnStart()
{ {
@ -39,14 +39,14 @@ namespace YooAsset
if (_steps == ESteps.CheckAppFootPrint) if (_steps == ESteps.CheckAppFootPrint)
{ {
var appFootPrint = new ApplicationFootPrint(_fileSytem); var appFootPrint = new ApplicationFootPrint(_fileSystem);
appFootPrint.Load(_fileSytem.PackageName); appFootPrint.Load(_fileSystem.PackageName);
// 如果水印发生变化,则说明覆盖安装后首次打开游戏 // 如果水印发生变化,则说明覆盖安装后首次打开游戏
if (appFootPrint.IsDirty()) if (appFootPrint.IsDirty())
{ {
_fileSytem.DeleteAllManifestFiles(); _fileSystem.DeleteAllManifestFiles();
appFootPrint.Coverage(_fileSytem.PackageName); appFootPrint.Coverage(_fileSystem.PackageName);
YooLogger.Warning("Delete manifest files when application foot print dirty !"); YooLogger.Warning("Delete manifest files when application foot print dirty !");
} }
@ -57,8 +57,8 @@ namespace YooAsset
{ {
if (_searchCacheFilesOp == null) if (_searchCacheFilesOp == null)
{ {
_searchCacheFilesOp = new SearchCacheFilesOperation(_fileSytem, _fileSytem.PackageName, _fileSytem.AppendFileExtension); _searchCacheFilesOp = new SearchCacheFilesOperation(_fileSystem, _fileSystem.PackageName, _fileSystem.AppendFileExtension);
OperationSystem.StartOperation(_fileSytem.PackageName, _searchCacheFilesOp); OperationSystem.StartOperation(_fileSystem.PackageName, _searchCacheFilesOp);
} }
Progress = _searchCacheFilesOp.Progress; Progress = _searchCacheFilesOp.Progress;
@ -72,8 +72,8 @@ namespace YooAsset
{ {
if (_verifyCacheFilesOp == null) if (_verifyCacheFilesOp == null)
{ {
_verifyCacheFilesOp = new VerifyCacheFilesOperation(_fileSytem, _fileSytem.FileVerifyLevel, _searchCacheFilesOp.Result); _verifyCacheFilesOp = new VerifyCacheFilesOperation(_fileSystem, _fileSystem.FileVerifyLevel, _searchCacheFilesOp.Result);
OperationSystem.StartOperation(_fileSytem.PackageName, _verifyCacheFilesOp); OperationSystem.StartOperation(_fileSystem.PackageName, _verifyCacheFilesOp);
} }
Progress = _verifyCacheFilesOp.Progress; Progress = _verifyCacheFilesOp.Progress;
@ -84,7 +84,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Succeed; Status = EOperationStatus.Succeed;
YooLogger.Log($"Package '{_fileSytem.PackageName}' cached files count : {_fileSytem.FileCount}"); YooLogger.Log($"Package '{_fileSystem.PackageName}' cached files count : {_fileSystem.FileCount}");
} }
else else
{ {

View File

@ -14,7 +14,7 @@ namespace YooAsset
base.OnCreate(packageName, rootDirectory); base.OnCreate(packageName, rootDirectory);
// 注意:重写保存根目录和临时目录 // 注意:重写保存根目录和临时目录
_saveFileRoot = PathUtility.Combine(_packageRoot, DefaultUnpackFileSystemDefine.SaveFilesFolderName); _cacheFileRoot = PathUtility.Combine(_packageRoot, DefaultUnpackFileSystemDefine.SaveFilesFolderName);
_tempFileRoot = PathUtility.Combine(_packageRoot, DefaultUnpackFileSystemDefine.TempFilesFolderName); _tempFileRoot = PathUtility.Combine(_packageRoot, DefaultUnpackFileSystemDefine.TempFilesFolderName);
} }
} }

View File

@ -0,0 +1,34 @@
using System.Collections.Generic;
namespace YooAsset
{
internal class DefaultUnpackRemoteServices : IRemoteServices
{
private readonly string _buildinPackageRoot;
protected readonly Dictionary<string, string> _mapping = new Dictionary<string, string>(10000);
public DefaultUnpackRemoteServices(string buildinPackRoot)
{
_buildinPackageRoot = buildinPackRoot;
}
string IRemoteServices.GetRemoteMainURL(string fileName)
{
return GetFileLoadURL(fileName);
}
string IRemoteServices.GetRemoteFallbackURL(string fileName)
{
return GetFileLoadURL(fileName);
}
private string GetFileLoadURL(string fileName)
{
if (_mapping.TryGetValue(fileName, out string url) == false)
{
string filePath = PathUtility.Combine(_buildinPackageRoot, fileName);
url = DownloadSystemHelper.ConvertToWWWPath(filePath);
_mapping.Add(fileName, url);
}
return url;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 32c355598c9dff847af87f4a867a2d5c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: