caihong_client/wb_unity_pro/Assets/Scripts/VerCheck.cs

852 lines
41 KiB
C#
Raw Permalink Normal View History

using UnityEngine;
using System.Collections;
using System.IO;
using FairyGUI;
using MiniJSON;
using UnityEngine.Networking;
using taurus.unity;
using System.Text;
using System;
using taurus.client;
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.width = GRoot.inst.width;
_version_view.height = GRoot.inst.height;
_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;
2025-09-22 17:27:49 +08:00
isDXYGFF= false;
isGFF = false;
2025-12-15 22:45:10 +08:00
string init_url = "http://8.148.219.235:19898/NewFK/config/init2_1.json";
//string init_url = "";
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 = "cfPrC3NCoGHakhAAAM0odQ9vPD2p/Z011HH1sH0lxS58Op1ba3Tbjv0PhHAydds8NO780Uy3jY0tUzMBS+7jtDi7r54wzAqakq0/mnktAl+VuXuOJ/PgxKwPLhdB2kIOK843dsQ8DGfjYj6eePEUAFHTa5ByVI1E2enwIJ3yWLdqMG6p9YuZWK0TqcO1Qky5+S7FbW6wmtVB8ZvaSurJ8AmFM0eCagnEORLiXqrIjpedNiZvLepIuJSYZwPvvg3CSbe6Lw8EN44kADNczTwreGMDPBPDWsMdPHmy6QIG1HoEHxXxDV6ImP6WSiy36+pYbO2e64H4/e7znPGUUUyLHSu3V64mOWoFeqIULQ+XZU+OWnwUZ+f4CyAm/XBr8kexCiwA/pQ7MTODmXDd5NDeWzaiBvXPd7VCvkyNmeIBAeFiawndXlvXzKpZcQ5ylauBWkxPQX0QrxZIaEZDtIdQNf3jNw3EfJBeMcgL3+mHcz3SzIOkWJoHsZR2F+i+TYQ/U1CU6vJRxi4VEnebxSWxwlIeBJsnsu9Jtl2tVbVBs1SF0Lj7vhEvlNhSja69QLQoBMPOXnk0AebOaRBL0d9IeY6pOIRJjt5QkaOO2A0TSlZY/YJU86zNlGJ9wlY3hlcSHBcgljsMT6ys2JBizZMl+bJ9nAEsNYUiwdSdjvXhjs+t0r5KY5jF4mRlzjLim5gDAVKuFhjhalCm5YS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EPZyeu5TnMpyd/D0ZCHaQAMI1exw/D2pDOlSmdOBQIcvE9R7R1eUe1QkpLTtNzHLVpoPHNTO4iyfXmTtJQKtKj2X+AkCdGoVV5J750dlVLywFFGu1Y0FA9M6g
int rc = DxyVest.Start(key);//AppVest.init("553c12676eb80b82183e0944df97cd19", "K8N/nk3cAxhGo7Oy0yoP/Ye5jcQUaMf+8+AutonLIoCXTbHXSHJ/D8W3/iIBHJq/4SABnAF7RvIeNRnF+x+wjB6cB1TEwIUviviQlofNvM4qJFLH55ON85n2pFBhSGW3qLF/");
if (rc != 150)
{
Debug.LogError("wwwwwwwwwwwwwwwwwwwwwww init failed");
ShowTip("GF init failed!", () =>
{
StartCoroutine(CheckNet());
});
}
// Debug.LogError("init successful");
conn.ip = "127.0.0.1";
2025-12-15 22:45:10 +08:00
conn.port = 37878;
//int rc1 = AppVest.getServerIPAndPort(ref conn, "", 8077);
//if (rc1 != 0)
//{
// ShowTip("getServerIPAndPort failed!", () =>
// {
// StartCoroutine(CheckNet());
// });
// yield break;
//}
}
2025-09-01 17:41:29 +08:00
init_url = "http://" + conn.ip + ":" + conn.port + "/NewFK/config/init2_1.json";
Debug.LogError("init_url : " + init_url);
}
// Debug.LogError("开始下载资源===>>>");
2025-12-15 22:45:10 +08:00
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)
{
string ac_url = "";
if (isGFF == false)
ac_url = string.Format("{0}/config/asset_config{1}.json", Hotupdate.PackUrl, server_version.ToString());
else
2025-09-01 17:41:29 +08:00
ac_url = string.Format("http://{0}/NewFK/config/asset_config{1}.json", conn.ip + ":" + conn.port, server_version.ToString());
Debug.Log(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;
if (!Directory.Exists(ResourcesManager.PACK_PATH))
{
Directory.CreateDirectory(ResourcesManager.PACK_PATH);
}
string copyVersionPath = Path.Combine(Application.streamingAssetsPath, "version.txt");
2025-09-12 02:47:38 +08:00
#if UNITY_IPHONE
2025-09-13 16:58:49 +08:00
string copyVersionString = "";
2025-09-12 02:47:38 +08:00
if (File.Exists(copyVersionPath))
{
2025-09-13 16:58:49 +08:00
copyVersionString = File.ReadAllText(copyVersionPath).Trim();
}
else
{
ShowTip("本地缓存版本加载失败", () =>
{
File.WriteAllText(Path.Combine(ResourcesManager.PACK_PATH, "version.txt"), "1.0.0");
StartCoroutine(CheckAssetConfig(server_version));
});
yield break;
2025-09-12 02:47:38 +08:00
}
#endif
#if UNITY_ANDROID
UnityWebRequest copyRequest = UnityWebRequest.Get(copyVersionPath);
yield return copyRequest.SendWebRequest();
if (copyRequest.isNetworkError || copyRequest.isHttpError)
{
2025-12-15 22:45:10 +08:00
/* ShowTip("本地缓存版本加载失败", () =>
{*/
File.WriteAllText(Path.Combine(ResourcesManager.PACK_PATH, "version.txt"), "1.0.0");
StartCoroutine(CheckAssetConfig(server_version));
2025-12-15 22:45:10 +08:00
//});
yield break;
}
2025-09-12 02:47:38 +08:00
string copyVersionString = copyRequest.downloadHandler.text.Trim();
2025-09-12 02:47:38 +08:00
#endif
bool isSame = copyVersionString.Equals(server_version.ToString());
if (isSame)
{
string copyZipPath = Path.Combine(Application.streamingAssetsPath, "Pack.byte");
2025-09-12 02:47:38 +08:00
#if UNITY_IPHONE
2025-09-22 17:27:49 +08:00
Byte[] zipData;
if (File.Exists(copyZipPath))
2025-09-13 16:58:49 +08:00
{
zipData = File.ReadAllBytes(copyZipPath);
}
else
2025-09-12 02:47:38 +08:00
{
2025-09-13 16:58:49 +08:00
ShowTip("本地缓存压缩包加载失败", () =>
{
StartCoroutine(CheckAssetConfig(server_version));
});
yield break;
2025-09-12 02:47:38 +08:00
}
2025-09-22 17:27:49 +08:00
/* if (zipData.LongLength < 1024)
{
ShowTip("本地缓存压缩包加载失败", () =>
{
StartCoroutine(CheckAssetConfig(server_version));
});
yield break;
}*/
string zipString = Path.Combine(Application.persistentDataPath, "Pack.byte");
File.WriteAllBytes(zipString, zipData);
2025-09-12 02:47:38 +08:00
#endif
#if UNITY_ANDROID
UnityWebRequest copyZipRequest = UnityWebRequest.Get(copyZipPath);
yield return copyZipRequest.SendWebRequest();
if (copyZipRequest.isNetworkError || copyZipRequest.isHttpError)
{
ShowTip("本地缓存压缩包加载失败", () =>
{
StartCoroutine(CheckAssetConfig(server_version));
});
yield break;
}
byte[] zipData = copyZipRequest.downloadHandler.data;
string zipString = Path.Combine(Application.persistentDataPath, "Pack.byte");
File.WriteAllBytes(zipString, zipData);
2025-09-22 17:27:49 +08:00
#endif
IFilePack zip = null;
zip = new FilePack20(zipString, PackMode.Read);
zip.UnPackFileSyn(ResourcesManager.PACK_PATH);
while (!zip.Complete)
{
_pd.value = zip.Progress*100;
yield return null;
}
StartCoroutine(CheckAssetConfig(server_version));
yield break;
}
else
{
File.WriteAllText(Path.Combine(ResourcesManager.PACK_PATH, "version.txt"), copyVersionString);
StartCoroutine(CheckAssetConfig(server_version));
yield break;
}
}
else
{
ShowTip("游戏资源下载失败,请检查您的网络设置!", () =>
{
StartCoroutine(CheckAssetConfig(server_version));
});
yield break;
}
}
}
else if (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
2025-09-01 17:41:29 +08:00
ac_url = string.Format("http://{0}/NewFK/config/asset_config{1}.json", conn.ip + ":" + conn.port, server_version.ToString());
// Debugger.LogError("CheckAssetConfig===>>>");
2025-12-15 22:45:10 +08:00
// 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;
}
//
2025-12-22 23:01:08 +08:00
v_tex_info.text = "正在检查资源中。。。";
GSlider _pd = _version_view.GetChild("pb_progress").asSlider;
2025-12-15 22:45:10 +08:00
_pd.value = 0.0;
2025-12-22 23:01:08 +08:00
//开始检查所有资源
bool size_check = false;
long total_size = 0;
StartCoroutine(VersionUpdateCheckSize2(asset_config_list, _pd,(all_size, finish) =>
{
total_size = all_size;
size_check = finish;
}));
while (!size_check)
{
yield return null;
}
Debug.Log($"总大小:{(total_size / 1024f / 1024f):F2} MB");
bool ver_check = false;
StartCoroutine(VersionUpdateCheck(asset_config_list, (progress, finish) =>
{
2025-12-22 23:01:08 +08:00
if (ver_check)
{
_pd.value = 100f;
ver_check = finish;
}
else
{
v_tex_info.text = $"正在下载资源({(progress / 1024f / 1024f):F2} MB/{(total_size / 1024f / 1024f):F2} MB";
_pd.value = progress / total_size * 100f;
ver_check = finish;
}
}));
while (!ver_check)
{
yield return null;
}
2025-12-22 23:01:08 +08:00
bool unZip_check = false;
v_tex_info.text = "正在解压文件(该过程不消耗流量)";
_pd.value = 100f;
StartCoroutine(VersionUpdateUnZip(asset_config_list, (finish) =>
{
unZip_check = finish;
}));
while (!unZip_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);
2025-12-22 23:01:08 +08:00
//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>
2025-12-22 23:01:08 +08:00
/// <param name="total_size"></param>
/// <returns></returns>
2025-12-22 23:01:08 +08:00
IEnumerator VersionUpdateCheck(ArrayList asset_config_list, System.Action<float, bool> onback)
{
Version local_version = Version.DEFUALT;
2025-12-22 23:01:08 +08:00
float download_size = 0;
for(int i=0;i< asset_config_list.Count; ++i)
{
var tem = asset_config_list[i] as Hashtable;
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;
version_update.SetTipCallback((text,callback)=>
{
ShowTip(text, callback);
});
version_update.LoadAsset();
while (!version_update.Done)
{
2025-12-22 23:01:08 +08:00
onback(download_size + version_update.Progress* (float)tem["size"], false);
yield return null;
}
2025-12-22 23:01:08 +08:00
download_size += (float)tem["size"];
ResourcesManager.ReadAssetConfig(b_path);
}
onback(1, true);
}
2025-12-22 23:01:08 +08:00
/// <summary>
/// 检查基本更新包大小
/// </summary>
/// <param name="asset_config_list"></param>
/// <param name="onback"></param>
/// <param name="tip"></param>
/// <returns></returns>
IEnumerator VersionUpdateCheckSize(ArrayList asset_config_list, System.Action<long, bool> onback)
{
Version local_version_one = Version.DEFUALT;
long totalSize = 0;
for (int i = 0; i < asset_config_list.Count; ++i)
{
var tem_one = asset_config_list[i] as Hashtable;
string b_path_one = "base/" + tem_one["name"].ToString();
local_version_one = Hotupdate.GetLocalVersion(b_path_one);
var update_pack2 = local_version_one == null || local_version_one.ContainAll(new Version((string)tem_one["ver"]));
string osPath = ResourcesManager.OS_Dir;
if (update_pack2)
{
var pack_path = string.Format("{0}/asset_pack{1}.bytes", b_path_one, (string)tem_one["ver"]);
var url = "";
if (VerCheck.Instance.isGFF == false && VerCheck.Instance.isDXYGFF == false)
url = string.Format("{0}/{1}/{2}", Hotupdate.PackUrl, osPath, pack_path);
else
url = string.Format("{0}/{1}/{2}", "http://" + VerCheck.Instance.conn.ip + ":" + VerCheck.Instance.conn.port + "/NewFKN", osPath, pack_path);
url = string.Format("{0}/{1}/{2}", Hotupdate.PackUrl, osPath, pack_path);
if (Application.platform == RuntimePlatform.WindowsEditor)
Debug.Log("check_url:" + url);
using (UnityWebRequest head = UnityWebRequest.Head(url))
{
yield return head.SendWebRequest();
#if UNITY_2020_2_OR_NEWER
if (head.result == UnityWebRequest.Result.Success)
#else
if (!head.isNetworkError && !head.isHttpError)
#endif
{
string len = head.GetResponseHeader("Content-Length");
if (!string.IsNullOrEmpty(len) && long.TryParse(len, out long size))
{
totalSize += size;
tem_one["size"] = size;
yield return null;
}
else
{
Debug.LogWarning($"无法获取文件大小: {url}");
yield return 0L;
}
}
else
{
Debug.LogError($"获取文件大小失败: {head.error}");
yield return 0L;
}
}
}
}
onback(totalSize, true);
}
IEnumerator VersionUpdateCheckSize2(ArrayList asset_config_list, GSlider gSlider, System.Action<long, bool> onback)
{
Version local_version = Version.DEFUALT;
long totalSize = 0;
float oneP = 100 / asset_config_list.Count;
for (int i = 0; i < asset_config_list.Count; ++i)
{
var tem = asset_config_list[i] as Hashtable;
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;
version_update.SetTipCallback((text, callback) =>
{
ShowTip(text, callback);
});
version_update.LoadAssetSize();
while (!version_update.Done)
{
gSlider.value = oneP * i + oneP* version_update.Progress;
yield return null;
}
tem["size"] = version_update.Size;
totalSize += (long)version_update.Size;
ResourcesManager.ReadAssetConfig(b_path);
}
onback(totalSize, true);
}
/// <summary>
/// 解压下载的资源文件
/// </summary>
/// <param name="asset_config_list"></param>
/// <param name="onback"></param>
/// <returns></returns>
IEnumerator VersionUpdateUnZip(ArrayList asset_config_list, System.Action<bool> onback)
{
for (int i = 0; i < asset_config_list.Count; ++i)
{
var tem = asset_config_list[i] as Hashtable;
string b_path = "base/" + tem["name"].ToString();
ResourcesManager.ReadAssetConfig(b_path);
yield return null;
}
onback(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);
}
}