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)
|
if (!request.downloadHandler.isDone)
|
||||||
yield break;
|
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;
|
yield break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ public static class AxiHttp
|
|||||||
public static long index = 0;
|
public static long index = 0;
|
||||||
static int singlePkgMaxRead = 1024;
|
static int singlePkgMaxRead = 1024;
|
||||||
|
|
||||||
public class WaitAxiRequest : UnityEngine.CustomYieldInstruction
|
public class WaitAxiRequest : UnityEngine.CustomYieldInstruction
|
||||||
{
|
{
|
||||||
public AxiRespInfo mReqAsync;
|
public AxiRespInfo mReqAsync;
|
||||||
public WaitAxiRequest(AxiRespInfo reqAsync)
|
public WaitAxiRequest(AxiRespInfo reqAsync)
|
||||||
@ -117,22 +117,7 @@ public static class AxiHttp
|
|||||||
{
|
{
|
||||||
public bool isDone = false;
|
public bool isDone = false;
|
||||||
public AxiDownLoadMode downloadMode = AxiDownLoadMode.NotDownLoad;
|
public AxiDownLoadMode downloadMode = AxiDownLoadMode.NotDownLoad;
|
||||||
public bool bHadErr
|
public string Err = null;
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return
|
|
||||||
isDone = true
|
|
||||||
&&
|
|
||||||
(
|
|
||||||
!string.IsNullOrEmpty(ErrInfo)
|
|
||||||
||
|
|
||||||
code != 200
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public string ErrInfo;
|
|
||||||
//public string Err = null;
|
|
||||||
public string host = "";//host主机头
|
public string host = "";//host主机头
|
||||||
public string url = "";//pathAndQuery
|
public string url = "";//pathAndQuery
|
||||||
public int port = 80;
|
public int port = 80;
|
||||||
@ -246,10 +231,10 @@ public static class AxiHttp
|
|||||||
bool foward_302 = true;
|
bool foward_302 = true;
|
||||||
string ourErrMsg = "";
|
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");
|
Log("ParseURI False");
|
||||||
respinfo.ErrInfo = ourErrMsg;
|
respinfo.Err = ourErrMsg;
|
||||||
respinfo.code = 0;
|
respinfo.code = 0;
|
||||||
respinfo.isDone = true;
|
respinfo.isDone = true;
|
||||||
return;
|
return;
|
||||||
@ -511,7 +496,7 @@ public static class AxiHttp
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
respinfo.ErrInfo = $"ex : {ex.ToString()}";
|
respinfo.Err = $"ex : {ex.ToString()}";
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@ -549,7 +534,7 @@ public static class AxiHttp
|
|||||||
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");
|
Log("ParseURI False");
|
||||||
respinfo.ErrInfo = ourErrMsg;
|
respinfo.Err = ourErrMsg;
|
||||||
respinfo.code = 0;
|
respinfo.code = 0;
|
||||||
respinfo.isDone = true;
|
respinfo.isDone = true;
|
||||||
return;
|
return;
|
||||||
@ -793,7 +778,7 @@ public static class AxiHttp
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
respinfo.ErrInfo = $"ex : {ex.ToString()}";
|
respinfo.Err = $"ex : {ex.ToString()}";
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@ -821,9 +806,9 @@ public static class AxiHttp
|
|||||||
{
|
{
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
respinfo.code = Tools.convertToInt(headers[i].Split(' ')[1]);
|
respinfo.code = Tools.convertToInt(headers[i].Split(' ')[1]);
|
||||||
if (respinfo.code != 200 && respinfo.code != 301 && respinfo.code != 302)
|
|
||||||
respinfo.ErrInfo = "code:" + respinfo.code;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -994,11 +979,11 @@ public static class AxiHttp
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
public static bool ParseURI(string strURI,
|
public static bool ParseURI(string strURI,
|
||||||
ref bool bIsSSL,
|
ref bool bIsSSL,
|
||||||
ref string strHost,
|
ref string strHost,
|
||||||
ref string strIP,
|
ref string strIP,
|
||||||
ref int Port,
|
ref int Port,
|
||||||
ref string strRelativePath,
|
ref string strRelativePath,
|
||||||
ref string errMsg)
|
ref string errMsg)
|
||||||
{
|
{
|
||||||
@ -1058,7 +1043,7 @@ public static class AxiHttp
|
|||||||
{
|
{
|
||||||
strIPRet = GetDnsIP(strAddressRet).ToString();
|
strIPRet = GetDnsIP(strAddressRet).ToString();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch(Exception ex)
|
||||||
{
|
{
|
||||||
errMsg = ex.ToString();
|
errMsg = ex.ToString();
|
||||||
return false;
|
return false;
|
||||||
@ -1179,6 +1164,7 @@ public static class AxiHttp
|
|||||||
Log($"BeginConnect {host}:{port} timeoutMSec=>{timeoutMSec}");
|
Log($"BeginConnect {host}:{port} timeoutMSec=>{timeoutMSec}");
|
||||||
tcpclient.BeginConnect(host, port, new AsyncCallback(CallBackMethod), tcpclient);
|
tcpclient.BeginConnect(host, port, new AsyncCallback(CallBackMethod), tcpclient);
|
||||||
|
|
||||||
|
|
||||||
if (TimeoutObject.WaitOne(timeoutMSec, false))
|
if (TimeoutObject.WaitOne(timeoutMSec, false))
|
||||||
{
|
{
|
||||||
if (IsConnectionSuccessful)
|
if (IsConnectionSuccessful)
|
||||||
|
@ -36,7 +36,7 @@ namespace AxibugEmuOnline.Client
|
|||||||
}
|
}
|
||||||
AxiHttpProxy.ShowAxiHttpDebugInfo(request.downloadHandler);
|
AxiHttpProxy.ShowAxiHttpDebugInfo(request.downloadHandler);
|
||||||
|
|
||||||
if (!request.downloadHandler.bHadErr)
|
if (request.downloadHandler.Err == null)
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(path);
|
Directory.CreateDirectory(path);
|
||||||
File.WriteAllBytes($"{path}/{url.GetHashCode()}", request.downloadHandler.data);
|
File.WriteAllBytes($"{path}/{url.GetHashCode()}", request.downloadHandler.data);
|
||||||
|
@ -4,6 +4,7 @@ using System.Collections;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.Networking;
|
||||||
|
|
||||||
namespace AxibugEmuOnline.Client
|
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 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 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)
|
public void GetNesRomList(Action<Resp_GameList> callback, int page, int pageSize = 10)
|
||||||
{
|
{
|
||||||
App.StartCoroutine(GetNesRomListFlow(page, pageSize, callback));
|
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)
|
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[] gb2312Bytes = Encoding.Default.GetBytes(searchKey);
|
||||||
//byte[] utf8Bytes = Encoding.Convert(Encoding.Default, Encoding.UTF8, gb2312Bytes);
|
byte[] utf8Bytes = Encoding.Convert(Encoding.Default, Encoding.UTF8, gb2312Bytes);
|
||||||
//// 将UTF-8编码的字节数组转换回字符串(此时是UTF-8编码的字符串)
|
// 将UTF-8编码的字节数组转换回字符串(此时是UTF-8编码的字符串)
|
||||||
//string utf8String = Encoding.UTF8.GetString(utf8Bytes);
|
string utf8String = Encoding.UTF8.GetString(utf8Bytes);
|
||||||
//searchKey = UrlEncode(utf8String);
|
searchKey = UrlEncode(utf8String);
|
||||||
//App.log.Info($"search->{utf8String} ->{searchKey}");
|
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($"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}&SearchKey={searchKey}");
|
||||||
AxiHttpProxy.SendWebRequestProxy request = AxiHttpProxy.Get(url);
|
|
||||||
yield return request.SendWebRequest;
|
yield return request.SendWebRequest;
|
||||||
if (!request.downloadHandler.isDone)
|
if (!request.downloadHandler.isDone)
|
||||||
{
|
{
|
||||||
@ -52,16 +63,13 @@ namespace AxibugEmuOnline.Client
|
|||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!request.downloadHandler.bHadErr)
|
if (request.downloadHandler.Err != null)
|
||||||
{
|
{
|
||||||
var resp = JsonUtility.FromJson<Resp_GameList>(request.downloadHandler.text);
|
App.log.Error(request.downloadHandler.Err);
|
||||||
callback.Invoke(resp);
|
callback.Invoke(null);
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
|
|
||||||
App.log.Error(request.downloadHandler.ErrInfo);
|
|
||||||
callback.Invoke(null);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
UnityWebRequest request = UnityWebRequest.Get($"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}&SearchKey={searchKey}");
|
UnityWebRequest request = UnityWebRequest.Get($"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}&SearchKey={searchKey}");
|
||||||
yield return request.SendWebRequest();
|
yield return request.SendWebRequest();
|
||||||
@ -72,12 +80,12 @@ namespace AxibugEmuOnline.Client
|
|||||||
yield break;
|
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)
|
private IEnumerator GetNesRomListFlow(int page, int pageSize, Action<Resp_GameList> callback)
|
||||||
{
|
{
|
||||||
string url = $"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}";
|
AxiHttpProxy.SendWebRequestProxy request = AxiHttpProxy.Get($"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}");
|
||||||
App.log.Info($"GetRomList=>{url}");
|
|
||||||
AxiHttpProxy.SendWebRequestProxy request = AxiHttpProxy.Get(url);
|
|
||||||
yield return request.SendWebRequest;
|
yield return request.SendWebRequest;
|
||||||
if (!request.downloadHandler.isDone)
|
if (!request.downloadHandler.isDone)
|
||||||
{
|
{
|
||||||
@ -85,16 +93,12 @@ namespace AxibugEmuOnline.Client
|
|||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//请求成功
|
if (request.downloadHandler.Err != null)
|
||||||
if (!request.downloadHandler.bHadErr)
|
|
||||||
{
|
{
|
||||||
var resp = JsonUtility.FromJson<Resp_GameList>(request.downloadHandler.text);
|
App.log.Error(request.downloadHandler.Err);
|
||||||
callback.Invoke(resp);
|
callback.Invoke(null);
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
|
|
||||||
App.log.Error(request.downloadHandler.ErrInfo);
|
|
||||||
callback.Invoke(null);
|
|
||||||
/*
|
/*
|
||||||
UnityWebRequest request = UnityWebRequest.Get($"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}");
|
UnityWebRequest request = UnityWebRequest.Get($"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}");
|
||||||
yield return request.SendWebRequest();
|
yield return request.SendWebRequest();
|
||||||
@ -105,6 +109,8 @@ namespace AxibugEmuOnline.Client
|
|||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
var resp = JsonUtility.FromJson<Resp_GameList>(request.downloadHandler.text);
|
||||||
|
callback.Invoke(resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerator GetNesRomInfo(int RomID, Action<Resp_RomInfo> callback)
|
public IEnumerator GetNesRomInfo(int RomID, Action<Resp_RomInfo> callback)
|
||||||
@ -118,17 +124,13 @@ namespace AxibugEmuOnline.Client
|
|||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//成功
|
if (request.downloadHandler.Err != null)
|
||||||
if (!request.downloadHandler.bHadErr)
|
|
||||||
{
|
{
|
||||||
var resp = JsonUtility.FromJson<Resp_RomInfo>(request.downloadHandler.text);
|
App.log.Error(request.downloadHandler.Err);
|
||||||
callback.Invoke(resp);
|
callback.Invoke(null);
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
|
|
||||||
App.log.Error(request.downloadHandler.ErrInfo);
|
|
||||||
callback.Invoke(null);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
UnityWebRequest request = UnityWebRequest.Get($"{WebSiteApi}/RomInfo?PType={PlatformType.Nes}&RomID={RomID}");
|
UnityWebRequest request = UnityWebRequest.Get($"{WebSiteApi}/RomInfo?PType={PlatformType.Nes}&RomID={RomID}");
|
||||||
yield return request.SendWebRequest();
|
yield return request.SendWebRequest();
|
||||||
@ -139,6 +141,8 @@ namespace AxibugEmuOnline.Client
|
|||||||
yield break;
|
yield break;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
var resp = JsonUtility.FromJson<Resp_RomInfo>(request.downloadHandler.text);
|
||||||
|
callback.Invoke(resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum PlatformType : byte
|
enum PlatformType : byte
|
||||||
|
@ -136,7 +136,7 @@ namespace AxibugEmuOnline.Client
|
|||||||
var request = downloadRequest;
|
var request = downloadRequest;
|
||||||
downloadRequest = null;
|
downloadRequest = null;
|
||||||
|
|
||||||
if (!request.downloadHandler.bHadErr)
|
if (request.downloadHandler.Err == null)
|
||||||
callback(request.downloadHandler.data);
|
callback(request.downloadHandler.data);
|
||||||
else
|
else
|
||||||
callback(null);
|
callback(null);
|
||||||
|
@ -7,160 +7,147 @@ using static AxibugEmuOnline.Client.HttpAPI;
|
|||||||
|
|
||||||
namespace AxibugEmuOnline.Client
|
namespace AxibugEmuOnline.Client
|
||||||
{
|
{
|
||||||
public class RomLib
|
public class RomLib
|
||||||
{
|
{
|
||||||
/// <summary> Rom请求,一页的大小 </summary>
|
/// <summary> Rom请求,一页的大小 </summary>
|
||||||
private const int PAGE_SIZE = 10;
|
private const int PAGE_SIZE = 10;
|
||||||
|
|
||||||
/// <summary> 请求指令 </summary>
|
/// <summary> 请求指令 </summary>
|
||||||
private HashSet<int> FetchPageCmd = new HashSet<int>();
|
private HashSet<int> FetchPageCmd = new HashSet<int>();
|
||||||
private RomFile[] nesRomFetchList;
|
private RomFile[] nesRomFetchList;
|
||||||
private Dictionary<int, RomFile> nesRomFileIdMapper = new Dictionary<int, RomFile>();
|
private Dictionary<int, RomFile> nesRomFileIdMapper = new Dictionary<int, RomFile>();
|
||||||
private Dictionary<string, RomFile> nesRomFileNameMapper = new Dictionary<string, RomFile>();
|
private Dictionary<string, RomFile> nesRomFileNameMapper = new Dictionary<string, RomFile>();
|
||||||
private HttpAPI.GetRomListAPI m_romGetFunc;
|
private HttpAPI.GetRomListAPI m_romGetFunc;
|
||||||
private HttpAPI.SearchRomListAPI m_romSearchFunc;
|
private HttpAPI.SearchRomListAPI m_romSearchFunc;
|
||||||
private EnumSupportEmuPlatform m_platform;
|
private EnumSupportEmuPlatform m_platform;
|
||||||
private string lastSearchKey;
|
|
||||||
|
|
||||||
public RomLib(EnumSupportEmuPlatform platform)
|
public RomLib(EnumSupportEmuPlatform platform)
|
||||||
{
|
{
|
||||||
m_platform = platform;
|
m_platform = platform;
|
||||||
switch (platform)
|
switch (platform)
|
||||||
{
|
{
|
||||||
case EnumSupportEmuPlatform.NES:
|
case EnumSupportEmuPlatform.NES:
|
||||||
m_romGetFunc = App.httpAPI.GetNesRomList;
|
m_romGetFunc = App.httpAPI.GetNesRomList;
|
||||||
m_romSearchFunc = App.httpAPI.SearchNesRomList;
|
m_romSearchFunc = App.httpAPI.SearchNesRomList;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public RomFile GetExistRom(string fileName)
|
public RomFile GetExistRom(string fileName)
|
||||||
{
|
{
|
||||||
var res = RomFile.CreateExistRom(m_platform, fileName);
|
var res = RomFile.CreateExistRom(m_platform, fileName);
|
||||||
|
|
||||||
nesRomFileNameMapper[res.FileName] = res;
|
nesRomFileNameMapper[res.FileName] = res;
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RomFile GetRomFile(string romFileName)
|
public RomFile GetRomFile(string romFileName)
|
||||||
{
|
{
|
||||||
RomFile romFile;
|
RomFile romFile;
|
||||||
nesRomFileNameMapper.TryGetValue(romFileName, out romFile);
|
nesRomFileNameMapper.TryGetValue(romFileName, out romFile);
|
||||||
return romFile;
|
return romFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary> 清除所有下载的Rom文件 </summary>
|
/// <summary> 清除所有下载的Rom文件 </summary>
|
||||||
public void ClearRomFile()
|
public void ClearRomFile()
|
||||||
{
|
{
|
||||||
var path = $"{App.PersistentDataPath}/RemoteRoms/{m_platform}";
|
var path = $"{App.PersistentDataPath}/RemoteRoms/{m_platform}";
|
||||||
if (Directory.Exists(path)) Directory.Delete(path, true);
|
if (Directory.Exists(path)) Directory.Delete(path, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> 移除一个已下载的Rom </summary>
|
/// <summary> 移除一个已下载的Rom </summary>
|
||||||
public void RemoveOneRomFile(RomFile romFile)
|
public void RemoveOneRomFile(RomFile romFile)
|
||||||
{
|
{
|
||||||
if (romFile.RomReady)
|
if (romFile.RomReady)
|
||||||
File.Delete(romFile.LocalFilePath);
|
File.Delete(romFile.LocalFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获得所有Rom文件
|
/// 获得所有Rom文件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="callback"></param>
|
/// <param name="callback"></param>
|
||||||
public void FetchRomCount(Action<RomFile[]> callback, string searchKey = null)
|
public void FetchRomCount(Action<RomFile[]> callback, string searchKey = null)
|
||||||
{
|
{
|
||||||
lastSearchKey = searchKey;
|
if (string.IsNullOrWhiteSpace(searchKey))
|
||||||
if (string.IsNullOrWhiteSpace(searchKey))
|
{
|
||||||
{
|
m_romGetFunc((romList) =>
|
||||||
m_romGetFunc((romList) =>
|
{
|
||||||
{
|
FetchPageCmd.Clear();
|
||||||
//TODO 请求失败对于romList为空时的处理
|
nesRomFileIdMapper.Clear();
|
||||||
|
nesRomFileNameMapper.Clear();
|
||||||
|
nesRomFetchList = new RomFile[romList.resultAllCount];
|
||||||
|
for (int i = 0; i < nesRomFetchList.Length; i++)
|
||||||
|
{
|
||||||
|
//以后考虑用对象池实例化RomFile
|
||||||
|
nesRomFetchList[i] = new RomFile(m_platform, i, i / PAGE_SIZE);
|
||||||
|
}
|
||||||
|
SaveRomInfoFromWeb(romList);
|
||||||
|
|
||||||
FetchPageCmd.Clear();
|
callback.Invoke(nesRomFetchList);
|
||||||
nesRomFileIdMapper.Clear();
|
}, 0, PAGE_SIZE);
|
||||||
nesRomFileNameMapper.Clear();
|
}
|
||||||
nesRomFetchList = new RomFile[romList.resultAllCount];
|
else
|
||||||
for (int i = 0; i < nesRomFetchList.Length; i++)
|
{
|
||||||
{
|
m_romSearchFunc((romList) =>
|
||||||
//以后考虑用对象池实例化RomFile
|
{
|
||||||
nesRomFetchList[i] = new RomFile(m_platform, i, i / PAGE_SIZE);
|
FetchPageCmd.Clear();
|
||||||
}
|
nesRomFileIdMapper.Clear();
|
||||||
SaveRomInfoFromWeb(romList);
|
nesRomFileNameMapper.Clear();
|
||||||
|
nesRomFetchList = new RomFile[romList.resultAllCount];
|
||||||
|
for (int i = 0; i < nesRomFetchList.Length; i++)
|
||||||
|
{
|
||||||
|
//以后考虑用对象池实例化RomFile
|
||||||
|
nesRomFetchList[i] = new RomFile(m_platform, i, i / PAGE_SIZE);
|
||||||
|
}
|
||||||
|
SaveRomInfoFromWeb(romList);
|
||||||
|
|
||||||
callback.Invoke(nesRomFetchList);
|
callback.Invoke(nesRomFetchList);
|
||||||
}, 0, PAGE_SIZE);
|
}, searchKey, 0, PAGE_SIZE);
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
|
||||||
m_romSearchFunc((romList) =>
|
|
||||||
{
|
|
||||||
//TODO 请求失败对于romList为空时的处理
|
|
||||||
|
|
||||||
FetchPageCmd.Clear();
|
public void BeginFetchRomInfo(RomFile romFile)
|
||||||
nesRomFileIdMapper.Clear();
|
{
|
||||||
nesRomFileNameMapper.Clear();
|
if (romFile.InfoReady) return;
|
||||||
nesRomFetchList = new RomFile[romList.resultAllCount];
|
|
||||||
for (int i = 0; i < nesRomFetchList.Length; i++)
|
|
||||||
{
|
|
||||||
//以后考虑用对象池实例化RomFile
|
|
||||||
nesRomFetchList[i] = new RomFile(m_platform, i, i / PAGE_SIZE);
|
|
||||||
}
|
|
||||||
SaveRomInfoFromWeb(romList);
|
|
||||||
|
|
||||||
callback.Invoke(nesRomFetchList);
|
FetchPageCmd.Add(romFile.Page);
|
||||||
}, searchKey, 0, PAGE_SIZE);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void BeginFetchRomInfo(RomFile romFile)
|
public void ExecuteFetchRomInfo()
|
||||||
{
|
{
|
||||||
if (romFile.InfoReady) return;
|
if (FetchPageCmd.Count == 0) return;
|
||||||
|
|
||||||
FetchPageCmd.Add(romFile.Page);
|
foreach (var pageNo in FetchPageCmd)
|
||||||
}
|
{
|
||||||
|
m_romGetFunc(SaveRomInfoFromWeb, pageNo, PAGE_SIZE);
|
||||||
|
}
|
||||||
|
FetchPageCmd.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
public void ExecuteFetchRomInfo()
|
private void SaveRomInfoFromWeb(Resp_GameList resp)
|
||||||
{
|
{
|
||||||
if (FetchPageCmd.Count == 0) return;
|
for (int i = 0; i < resp.gameList.Count; i++)
|
||||||
|
{
|
||||||
|
var webData = resp.gameList[i];
|
||||||
|
RomFile targetRomFile = nesRomFetchList[webData.orderid];
|
||||||
|
|
||||||
foreach (var pageNo in FetchPageCmd)
|
targetRomFile.SetWebData(webData);
|
||||||
{
|
nesRomFileIdMapper[webData.id] = nesRomFetchList[webData.orderid];
|
||||||
if (!string.IsNullOrEmpty(lastSearchKey))
|
nesRomFileNameMapper[targetRomFile.FileName] = targetRomFile;
|
||||||
{
|
}
|
||||||
m_romSearchFunc(SaveRomInfoFromWeb, lastSearchKey, pageNo, PAGE_SIZE);
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_romGetFunc(SaveRomInfoFromWeb, pageNo, PAGE_SIZE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
FetchPageCmd.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SaveRomInfoFromWeb(Resp_GameList resp)
|
public static string CalcHash(byte[] data)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < resp.gameList.Count; i++)
|
return Helper.FileMD5Hash(data);
|
||||||
{
|
}
|
||||||
var webData = resp.gameList[i];
|
|
||||||
RomFile targetRomFile = nesRomFetchList[webData.orderid];
|
|
||||||
|
|
||||||
targetRomFile.SetWebData(webData);
|
public void AddRomFile(RomFile rom)
|
||||||
nesRomFileIdMapper[webData.id] = nesRomFetchList[webData.orderid];
|
{
|
||||||
nesRomFileNameMapper[targetRomFile.FileName] = targetRomFile;
|
nesRomFileNameMapper[rom.FileName] = rom;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string CalcHash(byte[] data)
|
|
||||||
{
|
|
||||||
return Helper.FileMD5Hash(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddRomFile(RomFile rom)
|
|
||||||
{
|
|
||||||
nesRomFileNameMapper[rom.FileName] = rom;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user