引入最新版本的AxiNSApi

This commit is contained in:
sin365 2025-08-18 22:12:40 +08:00
parent 8afcbce6b1
commit 57c4947623
6 changed files with 384 additions and 214 deletions

View File

@ -15,6 +15,11 @@ public class AxiNS
} }
} }
/// <summary>
/// 延迟提交是否使用多线程
/// </summary>
public static bool usedmultithreading = false;
public AxiNSUser user; public AxiNSUser user;
public AxiNSMount mount; public AxiNSMount mount;
public AxiNSIO io; public AxiNSIO io;

View File

@ -309,12 +309,15 @@ public class AxiNSIO
} }
public byte[] LoadSwitchDataFile(string filename) public byte[] LoadSwitchDataFile(string filename)
{ {
LoadSwitchDataFile(filename, out byte[] outputData); byte[] outputData;
LoadSwitchDataFile(filename, out outputData);
return outputData; return outputData;
} }
public bool LoadSwitchDataFile(string filename, ref System.IO.MemoryStream ms) 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)) using (System.IO.BinaryWriter writer = new System.IO.BinaryWriter(ms))
{ {
@ -383,6 +386,7 @@ public class AxiNSIO
AxiNS.instance.wait.AddWait(wait); AxiNS.instance.wait.AddWait(wait);
return wait; return wait;
} }
public bool GetDirectoryFiles(string path, out string[] entrys) public bool GetDirectoryFiles(string path, out string[] entrys)
{ {
#if !UNITY_SWITCH || UNITY_EDITOR #if !UNITY_SWITCH || UNITY_EDITOR
@ -393,6 +397,7 @@ public class AxiNSIO
return GetDirectoryEntrys(path,nn.fs.OpenDirectoryMode.File,out entrys); return GetDirectoryEntrys(path,nn.fs.OpenDirectoryMode.File,out entrys);
#endif #endif
} }
public bool GetDirectoryDirs(string path, out string[] entrys) public bool GetDirectoryDirs(string path, out string[] entrys)
{ {
#if !UNITY_SWITCH || UNITY_EDITOR #if !UNITY_SWITCH || UNITY_EDITOR
@ -430,6 +435,7 @@ public class AxiNSIO
} }
#endif #endif
public bool GetDirectoryEntrysFullRecursion(string path, out string[] entrys) public bool GetDirectoryEntrysFullRecursion(string path, out string[] entrys)
{ {
#if UNITY_SWITCH #if UNITY_SWITCH
@ -462,7 +468,7 @@ public class AxiNSIO
entrys = temp.ToArray(); entrys = temp.ToArray();
return true; return true;
#else #else
entrys = default; entrys = null;
return false; return false;
#endif #endif
} }
@ -597,16 +603,83 @@ public class AxiNSIO
return CommitSave(); return CommitSave();
#endif #endif
} }
#if UNITY_SWITCH
public AxiNSWait_DeletePathDirRecursively DeletePathDirRecursivelyAsync(string filename) public AxiNSWait_DeletePathDirRecursively DeletePathDirRecursivelyAsync(string filename)
{ {
var wait = new AxiNSWait_DeletePathDirRecursively(filename); var wait = new AxiNSWait_DeletePathDirRecursively(filename);
AxiNS.instance.wait.AddWait(wait); AxiNS.instance.wait.AddWait(wait);
return 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 #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) public bool RenameDir(string oldpath, string newpath)
{ {
#if !UNITY_SWITCH #if !UNITY_SWITCH

View 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();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 23d5745b8989af04d8a871b5c7b65d50
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -117,3 +117,18 @@ public class AxiNSWait_DeletePathDir : AxiNSWaitBase
result = AxiNS.instance.io.DeletePathDir(req.filePath); 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);
}
}

View File

@ -4,21 +4,30 @@ using System.Threading;
public class AxiNSWaitHandle 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_QueueReady = new Queue<AxiNSWaitBase>();
static Queue<AxiNSWaitBase> m_QueueWork = new Queue<AxiNSWaitBase>(); static Queue<AxiNSWaitBase> m_QueueWork = new Queue<AxiNSWaitBase>();
public void AddWait(AxiNSWaitBase wait) public void AddWait(AxiNSWaitBase wait)
{ {
InitInternalThread();
lock (m_QueueReady) lock (m_QueueReady)
{ {
m_QueueReady.Enqueue(wait); m_QueueReady.Enqueue(wait);
} }
if (AxiNS.usedmultithreading)
{
InitInternalThread();
autoEvent.Set(); autoEvent.Set();
} }
else
{
InitMonoInit();
}
}
#region 线
static AutoResetEvent autoEvent = new AutoResetEvent(false);
static Thread waitThread = new Thread(Loop);
static bool bSingleInit = false;
static void InitInternalThread() static void InitInternalThread()
{ {
if (bSingleInit) return; if (bSingleInit) return;
@ -29,6 +38,23 @@ public class AxiNSWaitHandle
static void Loop() static void Loop()
{ {
while (autoEvent.WaitOne()) 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) lock (m_QueueReady)
{ {
@ -53,4 +79,3 @@ public class AxiNSWaitHandle
} }
} }
} }
}