From 7414f3313de0df9b1de313951d4d53bf74877ee5 Mon Sep 17 00:00:00 2001
From: client_Wu Xijin <364452445@qq.com>
Date: 星期三, 21 十一月 2018 14:49:23 +0800
Subject: [PATCH] 4906 【前端】【1.3】各平台强更开发
---
System/ClientVersion/VersionUtility.cs | 140 +++++++++++++++++++++++++++++++++++++---------
1 files changed, 111 insertions(+), 29 deletions(-)
diff --git a/System/ClientVersion/VersionUtility.cs b/System/ClientVersion/VersionUtility.cs
index b24c3ef..f144e43 100644
--- a/System/ClientVersion/VersionUtility.cs
+++ b/System/ClientVersion/VersionUtility.cs
@@ -11,24 +11,26 @@
using System.IO;
using Snxxz.UI;
using System.Text;
+using TableConfig;
[XLua.LuaCallCSharp]
public class VersionUtility : Singleton<VersionUtility>
-
{
- public static readonly string[] VERSION_URL = new string[] { "http://pub.game.2460web.com:11000/appversion/?" ,
- "http://111.230.234.252:11000/appversion/?"};
-
- const string VERSION_URL_PURE = "http://111.230.234.252:11000/purge/appversion/?";
+ public static readonly string[] VERSION_URL = new string[] {
+ "http://pub.game.2460web.com:11000/appversion/?" ,
+ "http://111.230.234.252:11000/appversion/?"};
public string androidRoot { get { return StringUtility.Contact(SDKUtility.Instance.DeviceRootPath, "/", VersionConfig.Get().bundleIdentifier); } }
+
public float progress {
- get { return RemoteFile.TotalDownloadedSize / ((float)versionInfo.GetLatestVersion().file_size * 1024); }
+ get { return RemoteFile.TotalDownloadedSize / ((float)GetApkSize() * 1024); }
}
public VersionInfo versionInfo { get; private set; }
public JsonData maoerVersion;
+ Dictionary<string, ApkDownUrl> apkDownUrls = new Dictionary<string, ApkDownUrl>();
+
public bool completed { get { return step == Step.Completed; } }
Step m_Step = Step.None;
@@ -72,27 +74,13 @@
versionInfo = JsonMapper.ToObject<VersionInfo>(_result);
if (NeedNormalUpdate())
{
- switch (Application.platform)
+ if (Application.isMobilePlatform)
{
- case RuntimePlatform.Android:
- if (File.Exists(GetApkLocalUrl()))
- {
- step = Step.ApkExist;
- WindowCenter.Instance.OpenFromLocal<VersionUpdateWin>();
- }
- else
- {
- step = Step.DownLoadPrepared;
- WindowCenter.Instance.OpenFromLocal<VersionUpdateWin>();
- }
- break;
- case RuntimePlatform.IPhonePlayer:
- step = Step.DownLoadPrepared;
- WindowCenter.Instance.OpenFromLocal<VersionUpdateWin>();
- break;
- default:
- step = Step.Completed;
- break;
+ RequestApkDownConfigs();
+ }
+ else
+ {
+ step = Step.Completed;
}
}
else
@@ -110,6 +98,53 @@
{
step = Step.None;
Clock.Create(DateTime.Now + new TimeSpan(TimeSpan.TicksPerSecond), RequestVersionCheck);
+ }
+ }
+
+ public void RequestApkDownConfigs()
+ {
+ var config = ApkUpdateUrlConfig.Get(VersionConfig.Get().appId, VersionConfig.Get().branch);
+ HttpRequest.Instance.RequestHttpGet(config.url, HttpRequest.defaultHttpContentType, 1, OnGetApkDownConfigs);
+ }
+
+ private void OnGetApkDownConfigs(bool _ok, string _result)
+ {
+ if (_ok)
+ {
+ var lines = _result.Split(new string[] { FileExtersion.lineSplit }, StringSplitOptions.RemoveEmptyEntries);
+ apkDownUrls.Clear();
+ for (int i = 0; i < lines.Length; i++)
+ {
+ var apkDownUrl = new ApkDownUrl(lines[i]);
+ apkDownUrls[apkDownUrl.flag] = apkDownUrl;
+ }
+
+ switch (Application.platform)
+ {
+ case RuntimePlatform.Android:
+ if (File.Exists(GetApkLocalUrl()))
+ {
+ step = Step.ApkExist;
+ WindowCenter.Instance.OpenFromLocal<VersionUpdateWin>();
+ }
+ else
+ {
+ step = Step.DownLoadPrepared;
+ WindowCenter.Instance.OpenFromLocal<VersionUpdateWin>();
+ }
+ break;
+ case RuntimePlatform.IPhonePlayer:
+ step = Step.DownLoadPrepared;
+ WindowCenter.Instance.OpenFromLocal<VersionUpdateWin>();
+ break;
+ default:
+ step = Step.Completed;
+ break;
+ }
+ }
+ else
+ {
+ Clock.Create(DateTime.Now + new TimeSpan(TimeSpan.TicksPerSecond), RequestApkDownConfigs);
}
}
@@ -171,8 +206,40 @@
}
else
{
- var version = versionInfo.GetLatestVersion();
- return version.download_url;
+ var flag = SDKUtility.Instance.GetPackageFlag();
+ if (apkDownUrls.ContainsKey(flag))
+ {
+ return apkDownUrls[flag].url;
+ }
+ else
+ {
+ return string.Empty;
+ }
+ }
+ }
+
+ public int GetApkSize()
+ {
+ if (versionInfo == null)
+ {
+ return 0;
+ }
+
+ if (IsMaoErGame())
+ {
+ return versionInfo.GetLatestVersion().file_size;
+ }
+ else
+ {
+ var flag = SDKUtility.Instance.GetPackageFlag();
+ if (apkDownUrls.ContainsKey(flag))
+ {
+ return apkDownUrls[flag].size;
+ }
+ else
+ {
+ return 0;
+ }
}
}
@@ -400,7 +467,6 @@
{
public int is_fullpackage;
public int file_size;
- public string download_url;
public string version_desc;
public DateTime public_time;
public int update_force;
@@ -415,6 +481,22 @@
public string url;
}
+ public struct ApkDownUrl
+ {
+ public string flag;
+ public string url;
+ public int size;
+
+ public ApkDownUrl(string content)
+ {
+ var strings = content.Split('\t');
+
+ flag = strings[0];
+ url = strings[1];
+ int.TryParse(strings[2], out size);
+ }
+ }
+
public enum Step
{
None,
--
Gitblit v1.8.0