This commit is contained in:
sin365 2025-06-16 11:15:21 +08:00
parent 59968bbd1f
commit 92169c2f87
2 changed files with 163 additions and 162 deletions

View File

@ -3,6 +3,7 @@ using nn.fs;
#endif
using System.Collections.Generic;
using System.Text.RegularExpressions;
public class AxiNSIO
{
@ -80,7 +81,10 @@ public class AxiNSIO
nn.Result result = nn.fs.FileSystem.GetEntryType(ref entryType, filePath);
//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
}
/// <summary>
@ -217,11 +221,41 @@ public class AxiNSIO
UnityEngine.Debug.LogError($"创建文件失败 {filePath} : " + result.GetErrorInfo());
return false;
}
//读取文件Handle
result = File.Open(ref fileHandle, filePath, OpenFileMode.Write);
}
else
UnityEngine.Debug.Log($"文件({filePath})存在,不必创建");
{
//读取文件Handle
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();
if (!result.IsSuccess())
{
@ -248,7 +282,7 @@ public class AxiNSIO
UnityEngine.Switch.Notification.LeaveExitRequestHandlingSection();
#endif
if(immediatelyCommit)
if (immediatelyCommit)
{
//必须得提交,否则没有真实写入
return CommitSave();
@ -278,7 +312,6 @@ public class AxiNSIO
LoadSwitchDataFile(filename, out byte[] outputData);
return outputData;
}
public bool LoadSwitchDataFile(string filename, ref System.IO.MemoryStream ms)
{
if (LoadSwitchDataFile(filename, out byte[] outputData))
@ -350,7 +383,6 @@ public class AxiNSIO
AxiNS.instance.wait.AddWait(wait);
return wait;
}
public bool GetDirectoryFiles(string path, out string[] entrys)
{
#if !UNITY_SWITCH || UNITY_EDITOR
@ -361,7 +393,6 @@ 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
@ -399,10 +430,10 @@ public class AxiNSIO
}
#endif
#if UNITY_SWITCH
public bool GetDirectoryEntrysFullRecursion(string path, out string[] entrys)
{
#if UNITY_SWITCH
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))
@ -430,8 +461,11 @@ public class AxiNSIO
nn.fs.Directory.Close(eHandle);
entrys = temp.ToArray();
return true;
}
#else
entrys = default;
return false;
#endif
}
public IEnumerable<string> EnumerateFiles(string path, string searchPattern)
{
@ -534,13 +568,7 @@ public class AxiNSIO
AxiNS.instance.wait.AddWait(wait);
return wait;
}
/// <summary>
/// 递归删除目录
/// </summary>
/// <param name="filename"></param>
/// <returns></returns>
public bool DeleteRecursivelyPathDir(string filename)
public bool DeletePathDirRecursively(string filename)
{
#if !UNITY_SWITCH
return false;
@ -558,7 +586,7 @@ public class AxiNSIO
result = nn.fs.Directory.DeleteRecursively(filename);
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;
}
@ -570,40 +598,14 @@ public class AxiNSIO
#endif
}
/// <summary>
/// 递归删除情况
/// </summary>
/// <param name="filename"></param>
/// <returns></returns>
public bool CleanRecursivelyPathDir(string filename)
#if UNITY_SWITCH
public AxiNSWait_DeletePathDirRecursively DeletePathDirRecursivelyAsync(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;
var wait = new AxiNSWait_DeletePathDirRecursively(filename);
AxiNS.instance.wait.AddWait(wait);
return wait;
}
#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)
{

View File

@ -8,7 +8,7 @@ public class AxiPlayerPrefsForFileSystem : AxiPlayerPrefsFileBase
Debug.Log($"AxiPlayerPrefsForPSVita Init");
}
public static Dictionary<string, AxiPlayerPrefsKeyValye> LoadData()
protected static Dictionary<string, AxiPlayerPrefsKeyValye> LoadData()
{
if (!AxiIO.AxiIO.io.file_Exists(AxiPlayerPrefsFilePath))
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);
byte[] dataByteArray;
@ -45,5 +45,4 @@ public class AxiPlayerPrefsForFileSystem : AxiPlayerPrefsFileBase
}
AxiIO.AxiIO.io.file_WriteAllBytes(AxiPlayerPrefsFilePath, dataByteArray, false);
}
}