update file system

This commit is contained in:
何冠峰
2024-07-05 15:10:07 +08:00
parent db8d09d0d6
commit 75511397d6
54 changed files with 510 additions and 1077 deletions
@@ -25,12 +25,9 @@ namespace YooAsset
protected readonly Dictionary<string, string> _buildinFilePaths = new Dictionary<string, string>(10000);
protected string _packageRoot;
/// <summary>
/// 解压文件系统
/// </summary>
// 解压文件系统
public IFileSystem UnpackFileSystem { private set; get; }
/// <summary>
/// 包裹名称
/// </summary>
@@ -110,27 +107,24 @@ namespace YooAsset
}
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(params object[] args)
{
throw new System.NotImplementedException();
var operation = new DBFSRequestPackageVersionOperation(this);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
public virtual FSClearAllBundleFilesOperation ClearAllBundleFilesAsync(params object[] args)
{
var operation = new DBFSClearAllBundleFilesOperation(this);
OperationSystem.StartOperation(PackageName, operation);
return operation;
return UnpackFileSystem.ClearAllBundleFilesAsync();
}
public virtual FSClearUnusedBundleFilesOperation ClearUnusedBundleFilesAsync(params object[] args)
{
PackageManifest manifest = args[0] as PackageManifest;
var operation = new DBFSClearUnusedBundleFilesOperation(this, manifest);
OperationSystem.StartOperation(PackageName, operation);
return operation;
return UnpackFileSystem.ClearUnusedBundleFilesAsync(manifest);
}
public virtual FSDownloadFileOperation DownloadFileAsync(params object[] args)
{
PackageBundle bundle = args[0] as PackageBundle;
int failedTryAgain = (int)args[2];
int timeout = (int)args[3];
string buidlinFilePath = GetBuildinFileLoadPath(bundle);
return UnpackFileSystem.DownloadFileAsync(bundle, buidlinFilePath, failedTryAgain, timeout);
}
@@ -176,7 +170,7 @@ namespace YooAsset
public virtual bool Belong(PackageBundle bundle)
{
return _wrappers.ContainsKey(bundle.BundleGUID);
return Belong(bundle.BundleGUID);
}
public virtual bool Belong(string bundleGUID)
{
@@ -184,7 +178,7 @@ namespace YooAsset
}
public virtual bool Exists(PackageBundle bundle)
{
return _wrappers.ContainsKey(bundle.BundleGUID);
return Exists(bundle.BundleGUID);
}
public virtual bool Exists(string bundleGUID)
{
@@ -199,7 +193,7 @@ namespace YooAsset
{
if (Belong(bundle) == false)
return false;
#if UNITY_ANDROID
return RawFileBuildPipeline || bundle.Encrypted;
#else
@@ -230,11 +224,11 @@ namespace YooAsset
public virtual byte[] ReadFileBytes(PackageBundle bundle)
{
return UnpackFileSystem.ReadFileBytes(bundle);
throw new System.NotImplementedException();
}
public virtual string ReadFileText(PackageBundle bundle)
{
return UnpackFileSystem.ReadFileText(bundle);
throw new System.NotImplementedException();
}
public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
@@ -1,45 +0,0 @@
namespace YooAsset
{
internal sealed class DBFSClearAllBundleFilesOperation : FSClearAllBundleFilesOperation
{
private enum ESteps
{
None,
ClearUnpackFileSystem,
Done,
}
private readonly DefaultBuildinFileSystem _fileSystem;
private FSClearAllBundleFilesOperation _unpackClearAllBundleFilesOp;
private ESteps _steps = ESteps.None;
internal DBFSClearAllBundleFilesOperation(DefaultBuildinFileSystem fileSystem)
{
_fileSystem = fileSystem;
}
internal override void InternalOnStart()
{
_steps = ESteps.ClearUnpackFileSystem;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.ClearUnpackFileSystem)
{
if (_unpackClearAllBundleFilesOp == null)
_unpackClearAllBundleFilesOp = _fileSystem.UnpackFileSystem.ClearAllBundleFilesAsync();
Progress = _unpackClearAllBundleFilesOp.Progress;
if (_unpackClearAllBundleFilesOp.IsDone == false)
return;
_steps = ESteps.Done;
Status = _unpackClearAllBundleFilesOp.Status;
Error = _unpackClearAllBundleFilesOp.Error;
}
}
}
}
@@ -1,47 +0,0 @@
namespace YooAsset
{
internal sealed class DBFSClearUnusedBundleFilesOperation : FSClearUnusedBundleFilesOperation
{
private enum ESteps
{
None,
ClearUnpackFileSystem,
Done,
}
private readonly DefaultBuildinFileSystem _fileSystem;
private readonly PackageManifest _manifest;
private FSClearUnusedBundleFilesOperation _unpackClearUnusedBundleFilesOp;
private ESteps _steps = ESteps.None;
internal DBFSClearUnusedBundleFilesOperation(DefaultBuildinFileSystem fileSystem, PackageManifest manifest)
{
_fileSystem = fileSystem;
_manifest = manifest;
}
internal override void InternalOnStart()
{
_steps = ESteps.ClearUnpackFileSystem;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.ClearUnpackFileSystem)
{
if (_unpackClearUnusedBundleFilesOp == null)
_unpackClearUnusedBundleFilesOp = _fileSystem.UnpackFileSystem.ClearUnusedBundleFilesAsync(_manifest);
Progress = _unpackClearUnusedBundleFilesOp.Progress;
if (_unpackClearUnusedBundleFilesOp.IsDone == false)
return;
_steps = ESteps.Done;
Status = _unpackClearUnusedBundleFilesOp.Status;
Error = _unpackClearUnusedBundleFilesOp.Error;
}
}
}
}
@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 1e0e1c080b28b3c45b401da4ac06f687
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,57 @@
namespace YooAsset
{
internal class DBFSRequestPackageVersionOperation : FSRequestPackageVersionOperation
{
private enum ESteps
{
None,
GetPackageVersion,
Done,
}
private readonly DefaultBuildinFileSystem _fileSystem;
private RequestBuildinPackageVersionOperation _requestBuildinPackageVersionOp;
private ESteps _steps = ESteps.None;
internal DBFSRequestPackageVersionOperation(DefaultBuildinFileSystem fileSystem)
{
_fileSystem = fileSystem;
}
internal override void InternalOnStart()
{
_steps = ESteps.GetPackageVersion;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.GetPackageVersion)
{
if (_requestBuildinPackageVersionOp == null)
{
_requestBuildinPackageVersionOp = new RequestBuildinPackageVersionOperation(_fileSystem);
OperationSystem.StartOperation(_fileSystem.PackageName, _requestBuildinPackageVersionOp);
}
if (_requestBuildinPackageVersionOp.IsDone == false)
return;
if (_requestBuildinPackageVersionOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
PackageVersion = _requestBuildinPackageVersionOp.PackageVersion;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _requestBuildinPackageVersionOp.Error;
}
}
}
}
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: a16dae8497d54984daa95a3682a7beb4
guid: f0b6ec24639af3741847a6a7ef09986a
MonoImporter:
externalObjects: {}
serializedVersion: 2
@@ -40,7 +40,6 @@ namespace YooAsset
protected string _tempFileRoot;
protected string _manifestFileRoot;
/// <summary>
/// 包裹名称
/// </summary>
@@ -270,17 +269,16 @@ namespace YooAsset
public virtual bool Belong(PackageBundle bundle)
{
// 注意:缓存文件系统保底加载!
return true;
return Belong(bundle.BundleGUID);
}
public virtual bool Belong(string bundleGUID)
{
// 注意:缓存文件系统保底加载!
return true;
}
public virtual bool Exists(PackageBundle packageBundle)
public virtual bool Exists(PackageBundle bundle)
{
return _wrappers.ContainsKey(packageBundle.BundleGUID);
return Exists(bundle.BundleGUID);
}
public virtual bool Exists(string bundleGUID)
{
@@ -19,23 +19,27 @@ namespace YooAsset
internal override void InternalOnStart()
{
_fileSavePath = _fileSystem.GetTempFilePath(Bundle);
// 注意:检测文件是否存在
if (_fileSystem.Exists(Bundle))
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.CreateRequest;
}
_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)
{
@@ -214,23 +218,27 @@ namespace YooAsset
internal override void InternalOnStart()
{
_fileSavePath = _fileSystem.GetTempFilePath(Bundle);
// 注意:检测文件是否存在
if (_fileSystem.Exists(Bundle))
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.CreateRequest;
}
_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)
{
@@ -12,7 +12,6 @@ namespace YooAsset
{
protected string _packageRoot;
/// <summary>
/// 包裹名称
/// </summary>
@@ -53,9 +52,9 @@ namespace YooAsset
#region 自定义参数
/// <summary>
/// 自定义参数:模拟运行的资源清单文件路径
/// 自定义参数:模拟构建结果
/// </summary>
public string SimulateManifestFilePath { private set; get; } = string.Empty;
public SimulateBuildResult BuildResult { private set; get; } = null;
#endregion
@@ -76,33 +75,32 @@ namespace YooAsset
}
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(params object[] args)
{
throw new System.NotImplementedException();
var operation = new DEFSRequestPackageVersionOperation(this);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
public virtual FSClearAllBundleFilesOperation ClearAllBundleFilesAsync(params object[] args)
{
var operation = new DEFSClearAllBundleFilesOperation(this);
var operation = new FSClearAllBundleFilesCompleteOperation();
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
public virtual FSClearUnusedBundleFilesOperation ClearUnusedBundleFilesAsync(params object[] args)
{
var operation = new DEFSClearUnusedBundleFilesOperation(this);
var operation = new FSClearUnusedBundleFilesCompleteOperation();
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
public virtual FSDownloadFileOperation DownloadFileAsync(params object[] args)
{
PackageBundle bundle = args[0] as PackageBundle;
var operation = new DEFSDownloadFileOperation(bundle);
OperationSystem.StartOperation(PackageName, operation);
return operation;
throw new System.NotImplementedException();
}
public virtual void SetParameter(string name, object value)
{
if (name == "SIMULATE_MANIFEST_FILE_PATH")
if (name == "SIMULATE_BUILD_RESULT")
{
SimulateManifestFilePath = (string)value;
BuildResult = (SimulateBuildResult)value;
}
else
{
@@ -1,20 +0,0 @@
namespace YooAsset
{
internal sealed class DEFSClearAllBundleFilesOperation : FSClearAllBundleFilesOperation
{
private readonly DefaultEditorFileSystem _fileSystem;
internal DEFSClearAllBundleFilesOperation(DefaultEditorFileSystem fileSystem)
{
_fileSystem = fileSystem;
}
internal override void InternalOnStart()
{
Status = EOperationStatus.Succeed;
}
internal override void InternalOnUpdate()
{
}
}
}
@@ -1,20 +0,0 @@
namespace YooAsset
{
internal sealed class DEFSClearUnusedBundleFilesOperation : FSClearUnusedBundleFilesOperation
{
private readonly DefaultEditorFileSystem _fileSystem;
internal DEFSClearUnusedBundleFilesOperation(DefaultEditorFileSystem fileSystem)
{
_fileSystem = fileSystem;
}
internal override void InternalOnStart()
{
Status = EOperationStatus.Succeed;
}
internal override void InternalOnUpdate()
{
}
}
}
@@ -1,17 +0,0 @@
namespace YooAsset
{
internal class DEFSDownloadFileOperation : FSDownloadFileOperation
{
internal DEFSDownloadFileOperation(PackageBundle bundle) : base(bundle)
{
}
internal override void InternalOnStart()
{
Status = EOperationStatus.Succeed;
}
internal override void InternalOnUpdate()
{
}
}
}
@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 06a8abe71cf3fe64180ec076a79b4b66
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,57 @@
namespace YooAsset
{
internal class DEFSRequestPackageVersionOperation : FSRequestPackageVersionOperation
{
private enum ESteps
{
None,
GetPackageVersion,
Done,
}
private readonly DefaultEditorFileSystem _fileSystem;
private LoadEditorPackageVersionOperation _loadEditorPackageVersionOp;
private ESteps _steps = ESteps.None;
internal DEFSRequestPackageVersionOperation(DefaultEditorFileSystem fileSystem)
{
_fileSystem = fileSystem;
}
internal override void InternalOnStart()
{
_steps = ESteps.GetPackageVersion;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.GetPackageVersion)
{
if (_loadEditorPackageVersionOp == null)
{
_loadEditorPackageVersionOp = new LoadEditorPackageVersionOperation(_fileSystem);
OperationSystem.StartOperation(_fileSystem.PackageName, _loadEditorPackageVersionOp);
}
if (_loadEditorPackageVersionOp.IsDone == false)
return;
if (_loadEditorPackageVersionOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
PackageVersion = _loadEditorPackageVersionOp.PackageVersion;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _loadEditorPackageVersionOp.Error;
}
}
}
}
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 624ca0ff2f0c7da4bb9c1a1d58e732b1
guid: 47293048f9cde3f46a1b297f1c2e3373
MonoImporter:
externalObjects: {}
serializedVersion: 2
@@ -38,7 +38,7 @@ namespace YooAsset
if (_steps == ESteps.LoadFileData)
{
string manifestFilePath = _fileSystem.SimulateManifestFilePath;
string manifestFilePath = _fileSystem.BuildResult.PackageManifestFilePath;
if (File.Exists(manifestFilePath))
{
_steps = ESteps.LoadManifest;
@@ -48,7 +48,7 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Simulation manifest file not found : {manifestFilePath}";
Error = $"Simulation package manifest file not found : {manifestFilePath}";
}
}
@@ -0,0 +1,51 @@
using System.IO;
namespace YooAsset
{
internal class LoadEditorPackageVersionOperation : AsyncOperationBase
{
private enum ESteps
{
None,
LoadVersion,
Done,
}
private readonly DefaultEditorFileSystem _fileSystem;
private ESteps _steps = ESteps.None;
public string PackageVersion { private set; get; }
internal LoadEditorPackageVersionOperation(DefaultEditorFileSystem fileSystem)
{
_fileSystem = fileSystem;
}
internal override void InternalOnStart()
{
_steps = ESteps.LoadVersion;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.LoadVersion)
{
string versionFilePath = _fileSystem.BuildResult.PackageVersionFilePath;
if (File.Exists(versionFilePath))
{
_steps = ESteps.Done;
PackageVersion = FileUtility.ReadAllText(versionFilePath);
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Simulation package version file not found : {versionFilePath}";
}
}
}
}
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 1f86d3bce4381694b8c619ceda2e7309
guid: a4278d490ca87354ab63b0bece1fdab7
MonoImporter:
externalObjects: {}
serializedVersion: 2
@@ -21,7 +21,6 @@ namespace YooAsset
protected readonly Dictionary<string, string> _webFilePaths = new Dictionary<string, string>(10000);
protected string _webPackageRoot = string.Empty;
/// <summary>
/// 包裹名称
/// </summary>
@@ -115,13 +114,13 @@ namespace YooAsset
}
public virtual FSClearAllBundleFilesOperation ClearAllBundleFilesAsync(params object[] args)
{
var operation = new DWFSClearAllBundleFilesOperation(this);
var operation = new FSClearAllBundleFilesCompleteOperation();
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
public virtual FSClearUnusedBundleFilesOperation ClearUnusedBundleFilesAsync(params object[] args)
{
var operation = new DWFSClearUnusedBundleFilesOperation(this);
var operation = new FSClearUnusedBundleFilesCompleteOperation();
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
@@ -1,20 +0,0 @@
namespace YooAsset
{
internal sealed class DWFSClearAllBundleFilesOperation : FSClearAllBundleFilesOperation
{
private readonly DefaultWebFileSystem _fileSystem;
internal DWFSClearAllBundleFilesOperation(DefaultWebFileSystem fileSystem)
{
_fileSystem = fileSystem;
}
internal override void InternalOnStart()
{
Status = EOperationStatus.Succeed;
}
internal override void InternalOnUpdate()
{
}
}
}
@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 68578d4c5e39a554aa3df2e7ec5218e9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -1,20 +0,0 @@
namespace YooAsset
{
internal sealed class DWFSClearUnusedBundleFilesOperation : FSClearUnusedBundleFilesOperation
{
private readonly DefaultWebFileSystem _fileSystem;
internal DWFSClearUnusedBundleFilesOperation(DefaultWebFileSystem fileSystem)
{
_fileSystem = fileSystem;
}
internal override void InternalOnStart()
{
Status = EOperationStatus.Succeed;
}
internal override void InternalOnUpdate()
{
}
}
}
@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 1560968379b66d440a94382b2a311a15
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,21 @@
namespace YooAsset
{
internal abstract class FSClearAllBundleFilesOperation : AsyncOperationBase
{
}
internal sealed class FSClearAllBundleFilesCompleteOperation : FSClearAllBundleFilesOperation
{
internal FSClearAllBundleFilesCompleteOperation()
{
}
internal override void InternalOnStart()
{
Status = EOperationStatus.Succeed;
}
internal override void InternalOnUpdate()
{
}
}
}
@@ -0,0 +1,21 @@
namespace YooAsset
{
internal abstract class FSClearUnusedBundleFilesOperation : AsyncOperationBase
{
}
internal sealed class FSClearUnusedBundleFilesCompleteOperation : FSClearUnusedBundleFilesOperation
{
internal FSClearUnusedBundleFilesCompleteOperation()
{
}
internal override void InternalOnStart()
{
Status = EOperationStatus.Succeed;
}
internal override void InternalOnUpdate()
{
}
}
}
@@ -7,6 +7,7 @@ namespace YooAsset
protected enum ESteps
{
None,
CheckExists,
CreateRequest,
CheckRequest,
VerifyTempFile,
@@ -1,7 +0,0 @@
namespace YooAsset
{
internal abstract class FSClearAllBundleFilesOperation : AsyncOperationBase
{
}
}
@@ -1,7 +0,0 @@
namespace YooAsset
{
internal abstract class FSClearUnusedBundleFilesOperation : AsyncOperationBase
{
}
}