forked from sin365/AxibugEmuOnline
阶段性继续完善AxiNSApi
This commit is contained in:
parent
37fad1c6a0
commit
2e5827f212
@ -24,21 +24,17 @@ public class AxiNSIO
|
||||
{
|
||||
#if UNITY_SWITCH && !UNITY_EDITOR
|
||||
|
||||
// 阻止用户在保存时,退出游戏 Switch 条例 0080
|
||||
UnityEngine.Switch.Notification.EnterExitRequestHandlingSection();
|
||||
using (AxiNSIOKeepingDisposable.Acquire())
|
||||
{
|
||||
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
|
||||
@ -162,11 +158,15 @@ public class AxiNSIO
|
||||
public bool FileToSaveWithCreate(string filePath, byte[] data, bool immediatelyCommit = true)
|
||||
{
|
||||
UnityEngine.Debug.Log($"FileToSaveWithCreate: {filePath}");
|
||||
lock (commitLock)
|
||||
{
|
||||
|
||||
#if !UNITY_SWITCH
|
||||
return false;
|
||||
#else
|
||||
lock (commitLock)
|
||||
{
|
||||
using (AxiNSIOKeepingDisposable.Acquire())
|
||||
{
|
||||
|
||||
if (!AxiNS.instance.mount.SaveIsMount)
|
||||
{
|
||||
UnityEngine.Debug.LogError($"Save 尚未挂载,无法存储 {filePath}");
|
||||
@ -202,39 +202,6 @@ public class AxiNSIO
|
||||
}
|
||||
}
|
||||
|
||||
//string directoryPath = System.IO.Path.GetDirectoryName(filePath.Replace(save_path, ""));
|
||||
//string fullDirectoryPath = $"{save_path}{directoryPath}";
|
||||
//UnityEngine.Debug.Log($"检查父目录: {fullDirectoryPath}");
|
||||
|
||||
//nn.fs.EntryType entryType = 0;
|
||||
//result = nn.fs.FileSystem.GetEntryType(ref entryType, fullDirectoryPath);
|
||||
//if (!result.IsSuccess() && nn.fs.FileSystem.ResultPathNotFound.Includes(result))
|
||||
//{
|
||||
// UnityEngine.Debug.Log($"父目录 {fullDirectoryPath} 不存在,尝试创建 (判断依据 result=>{result.ToString()})");
|
||||
// result = nn.fs.Directory.Create(fullDirectoryPath);
|
||||
// if (!result.IsSuccess())
|
||||
// {
|
||||
// UnityEngine.Debug.LogError($"创建父目录失败: {result.GetErrorInfo()}");
|
||||
// return false;
|
||||
// }
|
||||
// UnityEngine.Debug.Log($"父目录 {fullDirectoryPath} 创建成功");
|
||||
//}
|
||||
//else if (result.IsSuccess() && entryType != nn.fs.EntryType.Directory)
|
||||
//{
|
||||
// UnityEngine.Debug.LogError($"路径 {fullDirectoryPath} 已存在,但不是目录");
|
||||
// return false;
|
||||
//}
|
||||
//else if (!result.IsSuccess())
|
||||
//{
|
||||
// UnityEngine.Debug.LogError($"检查父目录失败: {result.GetErrorInfo()}");
|
||||
// return false;
|
||||
//}
|
||||
|
||||
#if UNITY_SWITCH && !UNITY_EDITOR
|
||||
// 阻止用户在保存时,退出游戏
|
||||
// Switch 条例 0080
|
||||
UnityEngine.Switch.Notification.EnterExitRequestHandlingSection();
|
||||
#endif
|
||||
if (CheckPathNotFound(filePath))
|
||||
{
|
||||
UnityEngine.Debug.Log($"文件({filePath})不存在需要创建");
|
||||
@ -299,13 +266,6 @@ public class AxiNSIO
|
||||
UnityEngine.Debug.Log("写入文件成功: " + filePath);
|
||||
|
||||
nn.fs.File.Close(fileHandle);
|
||||
|
||||
|
||||
#if UNITY_SWITCH && !UNITY_EDITOR
|
||||
// 停止阻止用户退出游戏
|
||||
UnityEngine.Switch.Notification.LeaveExitRequestHandlingSection();
|
||||
#endif
|
||||
|
||||
if (immediatelyCommit)
|
||||
{
|
||||
//必须得提交,否则没有真实写入
|
||||
@ -316,9 +276,10 @@ public class AxiNSIO
|
||||
SetCommitDirty();
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
/// <summary>
|
||||
/// 保存并创建文件(如果目录不存在回先自动创建目录)
|
||||
/// </summary>
|
||||
@ -531,14 +492,8 @@ public class AxiNSIO
|
||||
#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
|
||||
|
||||
using (AxiNSIOKeepingDisposable.Acquire())
|
||||
{
|
||||
if (CheckPathNotFound(filename))
|
||||
return false;
|
||||
nn.Result result;
|
||||
@ -548,13 +503,8 @@ public class AxiNSIO
|
||||
UnityEngine.Debug.LogError($"nn.fs.File.Delete 失败 {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
|
||||
return CommitSave();
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
public AxiNSWait_DeletePathFile DeletePathFileAsync(string filename)
|
||||
@ -568,13 +518,8 @@ public class AxiNSIO
|
||||
#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
|
||||
|
||||
using (AxiNSIOKeepingDisposable.Acquire())
|
||||
{
|
||||
if (CheckPathNotFound(filename))
|
||||
return false;
|
||||
nn.Result result;
|
||||
@ -584,12 +529,8 @@ public class AxiNSIO
|
||||
UnityEngine.Debug.LogError($"nn.fs.File.Delete 失败 {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
|
||||
return CommitSave();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
public AxiNSWait_DeletePathDir DeletePathDirAsync(string filename)
|
||||
@ -603,13 +544,8 @@ public class AxiNSIO
|
||||
#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
|
||||
|
||||
using (AxiNSIOKeepingDisposable.Acquire())
|
||||
{
|
||||
if (CheckPathNotFound(filename))
|
||||
return false;
|
||||
nn.Result result;
|
||||
@ -619,12 +555,8 @@ public class AxiNSIO
|
||||
UnityEngine.Debug.LogError($"nn.fs.File.Recursively 失败 {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
|
||||
return CommitSave();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
public AxiNSWait_DeletePathDirRecursively DeletePathDirRecursivelyAsync(string filename)
|
||||
@ -644,13 +576,8 @@ public class AxiNSIO
|
||||
#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
|
||||
|
||||
using (AxiNSIOKeepingDisposable.Acquire())
|
||||
{
|
||||
if (CheckPathNotFound(filename))
|
||||
return false;
|
||||
nn.Result result;
|
||||
@ -660,12 +587,8 @@ public class AxiNSIO
|
||||
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
|
||||
return CommitSave();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -679,13 +602,8 @@ public class AxiNSIO
|
||||
#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
|
||||
|
||||
using (AxiNSIOKeepingDisposable.Acquire())
|
||||
{
|
||||
if (CheckPathNotFound(filename))
|
||||
return false;
|
||||
nn.Result result;
|
||||
@ -695,12 +613,8 @@ public class AxiNSIO
|
||||
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
|
||||
return CommitSave();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -709,16 +623,10 @@ public class AxiNSIO
|
||||
#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
|
||||
|
||||
using (AxiNSIOKeepingDisposable.Acquire())
|
||||
{
|
||||
if (CheckPathNotFound(oldpath))
|
||||
return false;
|
||||
|
||||
nn.Result result;
|
||||
result = nn.fs.Directory.Rename(oldpath, newpath);
|
||||
if (result.IsSuccess() == false)
|
||||
@ -726,13 +634,8 @@ public class AxiNSIO
|
||||
UnityEngine.Debug.LogError($"nn.fs.File.Rename 失败 {oldpath} to {newpath} : 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
|
||||
return CommitSave();
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,56 @@
|
||||
#if UNITY_SWITCH
|
||||
using nn.fs;
|
||||
#endif
|
||||
|
||||
using System;
|
||||
|
||||
public class AxiNSIOKeepingDisposable : IDisposable
|
||||
{
|
||||
static object m_CurrLiveHandleLock = new object();
|
||||
static int m_CurrLiveHandleCounter = 0;
|
||||
static bool hadCounter { get { return m_CurrLiveHandleCounter > 0; } }
|
||||
public static AxiNSIOKeepingDisposable Acquire()
|
||||
{
|
||||
return new AxiNSIOKeepingDisposable();
|
||||
}
|
||||
static void UpdateKeepingState(bool add)
|
||||
{
|
||||
#if UNITY_SWITCH
|
||||
lock (m_CurrLiveHandleLock)
|
||||
{
|
||||
bool lasthadCounter = hadCounter;
|
||||
if (add)
|
||||
m_CurrLiveHandleCounter++;
|
||||
else
|
||||
m_CurrLiveHandleCounter--;
|
||||
|
||||
if (lasthadCounter == hadCounter)
|
||||
return;
|
||||
|
||||
if (hadCounter)
|
||||
{
|
||||
// This next line prevents the user from quitting the game while saving.
|
||||
// This is required for Nintendo Switch Guideline 0080
|
||||
// 开启:阻止用户在保存时,退出游戏 Switch 条例 0080
|
||||
UnityEngine.Switch.Notification.EnterExitRequestHandlingSection();
|
||||
UnityEngine.Debug.Log("开启:阻止用户在保存时,退出游戏 Switch 条例 0080");
|
||||
}
|
||||
else
|
||||
{
|
||||
// 取消:阻止用户在保存时,退出游戏 Switch 条例 0080
|
||||
// End preventing the user from quitting the game while saving.
|
||||
UnityEngine.Switch.Notification.LeaveExitRequestHandlingSection();
|
||||
UnityEngine.Debug.Log("取消:阻止用户在保存时,退出游戏 Switch 条例 0080");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
private AxiNSIOKeepingDisposable()
|
||||
{
|
||||
UpdateKeepingState(true);
|
||||
}
|
||||
void IDisposable.Dispose()
|
||||
{
|
||||
UpdateKeepingState(false);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e8a1c25dc774fb84fa91f4a87be0e507
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -7,7 +7,7 @@ public class AxiNSMono : MonoBehaviour
|
||||
float waittime;
|
||||
float lastinvokeTime;
|
||||
|
||||
public static void SetInvoke(Action _act, int _waitsec)
|
||||
public static void SetInvokeLoop(Action _act, int _waitsec)
|
||||
{
|
||||
GameObject gobj = GameObject.Find($"[{nameof(AxiNSMono)}]");
|
||||
if (gobj == null)
|
||||
|
||||
@ -49,7 +49,7 @@ public class AxiNSWaitHandle
|
||||
static void InitMonoInit()
|
||||
{
|
||||
if (bMonoInit) return;
|
||||
AxiNSMono.SetInvoke(Do,15);
|
||||
AxiNSMono.SetInvokeLoop(Do,15);
|
||||
bMonoInit = true;
|
||||
}
|
||||
#endregion
|
||||
|
||||
Loading…
Reference in New Issue
Block a user