254 lines
8.6 KiB
C#
254 lines
8.6 KiB
C#
|
using Axibug;
|
|||
|
using Axibug.Event;
|
|||
|
using Axibug.Resources;
|
|||
|
using Axibug.Runtime;
|
|||
|
using System;
|
|||
|
using System.IO;
|
|||
|
using UnityEngine;
|
|||
|
using static Axibug.Utility;
|
|||
|
using ProcedureOwner = Axibug.Fsm.IFsm<Axibug.Procedure.IProcedureManager>;
|
|||
|
|
|||
|
namespace Game
|
|||
|
{
|
|||
|
//<2F>汾<EFBFBD><E6B1BE><EFBFBD><EFBFBD>
|
|||
|
public class ProcedureCheckVersion : ProcedureBase
|
|||
|
{
|
|||
|
private bool _checkVersionComplete = false; //<2F>汾<EFBFBD><E6B1BE><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
private bool _needUpdateVersion = false; //<2F>Ƿ<EFBFBD><C7B7><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>
|
|||
|
private int _fileCount = 0; //<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ű<EFBFBD>Ϊ2<CEAA><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>غͷ<D8BA><CDB7><EFBFBD><EFBFBD><EFBFBD>version.txt
|
|||
|
NativeUpdateUI _updateUI;
|
|||
|
float delayTime = 0;
|
|||
|
|
|||
|
protected override void OnEnter(ProcedureOwner procedureOwner)
|
|||
|
{
|
|||
|
base.OnEnter(procedureOwner);
|
|||
|
|
|||
|
_checkVersionComplete = false;
|
|||
|
_needUpdateVersion = false;
|
|||
|
_fileCount = 0;
|
|||
|
|
|||
|
_updateUI = AppEntry.OpenNativeUI<NativeUpdateUI>("NativeUpdateUI");
|
|||
|
_updateUI.Show("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD>汾...");
|
|||
|
|
|||
|
AppEntry.Event.Subscribe(WebRequestSuccessEventArgs.EventId, OnWebRequestSuccess);
|
|||
|
AppEntry.Event.Subscribe(WebRequestFailureEventArgs.EventId, OnWebRequestFailure);
|
|||
|
|
|||
|
//<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>汾<EFBFBD><E6B1BE>
|
|||
|
HotData d = new HotData();
|
|||
|
d.Init();
|
|||
|
d.filename = HotPlatform.versionTxt;
|
|||
|
d.version_local = UnityEngine.Application.version;
|
|||
|
HotData.JsonList.Add(HotPlatform.versionTxt, d);
|
|||
|
HotData.curHot = d;//<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>ȸ<EFBFBD><C8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
HotData.xml.Init();
|
|||
|
RequestRemoteVersion();
|
|||
|
RequestLocalVersion();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>汾<EFBFBD><E6B1BE>Ϣ
|
|||
|
private void RequestRemoteVersion()
|
|||
|
{
|
|||
|
string url = Utility.Path.GetRemoteVersionFilePath();
|
|||
|
|
|||
|
Log.Debug($"remote url = {url}");
|
|||
|
AppEntry.WebRequest.AddWebRequest(url, true); //true<75><65><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD>ļ<EFBFBD>
|
|||
|
}
|
|||
|
|
|||
|
private void RequestLocalVersion()
|
|||
|
{
|
|||
|
string path = Utility.Path.GetLocalVersionFilePath();
|
|||
|
//Log.Debug($"local url = {path}");
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD>û<EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>ֱ<EFBFBD>Ӽ<EFBFBD>1
|
|||
|
if (!File.Exists(path))
|
|||
|
{
|
|||
|
_fileCount++;
|
|||
|
Log.Debug("<22><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
path = Text.Format("{0}{1}", "file:///", path);
|
|||
|
//Log.Debug($"AddWebRequest local url = {path}");
|
|||
|
|
|||
|
AppEntry.WebRequest.AddWebRequest(path, false); //false<73><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
|||
|
}
|
|||
|
|
|||
|
private void LoadLocalFile(FileList arr)
|
|||
|
{
|
|||
|
Log.Debug("<22><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|||
|
foreach (var d in arr.listinfo)
|
|||
|
{
|
|||
|
if (d.filename == HotPlatform.versionTxt)
|
|||
|
{
|
|||
|
HotData.curHot.version_local = d.hash;
|
|||
|
continue;
|
|||
|
}
|
|||
|
HotData.curHot.local.Add(d.filename, d);
|
|||
|
}
|
|||
|
|
|||
|
HotData.curHot.load_ab_fail = 0;
|
|||
|
}
|
|||
|
|
|||
|
private void LoadRemoteFile(FileList arr)
|
|||
|
{
|
|||
|
Log.Debug("Զ<><D4B6><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|||
|
foreach (var d in arr.listinfo)
|
|||
|
{
|
|||
|
//0 <20><>ȡ<EFBFBD>ͼ<EFBFBD><CDBC>汾
|
|||
|
if (d.filename == HotPlatform.versionCheck)
|
|||
|
{
|
|||
|
HotData.xml.versionCheck = d.hash;
|
|||
|
continue;
|
|||
|
}
|
|||
|
else if (d.filename == HotPlatform.versionTxt)
|
|||
|
{
|
|||
|
HotData.curHot.version_remote = d.hash;
|
|||
|
HotData.curHot.totalBytes = d.length;
|
|||
|
continue;
|
|||
|
}
|
|||
|
else if (d.filename == HotPlatform.loginServer)
|
|||
|
{
|
|||
|
string s = HotPlatform.ToDecrypt("1981", d.hash);
|
|||
|
string[] arr2 = s.Split(',');
|
|||
|
int size = arr2.Length;
|
|||
|
if (size < 4)
|
|||
|
continue;
|
|||
|
|
|||
|
for (int i = 0; i < size; i++)
|
|||
|
{
|
|||
|
if (i == 0)
|
|||
|
HotData.xml.xml_head = arr2[0];
|
|||
|
else if (i == 1)
|
|||
|
Int32.TryParse(arr2[1], out HotData.xml.xml_code);
|
|||
|
else if (i == 2)
|
|||
|
Int32.TryParse(arr2[2], out HotData.xml.xml_version);
|
|||
|
else if (i == 3)
|
|||
|
HotData.xml.xml_testcode = arr2[3];
|
|||
|
else
|
|||
|
{
|
|||
|
string[] arr3 = arr2[i].Split(':');
|
|||
|
if (arr3.Length == 2)
|
|||
|
{
|
|||
|
LoginServerData login = new LoginServerData();
|
|||
|
login.ip = arr3[0];
|
|||
|
Int32.TryParse(arr3[1], out login.port);
|
|||
|
HotData.xml.loginserver.Add(login);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
continue;
|
|||
|
}
|
|||
|
|
|||
|
HotData.curHot.remote.Add(d.filename, d);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
private void OnWebRequestSuccess(object sender, LogicEventArgs e)
|
|||
|
{
|
|||
|
WebRequestSuccessEventArgs ne = (WebRequestSuccessEventArgs)e;
|
|||
|
|
|||
|
byte[] versionInfoBytes = ne.GetWebResponseBytes();
|
|||
|
string versionInfoString = Converter.GetString(versionInfoBytes);
|
|||
|
|
|||
|
FileList arr = Json.ToObject<FileList>(versionInfoString);
|
|||
|
_fileCount++;
|
|||
|
try
|
|||
|
{
|
|||
|
if ((bool)ne.UserData == true)
|
|||
|
{
|
|||
|
LoadRemoteFile(arr);
|
|||
|
HotData.curHot.bytes = versionInfoBytes;
|
|||
|
HotData.curHot.load_ab_fail = 0;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
LoadLocalFile(arr);
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
Log.Error($"err:{ex.Message}", LogLevel.Error);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if (_fileCount != 2)
|
|||
|
return;
|
|||
|
|
|||
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
|||
|
_needUpdateVersion = AppEntry.HotUpdate.CheckVersionList();
|
|||
|
_checkVersionComplete = true;
|
|||
|
}
|
|||
|
|
|||
|
private void OnWebRequestFailure(object sender, LogicEventArgs e)
|
|||
|
{
|
|||
|
WebRequestFailureEventArgs ne = (WebRequestFailureEventArgs)e;
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
if ((bool)ne.UserData == true)
|
|||
|
{
|
|||
|
//HotfixEntry.UI.ShowMessageBox("ϵͳ<CFB5><CDB3>ʾ", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>汾<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><DCA3>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD>", "<22>˳<EFBFBD>",
|
|||
|
AppEntry.ShowMessageBox("ϵͳ<CFB5><CDB3>ʾ", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>汾<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><DCA3>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD>", "<22>˳<EFBFBD>",
|
|||
|
() => { RequestRemoteVersion(); } ,
|
|||
|
() => { AppEntry.QuitGame(); });
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//HotfixEntry.UI.ShowMessageBox("ϵͳ<CFB5><CDB3>ʾ", "<22><><EFBFBD>ذ汾<D8B0>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><DCA3>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD>", "<22>˳<EFBFBD>",
|
|||
|
AppEntry.ShowMessageBox("ϵͳ<CFB5><CDB3>ʾ", "<22><><EFBFBD>ذ汾<D8B0>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><DCA3>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD>", "<22>˳<EFBFBD>",
|
|||
|
() => { RequestLocalVersion(); },
|
|||
|
() => { AppEntry.QuitGame(); });
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
protected override void OnUpdate(ProcedureOwner procedureOwner, float elapseSeconds, float realElapseSeconds)
|
|||
|
{
|
|||
|
base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds);
|
|||
|
|
|||
|
_updateUI.RefreshPregress("<22><><EFBFBD>ڱȶ<DAB1><C8B6>ļ<EFBFBD>...", AppEntry.HotUpdate.ProcessValue);
|
|||
|
|
|||
|
if (!_checkVersionComplete)
|
|||
|
return;
|
|||
|
|
|||
|
if (_needUpdateVersion)
|
|||
|
{
|
|||
|
if (AppEntry.confirmUIGo != null)
|
|||
|
return;
|
|||
|
|
|||
|
AppEntry.ShowMessageBox("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ", $"<22><><EFBFBD>°汾<C2B0><E6B1BE>{AppEntry.HotUpdate.GetByteLengthString(HotData.curHot.totalBytes)}<7D><>Դ<EFBFBD><D4B4>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>Wifi<66><69><EFBFBD><EFBFBD>).\n<>Ƿ<EFBFBD><C7B7><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>?", "<22><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>", "<22>ݲ<EFBFBD><DDB2><EFBFBD><EFBFBD><EFBFBD>",
|
|||
|
() =>
|
|||
|
{
|
|||
|
ChangeState<ProcedureUpdateVersion>(procedureOwner);
|
|||
|
},
|
|||
|
() => { AppEntry.QuitGame(); });
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
delayTime += elapseSeconds;
|
|||
|
|
|||
|
if (delayTime < 1)
|
|||
|
return;
|
|||
|
|
|||
|
ChangeState<ProcedureInitSystem>(procedureOwner);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
protected override void OnLeave(ProcedureOwner procedureOwner, bool isShutdown)
|
|||
|
{
|
|||
|
AppEntry.Event.Unsubscribe(WebRequestSuccessEventArgs.EventId, OnWebRequestSuccess);
|
|||
|
AppEntry.Event.Unsubscribe(WebRequestFailureEventArgs.EventId, OnWebRequestFailure);
|
|||
|
|
|||
|
AppEntry.CloseNativeUI("NativeUpdateUI");
|
|||
|
_updateUI = null;
|
|||
|
|
|||
|
base.OnLeave(procedureOwner, isShutdown);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|