forked from sin365/AxibugEmuOnline
Compare commits
6 Commits
dbf79fc936
...
194150b911
Author | SHA1 | Date | |
---|---|---|---|
194150b911 | |||
72ca1e8b64 | |||
55a8e02a3a | |||
7c2709f335 | |||
90f23a1d3f | |||
540ceab377 |
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
@ -234,7 +249,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;
|
||||
@ -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
|
||||
{
|
||||
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -4,7 +4,6 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace AxibugEmuOnline.Client
|
||||
{
|
||||
@ -15,27 +14,7 @@ namespace AxibugEmuOnline.Client
|
||||
|
||||
public delegate void GetRomListAPI(Action<Resp_GameList> callback, int page, int pageSize = 10);
|
||||
public delegate void SearchRomListAPI(Action<Resp_GameList> callback, string searchKey, int page, int pageSize = 10);
|
||||
public static string UrlEncode(string str)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
foreach (char c in str)
|
||||
{
|
||||
if ((c >= '0' && c <= '9') ||
|
||||
(c >= 'a' && c <= 'z') ||
|
||||
(c >= 'A' && c <= 'Z') ||
|
||||
c == '-' || c == '_' || c == '.' || c == '!' || c == '~' || c == '*' || c == '\'' || c == '(' || c == ')')
|
||||
{
|
||||
sb.Append(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append('%').Append(((int)c).ToString("X2"));
|
||||
}
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
public void GetNesRomList(Action<Resp_GameList> callback, int page, int pageSize = 10)
|
||||
{
|
||||
App.StartCoroutine(GetNesRomListFlow(page, pageSize, callback));
|
||||
@ -47,15 +26,25 @@ namespace AxibugEmuOnline.Client
|
||||
}
|
||||
private IEnumerator SearchNesRomListFlow(string searchKey, int page, int pageSize, Action<Resp_GameList> callback)
|
||||
{
|
||||
//避免特殊字符和个别文字编码问题
|
||||
byte[] gb2312Bytes = Encoding.Default.GetBytes(searchKey);
|
||||
byte[] utf8Bytes = Encoding.Convert(Encoding.Default, Encoding.UTF8, gb2312Bytes);
|
||||
// 将UTF-8编码的字节数组转换回字符串(此时是UTF-8编码的字符串)
|
||||
string utf8String = Encoding.UTF8.GetString(utf8Bytes);
|
||||
searchKey = UrlEncode(utf8String);
|
||||
App.log.Info($"search->{utf8String} ->{searchKey}");
|
||||
|
||||
AxiHttpProxy.SendWebRequestProxy request = AxiHttpProxy.Get($"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}&SearchKey={searchKey}");
|
||||
if (!string.IsNullOrEmpty(searchKey))
|
||||
{
|
||||
string oldsearch = searchKey;
|
||||
//searchKey = System.Net.WebUtility.UrlEncode(searchKey);
|
||||
searchKey = AxiHttp.UrlEncode(searchKey);
|
||||
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编码的字符串)
|
||||
//string utf8String = Encoding.UTF8.GetString(utf8Bytes);
|
||||
//searchKey = UrlEncode(utf8String);
|
||||
//App.log.Info($"search->{utf8String} ->{searchKey}");
|
||||
string url = $"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}&SearchKey={searchKey}";
|
||||
App.log.Info($"GetRomList=>{url}");
|
||||
AxiHttpProxy.SendWebRequestProxy request = AxiHttpProxy.Get(url);
|
||||
yield return request.SendWebRequest;
|
||||
if (!request.downloadHandler.isDone)
|
||||
{
|
||||
@ -63,13 +52,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<Resp_GameList>(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();
|
||||
@ -80,12 +72,12 @@ namespace AxibugEmuOnline.Client
|
||||
yield break;
|
||||
}*/
|
||||
|
||||
var resp = JsonUtility.FromJson<Resp_GameList>(request.downloadHandler.text);
|
||||
callback.Invoke(resp);
|
||||
}
|
||||
private IEnumerator GetNesRomListFlow(int page, int pageSize, Action<Resp_GameList> callback)
|
||||
{
|
||||
AxiHttpProxy.SendWebRequestProxy request = AxiHttpProxy.Get($"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}");
|
||||
string url = $"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}";
|
||||
App.log.Info($"GetRomList=>{url}");
|
||||
AxiHttpProxy.SendWebRequestProxy request = AxiHttpProxy.Get(url);
|
||||
yield return request.SendWebRequest;
|
||||
if (!request.downloadHandler.isDone)
|
||||
{
|
||||
@ -93,12 +85,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<Resp_GameList>(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();
|
||||
@ -109,8 +105,6 @@ namespace AxibugEmuOnline.Client
|
||||
yield break;
|
||||
}
|
||||
*/
|
||||
var resp = JsonUtility.FromJson<Resp_GameList>(request.downloadHandler.text);
|
||||
callback.Invoke(resp);
|
||||
}
|
||||
|
||||
public IEnumerator GetNesRomInfo(int RomID, Action<Resp_RomInfo> callback)
|
||||
@ -124,13 +118,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<Resp_RomInfo>(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();
|
||||
@ -141,8 +139,6 @@ namespace AxibugEmuOnline.Client
|
||||
yield break;
|
||||
}*/
|
||||
|
||||
var resp = JsonUtility.FromJson<Resp_RomInfo>(request.downloadHandler.text);
|
||||
callback.Invoke(resp);
|
||||
}
|
||||
|
||||
enum PlatformType : byte
|
||||
|
@ -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);
|
||||
|
@ -20,6 +20,7 @@ namespace AxibugEmuOnline.Client
|
||||
private HttpAPI.GetRomListAPI m_romGetFunc;
|
||||
private HttpAPI.SearchRomListAPI m_romSearchFunc;
|
||||
private EnumSupportEmuPlatform m_platform;
|
||||
private string lastSearchKey;
|
||||
|
||||
public RomLib(EnumSupportEmuPlatform platform)
|
||||
{
|
||||
@ -71,10 +72,13 @@ namespace AxibugEmuOnline.Client
|
||||
/// <param name="callback"></param>
|
||||
public void FetchRomCount(Action<RomFile[]> callback, string searchKey = null)
|
||||
{
|
||||
lastSearchKey = searchKey;
|
||||
if (string.IsNullOrWhiteSpace(searchKey))
|
||||
{
|
||||
m_romGetFunc((romList) =>
|
||||
{
|
||||
//TODO 请求失败对于romList为空时的处理
|
||||
|
||||
FetchPageCmd.Clear();
|
||||
nesRomFileIdMapper.Clear();
|
||||
nesRomFileNameMapper.Clear();
|
||||
@ -93,6 +97,8 @@ namespace AxibugEmuOnline.Client
|
||||
{
|
||||
m_romSearchFunc((romList) =>
|
||||
{
|
||||
//TODO 请求失败对于romList为空时的处理
|
||||
|
||||
FetchPageCmd.Clear();
|
||||
nesRomFileIdMapper.Clear();
|
||||
nesRomFileNameMapper.Clear();
|
||||
@ -121,9 +127,16 @@ namespace AxibugEmuOnline.Client
|
||||
if (FetchPageCmd.Count == 0) return;
|
||||
|
||||
foreach (var pageNo in FetchPageCmd)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(lastSearchKey))
|
||||
{
|
||||
m_romSearchFunc(SaveRomInfoFromWeb, lastSearchKey, pageNo, PAGE_SIZE);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_romGetFunc(SaveRomInfoFromWeb, pageNo, PAGE_SIZE);
|
||||
}
|
||||
}
|
||||
FetchPageCmd.Clear();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user