This commit is contained in:
sin365 2025-04-29 00:07:14 +08:00
parent 4430b23fdf
commit 05ae1163e3
2 changed files with 230 additions and 202 deletions

View File

@ -232,7 +232,7 @@ public class AxiNSIO
} }
public bool LoadSwitchDataFile(string filename, out byte[] outputData) public bool LoadSwitchDataFile(string filename, out byte[] outputData)
{ {
#if !UNITY_SWITCH #if !UNITY_SWITCH || UNITY_EDITOR
outputData = null; outputData = null;
return false; return false;
#else #else
@ -292,7 +292,8 @@ public class AxiNSIO
public bool GetDirectoryFiles(string path, out string[] entrys) public bool GetDirectoryFiles(string path, out string[] entrys)
{ {
#if !UNITY_SWITCH #if !UNITY_SWITCH || UNITY_EDITOR
entrys = null; entrys = null;
return false; return false;
#else #else
@ -302,7 +303,7 @@ public class AxiNSIO
public bool GetDirectoryDirs(string path, out string[] entrys) public bool GetDirectoryDirs(string path, out string[] entrys)
{ {
#if !UNITY_SWITCH #if !UNITY_SWITCH || UNITY_EDITOR
entrys = null; entrys = null;
return false; return false;
#else #else
@ -313,10 +314,8 @@ public class AxiNSIO
#if UNITY_SWITCH #if UNITY_SWITCH
public bool GetDirectoryEntrys(string path, nn.fs.OpenDirectoryMode type, out string[] entrys) public bool GetDirectoryEntrys(string path, nn.fs.OpenDirectoryMode type, out string[] entrys)
{ {
entrys = null; nn.fs.DirectoryHandle eHandle = new nn.fs.DirectoryHandle();
return false; nn.Result result = nn.fs.Directory.Open(ref eHandle, path, type);
nn.fs.DirectoryHandle dirHandle = new nn.fs.DirectoryHandle();
nn.Result result = nn.fs.Directory.Open(ref dirHandle, path, type);
if (nn.fs.FileSystem.ResultPathNotFound.Includes(result)) if (nn.fs.FileSystem.ResultPathNotFound.Includes(result))
{ {
UnityEngine.Debug.Log($"目录 {path} 不存在"); UnityEngine.Debug.Log($"目录 {path} 不存在");
@ -324,24 +323,58 @@ public class AxiNSIO
return false; return false;
} }
long entryCount = 0; long entryCount = 0;
nn.fs.Directory.GetEntryCount(ref entryCount, dirHandle); nn.fs.Directory.GetEntryCount(ref entryCount, eHandle);
nn.fs.DirectoryEntry[] dirEntries = new nn.fs.DirectoryEntry[entryCount]; nn.fs.DirectoryEntry[] entries = new nn.fs.DirectoryEntry[entryCount];
long actualEntries = 0; long actualEntries = 0;
nn.fs.Directory.Read(ref actualEntries, dirEntries, dirHandle, entryCount); nn.fs.Directory.Read(ref actualEntries, entries, eHandle, entryCount);
entrys = new string[actualEntries]; entrys = new string[actualEntries];
for (int i = 0; i < actualEntries; i++) for (int i = 0; i < actualEntries; i++)
{ {
entrys[i] = dirEntries[i].name; entrys[i] = System.IO.Path.Combine(path, entries[i].name);
} }
nn.fs.Directory.Close(dirHandle); nn.fs.Directory.Close(eHandle);
return true;
}
#endif
#if UNITY_SWITCH
public bool GetDirectoryEntrysFullRecursion(string path, out string[] entrys)
{
nn.fs.DirectoryHandle eHandle = new nn.fs.DirectoryHandle();
nn.Result result = nn.fs.Directory.Open(ref eHandle, path, OpenDirectoryMode.All);
if (nn.fs.FileSystem.ResultPathNotFound.Includes(result))
{
UnityEngine.Debug.Log($"Ŀ¼ {path} ²»´æÔÚ");
entrys = null;
return false;
}
long entryCount = 0;
nn.fs.Directory.GetEntryCount(ref entryCount, eHandle);
nn.fs.DirectoryEntry[] entries = new nn.fs.DirectoryEntry[entryCount];
long actualEntries = 0;
nn.fs.Directory.Read(ref actualEntries, entries, eHandle, entryCount);
List<string> temp = new List<string>();
for (int i = 0; i < actualEntries; i++)
{
string singlePath = System.IO.Path.Combine(path, entries[i].name);
temp.Add(singlePath);
if (entries[i].entryType == EntryType.Directory && GetDirectoryEntrysFullRecursion(singlePath, out string[] singleEntryList))
{
temp.AddRange(singleEntryList);
}
}
nn.fs.Directory.Close(eHandle);
entrys = temp.ToArray();
return true; return true;
} }
#endif #endif
public IEnumerable<string> EnumerateFiles(string path, string searchPattern) public IEnumerable<string> EnumerateFiles(string path, string searchPattern)
{ {
#if !UNITY_SWITCH #if !UNITY_SWITCH || UNITY_EDITOR
yield break; yield break;
#else #else
// 将通配符转换为正则表达式(支持*和? // 将通配符转换为正则表达式(支持*和?

View File

@ -129,28 +129,26 @@ public class MainTest : MonoBehaviour
UnityEngine.Debug.Log($"result =>{result}"); UnityEngine.Debug.Log($"result =>{result}");
else else
{ {
UnityEngine.Debug.Log($"====EntrysList====");
foreach (var e in elist) foreach (var e in elist)
{ UnityEngine.Debug.Log(e);
UnityEngine.Debug.Log($"result =>{result}");
}
} }
} }
); text17.text = $"AxiNS.instance.io.GetDirectoryEntrys({"save:/"},nn.fs.OpenDirectoryMode.All,out var elist)"; ); text17.text = $"AxiNS.instance.io.GetDirectoryEntrys({"save:/"},nn.fs.OpenDirectoryMode.All,out var elist)";
btn18.onClick.AddListener(() => btn18.onClick.AddListener(() =>
{ {
bool result = AxiNS.instance.io.GetDirectoryEntrys("save:/axibug", nn.fs.OpenDirectoryMode.All, out var elist); bool result = AxiNS.instance.io.GetDirectoryEntrysFullRecursion("save:/",out var elist);
if (!result) if (!result)
UnityEngine.Debug.Log($"result =>{result}"); UnityEngine.Debug.Log($"result =>{result}");
else else
{ {
UnityEngine.Debug.Log($"==== FullRecursion Entrys List====");
foreach (var e in elist) foreach (var e in elist)
{ UnityEngine.Debug.Log(e);
UnityEngine.Debug.Log($"result =>{result}");
} }
} }
} ); text18.text = $"AxiNS.instance.io.GetDirectoryEntrysFullRecursion({"save:/"},out var elist)";
); text18.text = $"AxiNS.instance.io.GetDirectoryEntrys({"save:/axibug"},nn.fs.OpenDirectoryMode.All,out var elist)";
btn19.onClick.AddListener(() => btn19.onClick.AddListener(() =>
{ {
@ -159,10 +157,9 @@ public class MainTest : MonoBehaviour
UnityEngine.Debug.Log($"result =>{result}"); UnityEngine.Debug.Log($"result =>{result}");
else else
{ {
UnityEngine.Debug.Log($"====EntrysList====");
foreach (var e in elist) foreach (var e in elist)
{ UnityEngine.Debug.Log(e);
UnityEngine.Debug.Log($"result =>{result}");
}
} }
} }
); text19.text = $"AxiNS.instance.io.GetDirectoryEntrys({"save:/axibug/"},nn.fs.OpenDirectoryMode.All,out var elist)"; ); text19.text = $"AxiNS.instance.io.GetDirectoryEntrys({"save:/axibug/"},nn.fs.OpenDirectoryMode.All,out var elist)";
@ -174,10 +171,9 @@ public class MainTest : MonoBehaviour
UnityEngine.Debug.Log($"result =>{result}"); UnityEngine.Debug.Log($"result =>{result}");
else else
{ {
UnityEngine.Debug.Log($"====EntrysList====");
foreach (var e in elist) foreach (var e in elist)
{ UnityEngine.Debug.Log(e);
UnityEngine.Debug.Log($"result =>{result}");
}
} }
} }
); text20.text = $"AxiNS.instance.io.GetDirectoryDirs({"save:/"},out var elist)"; ); text20.text = $"AxiNS.instance.io.GetDirectoryDirs({"save:/"},out var elist)";
@ -189,10 +185,9 @@ public class MainTest : MonoBehaviour
UnityEngine.Debug.Log($"result =>{result}"); UnityEngine.Debug.Log($"result =>{result}");
else else
{ {
UnityEngine.Debug.Log($"====EntrysList====");
foreach (var e in elist) foreach (var e in elist)
{ UnityEngine.Debug.Log(e);
UnityEngine.Debug.Log($"result =>{result}");
}
} }
} }
); text21.text = $"AxiNS.instance.io.GetDirectoryFiles({"save:/"},out var elist)"; ); text21.text = $"AxiNS.instance.io.GetDirectoryFiles({"save:/"},out var elist)";