forked from sin365/AxibugEmuOnline
axio
This commit is contained in:
parent
59968bbd1f
commit
92169c2f87
@ -3,6 +3,7 @@ using nn.fs;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
public class AxiNSIO
|
public class AxiNSIO
|
||||||
{
|
{
|
||||||
@ -80,7 +81,10 @@ public class AxiNSIO
|
|||||||
nn.Result result = nn.fs.FileSystem.GetEntryType(ref entryType, filePath);
|
nn.Result result = nn.fs.FileSystem.GetEntryType(ref entryType, filePath);
|
||||||
//result.abortUnlessSuccess();
|
//result.abortUnlessSuccess();
|
||||||
//这个异常捕获。真的别扭
|
//这个异常捕获。真的别扭
|
||||||
return nn.fs.FileSystem.ResultPathAlreadyExists.Includes(result);
|
|
||||||
|
//日,FileSystem.ResultPathAlreadyExists 貌似不太行
|
||||||
|
//return nn.fs.FileSystem.ResultPathAlreadyExists.Includes(result);
|
||||||
|
return !nn.fs.FileSystem.ResultPathNotFound.Includes(result);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -217,11 +221,41 @@ public class AxiNSIO
|
|||||||
UnityEngine.Debug.LogError($"创建文件失败 {filePath} : " + result.GetErrorInfo());
|
UnityEngine.Debug.LogError($"创建文件失败 {filePath} : " + result.GetErrorInfo());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
//读取文件Handle
|
||||||
|
result = File.Open(ref fileHandle, filePath, OpenFileMode.Write);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
UnityEngine.Debug.Log($"文件({filePath})存在,不必创建");
|
{
|
||||||
|
//读取文件Handle
|
||||||
result = File.Open(ref fileHandle, filePath, OpenFileMode.Write);
|
result = File.Open(ref fileHandle, filePath, OpenFileMode.Write);
|
||||||
|
long currsize = 0;
|
||||||
|
File.GetSize(ref currsize, fileHandle);
|
||||||
|
if (currsize == data.Length)
|
||||||
|
{
|
||||||
|
UnityEngine.Debug.Log($"文件({filePath})存在,长度一致,不用重新创建");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UnityEngine.Debug.Log($"文件({filePath})存在,长度不一致,先删除再重建");
|
||||||
|
nn.fs.File.Close(fileHandle);
|
||||||
|
//删除
|
||||||
|
File.Delete(filePath);
|
||||||
|
//重新创建
|
||||||
|
result = nn.fs.File.Create(filePath, data.Length);
|
||||||
|
if (!result.IsSuccess())
|
||||||
|
{
|
||||||
|
UnityEngine.Debug.LogError($"创建文件失败 {filePath} : " + result.GetErrorInfo());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//重新读取文件Handle
|
||||||
|
result = File.Open(ref fileHandle, filePath, OpenFileMode.Write);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// //OpenFileMode.AllowAppend 好像不可用
|
||||||
|
// //result = File.Open(ref fileHandle, filePath, OpenFileMode.AllowAppend);
|
||||||
|
// result = File.Open(ref fileHandle, filePath, OpenFileMode.Write);
|
||||||
|
|
||||||
//result.abortUnlessSuccess();
|
//result.abortUnlessSuccess();
|
||||||
if (!result.IsSuccess())
|
if (!result.IsSuccess())
|
||||||
{
|
{
|
||||||
@ -278,7 +312,6 @@ public class AxiNSIO
|
|||||||
LoadSwitchDataFile(filename, out byte[] outputData);
|
LoadSwitchDataFile(filename, out byte[] 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))
|
if (LoadSwitchDataFile(filename, out byte[] outputData))
|
||||||
@ -350,7 +383,6 @@ 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
|
||||||
@ -361,7 +393,6 @@ 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
|
||||||
@ -399,10 +430,10 @@ public class AxiNSIO
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if UNITY_SWITCH
|
|
||||||
public bool GetDirectoryEntrysFullRecursion(string path, out string[] entrys)
|
public bool GetDirectoryEntrysFullRecursion(string path, out string[] entrys)
|
||||||
{
|
{
|
||||||
|
#if UNITY_SWITCH
|
||||||
|
|
||||||
nn.fs.DirectoryHandle eHandle = new nn.fs.DirectoryHandle();
|
nn.fs.DirectoryHandle eHandle = new nn.fs.DirectoryHandle();
|
||||||
nn.Result result = nn.fs.Directory.Open(ref eHandle, path, OpenDirectoryMode.All);
|
nn.Result result = nn.fs.Directory.Open(ref eHandle, path, OpenDirectoryMode.All);
|
||||||
if (nn.fs.FileSystem.ResultPathNotFound.Includes(result))
|
if (nn.fs.FileSystem.ResultPathNotFound.Includes(result))
|
||||||
@ -430,8 +461,11 @@ public class AxiNSIO
|
|||||||
nn.fs.Directory.Close(eHandle);
|
nn.fs.Directory.Close(eHandle);
|
||||||
entrys = temp.ToArray();
|
entrys = temp.ToArray();
|
||||||
return true;
|
return true;
|
||||||
}
|
#else
|
||||||
|
entrys = default;
|
||||||
|
return false;
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
public IEnumerable<string> EnumerateFiles(string path, string searchPattern)
|
public IEnumerable<string> EnumerateFiles(string path, string searchPattern)
|
||||||
{
|
{
|
||||||
@ -534,13 +568,7 @@ public class AxiNSIO
|
|||||||
AxiNS.instance.wait.AddWait(wait);
|
AxiNS.instance.wait.AddWait(wait);
|
||||||
return wait;
|
return wait;
|
||||||
}
|
}
|
||||||
|
public bool DeletePathDirRecursively(string filename)
|
||||||
/// <summary>
|
|
||||||
/// 递归删除目录
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="filename"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public bool DeleteRecursivelyPathDir(string filename)
|
|
||||||
{
|
{
|
||||||
#if !UNITY_SWITCH
|
#if !UNITY_SWITCH
|
||||||
return false;
|
return false;
|
||||||
@ -558,7 +586,7 @@ public class AxiNSIO
|
|||||||
result = nn.fs.Directory.DeleteRecursively(filename);
|
result = nn.fs.Directory.DeleteRecursively(filename);
|
||||||
if (result.IsSuccess() == false)
|
if (result.IsSuccess() == false)
|
||||||
{
|
{
|
||||||
UnityEngine.Debug.LogError($"nn.fs.File.DeleteRecursively 失败 {filename} : result=>{result.GetErrorInfo()}");
|
UnityEngine.Debug.LogError($"nn.fs.File.Recursively 失败 {filename} : result=>{result.GetErrorInfo()}");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -570,40 +598,14 @@ public class AxiNSIO
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
#if UNITY_SWITCH
|
||||||
/// 递归删除情况
|
public AxiNSWait_DeletePathDirRecursively DeletePathDirRecursivelyAsync(string filename)
|
||||||
/// </summary>
|
|
||||||
/// <param name="filename"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public bool CleanRecursivelyPathDir(string filename)
|
|
||||||
{
|
{
|
||||||
#if !UNITY_SWITCH
|
var wait = new AxiNSWait_DeletePathDirRecursively(filename);
|
||||||
return false;
|
AxiNS.instance.wait.AddWait(wait);
|
||||||
#else
|
return wait;
|
||||||
|
|
||||||
#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
|
#endif
|
||||||
return CommitSave();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool RenameDir(string oldpath, string newpath)
|
public bool RenameDir(string oldpath, string newpath)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -8,7 +8,7 @@ public class AxiPlayerPrefsForFileSystem : AxiPlayerPrefsFileBase
|
|||||||
Debug.Log($"AxiPlayerPrefsForPSVita Init");
|
Debug.Log($"AxiPlayerPrefsForPSVita Init");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Dictionary<string, AxiPlayerPrefsKeyValye> LoadData()
|
protected static Dictionary<string, AxiPlayerPrefsKeyValye> LoadData()
|
||||||
{
|
{
|
||||||
if (!AxiIO.AxiIO.io.file_Exists(AxiPlayerPrefsFilePath))
|
if (!AxiIO.AxiIO.io.file_Exists(AxiPlayerPrefsFilePath))
|
||||||
return new Dictionary<string, AxiPlayerPrefsKeyValye>();
|
return new Dictionary<string, AxiPlayerPrefsKeyValye>();
|
||||||
@ -32,7 +32,7 @@ public class AxiPlayerPrefsForFileSystem : AxiPlayerPrefsFileBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SaveData(Dictionary<string, AxiPlayerPrefsKeyValye> data)
|
protected static void SaveData(Dictionary<string, AxiPlayerPrefsKeyValye> data)
|
||||||
{
|
{
|
||||||
string jsonStr = AxiPlayerPrefsFileBase.DataToJsonStr(data);
|
string jsonStr = AxiPlayerPrefsFileBase.DataToJsonStr(data);
|
||||||
byte[] dataByteArray;
|
byte[] dataByteArray;
|
||||||
@ -45,5 +45,4 @@ public class AxiPlayerPrefsForFileSystem : AxiPlayerPrefsFileBase
|
|||||||
}
|
}
|
||||||
AxiIO.AxiIO.io.file_WriteAllBytes(AxiPlayerPrefsFilePath, dataByteArray, false);
|
AxiIO.AxiIO.io.file_WriteAllBytes(AxiPlayerPrefsFilePath, dataByteArray, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user