Add warning when asset path is invalid.

pull/11/head
hevinci 2022-05-12 23:13:21 +08:00
parent 2da81212b4
commit 09fac3bd64
8 changed files with 94 additions and 60 deletions

View File

@ -566,7 +566,7 @@ namespace YooAsset.Editor
public static string AbsolutePathToAssetPath(string absolutePath) public static string AbsolutePathToAssetPath(string absolutePath)
{ {
string content = GetRegularPath(absolutePath); string content = GetRegularPath(absolutePath);
return Substring(content, "Assets", true); return Substring(content, "Assets/", true);
} }
/// <summary> /// <summary>

View File

@ -126,6 +126,7 @@ namespace YooAsset
{ {
if (assetInfo.IsInvalid) if (assetInfo.IsInvalid)
{ {
YooLogger.Warning(assetInfo.Error);
CompletedProvider completedProvider = new CompletedProvider(assetInfo); CompletedProvider completedProvider = new CompletedProvider(assetInfo);
return completedProvider.CreateHandle<SceneOperationHandle>(); return completedProvider.CreateHandle<SceneOperationHandle>();
} }
@ -164,6 +165,7 @@ namespace YooAsset
{ {
if (assetInfo.IsInvalid) if (assetInfo.IsInvalid)
{ {
YooLogger.Warning(assetInfo.Error);
CompletedProvider completedProvider = new CompletedProvider(assetInfo); CompletedProvider completedProvider = new CompletedProvider(assetInfo);
return completedProvider.CreateHandle<AssetOperationHandle>(); return completedProvider.CreateHandle<AssetOperationHandle>();
} }
@ -188,6 +190,7 @@ namespace YooAsset
{ {
if (assetInfo.IsInvalid) if (assetInfo.IsInvalid)
{ {
YooLogger.Warning(assetInfo.Error);
CompletedProvider completedProvider = new CompletedProvider(assetInfo); CompletedProvider completedProvider = new CompletedProvider(assetInfo);
return completedProvider.CreateHandle<SubAssetsOperationHandle>(); return completedProvider.CreateHandle<SubAssetsOperationHandle>();
} }

View File

@ -25,6 +25,22 @@ namespace YooAsset
} }
} }
/// <summary>
/// 身份是否无效
/// </summary>
internal bool IsInvalid
{
get
{
return _patchAsset == null;
}
}
/// <summary>
/// 错误信息
/// </summary>
internal string Error { private set; get; }
/// <summary> /// <summary>
/// 资源对象名称 /// 资源对象名称
/// </summary> /// </summary>
@ -40,23 +56,8 @@ namespace YooAsset
/// </summary> /// </summary>
public System.Type AssetType { private set; get; } public System.Type AssetType { private set; get; }
/// <summary>
/// 身份是否无效
/// </summary>
public bool IsInvalid
{
get
{
return _patchAsset == null;
}
}
/// <summary>
/// 错误信息
/// </summary>
public string Error { private set; get; }
// 注意:这是一个内部类,严格限制外部创建。
private AssetInfo() private AssetInfo()
{ {
} }

View File

@ -63,8 +63,8 @@ namespace YooAsset
private readonly int _resourceVersion; private readonly int _resourceVersion;
private readonly int _timeout; private readonly int _timeout;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
private UnityWebDataRequester _downloaderHash; private UnityWebDataRequester _downloader1;
private UnityWebDataRequester _downloaderManifest; private UnityWebDataRequester _downloader2;
private float _verifyTime; private float _verifyTime;
internal HostPlayModeUpdateManifestOperation(HostPlayModeImpl impl, int resourceVersion, int timeout) internal HostPlayModeUpdateManifestOperation(HostPlayModeImpl impl, int resourceVersion, int timeout)
@ -87,26 +87,26 @@ namespace YooAsset
{ {
string webURL = GetPatchManifestRequestURL(YooAssetSettingsData.GetPatchManifestHashFileName(_resourceVersion)); string webURL = GetPatchManifestRequestURL(YooAssetSettingsData.GetPatchManifestHashFileName(_resourceVersion));
YooLogger.Log($"Beginning to request patch manifest hash : {webURL}"); YooLogger.Log($"Beginning to request patch manifest hash : {webURL}");
_downloaderHash = new UnityWebDataRequester(); _downloader1 = new UnityWebDataRequester();
_downloaderHash.SendRequest(webURL, _timeout); _downloader1.SendRequest(webURL, _timeout);
_steps = ESteps.CheckWebManifestHash; _steps = ESteps.CheckWebManifestHash;
} }
if (_steps == ESteps.CheckWebManifestHash) if (_steps == ESteps.CheckWebManifestHash)
{ {
if (_downloaderHash.IsDone() == false) if (_downloader1.IsDone() == false)
return; return;
// Check error // Check error
if (_downloaderHash.HasError()) if (_downloader1.HasError())
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = _downloaderHash.GetError(); Error = _downloader1.GetError();
} }
else else
{ {
string webManifestHash = _downloaderHash.GetText(); string webManifestHash = _downloader1.GetText();
string cachedManifestHash = GetSandboxPatchManifestFileHash(_resourceVersion); string cachedManifestHash = GetSandboxPatchManifestFileHash(_resourceVersion);
// 如果补丁清单文件的哈希值相同 // 如果补丁清单文件的哈希值相同
@ -122,34 +122,34 @@ namespace YooAsset
_steps = ESteps.LoadWebManifest; _steps = ESteps.LoadWebManifest;
} }
} }
_downloaderHash.Dispose(); _downloader1.Dispose();
} }
if (_steps == ESteps.LoadWebManifest) if (_steps == ESteps.LoadWebManifest)
{ {
string webURL = GetPatchManifestRequestURL(YooAssetSettingsData.GetPatchManifestFileName(_resourceVersion)); string webURL = GetPatchManifestRequestURL(YooAssetSettingsData.GetPatchManifestFileName(_resourceVersion));
YooLogger.Log($"Beginning to request patch manifest : {webURL}"); YooLogger.Log($"Beginning to request patch manifest : {webURL}");
_downloaderManifest = new UnityWebDataRequester(); _downloader2 = new UnityWebDataRequester();
_downloaderManifest.SendRequest(webURL, _timeout); _downloader2.SendRequest(webURL, _timeout);
_steps = ESteps.CheckWebManifest; _steps = ESteps.CheckWebManifest;
} }
if (_steps == ESteps.CheckWebManifest) if (_steps == ESteps.CheckWebManifest)
{ {
if (_downloaderManifest.IsDone() == false) if (_downloader2.IsDone() == false)
return; return;
// Check error // Check error
if (_downloaderManifest.HasError()) if (_downloader2.HasError())
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = _downloaderManifest.GetError(); Error = _downloader2.GetError();
} }
else else
{ {
// 解析补丁清单 // 解析补丁清单
if (ParseAndSaveRemotePatchManifest(_resourceVersion, _downloaderManifest.GetText())) if (ParseAndSaveRemotePatchManifest(_resourceVersion, _downloader2.GetText()))
{ {
_steps = ESteps.InitVerifyingCache; _steps = ESteps.InitVerifyingCache;
} }
@ -157,10 +157,10 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"URL : {_downloaderManifest.URL} Error : remote patch manifest content is invalid"; Error = $"URL : {_downloader2.URL} Error : remote patch manifest content is invalid";
} }
} }
_downloaderManifest.Dispose(); _downloader2.Dispose();
} }
if (_steps == ESteps.InitVerifyingCache) if (_steps == ESteps.InitVerifyingCache)
@ -207,18 +207,19 @@ namespace YooAsset
YooLogger.Log("Save remote patch manifest file."); YooLogger.Log("Save remote patch manifest file.");
string savePath = PathHelper.MakePersistentLoadPath(YooAssetSettingsData.GetPatchManifestFileName(updateResourceVersion)); string savePath = PathHelper.MakePersistentLoadPath(YooAssetSettingsData.GetPatchManifestFileName(updateResourceVersion));
PatchManifest.Serialize(savePath, _impl.LocalPatchManifest); PatchManifest.Serialize(savePath, remotePatchManifest);
return true; return true;
} }
catch (Exception e) catch (Exception e)
{ {
YooLogger.Warning(e.ToString()); YooLogger.Error(e.ToString());
return false; return false;
} }
} }
/// <summary> /// <summary>
/// 加载沙盒内的补丁清单 /// 加载沙盒内的补丁清单
/// 注意:在加载本地补丁清单之前,已经验证过文件的哈希值
/// </summary> /// </summary>
private void LoadSandboxPatchManifest(int updateResourceVersion) private void LoadSandboxPatchManifest(int updateResourceVersion)
{ {

View File

@ -81,7 +81,7 @@ namespace YooAsset
private readonly int _resourceVersion; private readonly int _resourceVersion;
private readonly int _timeout; private readonly int _timeout;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
private UnityWebDataRequester _downloaderManifest; private UnityWebDataRequester _downloader;
private PatchManifest _remotePatchManifest; private PatchManifest _remotePatchManifest;
internal HostPlayModeUpdatePackageOperation(HostPlayModeImpl impl, int resourceVersion, int timeout) internal HostPlayModeUpdatePackageOperation(HostPlayModeImpl impl, int resourceVersion, int timeout)
@ -104,28 +104,28 @@ namespace YooAsset
{ {
string webURL = GetPatchManifestRequestURL(YooAssetSettingsData.GetPatchManifestFileName(_resourceVersion)); string webURL = GetPatchManifestRequestURL(YooAssetSettingsData.GetPatchManifestFileName(_resourceVersion));
YooLogger.Log($"Beginning to request patch manifest : {webURL}"); YooLogger.Log($"Beginning to request patch manifest : {webURL}");
_downloaderManifest = new UnityWebDataRequester(); _downloader = new UnityWebDataRequester();
_downloaderManifest.SendRequest(webURL, _timeout); _downloader.SendRequest(webURL, _timeout);
_steps = ESteps.CheckWebManifest; _steps = ESteps.CheckWebManifest;
} }
if (_steps == ESteps.CheckWebManifest) if (_steps == ESteps.CheckWebManifest)
{ {
Progress = _downloaderManifest.Progress(); Progress = _downloader.Progress();
if (_downloaderManifest.IsDone() == false) if (_downloader.IsDone() == false)
return; return;
// Check error // Check error
if (_downloaderManifest.HasError()) if (_downloader.HasError())
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = _downloaderManifest.GetError(); Error = _downloader.GetError();
} }
else else
{ {
// 解析补丁清单 // 解析补丁清单
if (ParseRemotePatchManifest(_downloaderManifest.GetText())) if (ParseRemotePatchManifest(_downloader.GetText()))
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Succeed; Status = EOperationStatus.Succeed;
@ -134,10 +134,10 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"URL : {_downloaderManifest.URL} Error : remote patch manifest content is invalid"; Error = $"URL : {_downloader.URL} Error : remote patch manifest content is invalid";
} }
} }
_downloaderManifest.Dispose(); _downloader.Dispose();
} }
} }
@ -209,8 +209,8 @@ namespace YooAsset
continue; continue;
} }
// 注意:下载系统只会验证当前游戏版本的资源文件,对于其它游戏版本的差异文件不会在初始化的时候去做校验。 // 注意:通过比对文件大小做快速的文件校验!
// 注意:通过比对文件大小做实时的文件校验方式 // 注意:在初始化的时候会去做最终校验
string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.Hash); string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.Hash);
if (File.Exists(filePath)) if (File.Exists(filePath))
{ {

View File

@ -73,7 +73,7 @@ namespace YooAsset
if (EnableAddressable) if (EnableAddressable)
{ {
if (locationToLower) if (locationToLower)
YooLogger.Warning("Addressable not support location to lower !"); YooLogger.Error("Addressable not support location to lower !");
foreach (var patchAsset in AssetList) foreach (var patchAsset in AssetList)
{ {

View File

@ -12,18 +12,23 @@ namespace YooAsset
internal PatchManifest LocalPatchManifest { private set; get; } internal PatchManifest LocalPatchManifest { private set; get; }
// 参数相关 // 参数相关
internal bool LocationToLower { private set; get; } private bool _locationToLower;
internal bool ClearCacheWhenDirty { private set; get; } private bool _clearCacheWhenDirty;
private string _defaultHostServer; private string _defaultHostServer;
private string _fallbackHostServer; private string _fallbackHostServer;
public bool ClearCacheWhenDirty
{
get { return _clearCacheWhenDirty; }
}
/// <summary> /// <summary>
/// 异步初始化 /// 异步初始化
/// </summary> /// </summary>
public InitializationOperation InitializeAsync(bool locationToLower, bool clearCacheWhenDirty, string defaultHostServer, string fallbackHostServer) public InitializationOperation InitializeAsync(bool locationToLower, bool clearCacheWhenDirty, string defaultHostServer, string fallbackHostServer)
{ {
LocationToLower = locationToLower; _locationToLower = locationToLower;
ClearCacheWhenDirty = clearCacheWhenDirty; _clearCacheWhenDirty = clearCacheWhenDirty;
_defaultHostServer = defaultHostServer; _defaultHostServer = defaultHostServer;
_fallbackHostServer = fallbackHostServer; _fallbackHostServer = fallbackHostServer;
@ -293,7 +298,7 @@ namespace YooAsset
internal void SetLocalPatchManifest(PatchManifest patchManifest) internal void SetLocalPatchManifest(PatchManifest patchManifest)
{ {
LocalPatchManifest = patchManifest; LocalPatchManifest = patchManifest;
LocalPatchManifest.InitAssetPathMapping(LocationToLower); LocalPatchManifest.InitAssetPathMapping(_locationToLower);
} }
#region IBundleServices接口 #region IBundleServices接口

View File

@ -33,7 +33,7 @@ namespace YooAsset
/// <summary> /// <summary>
/// 初始化参数 /// 初始化参数
/// </summary> /// </summary>
public abstract class CreateParameters public abstract class InitializeParameters
{ {
/// <summary> /// <summary>
/// 资源定位地址大小写不敏感 /// 资源定位地址大小写不敏感
@ -64,7 +64,7 @@ namespace YooAsset
/// <summary> /// <summary>
/// 编辑器下模拟运行模式的初始化参数 /// 编辑器下模拟运行模式的初始化参数
/// </summary> /// </summary>
public class EditorSimulateModeParameters : CreateParameters public class EditorSimulateModeParameters : InitializeParameters
{ {
/// <summary> /// <summary>
/// 用于模拟运行的资源清单路径 /// 用于模拟运行的资源清单路径
@ -76,14 +76,14 @@ namespace YooAsset
/// <summary> /// <summary>
/// 离线运行模式的初始化参数 /// 离线运行模式的初始化参数
/// </summary> /// </summary>
public class OfflinePlayModeParameters : CreateParameters public class OfflinePlayModeParameters : InitializeParameters
{ {
} }
/// <summary> /// <summary>
/// 网络运行模式的初始化参数 /// 网络运行模式的初始化参数
/// </summary> /// </summary>
public class HostPlayModeParameters : CreateParameters public class HostPlayModeParameters : InitializeParameters
{ {
/// <summary> /// <summary>
/// 当缓存池被污染的时候清理缓存池 /// 当缓存池被污染的时候清理缓存池
@ -121,7 +121,7 @@ namespace YooAsset
/// <summary> /// <summary>
/// 异步初始化 /// 异步初始化
/// </summary> /// </summary>
public static InitializationOperation InitializeAsync(CreateParameters parameters) public static InitializationOperation InitializeAsync(InitializeParameters parameters)
{ {
if (parameters == null) if (parameters == null)
throw new Exception($"YooAsset create parameters is null."); throw new Exception($"YooAsset create parameters is null.");
@ -357,8 +357,31 @@ namespace YooAsset
DebugCheckInitialize(); DebugCheckInitialize();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
if (assetInfo.IsInvalid) if (assetInfo.IsInvalid)
{
YooLogger.Warning(assetInfo.Error);
return false; return false;
}
BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo);
if (bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
return true;
else
return false;
}
/// <summary>
/// 是否需要从远端更新下载
/// </summary>
/// <param name="location">资源的定位地址</param>
public static bool IsNeedDownloadFromRemote(AssetInfo assetInfo)
{
DebugCheckInitialize();
if (assetInfo.IsInvalid)
{
YooLogger.Warning(assetInfo.Error);
return false;
}
BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo); BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo);
if (bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote) if (bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
return true; return true;
@ -448,6 +471,7 @@ namespace YooAsset
{ {
if (assetInfo.IsInvalid) if (assetInfo.IsInvalid)
{ {
YooLogger.Warning(assetInfo.Error);
RawFileOperation operation = new CompletedRawFileOperation(assetInfo.Error, copyPath); RawFileOperation operation = new CompletedRawFileOperation(assetInfo.Error, copyPath);
OperationSystem.StartOperaiton(operation); OperationSystem.StartOperaiton(operation);
return operation; return operation;