From f2cd8cf71a54e251e5f507c7d69c6f91f90e5074 Mon Sep 17 00:00:00 2001
From: client_Hale <339726288@qq.com>
Date: 星期二, 25 九月 2018 20:23:14 +0800
Subject: [PATCH] Merge branch 'master' of http://192.168.0.87:10010/r/snxxz_scripts

---
 System/ClientVersion/VersionUtility.cs |  146 +++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 123 insertions(+), 23 deletions(-)

diff --git a/System/ClientVersion/VersionUtility.cs b/System/ClientVersion/VersionUtility.cs
index 53cdaa9..9eb49d0 100644
--- a/System/ClientVersion/VersionUtility.cs
+++ b/System/ClientVersion/VersionUtility.cs
@@ -20,21 +20,18 @@
 
     public string androidRoot { get { return StringUtility.Contact(SDKUtility.Instance.DeviceRootPath, "/", VersionConfig.Get().bundleIdentifier); } }
 
-    public float progress
-    {
+    public float progress {
         get { return RemoteFile.TotalDownloadedSize / ((float)versionInfo.GetLatestVersion().file_size * 1024); }
     }
 
-    public string apkLocalURL = string.Empty;
     public VersionInfo versionInfo { get; private set; }
+    public MaoErVersion maoerVersion;
     public bool completed { get { return step == Step.Completed; } }
 
     Step m_Step = Step.None;
-    public Step step
-    {
+    public Step step {
         get { return m_Step; }
-        private set
-        {
+        private set {
             if (m_Step != value)
             {
                 m_Step = value;
@@ -70,17 +67,12 @@
         if (_ok)
         {
             versionInfo = JsonMapper.ToObject<VersionInfo>(_result);
-            if (versionInfo.VersionCount > 0)
+            if (NeedUpdate())
             {
-                var version = versionInfo.GetLatestVersion();
-                var remoteURL = version.download_url;
-
                 switch (Application.platform)
                 {
                     case RuntimePlatform.Android:
-                        var fileName = Path.GetFileName(remoteURL);
-                        apkLocalURL = StringUtility.Contact(androidRoot, "/", fileName);
-                        if (File.Exists(apkLocalURL))
+                        if (File.Exists(GetApkLocalUrl()))
                         {
                             step = Step.ApkExist;
                             WindowCenter.Instance.OpenFromLocal<VersionUpdateWin>();
@@ -118,18 +110,74 @@
         }
     }
 
+    public bool NeedUpdate()
+    {
+        if (IsMaoErGame())
+        {
+            return versionInfo.downAsset == 0 && versionInfo.VersionCount > 0;
+        }
+        else
+        {
+            return versionInfo.downAsset == 1 && versionInfo.VersionCount > 0;
+        }
+    }
+
+    public string GetApkLocalUrl()
+    {
+        if (IsMaoErGame())
+        {
+            return StringUtility.Contact(androidRoot, "/", "maoErGame.apk");
+        }
+        else
+        {
+            var remoteURL = GetApkRemoteUrl();
+            var fileName = Path.GetFileName(remoteURL);
+            return StringUtility.Contact(androidRoot, "/", fileName);
+        }
+    }
+
+    public string GetApkRemoteUrl()
+    {
+        if (IsMaoErGame())
+        {
+            return maoerVersion.url;
+        }
+        else
+        {
+            var version = versionInfo.GetLatestVersion();
+            return version.download_url;
+        }
+    }
+
+    public string GetUpdateContent()
+    {
+        if (IsMaoErGame())
+        {
+            if (string.IsNullOrEmpty(maoerVersion.content))
+            {
+                return string.Empty;
+            }
+            else
+            {
+                return StringUtility.Contact(Language.GetFromLocal(30), "\r\n", maoerVersion.content);
+            }
+        }
+        else
+        {
+            return string.Empty;
+        }
+    }
+
     public void StartDownLoad()
     {
         step = Step.DownLoad;
-        var version = versionInfo.GetLatestVersion();
-        var remoteURL = version.download_url;
-        var fileName = Path.GetFileName(remoteURL);
-        apkLocalURL = StringUtility.Contact(androidRoot, "/", fileName);
+        var remoteURL = GetApkRemoteUrl();
+        var apkLocalUrl = GetApkLocalUrl();
 
         RemoteFile.Prepare();
 
         var remoteFile = new RemoteFile();
-        remoteFile.Init(remoteURL, apkLocalURL, null);
+        remoteFile.Init(remoteURL, apkLocalUrl, null);
         remoteFile.Begin(OnDownLoadApkCompleted);
     }
 
@@ -155,7 +203,7 @@
                 }
             }
 
-            SDKUtility.Instance.InstallAPK(apkLocalURL);
+            SDKUtility.Instance.InstallAPK(GetApkLocalUrl());
         }
         else
         {
@@ -168,10 +216,54 @@
         step = Step.Completed;
     }
 
-    const string maoerGameAppId = "mrgame";
+    static List<string> maoerGameAppId = new List<string> { "mrgame", "mrgameios" };
     public bool IsMaoErGame()
     {
-        return VersionConfig.Get().appId == maoerGameAppId;
+        return maoerGameAppId.Contains(VersionConfig.Get().appId);
+    }
+
+    public void RequestMaoErVersionCheck()
+    {
+        if (IsMaoErGame() && versionInfo.VersionCount > 0)
+        {
+            step = Step.None;
+            var tables = new Dictionary<string, string>();
+            tables["uid"] = ModelCenter.Instance.GetModel<LoginModel>().sdkLoginResult.account;
+            var url = "https://api.maoergame.com/update/download/url";
+
+            HttpRequest.Instance.RequestHttpPost(url, tables, HttpRequest.defaultHttpContentType, 1, OnMaoErVersionCheckResult);
+        }
+    }
+
+    private void OnMaoErVersionCheckResult(bool ok, string result)
+    {
+        if (ok)
+        {
+            try
+            {
+                maoerVersion = JsonMapper.ToObject<MaoErVersion>(result);
+                if (maoerVersion.code == 0)
+                {
+                    step = Step.DownLoadPrepared;
+                    WindowCenter.Instance.OpenFromLocal<VersionUpdateWin>();
+                }
+                else
+                {
+                    step = Step.None;
+                    Clock.Create(DateTime.Now + new TimeSpan(TimeSpan.TicksPerSecond), RequestMaoErVersionCheck);
+                }
+            }
+            catch (System.Exception ex)
+            {
+                step = Step.None;
+                Clock.Create(DateTime.Now + new TimeSpan(TimeSpan.TicksPerSecond), RequestMaoErVersionCheck);
+            }
+        }
+        else
+        {
+            step = Step.None;
+            Clock.Create(DateTime.Now + new TimeSpan(TimeSpan.TicksPerSecond), RequestMaoErVersionCheck);
+        }
     }
 
     public class VersionInfo
@@ -181,7 +273,7 @@
         public JsonData resource_url;
         public JsonData notice_flag;
         public Version[] versions;
-        public int downAsset =1;
+        public int downAsset = 1;
 
         public Version GetLatestVersion()
         {
@@ -240,6 +332,14 @@
         public string version_name;
     }
 
+    public struct MaoErVersion
+    {
+        public string msg;
+        public int code;
+        public string content;
+        public string url;
+    }
+
     public enum Step
     {
         None,

--
Gitblit v1.8.0