Browse Source

fix资源CDN不能访问时就卡死的bug

大爷 2 years ago
parent
commit
844611cf5f
1 changed files with 20 additions and 6 deletions
  1. 20 6
      Unity/Assets/Mono/YooAsset/PatchUpdater/PatchUpdater.cs

+ 20 - 6
Unity/Assets/Mono/YooAsset/PatchUpdater/PatchUpdater.cs

@@ -9,6 +9,7 @@ using ET;
 public static class PatchUpdater
 {
     private static bool _isRun = false;
+    private static int _retryCnt = 0;
 
     /// <summary>
     /// 下载器
@@ -135,23 +136,36 @@ public static class PatchUpdater
         }
         else if (msg is PatchEventMessageDefine.StaticVersionUpdateFailed)
         {
-            System.Action callback = () => { PatchUpdater.HandleOperation(EPatchOperation.TryUpdateStaticVersion); };
-            ET.Log.Info($"Failed to update static version, please check the network status.", callback);
+            ET.Log.Error($"Failed to update static version, please check the network status.");
+            ErrorRetry(EPatchOperation.TryUpdateStaticVersion);
         }
         else if (msg is PatchEventMessageDefine.PatchManifestUpdateFailed)
         {
-            System.Action callback = () => { PatchUpdater.HandleOperation(EPatchOperation.TryUpdatePatchManifest); };
-            ET.Log.Info($"Failed to update patch manifest, please check the network status.", callback);
+            ET.Log.Error($"Failed to update patch manifest, please check the network status.");
+            ErrorRetry(EPatchOperation.TryUpdatePatchManifest);
         }
         else if (msg is PatchEventMessageDefine.WebFileDownloadFailed)
         {
             var message = msg as PatchEventMessageDefine.WebFileDownloadFailed;
-            System.Action callback = () => { PatchUpdater.HandleOperation(EPatchOperation.TryDownloadWebFiles); };
-            ET.Log.Info($"Failed to download file : {message.FileName}", callback);
+            ET.Log.Error($"Failed to download file : {message.FileName}");
+            ErrorRetry(EPatchOperation.TryDownloadWebFiles);
         }
         else
         {
             throw new System.NotImplementedException($"{msg.GetType()}");
         }
     }
+
+    private static void ErrorRetry(EPatchOperation operation)
+    {
+        if (++_retryCnt >= 3)
+        {
+            Log.Error("Retry 3 times, Abort.");
+            s_UniTaskCompletionSource?.TrySetResult();
+        }
+        else
+        {
+            PatchUpdater.HandleOperation(operation);
+        }
+    }
 }