forked from sin365/AxibugEmuOnline
Compare commits
No commits in common. "194150b911ec13d3ccbf854b6d8ade71d92b17d7" and "dbf79fc936a4ac127e484a567bb385f8f4f0f45d" have entirely different histories.
194150b911
...
dbf79fc936
@ -130,9 +130,9 @@ namespace AxibugEmuOnline.Client.ClientCore
|
||||
if (!request.downloadHandler.isDone)
|
||||
yield break;
|
||||
|
||||
if (request.downloadHandler.bHadErr)
|
||||
if (request.downloadHandler.Err != null)
|
||||
{
|
||||
App.log.Error(request.downloadHandler.ErrInfo);
|
||||
App.log.Error(request.downloadHandler.Err);
|
||||
yield break;
|
||||
}
|
||||
|
||||
|
@ -117,22 +117,7 @@ public static class AxiHttp
|
||||
{
|
||||
public bool isDone = false;
|
||||
public AxiDownLoadMode downloadMode = AxiDownLoadMode.NotDownLoad;
|
||||
public bool bHadErr
|
||||
{
|
||||
get
|
||||
{
|
||||
return
|
||||
isDone = true
|
||||
&&
|
||||
(
|
||||
!string.IsNullOrEmpty(ErrInfo)
|
||||
||
|
||||
code != 200
|
||||
);
|
||||
}
|
||||
}
|
||||
public string ErrInfo;
|
||||
//public string Err = null;
|
||||
public string Err = null;
|
||||
public string host = "";//host主机头
|
||||
public string url = "";//pathAndQuery
|
||||
public int port = 80;
|
||||
@ -249,7 +234,7 @@ public static class AxiHttp
|
||||
if (!ParseURI(strURI, ref bSSL, ref strHost, ref strIP, ref port, ref strRelativePath,ref ourErrMsg))
|
||||
{
|
||||
Log("ParseURI False");
|
||||
respinfo.ErrInfo = ourErrMsg;
|
||||
respinfo.Err = ourErrMsg;
|
||||
respinfo.code = 0;
|
||||
respinfo.isDone = true;
|
||||
return;
|
||||
@ -511,7 +496,7 @@ public static class AxiHttp
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
respinfo.ErrInfo = $"ex : {ex.ToString()}";
|
||||
respinfo.Err = $"ex : {ex.ToString()}";
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -549,7 +534,7 @@ public static class AxiHttp
|
||||
if (!ParseURI(strURI, ref bSSL, ref strHost, ref strIP, ref port, ref strRelativePath, ref ourErrMsg))
|
||||
{
|
||||
Log("ParseURI False");
|
||||
respinfo.ErrInfo = ourErrMsg;
|
||||
respinfo.Err = ourErrMsg;
|
||||
respinfo.code = 0;
|
||||
respinfo.isDone = true;
|
||||
return;
|
||||
@ -793,7 +778,7 @@ public static class AxiHttp
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
respinfo.ErrInfo = $"ex : {ex.ToString()}";
|
||||
respinfo.Err = $"ex : {ex.ToString()}";
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -821,9 +806,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
|
||||
{
|
||||
@ -1179,6 +1164,7 @@ 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.bHadErr)
|
||||
if (request.downloadHandler.Err == null)
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
File.WriteAllBytes($"{path}/{url.GetHashCode()}", request.downloadHandler.data);
|
||||
|
@ -4,6 +4,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace AxibugEmuOnline.Client
|
||||
{
|
||||
@ -14,7 +15,27 @@ 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));
|
||||
@ -26,25 +47,15 @@ namespace AxibugEmuOnline.Client
|
||||
}
|
||||
private IEnumerator SearchNesRomListFlow(string searchKey, int page, int pageSize, Action<Resp_GameList> callback)
|
||||
{
|
||||
|
||||
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);
|
||||
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}");
|
||||
yield return request.SendWebRequest;
|
||||
if (!request.downloadHandler.isDone)
|
||||
{
|
||||
@ -52,16 +63,13 @@ namespace AxibugEmuOnline.Client
|
||||
yield break;
|
||||
}
|
||||
|
||||
if (!request.downloadHandler.bHadErr)
|
||||
if (request.downloadHandler.Err != null)
|
||||
{
|
||||
var resp = JsonUtility.FromJson<Resp_GameList>(request.downloadHandler.text);
|
||||
callback.Invoke(resp);
|
||||
App.log.Error(request.downloadHandler.Err);
|
||||
callback.Invoke(null);
|
||||
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();
|
||||
@ -72,12 +80,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)
|
||||
{
|
||||
string url = $"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}";
|
||||
App.log.Info($"GetRomList=>{url}");
|
||||
AxiHttpProxy.SendWebRequestProxy request = AxiHttpProxy.Get(url);
|
||||
AxiHttpProxy.SendWebRequestProxy request = AxiHttpProxy.Get($"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}");
|
||||
yield return request.SendWebRequest;
|
||||
if (!request.downloadHandler.isDone)
|
||||
{
|
||||
@ -85,16 +93,12 @@ namespace AxibugEmuOnline.Client
|
||||
yield break;
|
||||
}
|
||||
|
||||
//请求成功
|
||||
if (!request.downloadHandler.bHadErr)
|
||||
if (request.downloadHandler.Err != null)
|
||||
{
|
||||
var resp = JsonUtility.FromJson<Resp_GameList>(request.downloadHandler.text);
|
||||
callback.Invoke(resp);
|
||||
App.log.Error(request.downloadHandler.Err);
|
||||
callback.Invoke(null);
|
||||
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();
|
||||
@ -105,6 +109,8 @@ 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)
|
||||
@ -118,17 +124,13 @@ namespace AxibugEmuOnline.Client
|
||||
yield break;
|
||||
}
|
||||
|
||||
//成功
|
||||
if (!request.downloadHandler.bHadErr)
|
||||
if (request.downloadHandler.Err != null)
|
||||
{
|
||||
var resp = JsonUtility.FromJson<Resp_RomInfo>(request.downloadHandler.text);
|
||||
callback.Invoke(resp);
|
||||
App.log.Error(request.downloadHandler.Err);
|
||||
callback.Invoke(null);
|
||||
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();
|
||||
@ -139,6 +141,8 @@ 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.bHadErr)
|
||||
if (request.downloadHandler.Err == null)
|
||||
callback(request.downloadHandler.data);
|
||||
else
|
||||
callback(null);
|
||||
|
@ -20,7 +20,6 @@ namespace AxibugEmuOnline.Client
|
||||
private HttpAPI.GetRomListAPI m_romGetFunc;
|
||||
private HttpAPI.SearchRomListAPI m_romSearchFunc;
|
||||
private EnumSupportEmuPlatform m_platform;
|
||||
private string lastSearchKey;
|
||||
|
||||
public RomLib(EnumSupportEmuPlatform platform)
|
||||
{
|
||||
@ -72,13 +71,10 @@ 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();
|
||||
@ -97,8 +93,6 @@ namespace AxibugEmuOnline.Client
|
||||
{
|
||||
m_romSearchFunc((romList) =>
|
||||
{
|
||||
//TODO 请求失败对于romList为空时的处理
|
||||
|
||||
FetchPageCmd.Clear();
|
||||
nesRomFileIdMapper.Clear();
|
||||
nesRomFileNameMapper.Clear();
|
||||
@ -127,16 +121,9 @@ 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