forked from sin365/AxibugEmuOnline
补全Switch的Directory逻辑
This commit is contained in:
parent
24036739a7
commit
213ed7163c
@ -2,6 +2,10 @@
|
||||
using nn.fs;
|
||||
#endif
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
public class AxiNSIO
|
||||
{
|
||||
string save_name => AxiNS.instance.mount.SaveMountName;
|
||||
@ -62,8 +66,6 @@ public class AxiNSIO
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 保存并创建文件(如果目录不存在回先自动创建目录)
|
||||
/// </summary>
|
||||
@ -287,6 +289,85 @@ public class AxiNSIO
|
||||
AxiNS.instance.wait.AddWait(wait);
|
||||
return wait;
|
||||
}
|
||||
|
||||
public bool GetDirectoryFiles(string path, out string[] entrys)
|
||||
{
|
||||
#if !UNITY_SWITCH
|
||||
entrys = null;
|
||||
return false;
|
||||
#else
|
||||
return GetDirectoryEntrys(path,nn.fs.OpenDirectoryMode.File,out entrys);
|
||||
#endif
|
||||
}
|
||||
|
||||
public bool GetDirectoryDirs(string path, out string[] entrys)
|
||||
{
|
||||
#if !UNITY_SWITCH
|
||||
entrys = null;
|
||||
return false;
|
||||
#else
|
||||
return GetDirectoryEntrys(path, nn.fs.OpenDirectoryMode.Directory, out entrys);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if UNITY_SWITCH
|
||||
public bool GetDirectoryEntrys(string path, nn.fs.OpenDirectoryMode type, out string[] entrys)
|
||||
{
|
||||
entrys = null;
|
||||
return false;
|
||||
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))
|
||||
{
|
||||
UnityEngine.Debug.Log($"目录 {path} 不存在");
|
||||
entrys = null;
|
||||
return false;
|
||||
}
|
||||
long entryCount = 0;
|
||||
nn.fs.Directory.GetEntryCount(ref entryCount, dirHandle);
|
||||
nn.fs.DirectoryEntry[] dirEntries = new nn.fs.DirectoryEntry[entryCount];
|
||||
long actualEntries = 0;
|
||||
nn.fs.Directory.Read(ref actualEntries, dirEntries, dirHandle, entryCount);
|
||||
|
||||
entrys = new string[actualEntries];
|
||||
for (int i = 0; i < actualEntries; i++)
|
||||
{
|
||||
entrys[i] = dirEntries[i].name;
|
||||
}
|
||||
nn.fs.Directory.Close(dirHandle);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
public IEnumerable<string> EnumerateFiles(string path, string searchPattern)
|
||||
{
|
||||
#if !UNITY_SWITCH
|
||||
yield break;
|
||||
#else
|
||||
// 将通配符转换为正则表达式(支持*和?)
|
||||
var regexPattern = "^" +
|
||||
Regex.Escape(searchPattern)
|
||||
.Replace("\\*", ".*")
|
||||
.Replace("\\?", ".")
|
||||
+ "$";
|
||||
|
||||
var regex = new Regex(regexPattern, RegexOptions.IgnoreCase);
|
||||
|
||||
if (!GetDirectoryEntrys(path, nn.fs.OpenDirectoryMode.File, out string[] entrys))
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < entrys.Length; i++)
|
||||
{
|
||||
if (regex.IsMatch(System.IO.Path.GetFileName(entrys[i])))
|
||||
{
|
||||
yield return entrys[i];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public bool DeletePathFile(string filename)
|
||||
{
|
||||
#if !UNITY_SWITCH
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AxiIO
|
||||
{
|
||||
@ -15,7 +13,7 @@ namespace AxiIO
|
||||
if (m_io == null)
|
||||
{
|
||||
#if UNITY_SWITCH && !UNITY_EDITOR
|
||||
m_io = new NintendoSwitchIO();
|
||||
m_io = new NSwitchIO();
|
||||
#else
|
||||
m_io = new CSharpIO();
|
||||
#endif
|
||||
@ -50,7 +48,7 @@ namespace AxiIO
|
||||
AxiIO.io.file_WriteAllBytes(path, data);
|
||||
}
|
||||
|
||||
internal static void WriteAllBytesFromStream(string path, MemoryStream ms)
|
||||
internal static void WriteAllBytesFromStream(string path, System.IO.MemoryStream ms)
|
||||
{
|
||||
AxiIO.io.file_WriteAllBytes(path, ms);
|
||||
}
|
||||
@ -73,6 +71,16 @@ namespace AxiIO
|
||||
return AxiIO.io.dir_EnumerateFiles(path, searchPattern);
|
||||
}
|
||||
|
||||
public static string[] GetDirectories(string path)
|
||||
{
|
||||
return AxiIO.io.dir_GetDirectories(path);
|
||||
}
|
||||
|
||||
public static string[] GetFiles(string path)
|
||||
{
|
||||
return AxiIO.io.dir_GetFiles(path);
|
||||
}
|
||||
|
||||
internal static void Delete(string cacheDirPath, bool v)
|
||||
{
|
||||
AxiIO.io.dir_Delete(cacheDirPath, v);
|
||||
|
||||
@ -56,5 +56,15 @@ namespace AxiIO
|
||||
FileStream streaming = System.IO.File.OpenRead(filePath);
|
||||
return streaming.Read(readToArr, 0, 4);
|
||||
}
|
||||
|
||||
public string[] dir_GetDirectories(string path)
|
||||
{
|
||||
return System.IO.Directory.GetDirectories(path);
|
||||
}
|
||||
|
||||
public string[] dir_GetFiles(string path)
|
||||
{
|
||||
return System.IO.Directory.GetFiles(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -15,5 +15,7 @@ namespace AxiIO
|
||||
void file_WriteAllBytes(string filePath, byte[] data);
|
||||
void file_WriteAllBytes(string filePath, System.IO.MemoryStream ms);
|
||||
int file_ReadBytesToArr(string filePath, byte[] readToArr, int start, int len);
|
||||
string[] dir_GetDirectories(string path);
|
||||
string[] dir_GetFiles(string path);
|
||||
};
|
||||
}
|
||||
@ -1,12 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace AxiIO
|
||||
{
|
||||
public class NintendoSwitchIO : IAxiIO
|
||||
public class NSwitchIO : IAxiIO
|
||||
{
|
||||
public NintendoSwitchIO()
|
||||
public NSwitchIO()
|
||||
{
|
||||
AxiNS.instance.Init();
|
||||
}
|
||||
@ -22,7 +21,7 @@ namespace AxiIO
|
||||
|
||||
public IEnumerable<string> dir_EnumerateFiles(string path, string searchPattern)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return AxiNS.instance.io.EnumerateFiles(path, searchPattern);
|
||||
}
|
||||
|
||||
public bool dir_Exists(string dirpath)
|
||||
@ -30,6 +29,24 @@ namespace AxiIO
|
||||
return AxiNS.instance.io.CheckPathExists(dirpath);
|
||||
}
|
||||
|
||||
public string[] dir_GetDirectories(string path)
|
||||
{
|
||||
if (!AxiNS.instance.io.GetDirectoryDirs(path, out string[] result))
|
||||
{
|
||||
return new string[0];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public string[] dir_GetFiles(string path)
|
||||
{
|
||||
if (!AxiNS.instance.io.GetDirectoryFiles(path, out string[] result))
|
||||
{
|
||||
return new string[0];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void file_Delete(string filePath)
|
||||
{
|
||||
AxiNS.instance.io.DeletePathFile(filePath);
|
||||
@ -58,7 +75,7 @@ namespace AxiIO
|
||||
AxiNS.instance.io.FileToSaveWithCreate(filePath, data);
|
||||
}
|
||||
|
||||
public void file_WriteAllBytes(string filePath, MemoryStream ms)
|
||||
public void file_WriteAllBytes(string filePath, System.IO.MemoryStream ms)
|
||||
{
|
||||
AxiNS.instance.io.FileToSaveWithCreate(filePath, ms);
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user