yunque9/wb_unity_pro/Assets/Scripts/VerCheck.cs

701 lines
36 KiB
C#
Raw 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-01 17:41:29 +08:00
isDXYGFF= true;
isGFF = false;
//string init_url = "http://8.138.94.89:9898/NewFK/config/init2_1.json";
//公用
2025-09-01 17:41:29 +08:00
string init_url = "http://127.0.0.1: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
{
2025-09-01 17:41:29 +08:00
string key = "d6MHAIoszMfVxBgAAMFHsH2qndba+R2gZricU3IW0sKSDL00U3abXVpHTgKYP1W5FsYcvXfRUHK7ZFDRjnhVviePGNcDEl0HDkB8k6obByZi4T2r+RRKwLtLeO0lyc3g8Y7ZCSZ9tgNoFa82VLvGoF0pbqs7qMQTRFcct5lv4ENxmqEcQP3TDGoXF5W3Pubmf34dRy1wV+qipa5yidyi1REw/0tkcoOJAGo33hASot9Qzj9BBMOMS8/DzozVYadPvuF58eFpV05uzlDMYFUXYPRkMTkD+tQk+Lx+vG9wvDE5TgVHf+ZntF4xY+WeHF/2bZ6uF6sH8z/0/6sUuYHI9Zssi64kswwIIYiXmq+K1nE359ZDPuE6bwN1IplsDL6NJdgmf6xxYfufUxP9iuSgneO2baBAHrRfjh6ODGF4jaV4Zs7RdKATOTvVMGYc4P+WfEALL51Guh2IZjc2pVlJNKS1cq0akAap+gqdPPneJMmg799CodthT5+0UG043DPeESNl4EPcOcNyBKo9yJ26bgezSYqYtGDSFF6j9ijrvQpjWc2EwzfNDSGZ6frfyIAOkR1m3Me5sqBDV7A3zbo4/ERt5yPbkldMy9mt4yGGNc1uHTTDcpXUmvpcqAKOKhXmPUtDWnk3eEDX029HyExhY9awvqMGtpZ/qvhkqLJBetYv1NDrYwxzS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BUEfiJrVoiS0/lvq8RoAxfEJv8etFHjzBcXLbSGbG8pJuf1NWEJP/8XqldsRKHHygaj0qbj42epiu+jp9hC+Va06WIJZL0WOcQN82CrzndDjiiKrbCrU0mbir6YT9WO2EumliIe0J
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-09-01 17:41:29 +08:00
conn.port = 49898;
//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("开始下载资源===>>>");
// 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");
GButton viewBtn_showWait = _version_view.GetChild("GlobalModalWaiting") as GButton;
Version local_version = Hotupdate.GetLocalVersion(string.Empty);
ArrayList asset_config_list = null;
string asset_config_text = null;
viewBtn_showWait.title = "正在连接服务器...";
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
if (File.Exists(copyVersionPath))
{
string copyVersionString = File.ReadAllText(copyVersionPath).Trim();
}
#endif
#if UNITY_ANDROID
UnityWebRequest copyRequest = UnityWebRequest.Get(copyVersionPath);
yield return copyRequest.SendWebRequest();
if (copyRequest.isNetworkError || copyRequest.isHttpError)
{
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
string copyVersionString = copyRequest.downloadHandler.text.Trim();
2025-09-12 02:47:38 +08:00
#endif
bool isSame = copyVersionString.Equals(server_version.ToString());
if (isSame)
{
viewBtn_showWait.title = "正在解压资源...";
string copyZipPath = Path.Combine(Application.streamingAssetsPath, "Pack.byte");
2025-09-12 02:47:38 +08:00
#if UNITY_IPHONE
if (File.Exists(copyZipPath))
{
byte[] zipData = File.ReadAllBytes(copyZipPath);
}
#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;
2025-09-12 02:47:38 +08:00
#endif
string zipString = Path.Combine(Application.persistentDataPath, "Pack.byte");
File.WriteAllBytes(zipString, zipData);
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===>>>");
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;
}
//
viewBtn_showWait.title = "正在下载资源...";
v_tex_info.text = "正在检查资源。。。";
GSlider _pd = _version_view.GetChild("pb_progress").asSlider;
//GObject v_tex_pd = _version_view.GetChild("tex_value");
_pd.value = 0;
//v_tex_pd.text = "0%";
bool ver_check = false;
StartCoroutine(VersionUpdateCheck(asset_config_list, (progress, finish) =>
{
_pd.value = progress * 100f;
//v_tex_pd.text = $"{Mathf.Floor(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
{
viewBtn_showWait.title = "快马加鞭进入游戏中...";
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;
//GObject v_tex_pd = _version_view.GetChild("tex_value");
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;
//v_tex_pd.text = $"{Mathf.Floor((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);
}
}