forked from sin365/AxibugEmuOnline
引入最新版本的AxiNSApi
This commit is contained in:
parent
8afcbce6b1
commit
57c4947623
@ -15,6 +15,11 @@ public class AxiNS
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 延迟提交是否使用多线程
|
||||
/// </summary>
|
||||
public static bool usedmultithreading = false;
|
||||
|
||||
public AxiNSUser user;
|
||||
public AxiNSMount mount;
|
||||
public AxiNSIO io;
|
||||
|
||||
@ -309,12 +309,15 @@ public class AxiNSIO
|
||||
}
|
||||
public byte[] LoadSwitchDataFile(string filename)
|
||||
{
|
||||
LoadSwitchDataFile(filename, out byte[] outputData);
|
||||
byte[] outputData;
|
||||
LoadSwitchDataFile(filename, out outputData);
|
||||
return outputData;
|
||||
}
|
||||
|
||||
public bool LoadSwitchDataFile(string filename, ref System.IO.MemoryStream ms)
|
||||
{
|
||||
if (LoadSwitchDataFile(filename, out byte[] outputData))
|
||||
byte[] outputData;
|
||||
if (LoadSwitchDataFile(filename, out outputData))
|
||||
{
|
||||
using (System.IO.BinaryWriter writer = new System.IO.BinaryWriter(ms))
|
||||
{
|
||||
@ -383,6 +386,7 @@ public class AxiNSIO
|
||||
AxiNS.instance.wait.AddWait(wait);
|
||||
return wait;
|
||||
}
|
||||
|
||||
public bool GetDirectoryFiles(string path, out string[] entrys)
|
||||
{
|
||||
#if !UNITY_SWITCH || UNITY_EDITOR
|
||||
@ -393,6 +397,7 @@ public class AxiNSIO
|
||||
return GetDirectoryEntrys(path,nn.fs.OpenDirectoryMode.File,out entrys);
|
||||
#endif
|
||||
}
|
||||
|
||||
public bool GetDirectoryDirs(string path, out string[] entrys)
|
||||
{
|
||||
#if !UNITY_SWITCH || UNITY_EDITOR
|
||||
@ -430,6 +435,7 @@ public class AxiNSIO
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
public bool GetDirectoryEntrysFullRecursion(string path, out string[] entrys)
|
||||
{
|
||||
#if UNITY_SWITCH
|
||||
@ -462,7 +468,7 @@ public class AxiNSIO
|
||||
entrys = temp.ToArray();
|
||||
return true;
|
||||
#else
|
||||
entrys = default;
|
||||
entrys = null;
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
@ -597,16 +603,83 @@ public class AxiNSIO
|
||||
return CommitSave();
|
||||
#endif
|
||||
}
|
||||
|
||||
#if UNITY_SWITCH
|
||||
public AxiNSWait_DeletePathDirRecursively DeletePathDirRecursivelyAsync(string filename)
|
||||
{
|
||||
var wait = new AxiNSWait_DeletePathDirRecursively(filename);
|
||||
AxiNS.instance.wait.AddWait(wait);
|
||||
return wait;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// µÝ¹éɾ³ýĿ¼
|
||||
/// </summary>
|
||||
/// <param name="filename"></param>
|
||||
/// <returns></returns>
|
||||
public bool DeleteRecursivelyPathDir(string filename)
|
||||
{
|
||||
#if !UNITY_SWITCH
|
||||
return false;
|
||||
#else
|
||||
|
||||
#if UNITY_SWITCH && !UNITY_EDITOR
|
||||
// This next line prevents the user from quitting the game while saving.
|
||||
// This is required for Nintendo Switch Guideline 0080
|
||||
UnityEngine.Switch.Notification.EnterExitRequestHandlingSection();
|
||||
#endif
|
||||
|
||||
if (CheckPathNotFound(filename))
|
||||
return false;
|
||||
nn.Result result;
|
||||
result = nn.fs.Directory.DeleteRecursively(filename);
|
||||
if (result.IsSuccess() == false)
|
||||
{
|
||||
UnityEngine.Debug.LogError($"nn.fs.File.DeleteRecursively ʧ°Ü {filename} : result=>{result.GetErrorInfo()}");
|
||||
return false;
|
||||
}
|
||||
|
||||
#if UNITY_SWITCH && !UNITY_EDITOR
|
||||
// End preventing the user from quitting the game while saving.
|
||||
UnityEngine.Switch.Notification.LeaveExitRequestHandlingSection();
|
||||
#endif
|
||||
return CommitSave();
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// µÝ¹éɾ³ýÇé¿ö
|
||||
/// </summary>
|
||||
/// <param name="filename"></param>
|
||||
/// <returns></returns>
|
||||
public bool CleanRecursivelyPathDir(string filename)
|
||||
{
|
||||
#if !UNITY_SWITCH
|
||||
return false;
|
||||
#else
|
||||
|
||||
#if UNITY_SWITCH && !UNITY_EDITOR
|
||||
// This next line prevents the user from quitting the game while saving.
|
||||
// This is required for Nintendo Switch Guideline 0080
|
||||
UnityEngine.Switch.Notification.EnterExitRequestHandlingSection();
|
||||
#endif
|
||||
|
||||
if (CheckPathNotFound(filename))
|
||||
return false;
|
||||
nn.Result result;
|
||||
result = nn.fs.Directory.CleanRecursively(filename);
|
||||
if (result.IsSuccess() == false)
|
||||
{
|
||||
UnityEngine.Debug.LogError($"nn.fs.File.DeleteRecursively ʧ°Ü {filename} : result=>{result.GetErrorInfo()}");
|
||||
return false;
|
||||
}
|
||||
|
||||
#if UNITY_SWITCH && !UNITY_EDITOR
|
||||
// End preventing the user from quitting the game while saving.
|
||||
UnityEngine.Switch.Notification.LeaveExitRequestHandlingSection();
|
||||
#endif
|
||||
return CommitSave();
|
||||
#endif
|
||||
}
|
||||
|
||||
public bool RenameDir(string oldpath, string newpath)
|
||||
{
|
||||
#if !UNITY_SWITCH
|
||||
|
||||
41
AxibugEmuOnline.Client/Assets/Plugins/AxiNSApi/AxiNSMono.cs
Normal file
41
AxibugEmuOnline.Client/Assets/Plugins/AxiNSApi/AxiNSMono.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class AxiNSMono : MonoBehaviour
|
||||
{
|
||||
Action act;
|
||||
float waittime;
|
||||
float lastinvokeTime;
|
||||
|
||||
public static void SetInvoke(Action _act, int _waitsec)
|
||||
{
|
||||
GameObject gobj = GameObject.Find($"[{nameof(AxiNSMono)}]");
|
||||
if (gobj == null)
|
||||
{
|
||||
gobj = new GameObject();
|
||||
gobj.name = $"[{nameof(AxiNSMono)}]";
|
||||
GameObject.DontDestroyOnLoad(gobj);
|
||||
}
|
||||
AxiNSMono com = gobj.GetComponent<AxiNSMono>();
|
||||
if (com == null)
|
||||
{
|
||||
com = gobj.AddComponent<AxiNSMono>();
|
||||
}
|
||||
com.act = _act;
|
||||
com.waittime = _waitsec;
|
||||
}
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
Debug.Log("AxiNSMono Enable");
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (Time.time - lastinvokeTime < waittime)
|
||||
return;
|
||||
lastinvokeTime = Time.time;
|
||||
if (act != null)
|
||||
act.Invoke();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 23d5745b8989af04d8a871b5c7b65d50
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -117,3 +117,18 @@ public class AxiNSWait_DeletePathDir : AxiNSWaitBase
|
||||
result = AxiNS.instance.io.DeletePathDir(req.filePath);
|
||||
}
|
||||
}
|
||||
|
||||
public class AxiNSWait_DeletePathDirRecursively : AxiNSWaitBase
|
||||
{
|
||||
S_NSWAIT_Path req;
|
||||
public bool result;
|
||||
public AxiNSWait_DeletePathDirRecursively(string filePath)
|
||||
{
|
||||
req = new S_NSWAIT_Path() { filePath = filePath };
|
||||
}
|
||||
|
||||
public override void Invoke()
|
||||
{
|
||||
result = AxiNS.instance.io.DeletePathDirRecursively(req.filePath);
|
||||
}
|
||||
}
|
||||
@ -4,21 +4,30 @@ using System.Threading;
|
||||
|
||||
public class AxiNSWaitHandle
|
||||
{
|
||||
static AutoResetEvent autoEvent = new AutoResetEvent(false);
|
||||
static Thread waitThread = new Thread(Loop);
|
||||
static bool bSingleInit = false;
|
||||
static Queue<AxiNSWaitBase> m_QueueReady = new Queue<AxiNSWaitBase>();
|
||||
static Queue<AxiNSWaitBase> m_QueueWork = new Queue<AxiNSWaitBase>();
|
||||
public void AddWait(AxiNSWaitBase wait)
|
||||
{
|
||||
InitInternalThread();
|
||||
lock (m_QueueReady)
|
||||
{
|
||||
m_QueueReady.Enqueue(wait);
|
||||
}
|
||||
|
||||
if (AxiNS.usedmultithreading)
|
||||
{
|
||||
InitInternalThread();
|
||||
autoEvent.Set();
|
||||
}
|
||||
else
|
||||
{
|
||||
InitMonoInit();
|
||||
}
|
||||
}
|
||||
|
||||
#region 多线程实现
|
||||
static AutoResetEvent autoEvent = new AutoResetEvent(false);
|
||||
static Thread waitThread = new Thread(Loop);
|
||||
static bool bSingleInit = false;
|
||||
static void InitInternalThread()
|
||||
{
|
||||
if (bSingleInit) return;
|
||||
@ -29,6 +38,23 @@ public class AxiNSWaitHandle
|
||||
static void Loop()
|
||||
{
|
||||
while (autoEvent.WaitOne())
|
||||
{
|
||||
Do();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 主线程时间间隔实现
|
||||
static bool bMonoInit = false;
|
||||
static void InitMonoInit()
|
||||
{
|
||||
if (bMonoInit) return;
|
||||
AxiNSMono.SetInvoke(Do,15);
|
||||
bMonoInit = true;
|
||||
}
|
||||
#endregion
|
||||
|
||||
static void Do()
|
||||
{
|
||||
lock (m_QueueReady)
|
||||
{
|
||||
@ -52,5 +78,4 @@ public class AxiNSWaitHandle
|
||||
wait.SetDone();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user