diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/App.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/App.cs index d900c388..a17b958a 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/App.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/App.cs @@ -130,9 +130,9 @@ namespace AxibugEmuOnline.Client.ClientCore if (!request.downloadHandler.isDone) yield break; - if (request.downloadHandler.Err != null) + if (request.downloadHandler.bHadErr) { - App.log.Error(request.downloadHandler.Err); + App.log.Error(request.downloadHandler.ErrInfo); yield break; } diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttp.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttp.cs index 76fb09c5..17e42907 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttp.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttp.cs @@ -88,7 +88,7 @@ public static class AxiHttp public static long index = 0; static int singlePkgMaxRead = 1024; - public class WaitAxiRequest : UnityEngine.CustomYieldInstruction + public class WaitAxiRequest : UnityEngine.CustomYieldInstruction { public AxiRespInfo mReqAsync; public WaitAxiRequest(AxiRespInfo reqAsync) @@ -117,7 +117,22 @@ public static class AxiHttp { public bool isDone = false; public AxiDownLoadMode downloadMode = AxiDownLoadMode.NotDownLoad; - public string Err = null; + public bool bHadErr + { + get + { + return + isDone = true + && + ( + !string.IsNullOrEmpty(ErrInfo) + || + code != 200 + ); + } + } + public string ErrInfo; + //public string Err = null; public string host = "";//host主机头 public string url = "";//pathAndQuery public int port = 80; @@ -231,10 +246,10 @@ public static class AxiHttp bool foward_302 = true; string ourErrMsg = ""; - if (!ParseURI(strURI, ref bSSL, ref strHost, ref strIP, ref port, ref strRelativePath,ref ourErrMsg)) + if (!ParseURI(strURI, ref bSSL, ref strHost, ref strIP, ref port, ref strRelativePath, ref ourErrMsg)) { Log("ParseURI False"); - respinfo.Err = ourErrMsg; + respinfo.ErrInfo = ourErrMsg; respinfo.code = 0; respinfo.isDone = true; return; @@ -496,7 +511,7 @@ public static class AxiHttp } catch (Exception ex) { - respinfo.Err = $"ex : {ex.ToString()}"; + respinfo.ErrInfo = $"ex : {ex.ToString()}"; } finally { @@ -534,7 +549,7 @@ public static class AxiHttp if (!ParseURI(strURI, ref bSSL, ref strHost, ref strIP, ref port, ref strRelativePath, ref ourErrMsg)) { Log("ParseURI False"); - respinfo.Err = ourErrMsg; + respinfo.ErrInfo = ourErrMsg; respinfo.code = 0; respinfo.isDone = true; return; @@ -778,7 +793,7 @@ public static class AxiHttp } catch (Exception ex) { - respinfo.Err = $"ex : {ex.ToString()}"; + respinfo.ErrInfo = $"ex : {ex.ToString()}"; } finally { @@ -806,9 +821,9 @@ public static class AxiHttp { if (i == 0) { - respinfo.code = Tools.convertToInt(headers[i].Split(' ')[1]); - + if (respinfo.code != 200 && respinfo.code != 301 && respinfo.code != 302) + respinfo.ErrInfo = "code:" + respinfo.code; } else { @@ -979,11 +994,11 @@ public static class AxiHttp { return true; } - public static bool ParseURI(string strURI, - ref bool bIsSSL, - ref string strHost, - ref string strIP, - ref int Port, + public static bool ParseURI(string strURI, + ref bool bIsSSL, + ref string strHost, + ref string strIP, + ref int Port, ref string strRelativePath, ref string errMsg) { @@ -1043,7 +1058,7 @@ public static class AxiHttp { strIPRet = GetDnsIP(strAddressRet).ToString(); } - catch(Exception ex) + catch (Exception ex) { errMsg = ex.ToString(); return false; @@ -1164,7 +1179,6 @@ public static class AxiHttp Log($"BeginConnect {host}:{port} timeoutMSec=>{timeoutMSec}"); tcpclient.BeginConnect(host, port, new AsyncCallback(CallBackMethod), tcpclient); - if (TimeoutObject.WaitOne(timeoutMSec, false)) { if (IsConnectionSuccessful) diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/CacheManager.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/CacheManager.cs index 7d5e3b12..ff39204f 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/CacheManager.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/CacheManager.cs @@ -36,7 +36,7 @@ namespace AxibugEmuOnline.Client } AxiHttpProxy.ShowAxiHttpDebugInfo(request.downloadHandler); - if (request.downloadHandler.Err == null) + if (!request.downloadHandler.bHadErr) { Directory.CreateDirectory(path); File.WriteAllBytes($"{path}/{url.GetHashCode()}", request.downloadHandler.data); diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/HttpAPI.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/HttpAPI.cs index 5f23b727..d118f271 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/HttpAPI.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/HttpAPI.cs @@ -54,7 +54,7 @@ namespace AxibugEmuOnline.Client App.log.Info($"search->{oldsearch} ->{searchKey}"); //searchKey = HttpUtility.UrlDecode(searchKey); } - ////避免特殊字符和个别文字编码问题 + //避免特殊字符和个别文字编码问题 //byte[] gb2312Bytes = Encoding.Default.GetBytes(searchKey); //byte[] utf8Bytes = Encoding.Convert(Encoding.Default, Encoding.UTF8, gb2312Bytes); //// 将UTF-8编码的字节数组转换回字符串(此时是UTF-8编码的字符串) @@ -71,13 +71,16 @@ namespace AxibugEmuOnline.Client yield break; } - if (request.downloadHandler.Err != null) + if (!request.downloadHandler.bHadErr) { - App.log.Error(request.downloadHandler.Err); - callback.Invoke(null); + var resp = JsonUtility.FromJson(request.downloadHandler.text); + callback.Invoke(resp); yield break; } + App.log.Error(request.downloadHandler.ErrInfo); + callback.Invoke(null); + /* UnityWebRequest request = UnityWebRequest.Get($"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}&SearchKey={searchKey}"); yield return request.SendWebRequest(); @@ -88,8 +91,6 @@ namespace AxibugEmuOnline.Client yield break; }*/ - var resp = JsonUtility.FromJson(request.downloadHandler.text); - callback.Invoke(resp); } private IEnumerator GetNesRomListFlow(int page, int pageSize, Action callback) { @@ -103,12 +104,16 @@ namespace AxibugEmuOnline.Client yield break; } - if (request.downloadHandler.Err != null) + //请求成功 + if (!request.downloadHandler.bHadErr) { - App.log.Error(request.downloadHandler.Err); - callback.Invoke(null); + var resp = JsonUtility.FromJson(request.downloadHandler.text); + callback.Invoke(resp); yield break; } + + App.log.Error(request.downloadHandler.ErrInfo); + callback.Invoke(null); /* UnityWebRequest request = UnityWebRequest.Get($"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}"); yield return request.SendWebRequest(); @@ -119,8 +124,6 @@ namespace AxibugEmuOnline.Client yield break; } */ - var resp = JsonUtility.FromJson(request.downloadHandler.text); - callback.Invoke(resp); } public IEnumerator GetNesRomInfo(int RomID, Action callback) @@ -134,13 +137,17 @@ namespace AxibugEmuOnline.Client yield break; } - if (request.downloadHandler.Err != null) + //成功 + if (!request.downloadHandler.bHadErr) { - App.log.Error(request.downloadHandler.Err); - callback.Invoke(null); + var resp = JsonUtility.FromJson(request.downloadHandler.text); + callback.Invoke(resp); yield break; } + App.log.Error(request.downloadHandler.ErrInfo); + callback.Invoke(null); + /* UnityWebRequest request = UnityWebRequest.Get($"{WebSiteApi}/RomInfo?PType={PlatformType.Nes}&RomID={RomID}"); yield return request.SendWebRequest(); @@ -151,8 +158,6 @@ namespace AxibugEmuOnline.Client yield break; }*/ - var resp = JsonUtility.FromJson(request.downloadHandler.text); - callback.Invoke(resp); } enum PlatformType : byte diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/RomFile.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/RomFile.cs index 1142b32a..68c80391 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/RomFile.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/RomFile.cs @@ -136,7 +136,7 @@ namespace AxibugEmuOnline.Client var request = downloadRequest; downloadRequest = null; - if (request.downloadHandler.Err == null) + if (!request.downloadHandler.bHadErr) callback(request.downloadHandler.data); else callback(null);