This commit is contained in:
ALIENJACK 2024-12-25 01:05:55 +08:00
commit 5f1fbdd41f
9 changed files with 99 additions and 54 deletions

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 898ba71ded907534ba7eaada7855cadc

View File

@ -1,33 +0,0 @@
fileFormatVersion: 2
guid: 324deac494a24a7499801349c7908062
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 1
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
userData:
assetBundleName:
assetBundleVariant:

View File

@ -11,8 +11,65 @@ using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
public static class PSVThread
{
static AutoResetEvent autoEvent = new AutoResetEvent(false);
static Queue<Action> qActs = new Queue<Action>();
static Queue<Action> qWork = new Queue<Action>();
public static void DoTask(Action act)
{
#if UNITY_PSP2
AddSingleTask(act);
#else
ThreadPool.QueueUserWorkItem(new WaitCallback((state) => act.Invoke()));
#endif
}
#if UNITY_PSP2
static Thread psvThread = new Thread(Loop);
static bool bSingleInit = false;
static void SingleInit()
{
if (bSingleInit) return;
psvThread.Start();
bSingleInit = true;
}
static void AddSingleTask(Action act)
{
SingleInit();
lock (qActs)
{
qActs.Enqueue(act);
}
autoEvent.Set();
}
static void Loop()
{
while (autoEvent.WaitOne())
{
lock (qActs)
{
while (qActs.Count > 0) { qWork.Enqueue(qActs.Dequeue()); }
}
while (qWork.Count > 0)
{
Action act = qWork.Dequeue();
try
{
act.Invoke();
}
catch (Exception ex)
{
UnityEngine.Debug.Log(ex.ToString());
}
}
}
}
#endif
}
public static class AxiHttp
{
@ -127,8 +184,9 @@ public static class AxiHttp
AxiRespInfo respInfo = new AxiRespInfo();
respInfo.downloadMode = AxiDownLoadMode.NotDownLoad;
WaitAxiRequest respAsync = new WaitAxiRequest(respInfo);
Task task = new Task(() => SendAxiRequest(url, ref respInfo));
task.Start();
//Task task = new Task(() => SendAxiRequest(url, ref respInfo));
//task.Start()
PSVThread.DoTask(() => SendAxiRequest(url, ref respInfo));
return respAsync;
}
@ -144,17 +202,18 @@ public static class AxiHttp
{
AxiRespInfo respInfo = new AxiRespInfo();
respInfo.downloadMode = AxiDownLoadMode.DownLoadBytes;
Task task = new Task(() => SendAxiRequest(url, ref respInfo));
task.Start();
//Task task = new Task(() => SendAxiRequest(url, ref respInfo));
//task.Start();
PSVThread.DoTask(() => SendAxiRequest(url, ref respInfo));
return respInfo;
}
static void SendAxiRequest(string url, ref AxiRespInfo respinfo,int timeout = 1000 * 1000, string encoding = "UTF-8")
static void SendAxiRequest(string url, ref AxiRespInfo respinfo, int timeout = 1000 * 1000, string encoding = "UTF-8")
{
if (url.ToLower().StartsWith("https://"))
SendAxiRequestHttps(url, ref respinfo,timeout, encoding);// SendAxiRequestHttps(url, ref respinfo, timeout, encoding);
SendAxiRequestHttps(url, ref respinfo, timeout, encoding);// SendAxiRequestHttps(url, ref respinfo, timeout, encoding);
else
SendAxiRequestHttp(url, ref respinfo,timeout, encoding);
SendAxiRequestHttp(url, ref respinfo, timeout, encoding);
}
static void SendAxiRequestHttp(string url, ref AxiRespInfo respinfo, int timeout, string encoding)
@ -735,6 +794,9 @@ public static class AxiHttp
//}
respinfo.isDone = true;
}
if (client != null)
client.Dispose();
}
@ -1023,7 +1085,7 @@ public static class AxiHttp
{
try
{
Log($"convertToIntBy16 str- {str} lenght->{str.Length}");
//Log($"convertToIntBy16 str- {str} lenght->{str.Length}");
if (str.Length == 0)
return 0;
return Convert.ToInt32(str, 16);

View File

@ -1,4 +1,3 @@
using System.Collections;
using UnityEngine;
using static AxiHttp;
@ -46,6 +45,8 @@ public static class AxiHttpProxy
public static void ShowAxiHttpDebugInfo(AxiRespInfo resp)
{
#if UNITY_EDITOR
Debug.Log($"");
Debug.Log($"==== request ====");
Debug.Log($"url =>{resp.url}");
@ -70,6 +71,23 @@ public static class AxiHttpProxy
Debug.Log($"respInfo.fileName =>{resp.fileName}");
Debug.Log($"respInfo.NeedloadedLenght =>{resp.NeedloadedLenght}");
Debug.Log($"respInfo.loadedLenght =>{resp.loadedLenght}");
#else
Debug.Log($"==== request url => { resp.url}");
Debug.Log($"code =>{resp.code}");
Debug.Log($"respInfo.bTimeOut =>{resp.bTimeOut}");
Debug.Log($"==== response ====");
if (resp.downloadMode == AxiDownLoadMode.NotDownLoad)
{
Debug.Log($"body_text =>{resp.body}");
Debug.Log($"body_text.Length =>{resp.body.Length}");
}
else
{
Debug.Log($"==== download ====");
Debug.Log($"respInfo.loadedLenght =>{resp.loadedLenght}");
}
#endif
//if (resp.downloadMode == AxiDownLoadMode.DownLoadBytes)
//{
// if (resp.bTimeOut)

View File

@ -36,7 +36,7 @@ namespace AxibugEmuOnline.Client
}
AxiHttpProxy.ShowAxiHttpDebugInfo(request.downloadHandler);
if (request.downloadHandler.Err != null)
if (request.downloadHandler.Err == null)
{
Directory.CreateDirectory(path);
File.WriteAllBytes($"{path}/{url.GetHashCode()}", request.downloadHandler.data);

View File

@ -136,14 +136,10 @@ namespace AxibugEmuOnline.Client
var request = downloadRequest;
downloadRequest = null;
if (request.downloadHandler.Err != null)
{
callback(null);
}
else
{
if (request.downloadHandler.Err == null)
callback(request.downloadHandler.data);
}
else
callback(null);
//downloadRequest = UnityWebRequest.Get($"{App.httpAPI.WebHost}/{webData.url}");
//yield return downloadRequest.SendWebRequest();

View File

@ -1,6 +1,6 @@
using AxibugEmuOnline.Client.ClientCore;
using AxibugProtobuf;
using HaoYueNet.ClientNetworkNet.Standard2;
using HaoYueNet.ClientNetwork;
using System;
using System.Net.Sockets;
using System.Threading;