forked from sin365/AxibugEmuOnline
Compare commits
No commits in common. "97c278b4ec3e49e9afcb283b19b22cabea6ac4c9" and "cc57a1e0df757df8e274b4aa63d74123f2a491f9" have entirely different histories.
97c278b4ec
...
cc57a1e0df
@ -2,7 +2,6 @@
|
||||
using nn.fs;
|
||||
#endif
|
||||
|
||||
using nn.fs;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
@ -14,61 +13,6 @@ public class AxiNSIO
|
||||
#if UNITY_SWITCH
|
||||
private FileHandle fileHandle = new nn.fs.FileHandle();
|
||||
#endif
|
||||
|
||||
static object commitLock = new object();
|
||||
|
||||
static bool bDirty = false;
|
||||
|
||||
bool CommitSave()
|
||||
{
|
||||
lock (commitLock)
|
||||
{
|
||||
#if UNITY_SWITCH && !UNITY_EDITOR
|
||||
|
||||
// 阻止用户在保存时,退出游戏 Switch 条例 0080
|
||||
UnityEngine.Switch.Notification.EnterExitRequestHandlingSection();
|
||||
nn.Result ret = FileSystem.Commit(save_name);
|
||||
|
||||
if (!ret.IsSuccess())
|
||||
{
|
||||
UnityEngine.Debug.LogError($"FileSystem.Commit({save_name}) 失败: " + ret.GetErrorInfo());
|
||||
return false;
|
||||
}
|
||||
|
||||
// 停止阻止用户退出游戏
|
||||
UnityEngine.Switch.Notification.LeaveExitRequestHandlingSection();
|
||||
|
||||
bDirty = false;
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SetCommitDirty()
|
||||
{
|
||||
lock (commitLock)
|
||||
{
|
||||
bDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void ApplyAutoCommit()
|
||||
{
|
||||
bool temp;
|
||||
lock (commitLock)
|
||||
{
|
||||
temp = bDirty;
|
||||
}
|
||||
|
||||
if (temp)
|
||||
{
|
||||
CommitSave();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查Path是否存在
|
||||
/// </summary>
|
||||
@ -109,11 +53,8 @@ public class AxiNSIO
|
||||
/// <returns></returns>
|
||||
public bool CreateDir(string filePath)
|
||||
{
|
||||
lock (commitLock)
|
||||
{
|
||||
|
||||
#if !UNITY_SWITCH
|
||||
return false;
|
||||
return false;
|
||||
#else
|
||||
// 使用封装函数检查和创建父目录
|
||||
if (!EnsureParentDirectory(filePath, true))
|
||||
@ -123,7 +64,6 @@ public class AxiNSIO
|
||||
}
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -148,20 +88,16 @@ public class AxiNSIO
|
||||
AxiNS.instance.wait.AddWait(wait);
|
||||
return wait;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存并创建文件(如果目录不存在回先自动创建目录)
|
||||
/// </summary>
|
||||
/// <param name="filePath"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="immediatelyCommit">是否立即Commit到物理存储</param>
|
||||
/// <returns></returns>
|
||||
public bool FileToSaveWithCreate(string filePath, byte[] data, bool immediatelyCommit = true)
|
||||
public bool FileToSaveWithCreate(string filePath, byte[] data)
|
||||
{
|
||||
lock (commitLock)
|
||||
{
|
||||
#if !UNITY_SWITCH
|
||||
return false;
|
||||
return false;
|
||||
#else
|
||||
if (!AxiNS.instance.mount.SaveIsMount)
|
||||
{
|
||||
@ -245,24 +181,24 @@ public class AxiNSIO
|
||||
|
||||
nn.fs.File.Close(fileHandle);
|
||||
|
||||
|
||||
//必须得提交,否则没有真实写入
|
||||
result = FileSystem.Commit(save_name);
|
||||
//result.abortUnlessSuccess();
|
||||
if (!result.IsSuccess())
|
||||
{
|
||||
UnityEngine.Debug.LogError($"FileSystem.Commit({save_name}) 失败: " + result.GetErrorInfo());
|
||||
return false;
|
||||
}
|
||||
UnityEngine.Debug.Log($"FileSystem.Commit({save_name}) 成功: ");
|
||||
|
||||
|
||||
#if UNITY_SWITCH && !UNITY_EDITOR
|
||||
// 停止阻止用户退出游戏
|
||||
UnityEngine.Switch.Notification.LeaveExitRequestHandlingSection();
|
||||
#endif
|
||||
|
||||
if(immediatelyCommit)
|
||||
{
|
||||
//必须得提交,否则没有真实写入
|
||||
return CommitSave();
|
||||
}
|
||||
else
|
||||
{
|
||||
SetCommitDirty();
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 保存并创建文件(如果目录不存在回先自动创建目录)
|
||||
@ -296,7 +232,7 @@ public class AxiNSIO
|
||||
}
|
||||
public bool LoadSwitchDataFile(string filename, out byte[] outputData)
|
||||
{
|
||||
#if !UNITY_SWITCH || UNITY_EDITOR
|
||||
#if !UNITY_SWITCH
|
||||
outputData = null;
|
||||
return false;
|
||||
#else
|
||||
@ -356,8 +292,7 @@ public class AxiNSIO
|
||||
|
||||
public bool GetDirectoryFiles(string path, out string[] entrys)
|
||||
{
|
||||
#if !UNITY_SWITCH || UNITY_EDITOR
|
||||
|
||||
#if !UNITY_SWITCH
|
||||
entrys = null;
|
||||
return false;
|
||||
#else
|
||||
@ -367,7 +302,7 @@ public class AxiNSIO
|
||||
|
||||
public bool GetDirectoryDirs(string path, out string[] entrys)
|
||||
{
|
||||
#if !UNITY_SWITCH || UNITY_EDITOR
|
||||
#if !UNITY_SWITCH
|
||||
entrys = null;
|
||||
return false;
|
||||
#else
|
||||
@ -376,70 +311,38 @@ public class AxiNSIO
|
||||
}
|
||||
|
||||
#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)
|
||||
{
|
||||
nn.fs.DirectoryHandle eHandle = new nn.fs.DirectoryHandle();
|
||||
nn.Result result = nn.fs.Directory.Open(ref eHandle, 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, eHandle);
|
||||
nn.fs.DirectoryEntry[] entries = new nn.fs.DirectoryEntry[entryCount];
|
||||
long actualEntries = 0;
|
||||
nn.fs.Directory.Read(ref actualEntries, entries, eHandle, entryCount);
|
||||
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] = System.IO.Path.Combine(path, entries[i].name);
|
||||
}
|
||||
nn.fs.Directory.Close(eHandle);
|
||||
for (int i = 0; i < actualEntries; i++)
|
||||
{
|
||||
entrys[i] = dirEntries[i].name;
|
||||
}
|
||||
nn.fs.Directory.Close(dirHandle);
|
||||
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;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public IEnumerable<string> EnumerateFiles(string path, string searchPattern)
|
||||
{
|
||||
#if !UNITY_SWITCH || UNITY_EDITOR
|
||||
yield break;
|
||||
#if !UNITY_SWITCH
|
||||
yield break;
|
||||
#else
|
||||
// 将通配符转换为正则表达式(支持*和?)
|
||||
var regexPattern = "^" +
|
||||
@ -487,12 +390,18 @@ public class AxiNSIO
|
||||
UnityEngine.Debug.LogError($"nn.fs.File.Delete 失败 {filename} : result=>{result.GetErrorInfo()}");
|
||||
return false;
|
||||
}
|
||||
result = nn.fs.FileSystem.Commit(save_name);
|
||||
if (!result.IsSuccess())
|
||||
{
|
||||
UnityEngine.Debug.LogError($"FileSystem.Commit({save_name}) 失败: " + result.GetErrorInfo());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
#if UNITY_SWITCH && !UNITY_EDITOR
|
||||
// End preventing the user from quitting the game while saving.
|
||||
UnityEngine.Switch.Notification.LeaveExitRequestHandlingSection();
|
||||
#endif
|
||||
return CommitSave();
|
||||
|
||||
#endif
|
||||
}
|
||||
@ -523,12 +432,18 @@ public class AxiNSIO
|
||||
UnityEngine.Debug.LogError($"nn.fs.File.Delete 失败 {filename} : result=>{result.GetErrorInfo()}");
|
||||
return false;
|
||||
}
|
||||
result = nn.fs.FileSystem.Commit(save_name);
|
||||
if (!result.IsSuccess())
|
||||
{
|
||||
UnityEngine.Debug.LogError($"FileSystem.Commit({save_name}) 失败: " + result.GetErrorInfo());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
#if UNITY_SWITCH && !UNITY_EDITOR
|
||||
// End preventing the user from quitting the game while saving.
|
||||
UnityEngine.Switch.Notification.LeaveExitRequestHandlingSection();
|
||||
#endif
|
||||
return CommitSave();
|
||||
#endif
|
||||
}
|
||||
public AxiNSWait_DeletePathDir DeletePathDirAsync(string filename)
|
||||
@ -564,12 +479,18 @@ public class AxiNSIO
|
||||
UnityEngine.Debug.LogError($"nn.fs.File.DeleteRecursively 失败 {filename} : result=>{result.GetErrorInfo()}");
|
||||
return false;
|
||||
}
|
||||
result = nn.fs.FileSystem.Commit(save_name);
|
||||
if (!result.IsSuccess())
|
||||
{
|
||||
UnityEngine.Debug.LogError($"FileSystem.Commit({save_name}) 失败: " + result.GetErrorInfo());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
#if UNITY_SWITCH && !UNITY_EDITOR
|
||||
// End preventing the user from quitting the game while saving.
|
||||
UnityEngine.Switch.Notification.LeaveExitRequestHandlingSection();
|
||||
#endif
|
||||
return CommitSave();
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -599,12 +520,18 @@ public class AxiNSIO
|
||||
UnityEngine.Debug.LogError($"nn.fs.File.DeleteRecursively 失败 {filename} : result=>{result.GetErrorInfo()}");
|
||||
return false;
|
||||
}
|
||||
result = nn.fs.FileSystem.Commit(save_name);
|
||||
if (!result.IsSuccess())
|
||||
{
|
||||
UnityEngine.Debug.LogError($"FileSystem.Commit({save_name}) 失败: " + result.GetErrorInfo());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
#if UNITY_SWITCH && !UNITY_EDITOR
|
||||
// End preventing the user from quitting the game while saving.
|
||||
UnityEngine.Switch.Notification.LeaveExitRequestHandlingSection();
|
||||
#endif
|
||||
return CommitSave();
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -630,13 +557,18 @@ public class AxiNSIO
|
||||
UnityEngine.Debug.LogError($"nn.fs.File.Rename 失败 {oldpath} to {newpath} : result=>{result.GetErrorInfo()}");
|
||||
return false;
|
||||
}
|
||||
result = nn.fs.FileSystem.Commit(save_name);
|
||||
if (!result.IsSuccess())
|
||||
{
|
||||
UnityEngine.Debug.LogError($"FileSystem.Commit({save_name}) 失败: " + result.GetErrorInfo());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
#if UNITY_SWITCH && !UNITY_EDITOR
|
||||
// End preventing the user from quitting the game while saving.
|
||||
UnityEngine.Switch.Notification.LeaveExitRequestHandlingSection();
|
||||
#endif
|
||||
return CommitSave();
|
||||
|
||||
#endif
|
||||
}
|
||||
bool EnsureParentDirectory(string filePath, bool bAutoCreateDir = true)
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#if UNITY_SWITCH
|
||||
using nn.account;
|
||||
using static AxiHttp;
|
||||
#endif
|
||||
public class AxiNSMount
|
||||
{
|
||||
|
||||
@ -49,10 +49,6 @@ namespace AxibugEmuOnline.Client.ClientCore
|
||||
public static SonyVitaCommonDialog sonyVitaCommonDialog;
|
||||
#endif
|
||||
|
||||
#if UNITY_SWITCH
|
||||
public static SwitchCommon switchCommon;
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@ -142,15 +138,10 @@ namespace AxibugEmuOnline.Client.ClientCore
|
||||
// Directory.CreateDirectory("ux0:data/AxibugEmu");
|
||||
|
||||
#if UNITY_PSP2
|
||||
//释放解码 FMV的26M内存,一般游戏用不上(PSP才用那破玩意儿)
|
||||
UnityEngine.PSVita.PSVitaVideoPlayer.TransferMemToMonoHeap();
|
||||
//创建PSV弹窗UI
|
||||
sonyVitaCommonDialog = new GameObject().AddComponent<SonyVitaCommonDialog>();
|
||||
#endif
|
||||
|
||||
#if UNITY_SWITCH
|
||||
//创建创建Switch
|
||||
switchCommon = new GameObject().AddComponent<SwitchCommon>();
|
||||
//释放解码 FMV的26M内存,一般游戏用不上(PSP才用那破玩意儿)
|
||||
UnityEngine.PSVita.PSVitaVideoPlayer.TransferMemToMonoHeap();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using Sony.Vita.Dialog;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AxiIO
|
||||
{
|
||||
@ -44,15 +43,9 @@ namespace AxiIO
|
||||
return AxiIO.io.file_ReadBytesToArr(filePath, readToArr, start, len);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="ImmediatelyCommit">是否立即Commit到物理存储(目前只有NS对本参数有效)</param>
|
||||
internal static void WriteAllBytes(string path, byte[] data, bool ImmediatelyCommit = true)
|
||||
internal static void WriteAllBytes(string path, byte[] data)
|
||||
{
|
||||
AxiIO.io.file_WriteAllBytes(path, data, ImmediatelyCommit);
|
||||
AxiIO.io.file_WriteAllBytes(path, data);
|
||||
}
|
||||
|
||||
internal static void WriteAllBytesFromStream(string path, System.IO.MemoryStream ms)
|
||||
|
||||
@ -26,13 +26,7 @@ namespace AxiIO
|
||||
return System.IO.Directory.Exists(dirpath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="filePath"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="immediatelyCommit">是否立即Commit到物理存储(C#原生这里不需要)</param>
|
||||
public void file_WriteAllBytes(string filePath, byte[] data, bool immediatelyCommit = true)
|
||||
public void file_WriteAllBytes(string filePath, byte[] data)
|
||||
{
|
||||
System.IO.File.WriteAllBytes(filePath, data);
|
||||
}
|
||||
|
||||
@ -12,13 +12,7 @@ namespace AxiIO
|
||||
byte[] file_ReadAllBytes(string filePath);
|
||||
bool file_Exists(string filePath);
|
||||
void file_Delete(string filePath);
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="filePath"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="immediatelyCommit">是否立即Commit到物理存储(目前只有NS对本参数有效)</param>
|
||||
void file_WriteAllBytes(string filePath, byte[] data, bool immediatelyCommit = true);
|
||||
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);
|
||||
|
||||
@ -70,13 +70,7 @@ namespace AxiIO
|
||||
return templen;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="filePath"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="immediatelyCommit">是否立即Commit到物理存储</param>
|
||||
public void file_WriteAllBytes(string filePath, byte[] data, bool immediatelyCommit = true)
|
||||
public void file_WriteAllBytes(string filePath, byte[] data)
|
||||
{
|
||||
AxiNS.instance.io.FileToSaveWithCreate(filePath, data);
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ namespace AxibugEmuOnline.Client
|
||||
if (!request.downloadHandler.bHadErr)
|
||||
{
|
||||
AxiIO.Directory.CreateDirectory(path);
|
||||
AxiIO.File.WriteAllBytes($"{path}/{url.GetHashCode()}", request.downloadHandler.data, false);
|
||||
AxiIO.File.WriteAllBytes($"{path}/{url.GetHashCode()}", request.downloadHandler.data);
|
||||
callback.Invoke(request.downloadHandler.data);
|
||||
}
|
||||
else
|
||||
|
||||
@ -15,7 +15,6 @@ namespace AxibugEmuOnline.Client
|
||||
public static Action LoopAction_tick;
|
||||
public static Action LoopAction_1s;
|
||||
public static Action LoopAction_3s;
|
||||
public static Action LoopAction_15s;
|
||||
public Stopwatch sw = Stopwatch.StartNew();
|
||||
public TimeSpan LastStartPingTime;
|
||||
public int LastPingSeed;
|
||||
@ -43,7 +42,6 @@ namespace AxibugEmuOnline.Client
|
||||
}
|
||||
float LastLoopTime_1s;
|
||||
float LastLoopTime_3s;
|
||||
float LastLoopTime_15s;
|
||||
private void Update()
|
||||
{
|
||||
NetMsg.Instance.DequeueNesMsg();
|
||||
@ -61,12 +59,6 @@ namespace AxibugEmuOnline.Client
|
||||
LastLoopTime_3s = Time.time;
|
||||
LoopAction_3s?.Invoke();
|
||||
}
|
||||
|
||||
if (Time.time - LastLoopTime_15s > 15)
|
||||
{
|
||||
LastLoopTime_15s = Time.time;
|
||||
LoopAction_15s?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
void OnApplicationQuit()
|
||||
|
||||
@ -1,21 +0,0 @@
|
||||
using AxibugEmuOnline.Client;
|
||||
using UnityEngine;
|
||||
public class SwitchCommon : MonoBehaviour
|
||||
{
|
||||
void Start()
|
||||
{
|
||||
TickLoop.LoopAction_15s += ApplyCommit;
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
TickLoop.LoopAction_15s -= ApplyCommit;
|
||||
}
|
||||
|
||||
private void ApplyCommit()
|
||||
{
|
||||
#if UNITY_SWITCH
|
||||
AxiNS.instance.io.ApplyAutoCommit();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user