forked from sin365/AxibugEmuOnline
尝试TCP纯原生平替HTTP异步下载和接口请求,支持PSVita
This commit is contained in:
parent
30dd2ee9aa
commit
6c6761c4e3
@ -1,4 +1,4 @@
|
|||||||
using AxibugEmuOnline.Client.Manager;
|
using AxibugEmuOnline.Client.Manager;
|
||||||
using AxibugEmuOnline.Client.Network;
|
using AxibugEmuOnline.Client.Network;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@ -116,14 +116,21 @@ namespace AxibugEmuOnline.Client.ClientCore
|
|||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
|
|
||||||
UnityWebRequest request = UnityWebRequest.Get($"{App.httpAPI.WebSiteApi}/CheckStandInfo?platform={platform}&version={Application.version}");
|
AxiHttpProxy.SendWebRequestProxy request = AxiHttpProxy.Get($"{App.httpAPI.WebSiteApi}/CheckStandInfo?platform={platform}&version={Application.version}");
|
||||||
|
yield return request.SendWebRequest;
|
||||||
|
if (!request.downloadHandler.isDone)
|
||||||
|
yield break;
|
||||||
|
Resp_CheckStandInfo resp = JsonUtility.FromJson<Resp_CheckStandInfo>(request.downloadHandler.text);
|
||||||
|
|
||||||
|
/*UnityWebRequest request = UnityWebRequest.Get($"{App.httpAPI.WebSiteApi}/CheckStandInfo?platform={platform}&version={Application.version}");
|
||||||
yield return request.SendWebRequest();
|
yield return request.SendWebRequest();
|
||||||
|
|
||||||
if (request.result != UnityWebRequest.Result.Success)
|
if (request.result != UnityWebRequest.Result.Success)
|
||||||
yield break;
|
yield break;
|
||||||
|
|
||||||
App.log.Debug($"ApiResp => {request.downloadHandler.text}");
|
App.log.Debug($"ApiResp => {request.downloadHandler.text}");
|
||||||
Resp_CheckStandInfo resp = JsonUtility.FromJson<Resp_CheckStandInfo>(request.downloadHandler.text);
|
Resp_CheckStandInfo resp = JsonUtility.FromJson<Resp_CheckStandInfo>(request.downloadHandler.text);*/
|
||||||
|
|
||||||
//需要更新
|
//需要更新
|
||||||
if (resp.needUpdateClient == 1)
|
if (resp.needUpdateClient == 1)
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5034475933564b54db148790f0ae2501
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
1142
AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttp.cs
Normal file
1142
AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttp.cs
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5a498f74133ebfa4fa238a33a1c4c0c3
|
@ -0,0 +1,101 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using UnityEngine;
|
||||||
|
using static AxiHttp;
|
||||||
|
|
||||||
|
public static class AxiHttpProxy
|
||||||
|
{
|
||||||
|
public static SendWebRequestProxy Get(string url)
|
||||||
|
{
|
||||||
|
return new SendWebRequestProxy(AxiRequestAsync(url));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SendDownLoadProxy GetDownLoad(string url)
|
||||||
|
{
|
||||||
|
return new SendDownLoadProxy(AxiDownloadAsync(url));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class SendWebRequestProxy
|
||||||
|
{
|
||||||
|
public WaitAxiRequest SendWebRequest;
|
||||||
|
public AxiRespInfo downloadHandler => SendWebRequest.mReqAsync;
|
||||||
|
public SendWebRequestProxy(WaitAxiRequest request)
|
||||||
|
{
|
||||||
|
SendWebRequest = request;
|
||||||
|
}
|
||||||
|
~SendWebRequestProxy()
|
||||||
|
{
|
||||||
|
SendWebRequest = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class SendDownLoadProxy
|
||||||
|
{
|
||||||
|
public AxiRespInfo downloadHandler;
|
||||||
|
public SendDownLoadProxy(AxiRespInfo re)
|
||||||
|
{
|
||||||
|
downloadHandler = re;
|
||||||
|
}
|
||||||
|
~SendDownLoadProxy()
|
||||||
|
{
|
||||||
|
downloadHandler = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void ShowAxiHttpDebugInfo(AxiRespInfo resp)
|
||||||
|
{
|
||||||
|
Debug.Log($"");
|
||||||
|
Debug.Log($"==== request ====");
|
||||||
|
Debug.Log($"url =>{resp.url}");
|
||||||
|
Debug.Log($"Raw =>{resp.requestRaw}");
|
||||||
|
Debug.Log($"code =>{resp.code}");
|
||||||
|
Debug.Log($"respInfo.bTimeOut =>{resp.bTimeOut}");
|
||||||
|
Debug.Log($"");
|
||||||
|
Debug.Log($"==== response ====");
|
||||||
|
Debug.Log($"==== header ====");
|
||||||
|
Debug.Log($"header =>{resp.header}");
|
||||||
|
Debug.Log($"HeadersCount =>{resp.headers.Count}");
|
||||||
|
foreach (var kv in resp.headers)
|
||||||
|
Debug.Log($"{kv.Key} => {kv.Value}");
|
||||||
|
Debug.Log($"");
|
||||||
|
Debug.Log($"==== body ====");
|
||||||
|
Debug.Log($"body_text =>{resp.body}");
|
||||||
|
Debug.Log($"body_text.Length =>{resp.body.Length}");
|
||||||
|
Debug.Log($"bodyRaw.Length =>{resp.bodyRaw?.Length}");
|
||||||
|
Debug.Log($"");
|
||||||
|
Debug.Log($"==== download ====");
|
||||||
|
Debug.Log($"downloadMode =>{resp.downloadMode}");
|
||||||
|
Debug.Log($"respInfo.fileName =>{resp.fileName}");
|
||||||
|
Debug.Log($"respInfo.NeedloadedLenght =>{resp.NeedloadedLenght}");
|
||||||
|
Debug.Log($"respInfo.loadedLenght =>{resp.loadedLenght}");
|
||||||
|
//if (resp.downloadMode == AxiDownLoadMode.DownLoadBytes)
|
||||||
|
//{
|
||||||
|
// if (resp.bTimeOut)
|
||||||
|
// {
|
||||||
|
// Debug.Log($"DownLoad Timeout!");
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// string downloadSavePath;
|
||||||
|
// if (Application.platform == RuntimePlatform.PSP2)
|
||||||
|
// {
|
||||||
|
// downloadSavePath = dataAxibugPath + "/" + resp.fileName;
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// downloadSavePath = persistentDataPath + "/" + resp.fileName;
|
||||||
|
// }
|
||||||
|
// try
|
||||||
|
// {
|
||||||
|
// File.WriteAllBytes(downloadSavePath, resp.bodyRaw);
|
||||||
|
// Debug.Log($"DownLoad OK");
|
||||||
|
// }
|
||||||
|
// catch (Exception ex)
|
||||||
|
// {
|
||||||
|
// Debug.Log($"DownLoad Err {ex.ToString()}");
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ec8e2e405992b234eb08896da0f85317
|
@ -18,7 +18,7 @@ namespace AxibugEmuOnline.Client
|
|||||||
GetCacheData(url, TextureCacheDirPath, callback);
|
GetCacheData(url, TextureCacheDirPath, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> 移除文件缓存 </summary>
|
/// <summary> 移除文件缓存 </summary>
|
||||||
public void ClearCaches()
|
public void ClearCaches()
|
||||||
{
|
{
|
||||||
if (Directory.Exists(CacheDirPath))
|
if (Directory.Exists(CacheDirPath))
|
||||||
@ -27,6 +27,25 @@ namespace AxibugEmuOnline.Client
|
|||||||
|
|
||||||
IEnumerator DownloadFromURL(string url, string path, Action<byte[]> callback)
|
IEnumerator DownloadFromURL(string url, string path, Action<byte[]> callback)
|
||||||
{
|
{
|
||||||
|
AxiHttpProxy.SendDownLoadProxy request = AxiHttpProxy.GetDownLoad($"{App.httpAPI.WebHost}/{url}");
|
||||||
|
|
||||||
|
while (!request.downloadHandler.isDone)
|
||||||
|
{
|
||||||
|
yield return null;
|
||||||
|
//Debug.Log($"下载进度:{respInfo.DownLoadPr} ->{respInfo.loadedLenght}/{respInfo.NeedloadedLenght}");
|
||||||
|
}
|
||||||
|
AxiHttpProxy.ShowAxiHttpDebugInfo(request.downloadHandler);
|
||||||
|
|
||||||
|
if (request.downloadHandler.Err != null)
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
File.WriteAllBytes($"{path}/{url.GetHashCode()}", request.downloadHandler.data);
|
||||||
|
callback.Invoke(request.downloadHandler.data);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
callback.Invoke(null);
|
||||||
|
|
||||||
|
/*
|
||||||
var request = UnityWebRequest.Get($"{App.httpAPI.WebHost}/{url}");
|
var request = UnityWebRequest.Get($"{App.httpAPI.WebHost}/{url}");
|
||||||
yield return request.SendWebRequest();
|
yield return request.SendWebRequest();
|
||||||
|
|
||||||
@ -38,6 +57,7 @@ namespace AxibugEmuOnline.Client
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
callback.Invoke(null);
|
callback.Invoke(null);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dictionary<string, object> cachesInMemory = new Dictionary<string, object>();
|
private Dictionary<string, object> cachesInMemory = new Dictionary<string, object>();
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using AxibugEmuOnline.Client.ClientCore;
|
using AxibugEmuOnline.Client.ClientCore;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -26,6 +26,16 @@ 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)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
AxiHttpProxy.SendWebRequestProxy request = AxiHttpProxy.Get($"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}&SearchKey={searchKey}");
|
||||||
|
yield return request.SendWebRequest;
|
||||||
|
if (!request.downloadHandler.isDone)
|
||||||
|
{
|
||||||
|
callback.Invoke(null);
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
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();
|
||||||
|
|
||||||
@ -33,13 +43,21 @@ namespace AxibugEmuOnline.Client
|
|||||||
{
|
{
|
||||||
callback.Invoke(null);
|
callback.Invoke(null);
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
var resp = JsonUtility.FromJson<Resp_GameList>(request.downloadHandler.text);
|
var resp = JsonUtility.FromJson<Resp_GameList>(request.downloadHandler.text);
|
||||||
callback.Invoke(resp);
|
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)
|
||||||
{
|
{
|
||||||
|
AxiHttpProxy.SendWebRequestProxy request = AxiHttpProxy.Get($"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}");
|
||||||
|
yield return request.SendWebRequest;
|
||||||
|
if (!request.downloadHandler.isDone)
|
||||||
|
{
|
||||||
|
callback.Invoke(null);
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
/*
|
||||||
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();
|
||||||
|
|
||||||
@ -48,13 +66,23 @@ namespace AxibugEmuOnline.Client
|
|||||||
callback.Invoke(null);
|
callback.Invoke(null);
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
var resp = JsonUtility.FromJson<Resp_GameList>(request.downloadHandler.text);
|
var resp = JsonUtility.FromJson<Resp_GameList>(request.downloadHandler.text);
|
||||||
callback.Invoke(resp);
|
callback.Invoke(resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerator GetNesRomInfo(int RomID, Action<Resp_RomInfo> callback)
|
public IEnumerator GetNesRomInfo(int RomID, Action<Resp_RomInfo> callback)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
AxiHttpProxy.SendWebRequestProxy request = AxiHttpProxy.Get($"{WebSiteApi}/RomInfo?PType={PlatformType.Nes}&RomID={RomID}");
|
||||||
|
yield return request.SendWebRequest;
|
||||||
|
if (!request.downloadHandler.isDone)
|
||||||
|
{
|
||||||
|
callback.Invoke(null);
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
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();
|
||||||
|
|
||||||
@ -62,7 +90,7 @@ namespace AxibugEmuOnline.Client
|
|||||||
{
|
{
|
||||||
callback.Invoke(null);
|
callback.Invoke(null);
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
var resp = JsonUtility.FromJson<Resp_RomInfo>(request.downloadHandler.text);
|
var resp = JsonUtility.FromJson<Resp_RomInfo>(request.downloadHandler.text);
|
||||||
callback.Invoke(resp);
|
callback.Invoke(resp);
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
using AxibugEmuOnline.Client.ClientCore;
|
using AxibugEmuOnline.Client.ClientCore;
|
||||||
using ICSharpCode.SharpZipLib.Zip;
|
using ICSharpCode.SharpZipLib.Zip;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using UnityEngine;
|
||||||
using UnityEngine.Networking;
|
using UnityEngine.Networking;
|
||||||
|
|
||||||
namespace AxibugEmuOnline.Client
|
namespace AxibugEmuOnline.Client
|
||||||
@ -12,7 +13,8 @@ namespace AxibugEmuOnline.Client
|
|||||||
private HttpAPI.Resp_RomInfo webData;
|
private HttpAPI.Resp_RomInfo webData;
|
||||||
private bool hasLocalFile;
|
private bool hasLocalFile;
|
||||||
private EnumPlatform platform;
|
private EnumPlatform platform;
|
||||||
private UnityWebRequest downloadRequest;
|
//private UnityWebRequest downloadRequest;
|
||||||
|
private AxiHttpProxy.SendDownLoadProxy downloadRequest;
|
||||||
|
|
||||||
public bool IsUserRom { get; private set; }
|
public bool IsUserRom { get; private set; }
|
||||||
|
|
||||||
@ -24,9 +26,14 @@ namespace AxibugEmuOnline.Client
|
|||||||
|
|
||||||
/// <summary> 指示该Rom文件是否已下载完毕 </summary>
|
/// <summary> 指示该Rom文件是否已下载完毕 </summary>
|
||||||
public bool RomReady => hasLocalFile;
|
public bool RomReady => hasLocalFile;
|
||||||
|
///// <summary> 指示是否正在下载Rom文件 </summary>
|
||||||
|
//public bool IsDownloading => downloadRequest != null && downloadRequest.result == UnityWebRequest.Result.InProgress;
|
||||||
|
//public float Progress => IsDownloading ? downloadRequest.downloadProgress : 0;
|
||||||
|
|
||||||
/// <summary> 指示是否正在下载Rom文件 </summary>
|
/// <summary> 指示是否正在下载Rom文件 </summary>
|
||||||
public bool IsDownloading => downloadRequest != null && downloadRequest.result == UnityWebRequest.Result.InProgress;
|
public bool IsDownloading => downloadRequest != null && !downloadRequest.downloadHandler.isDone;
|
||||||
public float Progress => IsDownloading ? downloadRequest.downloadProgress : 0;
|
public float Progress => IsDownloading ? downloadRequest.downloadHandler.DownLoadPr : 0;
|
||||||
|
|
||||||
|
|
||||||
public EnumPlatform Platform => platform;
|
public EnumPlatform Platform => platform;
|
||||||
/// <summary> 指示该Rom信息是否已填充 </summary>
|
/// <summary> 指示该Rom信息是否已填充 </summary>
|
||||||
@ -114,13 +121,19 @@ namespace AxibugEmuOnline.Client
|
|||||||
|
|
||||||
private IEnumerator DownloadRemoteRom(Action<byte[]> callback)
|
private IEnumerator DownloadRemoteRom(Action<byte[]> callback)
|
||||||
{
|
{
|
||||||
downloadRequest = UnityWebRequest.Get($"{App.httpAPI.WebHost}/{webData.url}");
|
downloadRequest = AxiHttpProxy.GetDownLoad($"{App.httpAPI.WebHost}/{webData.url}");
|
||||||
yield return downloadRequest.SendWebRequest();
|
|
||||||
|
while (!downloadRequest.downloadHandler.isDone)
|
||||||
|
{
|
||||||
|
yield return null;
|
||||||
|
Debug.Log($"下载进度:{downloadRequest.downloadHandler.DownLoadPr} ->{downloadRequest.downloadHandler.loadedLenght}/{downloadRequest.downloadHandler.NeedloadedLenght}");
|
||||||
|
}
|
||||||
|
AxiHttpProxy.ShowAxiHttpDebugInfo(downloadRequest.downloadHandler);
|
||||||
|
|
||||||
var request = downloadRequest;
|
var request = downloadRequest;
|
||||||
downloadRequest = null;
|
downloadRequest = null;
|
||||||
|
|
||||||
if (request.result != UnityWebRequest.Result.Success)
|
if (request.downloadHandler.Err != null)
|
||||||
{
|
{
|
||||||
callback(null);
|
callback(null);
|
||||||
}
|
}
|
||||||
@ -128,6 +141,21 @@ namespace AxibugEmuOnline.Client
|
|||||||
{
|
{
|
||||||
callback(request.downloadHandler.data);
|
callback(request.downloadHandler.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//downloadRequest = UnityWebRequest.Get($"{App.httpAPI.WebHost}/{webData.url}");
|
||||||
|
//yield return downloadRequest.SendWebRequest();
|
||||||
|
|
||||||
|
//var request = downloadRequest;
|
||||||
|
//downloadRequest = null;
|
||||||
|
|
||||||
|
//if (request.result != UnityWebRequest.Result.Success)
|
||||||
|
//{
|
||||||
|
// callback(null);
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//{
|
||||||
|
// callback(request.downloadHandler.data);
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetWebData(HttpAPI.Resp_RomInfo resp_RomInfo)
|
public void SetWebData(HttpAPI.Resp_RomInfo resp_RomInfo)
|
||||||
|
Loading…
Reference in New Issue
Block a user