552 lines
27 KiB
Plaintext
552 lines
27 KiB
Plaintext
|
|
using UnityEngine;
|
||
|
|
using System.Collections;
|
||
|
|
using System.IO;
|
||
|
|
using FairyGUI;
|
||
|
|
using MiniJSON;
|
||
|
|
using UnityEngine.Networking;
|
||
|
|
using taurus.unity;
|
||
|
|
using System.Text;
|
||
|
|
using System;
|
||
|
|
|
||
|
|
public class VerCheck : MonoBehaviour
|
||
|
|
{
|
||
|
|
GComponent _version_view;
|
||
|
|
public static VerCheck Instance { get; private set; }
|
||
|
|
public securityConnection conn;
|
||
|
|
public bool isGFF = false;
|
||
|
|
public bool isDXYGFF = true;
|
||
|
|
|
||
|
|
void Awake()
|
||
|
|
{
|
||
|
|
Instance = this;
|
||
|
|
}
|
||
|
|
|
||
|
|
// Use this for initialization
|
||
|
|
void Start()
|
||
|
|
{
|
||
|
|
GameApplication.Instance.isAndroid64bit = IsAndroid64bit();
|
||
|
|
CreateVersionView();
|
||
|
|
StartCoroutine(CheckNet());
|
||
|
|
}
|
||
|
|
|
||
|
|
internal void ResetGame()
|
||
|
|
{
|
||
|
|
CreateVersionView();
|
||
|
|
StartCoroutine(__WaitReset());
|
||
|
|
}
|
||
|
|
|
||
|
|
IEnumerator __WaitReset()
|
||
|
|
{
|
||
|
|
var _luaClient = GameApplication.Instance.GetComponent<DSLuaClient>();
|
||
|
|
UnityEngine.Object.Destroy(_luaClient);
|
||
|
|
System.GC.Collect();
|
||
|
|
FontManager.Clear();
|
||
|
|
UIPackage.RemoveAllPackages();
|
||
|
|
ResourcesManager.DestroyAll();
|
||
|
|
CreateVersionView();
|
||
|
|
yield return null;
|
||
|
|
StartCoroutine(CheckNet());
|
||
|
|
}
|
||
|
|
|
||
|
|
void CreateVersionView()
|
||
|
|
{
|
||
|
|
ResourcesManager.ReadAssetConfig("base/embed");
|
||
|
|
UIPackage.AddPackage("base/embed/ui/Hotupdate");
|
||
|
|
if (_version_view != null) _version_view.Dispose();
|
||
|
|
_version_view = null;
|
||
|
|
_version_view = UIPackage.CreateObjectFromURL("ui://Hotupdate/Version").asCom;
|
||
|
|
GRoot.inst.AddChildAt(_version_view,0);
|
||
|
|
_version_view.x = (GRoot.inst.width - _version_view.width) / 2;
|
||
|
|
Debug.LogError(Application.persistentDataPath);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
public bool IsAndroid64bit()
|
||
|
|
{
|
||
|
|
#if UNITY_ANDROID && !UNITY_EDITOR
|
||
|
|
if (IntPtr.Size == 8)
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
#else
|
||
|
|
return false;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
IEnumerator CheckNet()
|
||
|
|
{
|
||
|
|
string json_data = string.Empty;
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
isDXYGFF= false;
|
||
|
|
isGFF = false;
|
||
|
|
|
||
|
|
string init_url = "http://8.138.120.167:9898/NewFK/config/init2_1.json";
|
||
|
|
|
||
|
|
if (isGFF == false && isDXYGFF == false)
|
||
|
|
{
|
||
|
|
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
if (isGFF)
|
||
|
|
{
|
||
|
|
int rc = AppVest.init("8ef91e7e799b5851a8ce810aae0c697c", "U5ayF4voVvRh1ElqBIVUCR9dSFskPGvCkfreFxdxzi39hoU0faqZWjFzC90Cta50egaQatCbPxm6XTlvi2+o++PrSozoZ+HUUY0y8tBloMWaOYQX59SAhjA/DyIDHJgGbE1I");
|
||
|
|
if (rc != 0)
|
||
|
|
{
|
||
|
|
// Debug.LogError("init failed");
|
||
|
|
ShowTip("GF init failed!", () =>
|
||
|
|
{
|
||
|
|
StartCoroutine(CheckNet());
|
||
|
|
});
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
// Debug.LogError("init successful");
|
||
|
|
|
||
|
|
|
||
|
|
conn.ip = "";
|
||
|
|
conn.port = 0;
|
||
|
|
int rc1 = AppVest.getServerIPAndPort(ref conn, "", 5021);
|
||
|
|
if (rc1 != 0)
|
||
|
|
{
|
||
|
|
ShowTip("getServerIPAndPort failed!", () =>
|
||
|
|
{
|
||
|
|
StartCoroutine(CheckNet());
|
||
|
|
});
|
||
|
|
yield break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
string key = "MO/rC2vz5tsibxAAAIx4h56TvCE0HQxZZmi5HiuH62YiTZBazNXaeFPIjlIQq+qecRuI2e7miDQkWKUDOciwmuFuiGj6HbnIuEPNa465SLp9G6wP/RJ3O8RbNnQv1z+JF/JwoSOBolNhvyCqGBylag/qhR0coJvO9kyjnuZEmOAERFOaSaaW+nhYrT7wyyOntcpkRFEhbXZXoKnV3QNrHCY/ptPICyFoU4mjwvJc3Cop+ugc31SO4dXcQ6f7wBx17JEYsSVO3qqo+vDGfaqD+cN+q+IZTzvRsMP868Z5bJFtLtRgRCsF2Rs+cuNjxmQrWUjjfBU5W51VRQBhUfLiL45eWU/UIrWXedDG2dtXbulf0ZF+lO58M9E3C/0qo4goW0JUBGwVVTaSSwNDcYHA/NYWAn9gZJme4CZ8nRe2bNRInn6YA2l8SXxb6knrOMBQdQ0nFKEJxvaotCJGl7Yf2t0t+tICKPlsmLcCBXhQsqhkCRtEw3JDY8lxjXbpc054+kRtU6f/akOQ0JPSxkhSdyQC/kNy6ceNOPHfWvMv0aFWjjeh0QFc7Lq2uCVrVCUC3vHuG5yvCE+hKRd2bY85boC68UwdADAT25bmor8CKiP9WiKhPCDjpgh+45zlh6QHgE0Ggrvy/E5sZkhx8TU81DDqtHGposTtCBomy982kSDYWJRzbo4CbOGR2tHHL9kHU65mvOamTKjfH1ufm1yjpN0G9wF81bStmtOx/Rbbwa54C3QL4GFxzoXjZnmEa/b8AKmp4XjYi9mvdP0J+yBLmW455pKrV9fWzUOagj96o3e/0NqOG24qXwCTGm/0fokCv3AHG6aKWa4UXQbA/GbyQkte1iqO7P/ZFe3af+Mkf4kt3wCOFHBA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MPRjS0yO7ir5gj50GehaWU0RG4wUhEIrgfK/GsIttHPvud4n8UJSPqAPvJuApGsbExUMCr+m6b+fV+m/XyShE/P8WKIKPwwMC/ged4MVADJKShLu70eVrajd";
|
||
|
|
int rc = DxyVest.Start(key);//AppVest.init("553c12676eb80b82183e0944df97cd19", "K8N/nk3cAxhGo7Oy0yoP/Ye5jcQUaMf+8+AutonLIoCXTbHXSHJ/D8W3/iIBHJq/4SABnAF7RvIeNRnF+x+wjB6cB1TEwIUviviQlofNvM4qJFLH55ON85n2pFBhSGW3qLF/");
|
||
|
|
if (rc != 150)
|
||
|
|
//if (rc != 0)
|
||
|
|
{
|
||
|
|
Debug.LogError("wwwwwwwwwwwwwwwwwwwwwww init failed");
|
||
|
|
ShowTip("GF init failed!", () =>
|
||
|
|
{
|
||
|
|
StartCoroutine(CheckNet());
|
||
|
|
});
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
// Debug.LogError("init successful");
|
||
|
|
|
||
|
|
|
||
|
|
conn.ip = "127.0.0.1";
|
||
|
|
conn.port = 49898;
|
||
|
|
//int rc1 = AppVest.getServerIPAndPort(ref conn, "", 8077);
|
||
|
|
//if (rc1 != 0)
|
||
|
|
//{
|
||
|
|
// ShowTip("getServerIPAndPort failed!", () =>
|
||
|
|
// {
|
||
|
|
// StartCoroutine(CheckNet());
|
||
|
|
// });
|
||
|
|
// yield break;
|
||
|
|
//}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
// init_url = "http://" + conn.ip + ":" + conn.port + "/NewFK/config/init2_1.json";
|
||
|
|
init_url = "https://yunque911.oss-cn-hangzhou.aliyuncs.com/NewFK/config/init2_1.json";
|
||
|
|
// Debug.LogError("init_url : " + init_url);
|
||
|
|
}
|
||
|
|
// Debug.LogError("开始下载资源===>>>");
|
||
|
|
// Debug.LogError(init_url);
|
||
|
|
//Debug.LogError("init_url============================ "+ init_url);
|
||
|
|
float downTimeOut = 5;
|
||
|
|
using (WWW request1 = new WWW(init_url))
|
||
|
|
{
|
||
|
|
float timeOut = Time.time;
|
||
|
|
float process = request1.progress;
|
||
|
|
while (request1!=null && request1.isDone==false)
|
||
|
|
{
|
||
|
|
//Debug.LogError("wwwwwwwwwwwwwwwwwww11111111111111111111111");
|
||
|
|
if(process<request1.progress)
|
||
|
|
{
|
||
|
|
timeOut = Time.time;
|
||
|
|
process = request1.progress;
|
||
|
|
}
|
||
|
|
|
||
|
|
if(Time.time-timeOut>downTimeOut)
|
||
|
|
{
|
||
|
|
ShowTip("资源配置下载失败,请检查您的网络设置!", () =>
|
||
|
|
{
|
||
|
|
StartCoroutine(CheckNet());
|
||
|
|
});
|
||
|
|
yield break;
|
||
|
|
}
|
||
|
|
|
||
|
|
yield return null;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
yield return request1;
|
||
|
|
// Debug.LogError("request1.error"+request1.error);
|
||
|
|
if (string.IsNullOrEmpty(request1.error))
|
||
|
|
{
|
||
|
|
//Debug.LogError("wwwwwwwwwwwwwwwww222222222222222222222222");
|
||
|
|
json_data = request1.text;
|
||
|
|
|
||
|
|
//优化
|
||
|
|
GameApplication.Instance.GameInfo = json_data;
|
||
|
|
Hashtable json = Json.Deserialize(json_data) as Hashtable;
|
||
|
|
//json["pack_url"] = "http://8.134.59.224:8909/NewFKtest";
|
||
|
|
Hotupdate.PackUrl = (string)json["pack_url"];
|
||
|
|
|
||
|
|
Hashtable _plat_data = null;
|
||
|
|
#if UNITY_IPHONE
|
||
|
|
_plat_data = json["iOS"] as Hashtable;
|
||
|
|
#endif
|
||
|
|
#if UNITY_ANDROID
|
||
|
|
_plat_data = json["Android"] as Hashtable;
|
||
|
|
#endif
|
||
|
|
#if UNITY_STANDALONE
|
||
|
|
_plat_data = json["Win"] as Hashtable;
|
||
|
|
#endif
|
||
|
|
var check = _plat_data[string.Format("check{0}", GameApplication.AppVersion.ToString())];
|
||
|
|
if (check != null && (bool)check)
|
||
|
|
{
|
||
|
|
GameApplication.HideSdk = true;
|
||
|
|
GameApplication.Instance.accountTest = false;
|
||
|
|
}
|
||
|
|
|
||
|
|
Version server_version = new Version((string)_plat_data["version"]);
|
||
|
|
if (!GameApplication.HideSdk)
|
||
|
|
{
|
||
|
|
if (GameApplication.AppVersion.max_version < server_version.max_version || (GameApplication.AppVersion.max_version == server_version.max_version && GameApplication.AppVersion.min_version < server_version.min_version))
|
||
|
|
{
|
||
|
|
ShowTip("您版本需要更新!", () =>
|
||
|
|
{
|
||
|
|
#if UNITY_ANDROID
|
||
|
|
StartCoroutine(DownApp((string)_plat_data["appurl"], server_version.ToString()));
|
||
|
|
#else
|
||
|
|
DeleteOldPack();
|
||
|
|
Application.OpenURL((string)_plat_data["appurl"]);
|
||
|
|
Application.Quit();
|
||
|
|
#endif
|
||
|
|
});
|
||
|
|
yield break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
Voice.VoiceUpload = json["voice_upload_url"] as string;
|
||
|
|
Voice.VoiceDownload = json["voice_download_url"] as string;
|
||
|
|
//GameApplication.PackVersion = server_version.pack_version;
|
||
|
|
|
||
|
|
if (!GameApplication.Instance.buildApp)
|
||
|
|
{
|
||
|
|
GameApplication.AppVersion.FillData(server_version);
|
||
|
|
_version_view.Dispose();
|
||
|
|
GameApplication.Instance.StartGame();
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
StartCoroutine(CheckAssetConfig(server_version));
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
ShowTip("资源配置下载失败,请检查您的网络设置!", () =>
|
||
|
|
{
|
||
|
|
StartCoroutine(CheckNet());
|
||
|
|
});
|
||
|
|
//yield break;
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
IEnumerator CheckAssetConfig(Version server_version)
|
||
|
|
{
|
||
|
|
GObject v_tex_info = _version_view.GetChild("tex_info");
|
||
|
|
Version local_version = Hotupdate.GetLocalVersion(string.Empty);
|
||
|
|
ArrayList asset_config_list = null;
|
||
|
|
string asset_config_text = null;
|
||
|
|
if (local_version == null || local_version.ContainAll(server_version))
|
||
|
|
{
|
||
|
|
string ac_url="";
|
||
|
|
if(isGFF==false)
|
||
|
|
ac_url = string.Format("{0}/config/asset_config{1}.json", Hotupdate.PackUrl, server_version.ToString());
|
||
|
|
else
|
||
|
|
ac_url = string.Format("http://{0}/NewFK/config/asset_config{1}.json", conn.ip + ":" + conn.port, server_version.ToString());
|
||
|
|
|
||
|
|
// Debugger.LogError("CheckAssetConfig===>>>");
|
||
|
|
// Debugger.LogError(ac_url);
|
||
|
|
|
||
|
|
float downTimeOut = 5;
|
||
|
|
using (var request = new WWW(ac_url))
|
||
|
|
{
|
||
|
|
float timeOut = Time.time;
|
||
|
|
float process = request.progress;
|
||
|
|
while (request != null && request.isDone == false)
|
||
|
|
{
|
||
|
|
if (process < request.progress)
|
||
|
|
{
|
||
|
|
timeOut = Time.time;
|
||
|
|
process = request.progress;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (Time.time - timeOut > downTimeOut)
|
||
|
|
{
|
||
|
|
ShowTip("游戏配置下载异常,请检查您的网络设置!", () =>
|
||
|
|
{
|
||
|
|
StartCoroutine(CheckNet());
|
||
|
|
});
|
||
|
|
yield break;
|
||
|
|
}
|
||
|
|
|
||
|
|
yield return null;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
yield return request;
|
||
|
|
if (string.IsNullOrEmpty(request.error))
|
||
|
|
{
|
||
|
|
asset_config_text = request.text;
|
||
|
|
asset_config_list = Json.Deserialize(asset_config_text) as ArrayList;
|
||
|
|
|
||
|
|
if (asset_config_list == null)
|
||
|
|
{
|
||
|
|
ShowTip("游戏配置下载异常,请检查您的网络设置!", () =>
|
||
|
|
{
|
||
|
|
StartCoroutine(CheckAssetConfig(server_version));
|
||
|
|
});
|
||
|
|
yield break;
|
||
|
|
}
|
||
|
|
//
|
||
|
|
v_tex_info.text = "正在检查资源。。。";
|
||
|
|
GSlider _pd = _version_view.GetChild("pb_progress").asSlider;
|
||
|
|
_pd.value = 0.0;
|
||
|
|
|
||
|
|
bool ver_check = false;
|
||
|
|
StartCoroutine(VersionUpdateCheck(asset_config_list, (progress, finish) =>
|
||
|
|
{
|
||
|
|
_pd.value = progress * 100f;
|
||
|
|
ver_check = finish;
|
||
|
|
}, v_tex_info));
|
||
|
|
|
||
|
|
while (!ver_check)
|
||
|
|
{
|
||
|
|
yield return null;
|
||
|
|
}
|
||
|
|
string arv = string.Format("{0}asset_config{1}.json", ResourcesManager.PACK_PATH, server_version.ToString());
|
||
|
|
File.WriteAllText(arv, asset_config_text, System.Text.Encoding.UTF8);
|
||
|
|
string rv = ResourcesManager.PACK_PATH + "version.txt";
|
||
|
|
File.WriteAllText(rv, server_version.ToString(), System.Text.Encoding.UTF8);
|
||
|
|
|
||
|
|
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
ShowTip("游戏资源下载失败,请检查您的网络设置!", () =>
|
||
|
|
{
|
||
|
|
StartCoroutine(CheckAssetConfig(server_version));
|
||
|
|
});
|
||
|
|
yield break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}else
|
||
|
|
{
|
||
|
|
// string arv = string.Format("{0}asset_config{1}.json", ResourcesManager.PACK_PATH, server_version.ToString());
|
||
|
|
string arv =ResourcesManager.PACK_PATH+"asset_config"+server_version.ToString()+".json";
|
||
|
|
//Debug.LogError("ARV===>>>" + arv);
|
||
|
|
try
|
||
|
|
{
|
||
|
|
asset_config_text = File.ReadAllText(arv);
|
||
|
|
asset_config_list = Json.Deserialize(asset_config_text) as ArrayList;
|
||
|
|
foreach (Hashtable tem in asset_config_list)
|
||
|
|
{
|
||
|
|
string b_path = "base/" + tem["name"];
|
||
|
|
ResourcesManager.ReadAssetConfig(b_path);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
catch (Exception s)
|
||
|
|
{
|
||
|
|
Debug.LogError(s.ToString());
|
||
|
|
ShowTip("游戏资源损坏,请重新安装新包!", () =>
|
||
|
|
{
|
||
|
|
StartCoroutine(CheckAssetConfig(server_version));
|
||
|
|
});
|
||
|
|
yield break;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
//IEnumerator enumerator = asset_config_list.GetEnumerator();
|
||
|
|
//try
|
||
|
|
//{
|
||
|
|
// while (enumerator!=null && enumerator.MoveNext())
|
||
|
|
// {
|
||
|
|
// Hashtable hashtable = (Hashtable)enumerator.Current;
|
||
|
|
// string base_path = "base/" + hashtable["name"].ToString();
|
||
|
|
// ResourcesManager.ReadAssetConfig(base_path);
|
||
|
|
// yield return null;
|
||
|
|
// }
|
||
|
|
//}
|
||
|
|
//finally
|
||
|
|
//{
|
||
|
|
// IDisposable disposable;
|
||
|
|
// if ((disposable = (enumerator as IDisposable)) != null)
|
||
|
|
// {
|
||
|
|
// disposable.Dispose();
|
||
|
|
// }
|
||
|
|
//}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
GameApplication.AppVersion.FillData(server_version);
|
||
|
|
v_tex_info.text = "正在加载资源请稍后。。";
|
||
|
|
//ResourcesManager.Init();
|
||
|
|
yield return null;
|
||
|
|
_version_view.Dispose();
|
||
|
|
GameApplication.Instance.StartGame();
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 检查基本更新包
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="asset_config_list"></param>
|
||
|
|
/// <param name="onback"></param>
|
||
|
|
/// <param name="tip"></param>
|
||
|
|
/// <returns></returns>
|
||
|
|
IEnumerator VersionUpdateCheck(ArrayList asset_config_list, System.Action<float, bool> onback, FairyGUI.GObject tip)
|
||
|
|
{
|
||
|
|
Version local_version = Version.DEFUALT;
|
||
|
|
for(int i=0;i< asset_config_list.Count; ++i)
|
||
|
|
{
|
||
|
|
var tem = asset_config_list[i] as Hashtable;
|
||
|
|
//if (GameApplication.HideSdk)
|
||
|
|
//{
|
||
|
|
// if (!tem.ContainsKey("check")) continue;
|
||
|
|
// if (!(bool)tem["check"]) continue;
|
||
|
|
//}
|
||
|
|
|
||
|
|
|
||
|
|
string b_path = "base/" + tem["name"].ToString();
|
||
|
|
Hotupdate version_update = new Hotupdate(b_path + "/", local_version, new Version((string)tem["ver"]));
|
||
|
|
version_update.AssetName = b_path;
|
||
|
|
version_update.HideDetail = true;
|
||
|
|
#if UNITY_ANDROID && !UNITY_EDITOR
|
||
|
|
//if (GameApplication.Instance.isAndroid64bit==false)
|
||
|
|
//{
|
||
|
|
// if (tem["name"].ToString()=="base_script")
|
||
|
|
// {
|
||
|
|
// version_update.isBuild32lua = true;
|
||
|
|
// }
|
||
|
|
//}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
version_update.SetTipCallback((text,callback)=>
|
||
|
|
{
|
||
|
|
ShowTip(text, callback);
|
||
|
|
});
|
||
|
|
version_update.LoadAsset();
|
||
|
|
while (!version_update.Done)
|
||
|
|
{
|
||
|
|
onback(version_update.Progress, false);
|
||
|
|
tip.text = version_update.TextTip;
|
||
|
|
yield return null;
|
||
|
|
}
|
||
|
|
ResourcesManager.ReadAssetConfig(b_path);
|
||
|
|
}
|
||
|
|
onback(1, true);
|
||
|
|
}
|
||
|
|
|
||
|
|
#if UNITY_ANDROID
|
||
|
|
IEnumerator DownApp(string appurl,string version)
|
||
|
|
{
|
||
|
|
var v_tex_info = _version_view.GetChild("tex_info");
|
||
|
|
v_tex_info.text = "正在下载新的安装包(0KB/0KB)";
|
||
|
|
var _pd = _version_view.GetChild("pb_progress").asSlider;
|
||
|
|
var request = new BestHTTP.HTTPRequest(new System.Uri(appurl));
|
||
|
|
request.EnableTimoutForStreaming = false;
|
||
|
|
request.UseStreaming = true;
|
||
|
|
request.IsKeepAlive = true;
|
||
|
|
request.Send();
|
||
|
|
var filePath = Application.persistentDataPath + "/update" + version + ".apk";
|
||
|
|
if (File.Exists(filePath))
|
||
|
|
{
|
||
|
|
File.Delete(filePath);
|
||
|
|
}
|
||
|
|
FileStream stream = null;
|
||
|
|
request.OnProgress = (originalRequest, downloaded, downloadLength) =>
|
||
|
|
{
|
||
|
|
v_tex_info.text = string.Format("正在下载新的安装包({0}KB/{1}KB)", downloaded / 1024, downloadLength / 1024);
|
||
|
|
_pd.value = (downloaded / (float)downloadLength) * 100;
|
||
|
|
var fragments = originalRequest.Response.GetStreamedFragments();
|
||
|
|
if (fragments != null)
|
||
|
|
{
|
||
|
|
if (stream == null)
|
||
|
|
{
|
||
|
|
stream = File.Create(filePath);
|
||
|
|
}
|
||
|
|
foreach(byte[] buffer in fragments)
|
||
|
|
{
|
||
|
|
stream.Write(buffer, 0, buffer.Length);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
};
|
||
|
|
while (request.State < BestHTTP.HTTPRequestStates.Finished)
|
||
|
|
{
|
||
|
|
yield return null;
|
||
|
|
}
|
||
|
|
yield return new WaitForSeconds(1);
|
||
|
|
stream.Dispose();
|
||
|
|
request.OnProgress = null;
|
||
|
|
if (request.State == BestHTTP.HTTPRequestStates.Finished && request.Response.IsSuccess)
|
||
|
|
{
|
||
|
|
DeleteOldPack();
|
||
|
|
PlatformAndroid.Instance.UpdateApp(filePath);
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
ShowTip("请检查您的网络设置!", () =>
|
||
|
|
{
|
||
|
|
StartCoroutine(DownApp(appurl, version));
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
public void ShowTip(string text, System.Action callback)
|
||
|
|
{
|
||
|
|
var ctr_state = _version_view.GetController("state");
|
||
|
|
ctr_state.selectedIndex = 1;
|
||
|
|
_version_view.GetChild("tex_tip").text = text;
|
||
|
|
_version_view.GetChild("btn_ok").onClick.Set(() =>
|
||
|
|
{
|
||
|
|
ctr_state.selectedIndex = 0;
|
||
|
|
if (callback != null) callback();
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 移除本地缓存包
|
||
|
|
/// </summary>
|
||
|
|
public static void DeleteOldPack()
|
||
|
|
{
|
||
|
|
string dir = ResourcesManager.RES_PATH;
|
||
|
|
string rv = dir + "version.txt";
|
||
|
|
if (File.Exists(rv)) File.Delete(rv);
|
||
|
|
if (Directory.Exists(dir)) Directory.Delete(dir, true);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
}
|