diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttp.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttp.cs index 82c200be..c5d8922f 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttp.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttp.cs @@ -1,79 +1,79 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; +using System; +using System.Collections.Generic; +using System.Diagnostics; using System.IO.Compression; -using System.Net; -using System.Net.Security; -using System.Net.Sockets; -using System.Security.Authentication; -using System.Security.Cryptography.X509Certificates; -using System.Text; -using System.Text.RegularExpressions; -using System.Threading; - -public static class PSVThread +using System.Net; +using System.Net.Security; +using System.Net.Sockets; +using System.Security.Authentication; +using System.Security.Cryptography.X509Certificates; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading; + +public static class PSVThread { -#if UNITY_PSP2 - static AutoResetEvent autoEvent = new AutoResetEvent(false); - static Queue qActs = new Queue(); - static Queue qWork = new Queue(); -#endif +#if UNITY_PSP2 + static AutoResetEvent autoEvent = new AutoResetEvent(false); + static Queue qActs = new Queue(); + static Queue qWork = new Queue(); +#endif public static void DoTask(Action act) { -#if UNITY_PSP2 - AddSingleTask(act); -#else +#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 +#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 { public const char T = '\n'; public const string CT = "\r\n"; @@ -1016,10 +1016,10 @@ public static class AxiHttp string strRelativePathRet; string strIPRet; - /*string strProtocol = strURI.Substring(0, 7); - if (strProtocol != "http://" - || - strProtocol != "https://") + /*string strProtocol = strURI.Substring(0, 7); + if (strProtocol != "http://" + || + strProtocol != "https://") return false;*/ if (!strURI.ToLower().StartsWith("http://") || strURI.ToLower().StartsWith("https://")) @@ -1109,11 +1109,11 @@ public static class AxiHttp return (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds; } - /// - /// 将16进制转换成10进制 - /// - /// 16进制字符串 - /// + /// + /// 将16进制转换成10进制 + /// + /// 16进制字符串 + /// public static int convertToIntBy16(String str) { try @@ -1145,11 +1145,11 @@ public static class AxiHttp } - /// - /// 将字符串转换成数字,错误返回0 - /// - /// 字符串 - /// + /// + /// 将字符串转换成数字,错误返回0 + /// + /// 字符串 + /// public static int convertToInt(String str) { @@ -1231,6 +1231,6 @@ public static class AxiHttp TimeoutObject.Set(); } } - } - + } + } \ No newline at end of file diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttp.cs.meta b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttp.cs.meta index d25c76e1..2a726db0 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttp.cs.meta +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttp.cs.meta @@ -1,2 +1,11 @@ fileFormatVersion: 2 -guid: 5a498f74133ebfa4fa238a33a1c4c0c3 \ No newline at end of file +guid: 5a498f74133ebfa4fa238a33a1c4c0c3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttpProxy.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttpProxy.cs index 4ab124f2..e22839c0 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttpProxy.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttpProxy.cs @@ -1,7 +1,7 @@ -using UnityEngine; -using static AxiHttp; - -public static class AxiHttpProxy +using UnityEngine; +using static AxiHttp; + +public static class AxiHttpProxy { public static SendWebRequestProxy Get(string url) { @@ -46,7 +46,7 @@ public static class AxiHttpProxy public static void ShowAxiHttpDebugInfo(AxiRespInfo resp) { -#if UNITY_EDITOR +#if UNITY_EDITOR Debug.Log($""); Debug.Log($"==== request ===="); Debug.Log($"url =>{resp.url}"); @@ -75,22 +75,22 @@ public static class AxiHttpProxy { Debug.LogError($"code->{resp.code} err->{resp.ErrInfo} url->{resp.url}"); } -#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 +#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) //{ @@ -118,6 +118,6 @@ public static class AxiHttpProxy // Debug.Log($"DownLoad Err {ex.ToString()}"); // } //} - } - + } + } \ No newline at end of file diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttpProxy.cs.meta b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttpProxy.cs.meta index ece4507c..35f7c57a 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttpProxy.cs.meta +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttpProxy.cs.meta @@ -1,2 +1,11 @@ fileFormatVersion: 2 -guid: ec8e2e405992b234eb08896da0f85317 \ No newline at end of file +guid: ec8e2e405992b234eb08896da0f85317 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttpTest.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttpTest.cs new file mode 100644 index 00000000..56b3d0fc --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttpTest.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections; +using UnityEngine; + +public class AxiHttpTest : MonoBehaviour +{ + // Start is called once before the first execution of Update after the MonoBehaviour is created + void Start() + { + + } + + // Update is called once per frame + void Update() + { + if (Input.GetKeyDown(KeyCode.T)) + { + //for (int i = 0; i < 1000; i++) + StartCoroutine(DownloadFromURL("http://emu.axibug.com/UserSav/12/Nes/190/1/1.sav", "D:/1.bin", null)); + } + } + + IEnumerator DownloadFromURL(string url, string path, Action callback) + { + + for (int i = 0; i < 1000; i++) + { + AxiHttpProxy.SendDownLoadProxy request = AxiHttpProxy.GetDownLoad(url); + + while (!request.downloadHandler.isDone) + { + Debug.Log($"ؽȣ{request.downloadHandler.DownLoadPr} ->{request.downloadHandler.loadedLenght}/{request.downloadHandler.NeedloadedLenght}"); + yield return null; + } + AxiHttpProxy.ShowAxiHttpDebugInfo(request.downloadHandler); + Debug.Log($"ؽ:data.Length=>" + request.downloadHandler.data.Length); + } + + + //if (!request.downloadHandler.bHadErr) + //{ + // AxiIO.Directory.CreateDirectory(path); + // AxiIO.File.WriteAllBytes($"{path}/{url.GetHashCode()}", request.downloadHandler.data, false); + // callback?.Invoke(request.downloadHandler.data); + //} + //else + //{ + // callback?.Invoke(null); + //} + } +} diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttpTest.cs.meta b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttpTest.cs.meta new file mode 100644 index 00000000..3c638f40 --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiHttp/AxiHttpTest.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 873427ab0a955e64fa2444505ef0775c \ No newline at end of file