From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../Scripts/XUtliPoolLib/XUpdater/XVersion.cs | 174 +++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 Client/Assets/Scripts/XUtliPoolLib/XUpdater/XVersion.cs (limited to 'Client/Assets/Scripts/XUtliPoolLib/XUpdater/XVersion.cs') 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.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.singleton.UpdatePath + XVersion.LOCAL_VERSION_FILE; + } + + public void ServerDownload(HandleVersionDownload callback1, HandleVersionLoaded callback2) + { + base.StopAllCoroutines(); + string text = XSingleton.singleton.HostUrl + XSingleton.singleton.Platform; + XSingleton.singleton.SetStatus(XSingleton.singleton.GetString("XUPDATE_INFO_CONNECTING"), byte.MaxValue, byte.MaxValue, byte.MaxValue); + XSingleton.singleton.AddLog("connecting to update server: ", text, null, null, null, null, XDebugColor.XDebug_None); + this._time_out_token = XSingleton.singleton.SetTimer(5f, new XTimerMgr.ElapsedEventHandler(this.OnTimeOut), null); + base.StartCoroutine(this.DownloadVersion(XSingleton.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.singleton.SetStatus(XSingleton.singleton.GetString("XUPDATE_INFO_CHECKUPDATING"), byte.MaxValue, byte.MaxValue, byte.MaxValue); + XSingleton.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.singleton.AddErrorLog("load server manifest bundle error.", null, null, null, null, null); + XSingleton.singleton.SetStatus(XSingleton.singleton.GetString("XUPDATE_ERROR_FETCHMANIFESTERROR"), byte.MaxValue, byte.MaxValue, byte.MaxValue); + XSingleton.singleton.OnError(); + } + else + { + UnityEngine.Object asset = ab.LoadAsset("manifest", typeof(TextAsset)); + bool flag5 = asset == null; + if (flag5) + { + XSingleton.singleton.AddErrorLog("load server manifest bundle error.", null, null, null, null, null); + XSingleton.singleton.SetStatus(XSingleton.singleton.GetString("XUPDATE_ERROR_FETCHMANIFESTERROR"), byte.MaxValue, byte.MaxValue, byte.MaxValue); + XSingleton.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.singleton.DevStart(); + } + else + { + XSingleton.singleton.AddErrorLog(this._server_Version.error, null, null, null, null, null); + XSingleton.singleton.SetStatus(XSingleton.singleton.GetString("XUPDATE_ERROR_FETCHMANIFESTERROR"), byte.MaxValue, byte.MaxValue, byte.MaxValue); + XSingleton.singleton.OnError(); + } + } + this._server_Version.Dispose(); + this._server_Version = null; + } + else + { + XSingleton.singleton.AddErrorLog("ERROR: _server_Version is NULL!", null, null, null, null, null); + XSingleton.singleton.SetStatus(XSingleton.singleton.GetString("XUPDATE_ERROR_FETCHMANIFESTERROR"), byte.MaxValue, byte.MaxValue, byte.MaxValue); + XSingleton.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.singleton.DevStart(); + bool flag2 = (int)Application.platform == 7 || Application.platform == 0; + if (flag2) + { + XSingleton.singleton.AddErrorLog("Connect to update server timeout...", null, null, null, null, null); + } + } + else + { + XSingleton.singleton.SetStatus(XSingleton.singleton.GetString("XUPDATE_ERROR_CANNOTCONNECTTOSERVER"), byte.MaxValue, byte.MaxValue, byte.MaxValue); + XSingleton.singleton.OnError(); + } + base.StopAllCoroutines(); + this._server_Version.Dispose(); + this._server_Version = null; + } + } +} -- cgit v1.1-26-g67d0