diff options
author | chai <chaifix@163.com> | 2021-01-25 14:28:30 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-01-25 14:28:30 +0800 |
commit | 6eb915c129fc90c6f4c82ae097dd6ffad5239efc (patch) | |
tree | 7dd2be50edf41f36b60fac84696e731c13afe617 /Client/Assets/Scripts/XUtliPoolLib/XUpdater/XVersion.cs |
+scripts
Diffstat (limited to 'Client/Assets/Scripts/XUtliPoolLib/XUpdater/XVersion.cs')
-rw-r--r-- | Client/Assets/Scripts/XUtliPoolLib/XUpdater/XVersion.cs | 174 |
1 files changed, 174 insertions, 0 deletions
diff --git a/Client/Assets/Scripts/XUtliPoolLib/XUpdater/XVersion.cs b/Client/Assets/Scripts/XUtliPoolLib/XUpdater/XVersion.cs new file mode 100644 index 00000000..6c9759de --- /dev/null +++ b/Client/Assets/Scripts/XUtliPoolLib/XUpdater/XVersion.cs @@ -0,0 +1,174 @@ +using System;
+using System.Collections;
+using System.IO;
+using System.Threading;
+using UnityEngine;
+using XUtliPoolLib;
+
+namespace XUpdater
+{
+ internal sealed class XVersion : MonoBehaviour
+ {
+ public static string VERSION_FILE
+ {
+ get
+ {
+ return string.Format("manifest.{0}.assetbundle", XSingleton<XUpdater>.singleton.TargetVersion.ToString());
+ }
+ }
+
+ public static readonly string LOCAL_VERSION_FILE = "manifest.asset";
+
+ private WWW _server_Version = null;
+
+ private uint _time_out_token = 0u;
+
+ private delegate void HandleFinishDownload(WWW www, string error);
+
+ public static string GetLocalVersion()
+ {
+ return XSingleton<XCaching>.singleton.UpdatePath + XVersion.LOCAL_VERSION_FILE;
+ }
+
+ public void ServerDownload(HandleVersionDownload callback1, HandleVersionLoaded callback2)
+ {
+ base.StopAllCoroutines();
+ string text = XSingleton<XCaching>.singleton.HostUrl + XSingleton<XUpdater>.singleton.Platform;
+ XSingleton<XLoadingUI>.singleton.SetStatus(XSingleton<XStringTable>.singleton.GetString("XUPDATE_INFO_CONNECTING"), byte.MaxValue, byte.MaxValue, byte.MaxValue);
+ XSingleton<XDebug>.singleton.AddLog("connecting to update server: ", text, null, null, null, null, XDebugColor.XDebug_None);
+ this._time_out_token = XSingleton<XTimerMgr>.singleton.SetTimer(5f, new XTimerMgr.ElapsedEventHandler(this.OnTimeOut), null);
+ base.StartCoroutine(this.DownloadVersion(XSingleton<XCaching>.singleton.MakeToken(text + XVersion.VERSION_FILE), callback1, callback2));
+ }
+
+ private IEnumerator DownloadVersion(string url, HandleVersionDownload callback1, HandleVersionLoaded callback2)
+ {
+ this._server_Version = new WWW(url);
+ yield return this._server_Version;
+ XSingleton<XLoadingUI>.singleton.SetStatus(XSingleton<XStringTable>.singleton.GetString("XUPDATE_INFO_CHECKUPDATING"), byte.MaxValue, byte.MaxValue, byte.MaxValue);
+ XSingleton<XTimerMgr>.singleton.KillTimer(this._time_out_token);
+ bool flag = this._server_Version != null;
+ if (flag)
+ {
+ bool flag2 = string.IsNullOrEmpty(this._server_Version.error);
+ if (flag2)
+ {
+ bool flag3 = callback1 != null;
+ if (flag3)
+ {
+ AssetBundle ab = this._server_Version.assetBundle;
+ bool flag4 = ab == null;
+ if (flag4)
+ {
+ XSingleton<XDebug>.singleton.AddErrorLog("load server manifest bundle error.", null, null, null, null, null);
+ XSingleton<XLoadingUI>.singleton.SetStatus(XSingleton<XStringTable>.singleton.GetString("XUPDATE_ERROR_FETCHMANIFESTERROR"), byte.MaxValue, byte.MaxValue, byte.MaxValue);
+ XSingleton<XUpdater>.singleton.OnError();
+ }
+ else
+ {
+ UnityEngine.Object asset = ab.LoadAsset("manifest", typeof(TextAsset));
+ bool flag5 = asset == null;
+ if (flag5)
+ {
+ XSingleton<XDebug>.singleton.AddErrorLog("load server manifest bundle error.", null, null, null, null, null);
+ XSingleton<XLoadingUI>.singleton.SetStatus(XSingleton<XStringTable>.singleton.GetString("XUPDATE_ERROR_FETCHMANIFESTERROR"), byte.MaxValue, byte.MaxValue, byte.MaxValue);
+ XSingleton<XUpdater>.singleton.OnError();
+ }
+ else
+ {
+ AsyncVersionProcessRequest avpr = callback1(asset as TextAsset);
+ while (!avpr.IsDone)
+ {
+ Thread.Sleep(1);
+ }
+ bool flag6 = callback2 != null;
+ if (flag6)
+ {
+ callback2(avpr.IsCorrect);
+ }
+ ab.Unload(false);
+ avpr = null;
+ }
+ asset = null;
+ }
+ ab = null;
+ }
+ }
+ else
+ {
+ bool flag7 = XUpdater.LaunchMode == XLaunchMode.Dev;
+ if (flag7)
+ {
+ XSingleton<XUpdater>.singleton.DevStart();
+ }
+ else
+ {
+ XSingleton<XDebug>.singleton.AddErrorLog(this._server_Version.error, null, null, null, null, null);
+ XSingleton<XLoadingUI>.singleton.SetStatus(XSingleton<XStringTable>.singleton.GetString("XUPDATE_ERROR_FETCHMANIFESTERROR"), byte.MaxValue, byte.MaxValue, byte.MaxValue);
+ XSingleton<XUpdater>.singleton.OnError();
+ }
+ }
+ this._server_Version.Dispose();
+ this._server_Version = null;
+ }
+ else
+ {
+ XSingleton<XDebug>.singleton.AddErrorLog("ERROR: _server_Version is NULL!", null, null, null, null, null);
+ XSingleton<XLoadingUI>.singleton.SetStatus(XSingleton<XStringTable>.singleton.GetString("XUPDATE_ERROR_FETCHMANIFESTERROR"), byte.MaxValue, byte.MaxValue, byte.MaxValue);
+ XSingleton<XUpdater>.singleton.OnError();
+ }
+ yield break;
+ }
+
+ private IEnumerator LocalDownload(XVersion.HandleFinishDownload callback)
+ {
+ string path = Application.persistentDataPath + XVersion.VERSION_FILE;
+ bool flag = !File.Exists(path);
+ if (flag)
+ {
+ bool flag2 = callback != null;
+ if (flag2)
+ {
+ callback(null, null);
+ }
+ }
+ else
+ {
+ string local_location = "file://" + path;
+ WWW localVersion = new WWW(local_location);
+ yield return localVersion;
+ bool flag3 = callback != null;
+ if (flag3)
+ {
+ callback(localVersion, localVersion.error);
+ }
+ localVersion.Dispose();
+ localVersion = null;
+ local_location = null;
+ localVersion = null;
+ }
+ yield break;
+ }
+
+ private void OnTimeOut(object o)
+ {
+ bool flag = XUpdater.LaunchMode == XLaunchMode.Dev;
+ if (flag)
+ {
+ XSingleton<XUpdater>.singleton.DevStart();
+ bool flag2 = (int)Application.platform == 7 || Application.platform == 0;
+ if (flag2)
+ {
+ XSingleton<XDebug>.singleton.AddErrorLog("Connect to update server timeout...", null, null, null, null, null);
+ }
+ }
+ else
+ {
+ XSingleton<XLoadingUI>.singleton.SetStatus(XSingleton<XStringTable>.singleton.GetString("XUPDATE_ERROR_CANNOTCONNECTTOSERVER"), byte.MaxValue, byte.MaxValue, byte.MaxValue);
+ XSingleton<XUpdater>.singleton.OnError();
+ }
+ base.StopAllCoroutines();
+ this._server_Version.Dispose();
+ this._server_Version = null;
+ }
+ }
+}
|