Compare commits
3 Commits
37fad1c6a0
...
b85f2ddbbd
| Author | SHA1 | Date | |
|---|---|---|---|
| b85f2ddbbd | |||
| 8669c7a613 | |||
| 2e5827f212 |
@ -24,21 +24,17 @@ public class AxiNSIO
|
|||||||
{
|
{
|
||||||
#if UNITY_SWITCH && !UNITY_EDITOR
|
#if UNITY_SWITCH && !UNITY_EDITOR
|
||||||
|
|
||||||
// 阻止用户在保存时,退出游戏 Switch 条例 0080
|
using (AxiNSIOKeepingDisposable.Acquire())
|
||||||
UnityEngine.Switch.Notification.EnterExitRequestHandlingSection();
|
|
||||||
nn.Result ret = FileSystem.Commit(save_name);
|
|
||||||
|
|
||||||
if (!ret.IsSuccess())
|
|
||||||
{
|
{
|
||||||
UnityEngine.Debug.LogError($"FileSystem.Commit({save_name}) 失败: " + ret.GetErrorInfo());
|
nn.Result ret = FileSystem.Commit(save_name);
|
||||||
return false;
|
if (!ret.IsSuccess())
|
||||||
|
{
|
||||||
|
UnityEngine.Debug.LogError($"FileSystem.Commit({save_name}) 失败: " + ret.GetErrorInfo());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bDirty = false;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 停止阻止用户退出游戏
|
|
||||||
UnityEngine.Switch.Notification.LeaveExitRequestHandlingSection();
|
|
||||||
|
|
||||||
bDirty = false;
|
|
||||||
return true;
|
|
||||||
#else
|
#else
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
@ -162,162 +158,127 @@ public class AxiNSIO
|
|||||||
public bool FileToSaveWithCreate(string filePath, byte[] data, bool immediatelyCommit = true)
|
public bool FileToSaveWithCreate(string filePath, byte[] data, bool immediatelyCommit = true)
|
||||||
{
|
{
|
||||||
UnityEngine.Debug.Log($"FileToSaveWithCreate: {filePath}");
|
UnityEngine.Debug.Log($"FileToSaveWithCreate: {filePath}");
|
||||||
lock (commitLock)
|
|
||||||
{
|
|
||||||
#if !UNITY_SWITCH
|
#if !UNITY_SWITCH
|
||||||
return false;
|
return false;
|
||||||
#else
|
#else
|
||||||
if (!AxiNS.instance.mount.SaveIsMount)
|
lock (commitLock)
|
||||||
|
{
|
||||||
|
using (AxiNSIOKeepingDisposable.Acquire())
|
||||||
{
|
{
|
||||||
UnityEngine.Debug.LogError($"Save 尚未挂载,无法存储 {filePath}");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
nn.Result result;
|
if (!AxiNS.instance.mount.SaveIsMount)
|
||||||
|
|
||||||
//取出父级目录
|
|
||||||
string dirpath = string.Empty;
|
|
||||||
//string filePath = "save:/AxibugEmu/Caches/Texture/516322966";
|
|
||||||
string mountRoot = null;
|
|
||||||
int colonSlashIndex = filePath.IndexOf(":/");
|
|
||||||
if (colonSlashIndex > 0)
|
|
||||||
mountRoot = filePath.Substring(0, colonSlashIndex + 1); // 例如 "save:"
|
|
||||||
|
|
||||||
int lastSlashIndex = filePath.LastIndexOf('/');
|
|
||||||
if (lastSlashIndex >= 0)
|
|
||||||
{
|
|
||||||
string parent = filePath.Substring(0, lastSlashIndex);
|
|
||||||
if (mountRoot != null && !parent.Equals(mountRoot, StringComparison.OrdinalIgnoreCase))
|
|
||||||
dirpath = parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(dirpath))
|
|
||||||
{
|
|
||||||
// 使用封装函数检查和创建父目录
|
|
||||||
if (!EnsureParentDirectory(dirpath, true))
|
|
||||||
{
|
{
|
||||||
UnityEngine.Debug.LogError($"无法确保父目录,文件写入取消: {filePath}");
|
UnityEngine.Debug.LogError($"Save 尚未挂载,无法存储 {filePath}");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//string directoryPath = System.IO.Path.GetDirectoryName(filePath.Replace(save_path, ""));
|
nn.Result result;
|
||||||
//string fullDirectoryPath = $"{save_path}{directoryPath}";
|
|
||||||
//UnityEngine.Debug.Log($"检查父目录: {fullDirectoryPath}");
|
|
||||||
|
|
||||||
//nn.fs.EntryType entryType = 0;
|
//取出父级目录
|
||||||
//result = nn.fs.FileSystem.GetEntryType(ref entryType, fullDirectoryPath);
|
string dirpath = string.Empty;
|
||||||
//if (!result.IsSuccess() && nn.fs.FileSystem.ResultPathNotFound.Includes(result))
|
//string filePath = "save:/AxibugEmu/Caches/Texture/516322966";
|
||||||
//{
|
string mountRoot = null;
|
||||||
// UnityEngine.Debug.Log($"父目录 {fullDirectoryPath} 不存在,尝试创建 (判断依据 result=>{result.ToString()})");
|
int colonSlashIndex = filePath.IndexOf(":/");
|
||||||
// result = nn.fs.Directory.Create(fullDirectoryPath);
|
if (colonSlashIndex > 0)
|
||||||
// if (!result.IsSuccess())
|
mountRoot = filePath.Substring(0, colonSlashIndex + 1); // 例如 "save:"
|
||||||
// {
|
|
||||||
// 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
|
int lastSlashIndex = filePath.LastIndexOf('/');
|
||||||
// 阻止用户在保存时,退出游戏
|
if (lastSlashIndex >= 0)
|
||||||
// Switch 条例 0080
|
|
||||||
UnityEngine.Switch.Notification.EnterExitRequestHandlingSection();
|
|
||||||
#endif
|
|
||||||
if (CheckPathNotFound(filePath))
|
|
||||||
{
|
|
||||||
UnityEngine.Debug.Log($"文件({filePath})不存在需要创建");
|
|
||||||
result = nn.fs.File.Create(filePath, data.Length); //this makes a file the size of your save journal. You may want to make a file smaller than this.
|
|
||||||
//result.abortUnlessSuccess();
|
|
||||||
if (!result.IsSuccess())
|
|
||||||
{
|
{
|
||||||
UnityEngine.Debug.LogError($"创建文件失败 {filePath} : " + result.GetErrorInfo());
|
string parent = filePath.Substring(0, lastSlashIndex);
|
||||||
return false;
|
if (mountRoot != null && !parent.Equals(mountRoot, StringComparison.OrdinalIgnoreCase))
|
||||||
|
dirpath = parent;
|
||||||
}
|
}
|
||||||
//读取文件Handle
|
|
||||||
result = File.Open(ref fileHandle, filePath, OpenFileMode.Write);
|
|
||||||
}
|
if (!string.IsNullOrWhiteSpace(dirpath))
|
||||||
else
|
|
||||||
{
|
|
||||||
//读取文件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})存在,长度一致,不用重新创建");
|
// 使用封装函数检查和创建父目录
|
||||||
|
if (!EnsureParentDirectory(dirpath, true))
|
||||||
|
{
|
||||||
|
UnityEngine.Debug.LogError($"无法确保父目录,文件写入取消: {filePath}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (CheckPathNotFound(filePath))
|
||||||
{
|
{
|
||||||
UnityEngine.Debug.Log($"文件({filePath})存在,长度不一致,先删除再重建");
|
UnityEngine.Debug.Log($"文件({filePath})不存在需要创建");
|
||||||
nn.fs.File.Close(fileHandle);
|
result = nn.fs.File.Create(filePath, data.Length); //this makes a file the size of your save journal. You may want to make a file smaller than this.
|
||||||
//删除
|
//result.abortUnlessSuccess();
|
||||||
File.Delete(filePath);
|
|
||||||
//重新创建
|
|
||||||
result = nn.fs.File.Create(filePath, data.Length);
|
|
||||||
if (!result.IsSuccess())
|
if (!result.IsSuccess())
|
||||||
{
|
{
|
||||||
UnityEngine.Debug.LogError($"创建文件失败 {filePath} : " + result.GetErrorInfo());
|
UnityEngine.Debug.LogError($"创建文件失败 {filePath} : " + result.GetErrorInfo());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//重新读取文件Handle
|
//读取文件Handle
|
||||||
result = File.Open(ref fileHandle, filePath, OpenFileMode.Write);
|
result = File.Open(ref fileHandle, filePath, OpenFileMode.Write);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//读取文件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())
|
||||||
|
{
|
||||||
|
UnityEngine.Debug.LogError($"失败 File.Open(ref filehandle, {filePath}, OpenFileMode.Write): " + result.GetErrorInfo());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
UnityEngine.Debug.Log($"成功 File.Open(ref filehandle, {filePath}, OpenFileMode.Write)");
|
||||||
|
|
||||||
|
//nn.fs.WriteOption.Flush 应该就是覆盖写入
|
||||||
|
result = nn.fs.File.Write(fileHandle, 0, data, data.Length, nn.fs.WriteOption.Flush); // Writes and flushes the write at the same time
|
||||||
|
//result.abortUnlessSuccess();
|
||||||
|
if (!result.IsSuccess())
|
||||||
|
{
|
||||||
|
UnityEngine.Debug.LogError("写入文件失败: " + result.GetErrorInfo());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
UnityEngine.Debug.Log("写入文件成功: " + filePath);
|
||||||
|
|
||||||
|
nn.fs.File.Close(fileHandle);
|
||||||
|
if (immediatelyCommit)
|
||||||
|
{
|
||||||
|
//必须得提交,否则没有真实写入
|
||||||
|
return CommitSave();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetCommitDirty();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// //OpenFileMode.AllowAppend 好像不可用
|
|
||||||
// //result = File.Open(ref fileHandle, filePath, OpenFileMode.AllowAppend);
|
|
||||||
// result = File.Open(ref fileHandle, filePath, OpenFileMode.Write);
|
|
||||||
|
|
||||||
//result.abortUnlessSuccess();
|
|
||||||
if (!result.IsSuccess())
|
|
||||||
{
|
|
||||||
UnityEngine.Debug.LogError($"失败 File.Open(ref filehandle, {filePath}, OpenFileMode.Write): " + result.GetErrorInfo());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
UnityEngine.Debug.Log($"成功 File.Open(ref filehandle, {filePath}, OpenFileMode.Write)");
|
|
||||||
|
|
||||||
//nn.fs.WriteOption.Flush 应该就是覆盖写入
|
|
||||||
result = nn.fs.File.Write(fileHandle, 0, data, data.Length, nn.fs.WriteOption.Flush); // Writes and flushes the write at the same time
|
|
||||||
//result.abortUnlessSuccess();
|
|
||||||
if (!result.IsSuccess())
|
|
||||||
{
|
|
||||||
UnityEngine.Debug.LogError("写入文件失败: " + result.GetErrorInfo());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
UnityEngine.Debug.Log("写入文件成功: " + filePath);
|
|
||||||
|
|
||||||
nn.fs.File.Close(fileHandle);
|
|
||||||
|
|
||||||
|
|
||||||
#if UNITY_SWITCH && !UNITY_EDITOR
|
|
||||||
// 停止阻止用户退出游戏
|
|
||||||
UnityEngine.Switch.Notification.LeaveExitRequestHandlingSection();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (immediatelyCommit)
|
|
||||||
{
|
|
||||||
//必须得提交,否则没有真实写入
|
|
||||||
return CommitSave();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SetCommitDirty();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 保存并创建文件(如果目录不存在回先自动创建目录)
|
/// 保存并创建文件(如果目录不存在回先自动创建目录)
|
||||||
@ -531,30 +492,19 @@ public class AxiNSIO
|
|||||||
#if !UNITY_SWITCH
|
#if !UNITY_SWITCH
|
||||||
return false;
|
return false;
|
||||||
#else
|
#else
|
||||||
|
using (AxiNSIOKeepingDisposable.Acquire())
|
||||||
|
|
||||||
#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.File.Delete(filename);
|
|
||||||
if (result.IsSuccess() == false)
|
|
||||||
{
|
{
|
||||||
UnityEngine.Debug.LogError($"nn.fs.File.Delete 失败 {filename} : result=>{result.GetErrorInfo()}");
|
if (CheckPathNotFound(filename))
|
||||||
return false;
|
return false;
|
||||||
|
nn.Result result;
|
||||||
|
result = nn.fs.File.Delete(filename);
|
||||||
|
if (result.IsSuccess() == false)
|
||||||
|
{
|
||||||
|
UnityEngine.Debug.LogError($"nn.fs.File.Delete 失败 {filename} : result=>{result.GetErrorInfo()}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return CommitSave();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if UNITY_SWITCH && !UNITY_EDITOR
|
|
||||||
// End preventing the user from quitting the game while saving.
|
|
||||||
UnityEngine.Switch.Notification.LeaveExitRequestHandlingSection();
|
|
||||||
#endif
|
|
||||||
return CommitSave();
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
public AxiNSWait_DeletePathFile DeletePathFileAsync(string filename)
|
public AxiNSWait_DeletePathFile DeletePathFileAsync(string filename)
|
||||||
@ -568,28 +518,19 @@ public class AxiNSIO
|
|||||||
#if !UNITY_SWITCH
|
#if !UNITY_SWITCH
|
||||||
return false;
|
return false;
|
||||||
#else
|
#else
|
||||||
|
using (AxiNSIOKeepingDisposable.Acquire())
|
||||||
#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.Delete(filename);
|
|
||||||
if (result.IsSuccess() == false)
|
|
||||||
{
|
{
|
||||||
UnityEngine.Debug.LogError($"nn.fs.File.Delete 失败 {filename} : result=>{result.GetErrorInfo()}");
|
if (CheckPathNotFound(filename))
|
||||||
return false;
|
return false;
|
||||||
|
nn.Result result;
|
||||||
|
result = nn.fs.Directory.Delete(filename);
|
||||||
|
if (result.IsSuccess() == false)
|
||||||
|
{
|
||||||
|
UnityEngine.Debug.LogError($"nn.fs.File.Delete 失败 {filename} : result=>{result.GetErrorInfo()}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return CommitSave();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if UNITY_SWITCH && !UNITY_EDITOR
|
|
||||||
// End preventing the user from quitting the game while saving.
|
|
||||||
UnityEngine.Switch.Notification.LeaveExitRequestHandlingSection();
|
|
||||||
#endif
|
|
||||||
return CommitSave();
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
public AxiNSWait_DeletePathDir DeletePathDirAsync(string filename)
|
public AxiNSWait_DeletePathDir DeletePathDirAsync(string filename)
|
||||||
@ -603,28 +544,19 @@ public class AxiNSIO
|
|||||||
#if !UNITY_SWITCH
|
#if !UNITY_SWITCH
|
||||||
return false;
|
return false;
|
||||||
#else
|
#else
|
||||||
|
using (AxiNSIOKeepingDisposable.Acquire())
|
||||||
#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.DeleteRecursively(filename);
|
|
||||||
if (result.IsSuccess() == false)
|
|
||||||
{
|
{
|
||||||
UnityEngine.Debug.LogError($"nn.fs.File.Recursively 失败 {filename} : result=>{result.GetErrorInfo()}");
|
if (CheckPathNotFound(filename))
|
||||||
return false;
|
return false;
|
||||||
|
nn.Result result;
|
||||||
|
result = nn.fs.Directory.DeleteRecursively(filename);
|
||||||
|
if (result.IsSuccess() == false)
|
||||||
|
{
|
||||||
|
UnityEngine.Debug.LogError($"nn.fs.File.Recursively 失败 {filename} : result=>{result.GetErrorInfo()}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return CommitSave();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if UNITY_SWITCH && !UNITY_EDITOR
|
|
||||||
// End preventing the user from quitting the game while saving.
|
|
||||||
UnityEngine.Switch.Notification.LeaveExitRequestHandlingSection();
|
|
||||||
#endif
|
|
||||||
return CommitSave();
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
public AxiNSWait_DeletePathDirRecursively DeletePathDirRecursivelyAsync(string filename)
|
public AxiNSWait_DeletePathDirRecursively DeletePathDirRecursivelyAsync(string filename)
|
||||||
@ -644,28 +576,19 @@ public class AxiNSIO
|
|||||||
#if !UNITY_SWITCH
|
#if !UNITY_SWITCH
|
||||||
return false;
|
return false;
|
||||||
#else
|
#else
|
||||||
|
using (AxiNSIOKeepingDisposable.Acquire())
|
||||||
#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.DeleteRecursively(filename);
|
|
||||||
if (result.IsSuccess() == false)
|
|
||||||
{
|
{
|
||||||
UnityEngine.Debug.LogError($"nn.fs.File.DeleteRecursively 失败 {filename} : result=>{result.GetErrorInfo()}");
|
if (CheckPathNotFound(filename))
|
||||||
return false;
|
return false;
|
||||||
|
nn.Result result;
|
||||||
|
result = nn.fs.Directory.DeleteRecursively(filename);
|
||||||
|
if (result.IsSuccess() == false)
|
||||||
|
{
|
||||||
|
UnityEngine.Debug.LogError($"nn.fs.File.DeleteRecursively 失败 {filename} : result=>{result.GetErrorInfo()}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return CommitSave();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if UNITY_SWITCH && !UNITY_EDITOR
|
|
||||||
// End preventing the user from quitting the game while saving.
|
|
||||||
UnityEngine.Switch.Notification.LeaveExitRequestHandlingSection();
|
|
||||||
#endif
|
|
||||||
return CommitSave();
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -679,28 +602,19 @@ public class AxiNSIO
|
|||||||
#if !UNITY_SWITCH
|
#if !UNITY_SWITCH
|
||||||
return false;
|
return false;
|
||||||
#else
|
#else
|
||||||
|
using (AxiNSIOKeepingDisposable.Acquire())
|
||||||
#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()}");
|
if (CheckPathNotFound(filename))
|
||||||
return false;
|
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;
|
||||||
|
}
|
||||||
|
return CommitSave();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if UNITY_SWITCH && !UNITY_EDITOR
|
|
||||||
// End preventing the user from quitting the game while saving.
|
|
||||||
UnityEngine.Switch.Notification.LeaveExitRequestHandlingSection();
|
|
||||||
#endif
|
|
||||||
return CommitSave();
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -709,30 +623,19 @@ public class AxiNSIO
|
|||||||
#if !UNITY_SWITCH
|
#if !UNITY_SWITCH
|
||||||
return false;
|
return false;
|
||||||
#else
|
#else
|
||||||
|
using (AxiNSIOKeepingDisposable.Acquire())
|
||||||
#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(oldpath))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
nn.Result result;
|
|
||||||
result = nn.fs.Directory.Rename(oldpath, newpath);
|
|
||||||
if (result.IsSuccess() == false)
|
|
||||||
{
|
{
|
||||||
UnityEngine.Debug.LogError($"nn.fs.File.Rename 失败 {oldpath} to {newpath} : result=>{result.GetErrorInfo()}");
|
if (CheckPathNotFound(oldpath))
|
||||||
return false;
|
return false;
|
||||||
|
nn.Result result;
|
||||||
|
result = nn.fs.Directory.Rename(oldpath, newpath);
|
||||||
|
if (result.IsSuccess() == false)
|
||||||
|
{
|
||||||
|
UnityEngine.Debug.LogError($"nn.fs.File.Rename 失败 {oldpath} to {newpath} : result=>{result.GetErrorInfo()}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return CommitSave();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if UNITY_SWITCH && !UNITY_EDITOR
|
|
||||||
// End preventing the user from quitting the game while saving.
|
|
||||||
UnityEngine.Switch.Notification.LeaveExitRequestHandlingSection();
|
|
||||||
#endif
|
|
||||||
return CommitSave();
|
|
||||||
|
|
||||||
#endif
|
#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 waittime;
|
||||||
float lastinvokeTime;
|
float lastinvokeTime;
|
||||||
|
|
||||||
public static void SetInvoke(Action _act, int _waitsec)
|
public static void SetInvokeLoop(Action _act, int _waitsec)
|
||||||
{
|
{
|
||||||
GameObject gobj = GameObject.Find($"[{nameof(AxiNSMono)}]");
|
GameObject gobj = GameObject.Find($"[{nameof(AxiNSMono)}]");
|
||||||
if (gobj == null)
|
if (gobj == null)
|
||||||
|
|||||||
@ -49,7 +49,7 @@ public class AxiNSWaitHandle
|
|||||||
static void InitMonoInit()
|
static void InitMonoInit()
|
||||||
{
|
{
|
||||||
if (bMonoInit) return;
|
if (bMonoInit) return;
|
||||||
AxiNSMono.SetInvoke(Do,15);
|
AxiNSMono.SetInvokeLoop(Do,15);
|
||||||
bMonoInit = true;
|
bMonoInit = true;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using System;
|
#if !UNITY_SWITCH
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -172,3 +173,4 @@ namespace AxiReplay
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
@ -1,4 +1,5 @@
|
|||||||
using System;
|
#if !UNITY_SWITCH
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -156,3 +157,4 @@ namespace AxiReplay
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
@ -82,7 +82,6 @@ namespace Essgee.Utilities
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public static void Write(this System.IO.BinaryWriter bw, byte* bufferPtr, int offset, int count)
|
public static void Write(this System.IO.BinaryWriter bw, byte* bufferPtr, int offset, int count)
|
||||||
{
|
{
|
||||||
// 使用指针复制数据到临时数组
|
// 使用指针复制数据到临时数组
|
||||||
@ -90,21 +89,22 @@ namespace Essgee.Utilities
|
|||||||
// 使用BinaryWriter写入临时数组
|
// 使用BinaryWriter写入临时数组
|
||||||
bw.Write(TempBuffer_src, 0, count);
|
bw.Write(TempBuffer_src, 0, count);
|
||||||
}
|
}
|
||||||
public static void Write(this System.IO.FileStream fs, byte* bufferPtr, int offset, int count)
|
|
||||||
{
|
//public static void Write(this System.IO.FileStream fs, byte* bufferPtr, int offset, int count)
|
||||||
// 使用指针复制数据到临时数组
|
//{
|
||||||
Buffer.MemoryCopy(bufferPtr + offset, TempBuffer, 0, count);
|
// // 使用指针复制数据到临时数组
|
||||||
// 使用BinaryWriter写入临时数组
|
// Buffer.MemoryCopy(bufferPtr + offset, TempBuffer, 0, count);
|
||||||
fs.Write(TempBuffer_src, 0, count);
|
// // 使用BinaryWriter写入临时数组
|
||||||
}
|
// fs.Write(TempBuffer_src, 0, count);
|
||||||
public static int Read(this System.IO.FileStream fs, byte* bufferPtr, int offset, int count)
|
//}
|
||||||
{
|
//public static int Read(this System.IO.FileStream fs, byte* bufferPtr, int offset, int count)
|
||||||
// 使用BinaryWriter写入临时数组
|
//{
|
||||||
count = fs.Read(TempBuffer_src, offset, count);
|
// // 使用BinaryWriter写入临时数组
|
||||||
// 使用指针复制数据到临时数组
|
// count = fs.Read(TempBuffer_src, offset, count);
|
||||||
Buffer.MemoryCopy(TempBuffer, bufferPtr + offset, 0, count);
|
// // 使用指针复制数据到临时数组
|
||||||
return count;
|
// Buffer.MemoryCopy(TempBuffer, bufferPtr + offset, 0, count);
|
||||||
}
|
// return count;
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal unsafe static class AxiArray
|
internal unsafe static class AxiArray
|
||||||
|
|||||||
@ -39,6 +39,7 @@ namespace Essgee.Emulation
|
|||||||
var fileExtension = System.IO.Path.GetExtension(fileName);
|
var fileExtension = System.IO.Path.GetExtension(fileName);
|
||||||
if (fileExtension == ".zip")
|
if (fileExtension == ".zip")
|
||||||
{
|
{
|
||||||
|
UnityEngine.Debug.Log("使用ZipFile.Open解压Zip:"+fileName);
|
||||||
using (var zip = ZipFile.Open(fileName, ZipArchiveMode.Read))
|
using (var zip = ZipFile.Open(fileName, ZipArchiveMode.Read))
|
||||||
{
|
{
|
||||||
foreach (var entry in zip.Entries)
|
foreach (var entry in zip.Entries)
|
||||||
@ -60,7 +61,7 @@ namespace Essgee.Emulation
|
|||||||
else if (fileExtensionSystemDictionary.ContainsKey(fileExtension))
|
else if (fileExtensionSystemDictionary.ContainsKey(fileExtension))
|
||||||
{
|
{
|
||||||
machineType = fileExtensionSystemDictionary[fileExtension];
|
machineType = fileExtensionSystemDictionary[fileExtension];
|
||||||
romData = System.IO.File.ReadAllBytes(fileName);
|
romData = EmulatorHandler.io.File_ReadAllBytes(fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex) when (!AppEnvironment.DebugMode)
|
catch (Exception ex) when (!AppEnvironment.DebugMode)
|
||||||
|
|||||||
@ -1805,7 +1805,9 @@ namespace IngameDebugConsole
|
|||||||
|
|
||||||
public void SaveLogsToFile( string filePath )
|
public void SaveLogsToFile( string filePath )
|
||||||
{
|
{
|
||||||
|
#if !UNITY_SWITCH
|
||||||
File.WriteAllText( filePath, GetAllLogs() );
|
File.WriteAllText( filePath, GetAllLogs() );
|
||||||
|
#endif
|
||||||
Debug.Log( "Logs saved to: " + filePath );
|
Debug.Log( "Logs saved to: " + filePath );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1815,7 +1817,7 @@ namespace IngameDebugConsole
|
|||||||
if( !avoidScreenCutout )
|
if( !avoidScreenCutout )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#if UNITY_2017_2_OR_NEWER && ( UNITY_EDITOR || UNITY_ANDROID || UNITY_IOS )
|
#if UNITY_2017_2_OR_NEWER && (UNITY_EDITOR || UNITY_ANDROID || UNITY_IOS)
|
||||||
// Check if there is a cutout at the top of the screen
|
// Check if there is a cutout at the top of the screen
|
||||||
int screenHeight = Screen.height;
|
int screenHeight = Screen.height;
|
||||||
float safeYMax = Screen.safeArea.yMax;
|
float safeYMax = Screen.safeArea.yMax;
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
|
#if !UNITY_SWITCH
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace MAME.Core
|
namespace MAME.Core
|
||||||
@ -81,4 +81,5 @@ namespace MAME.Core
|
|||||||
mWriter.Flush();
|
mWriter.Flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
@ -93,7 +93,6 @@ namespace StoicGooseUnity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public static void Write(this System.IO.BinaryWriter bw, byte* bufferPtr, int offset, int count)
|
public static void Write(this System.IO.BinaryWriter bw, byte* bufferPtr, int offset, int count)
|
||||||
{
|
{
|
||||||
// 使用指针复制数据到临时数组
|
// 使用指针复制数据到临时数组
|
||||||
@ -101,6 +100,7 @@ namespace StoicGooseUnity
|
|||||||
// 使用BinaryWriter写入临时数组
|
// 使用BinaryWriter写入临时数组
|
||||||
bw.Write(TempBuffer_src, 0, count);
|
bw.Write(TempBuffer_src, 0, count);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
public static void Write(this System.IO.FileStream fs, byte* bufferPtr, int offset, int count)
|
public static void Write(this System.IO.FileStream fs, byte* bufferPtr, int offset, int count)
|
||||||
{
|
{
|
||||||
// 使用指针复制数据到临时数组
|
// 使用指针复制数据到临时数组
|
||||||
@ -115,7 +115,7 @@ namespace StoicGooseUnity
|
|||||||
// 使用指针复制数据到临时数组
|
// 使用指针复制数据到临时数组
|
||||||
Buffer.MemoryCopy(TempBuffer, bufferPtr + offset, 0, count);
|
Buffer.MemoryCopy(TempBuffer, bufferPtr + offset, 0, count);
|
||||||
return count;
|
return count;
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
internal unsafe static class AxiArray
|
internal unsafe static class AxiArray
|
||||||
|
|||||||
@ -66,6 +66,10 @@ namespace Coffee.UIExtensions
|
|||||||
|
|
||||||
static void SaveMaterial(Material mat, Shader shader, bool isMainAsset)
|
static void SaveMaterial(Material mat, Shader shader, bool isMainAsset)
|
||||||
{
|
{
|
||||||
|
#if !UNITY_EDITOR
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
|
|
||||||
string materialPath = GetDefaultMaterialPath(shader);
|
string materialPath = GetDefaultMaterialPath(shader);
|
||||||
|
|
||||||
#if UIEFFECT_SEPARATE
|
#if UIEFFECT_SEPARATE
|
||||||
|
|||||||
@ -29,8 +29,8 @@ public class UMAME : EmuCore<ulong>
|
|||||||
public UniTimeSpan mTimeSpan;
|
public UniTimeSpan mTimeSpan;
|
||||||
public bool bQuickTestRom = false;
|
public bool bQuickTestRom = false;
|
||||||
public string mQuickTestRom = string.Empty;
|
public string mQuickTestRom = string.Empty;
|
||||||
public ReplayWriter mReplayWriter;
|
//public ReplayWriter mReplayWriter;
|
||||||
public ReplayReader mReplayReader;
|
//public ReplayReader mReplayReader;
|
||||||
public long currEmuFrame => emu.currEmuFrame;
|
public long currEmuFrame => emu.currEmuFrame;
|
||||||
public static System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
|
public static System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
|
||||||
public static bool bInGame { get; private set; }
|
public static bool bInGame { get; private set; }
|
||||||
@ -125,7 +125,7 @@ public class UMAME : EmuCore<ulong>
|
|||||||
{
|
{
|
||||||
emu.ResetRomRoot(RomPath);
|
emu.ResetRomRoot(RomPath);
|
||||||
//Application.targetFrameRate = 60;
|
//Application.targetFrameRate = 60;
|
||||||
mReplayWriter = new ReplayWriter(mChangeRomName, "fuck", ReplayData.ReplayFormat.FM32IP64, Encoding.UTF8);
|
//mReplayWriter = new ReplayWriter(mChangeRomName, "fuck", ReplayData.ReplayFormat.FM32IP64, Encoding.UTF8);
|
||||||
mChangeRomName = loadRom;
|
mChangeRomName = loadRom;
|
||||||
StopGame();
|
StopGame();
|
||||||
//读取ROM
|
//读取ROM
|
||||||
@ -161,7 +161,7 @@ public class UMAME : EmuCore<ulong>
|
|||||||
mUniKeyboard.SyncInput(InputData);
|
mUniKeyboard.SyncInput(InputData);
|
||||||
emu.UpdateFrame();
|
emu.UpdateFrame();
|
||||||
//写入replay
|
//写入replay
|
||||||
UMAME.instance.mReplayWriter.NextFramebyFrameIdx((int)UMAME.instance.mUniVideoPlayer.mFrame, InputData);
|
//UMAME.instance.mReplayWriter.NextFramebyFrameIdx((int)UMAME.instance.mUniVideoPlayer.mFrame, InputData);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,7 +188,7 @@ public class UMAME : EmuCore<ulong>
|
|||||||
{
|
{
|
||||||
string Path = SavePath + Machine.sName + ".rp";
|
string Path = SavePath + Machine.sName + ".rp";
|
||||||
string dbgPath = SavePath + Machine.sName + ".rpwrite";
|
string dbgPath = SavePath + Machine.sName + ".rpwrite";
|
||||||
mReplayWriter.SaveData(Path, true, dbgPath);
|
//mReplayWriter.SaveData(Path, true, dbgPath);
|
||||||
}
|
}
|
||||||
public void StopGame()
|
public void StopGame()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -121,34 +121,35 @@ public class UniKeyboard : MonoBehaviour, IKeyboard
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public class ReplayMode
|
// public class ReplayMode
|
||||||
{
|
// {
|
||||||
ulong currInputData;
|
// ulong currInputData;
|
||||||
|
|
||||||
public ReplayMode()
|
// public ReplayMode()
|
||||||
{
|
// {
|
||||||
}
|
// }
|
||||||
|
|
||||||
public ulong GetPressedKeys()
|
// public ulong GetPressedKeys()
|
||||||
{
|
// {
|
||||||
int targetFrame = (int)UMAME.instance.mUniVideoPlayer.mFrame;
|
// int targetFrame = (int)UMAME.instance.mUniVideoPlayer.mFrame;
|
||||||
AxiReplay.ReplayStep stepData;
|
// AxiReplay.ReplayStep stepData;
|
||||||
//有变化
|
|
||||||
if (UMAME.instance.mReplayReader.NextFramebyFrameIdx(targetFrame, out stepData))
|
// //有变化
|
||||||
{
|
// if (UMAME.instance.mReplayReader.NextFramebyFrameIdx(targetFrame, out stepData))
|
||||||
#if UNITY_EDITOR
|
// {
|
||||||
string ShowKeyNames = string.Empty;
|
//#if UNITY_EDITOR
|
||||||
foreach (string keyname in GetInputpDataToMotionKey(currInputData))
|
// string ShowKeyNames = string.Empty;
|
||||||
{
|
// foreach (string keyname in GetInputpDataToMotionKey(currInputData))
|
||||||
ShowKeyNames += keyname + " |";
|
// {
|
||||||
}
|
// ShowKeyNames += keyname + " |";
|
||||||
Debug.Log("GetPressedKeys=>" + ShowKeyNames);
|
// }
|
||||||
#endif
|
// Debug.Log("GetPressedKeys=>" + ShowKeyNames);
|
||||||
currInputData = stepData.InPut;
|
//#endif
|
||||||
}
|
// currInputData = stepData.InPut;
|
||||||
return currInputData;
|
// }
|
||||||
}
|
// return currInputData;
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user