Compare commits

...

5 Commits

25 changed files with 768 additions and 257 deletions

View File

@ -3,6 +3,7 @@ using nn.fs;
#endif
using System.Collections.Generic;
using System.Text.RegularExpressions;
public class AxiNSIO
{
@ -40,31 +41,31 @@ public class AxiNSIO
#else
return false;
#endif
}
}
void SetCommitDirty()
{
lock (commitLock)
{
bDirty = true;
}
}
public void ApplyAutoCommit()
{
bool temp;
lock (commitLock)
{
temp = bDirty;
}
if (temp)
{
CommitSave();
}
}
}
void SetCommitDirty()
{
lock (commitLock)
{
bDirty = true;
}
}
public void ApplyAutoCommit()
{
bool temp;
lock (commitLock)
{
temp = bDirty;
}
if (temp)
{
CommitSave();
}
}
/// <summary>
/// 检查Path是否存在
@ -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>
@ -112,13 +116,13 @@ public class AxiNSIO
#if !UNITY_SWITCH
return false;
#else
// 使用封装函数检查和创建父目录
if (!EnsureParentDirectory(filePath, true))
{
UnityEngine.Debug.LogError($"无法确保父目录,文件写入取消: {filePath}");
return false;
}
return true;
// 使用封装函数检查和创建父目录
if (!EnsureParentDirectory(filePath, true))
{
UnityEngine.Debug.LogError($"无法确保父目录,文件写入取消: {filePath}");
return false;
}
return true;
#endif
}
}
@ -160,104 +164,134 @@ public class AxiNSIO
#if !UNITY_SWITCH
return false;
#else
if (!AxiNS.instance.mount.SaveIsMount)
{
UnityEngine.Debug.LogError($"Save 尚未挂载,无法存储 {filePath}");
return false;
}
if (!AxiNS.instance.mount.SaveIsMount)
{
UnityEngine.Debug.LogError($"Save 尚未挂载,无法存储 {filePath}");
return false;
}
nn.Result result;
nn.Result result;
#if UNITY_SWITCH && !UNITY_EDITOR
// 阻止用户在保存时,退出游戏
// Switch 条例 0080
UnityEngine.Switch.Notification.EnterExitRequestHandlingSection();
#endif
// 使用封装函数检查和创建父目录
if (!EnsureParentDirectory(filePath, true))
{
UnityEngine.Debug.LogError($"无法确保父目录,文件写入取消: {filePath}");
return false;
}
//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 (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())
// 使用封装函数检查和创建父目录
if (!EnsureParentDirectory(filePath, true))
{
UnityEngine.Debug.LogError($"创建文件失败 {filePath} : " + result.GetErrorInfo());
UnityEngine.Debug.LogError($"无法确保父目录,文件写入取消: {filePath}");
return false;
}
}
else
UnityEngine.Debug.Log($"文件({filePath})存在,不必创建");
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)");
//string directoryPath = System.IO.Path.GetDirectoryName(filePath.Replace(save_path, ""));
//string fullDirectoryPath = $"{save_path}{directoryPath}";
//UnityEngine.Debug.Log($"检查父目录: {fullDirectoryPath}");
//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.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 (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());
return false;
}
//读取文件Handle
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);
nn.fs.File.Close(fileHandle);
#if UNITY_SWITCH && !UNITY_EDITOR
// 停止阻止用户退出游戏
UnityEngine.Switch.Notification.LeaveExitRequestHandlingSection();
#endif
if(immediatelyCommit)
{
//必须得提交,否则没有真实写入
return CommitSave();
}
else
{
SetCommitDirty();
return true;
}
if (immediatelyCommit)
{
//必须得提交,否则没有真实写入
return CommitSave();
}
else
{
SetCommitDirty();
return true;
}
#endif
}
}
@ -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
public bool GetDirectoryEntrysFullRecursion(string path, out string[] entrys)
{
#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))
@ -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;
}
#if UNITY_SWITCH && !UNITY_EDITOR
// End preventing the user from quitting the game while saving.
UnityEngine.Switch.Notification.LeaveExitRequestHandlingSection();
#endif
return CommitSave();
#endif
var wait = new AxiNSWait_DeletePathDirRecursively(filename);
AxiNS.instance.wait.AddWait(wait);
return wait;
}
#endif
public bool RenameDir(string oldpath, string newpath)
{

View File

@ -64,6 +64,10 @@ namespace AxibugEmuOnline.Client.ClientCore
#else
Application.persistentDataPath;
#endif
public static string PersistentDataRootPath()
{
return s_persistentRoot;
}
public static string PersistentDataPath(RomPlatformType emuPlatform)
{

View File

@ -1,19 +1,20 @@
using System.Collections.Generic;
using UnityEngine;
namespace AxiIO
{
public static class AxiIO
{
static IAxiIO m_io;
public static IAxiIO io
public static IAxiIO io
{
get
{
//Debug.Log("[AxiIO]");
if (m_io == null)
{
#if UNITY_SWITCH && !UNITY_EDITOR
m_io = new NSwitchIO();
m_io = new NSwitchIO();
#else
m_io = new CSharpIO();
#endif

View File

@ -1,2 +1,11 @@
fileFormatVersion: 2
guid: 32f63f62398d8184590292135b011084
guid: 32f63f62398d8184590292135b011084
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -5,8 +5,12 @@ using System.IO;
namespace AxiIO
{
public class CSharpIO : IAxiIO
{
public void dir_CreateDirectory(string dirpath)
{
public void Ping()
{
throw new NotImplementedException();
}
public void dir_CreateDirectory(string dirpath)
{
System.IO.Directory.CreateDirectory(dirpath);
}
@ -72,5 +76,6 @@ namespace AxiIO
{
return System.IO.Directory.GetFiles(path);
}
}
}
}

View File

@ -1,2 +1,11 @@
fileFormatVersion: 2
guid: f01df62ce36a4da4f9a20b4758d59102
guid: f01df62ce36a4da4f9a20b4758d59102
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -23,5 +23,6 @@ namespace AxiIO
int file_ReadBytesToArr(string filePath, byte[] readToArr, int start, int len);
string[] dir_GetDirectories(string path);
string[] dir_GetFiles(string path);
};
void Ping();
};
}

View File

@ -1,2 +1,11 @@
fileFormatVersion: 2
guid: 588eae2a7e121cc40907d8ac6f4250d4
guid: 588eae2a7e121cc40907d8ac6f4250d4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,89 +1,127 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace AxiIO
{
public class NSwitchIO : IAxiIO
{
public NSwitchIO()
{
AxiNS.instance.Init();
}
public void dir_CreateDirectory(string dirpath)
{
AxiNS.instance.io.CreateDir(dirpath);
}
public class NSwitchIO : IAxiIO
{
public NSwitchIO()
{
Debug.Log($"NSwitchIO Init");
//return;
AxiNS.instance.Init();
}
public void dir_Delete(string path, bool recursive)
{
AxiNS.instance.io.DeletePathFile(path);
}
public void Ping()
{
throw new NotImplementedException();
}
public void dir_CreateDirectory(string dirpath)
{
//Debug.Log($"dir_CreateDirectory");
//return;
AxiNS.instance.io.CreateDir(dirpath);
}
public IEnumerable<string> dir_EnumerateFiles(string path, string searchPattern)
{
return AxiNS.instance.io.EnumerateFiles(path, searchPattern);
}
public void dir_Delete(string path, bool recursive)
{
//Debug.Log($"dir_Delete recursive:{recursive}");
//return;
if (recursive)
AxiNS.instance.io.DeletePathDirRecursively(path);
else
AxiNS.instance.io.DeletePathDir(path);
}
public bool dir_Exists(string dirpath)
{
return AxiNS.instance.io.CheckPathExists(dirpath);
}
public IEnumerable<string> dir_EnumerateFiles(string path, string searchPattern)
{
//Debug.Log($"dir_EnumerateFiles path=>{path} searchPattern=>{searchPattern}");
//return default;
return AxiNS.instance.io.EnumerateFiles(path, searchPattern);
}
public string[] dir_GetDirectories(string path)
{
if (!AxiNS.instance.io.GetDirectoryDirs(path, out string[] result))
{
return new string[0];
}
return result;
}
public bool dir_Exists(string dirpath)
{
//Debug.Log($"dir_Exists path=>{dirpath}");
//return default;
return AxiNS.instance.io.CheckPathExists(dirpath);
}
public string[] dir_GetFiles(string path)
{
if (!AxiNS.instance.io.GetDirectoryFiles(path, out string[] result))
{
return new string[0];
}
return result;
}
public string[] dir_GetDirectories(string path)
{
//Debug.Log($"dir_GetDirectories path=>{path}");
//return default;
if (!AxiNS.instance.io.GetDirectoryDirs(path, out string[] result))
{
return new string[0];
}
return result;
}
public void file_Delete(string filePath)
{
AxiNS.instance.io.DeletePathFile(filePath);
}
public string[] dir_GetFiles(string path)
{
//Debug.Log($"dir_GetFiles path=>{path}");
//return default;
if (!AxiNS.instance.io.GetDirectoryFiles(path, out string[] result))
{
return new string[0];
}
return result;
}
public bool file_Exists(string filePath)
{
return AxiNS.instance.io.CheckPathExists(filePath);
}
public void file_Delete(string filePath)
{
//Debug.Log($"file_Delete path=>{filePath}");
//return;
AxiNS.instance.io.DeletePathFile(filePath);
}
public byte[] file_ReadAllBytes(string filePath)
{
return AxiNS.instance.io.LoadSwitchDataFile(filePath);
}
public bool file_Exists(string filePath)
{
//Debug.Log($"file_Exists path=>{filePath}");
//return default;
bool result = AxiNS.instance.io.CheckPathExists(filePath);
//Debug.Log($"file_Exists path=>{filePath} result=>{result}");
return result;
}
public int file_ReadBytesToArr(string filePath, byte[] readToArr, int start, int len)
{
byte[] bytes = file_ReadAllBytes(filePath);
int templen = Math.Min(len, bytes.Length);
Array.Copy(readToArr, readToArr, len);
return templen;
}
public byte[] file_ReadAllBytes(string filePath)
{
//Debug.Log($"file_ReadAllBytes path=>{filePath}");
//return default;
return AxiNS.instance.io.LoadSwitchDataFile(filePath);
}
/// <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)
{
AxiNS.instance.io.FileToSaveWithCreate(filePath, data);
}
public int file_ReadBytesToArr(string filePath, byte[] readToArr, int start, int len)
{
//Debug.Log($"file_ReadBytesToArr filePath=>{filePath},readToArr.Length=>{readToArr.Length},start=>{start},len=>{len}");
//return default;
byte[] bytes = file_ReadAllBytes(filePath);
int templen = Math.Min(len, bytes.Length);
Array.Copy(readToArr, readToArr, len);
return templen;
}
public void file_WriteAllBytes(string filePath, System.IO.MemoryStream ms)
{
AxiNS.instance.io.FileToSaveWithCreate(filePath, ms);
}
}
/// <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)
{
//Debug.Log($"file_WriteAllBytes filePath=>{filePath},data.Length=>{data.Length},immediatelyCommit=>{immediatelyCommit}");
//return;
AxiNS.instance.io.FileToSaveWithCreate(filePath, data, immediatelyCommit);
}
public void file_WriteAllBytes(string filePath, System.IO.MemoryStream ms)
{
//Debug.Log($"file_WriteAllBytes filePath=>{filePath},ms.Length=>{ms.Length}");
//return;
AxiNS.instance.io.FileToSaveWithCreate(filePath, ms);
}
}
}

View File

@ -1,2 +1,11 @@
fileFormatVersion: 2
guid: 3da9b14bf7568f34989774dc5f5fbcf4
guid: 3da9b14bf7568f34989774dc5f5fbcf4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a68ab2d5a12fb19428369238ea0fe27f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,44 @@
using AxibugEmuOnline.Client.ClientCore;
public static class AxiPlayerPrefs
{
//#if UNITY_SWITCH && !UNITY_EDITOR
// public static string SaveDataRootDirPath = "save:/axibug";
//#elif UNITY_PSP2 && !UNITY_EDITOR
// public static string SaveDataRootDirPath = "ux0:data/axibug";
//#else
// public static string SaveDataRootDirPath = UnityEngine.Application.persistentDataPath;
//#endif
//使用统一的平台宏区分目录
public static string SaveDataRootDirPath => App.PersistentDataRootPath();
static IAxiPlayerPrefs m_axiPlayerPrefs;
static IAxiPlayerPrefs axiPlayerPrefs
{
get
{
if (m_axiPlayerPrefs == null)
{
#if UNITY_SWITCH || UNITY_PSP2
m_axiPlayerPrefs = new AxiPlayerPrefsForFileSystem();
#else
m_axiPlayerPrefs = new AxiPlayerPrefsForUnity();
#endif
}
return m_axiPlayerPrefs;
}
}
public static float GetFloat(string key) { return axiPlayerPrefs.GetFloat(key); }
public static void SetFloat(string key, float value) { axiPlayerPrefs.SetFloat(key, value); }
public static float GetFloat(string key, float defaultValue) { return axiPlayerPrefs.GetFloat(key, defaultValue); }
public static int GetInt(string key) { return axiPlayerPrefs.GetInt(key); }
public static void SetInt(string key, int value) { axiPlayerPrefs.SetInt(key, value); }
public static int GetInt(string key, int defaultValue) { return axiPlayerPrefs.GetInt(key, defaultValue); }
public static string GetString(string key) { return axiPlayerPrefs.GetString(key); }
public static void SetString(string key, string value) { axiPlayerPrefs.SetString(key, value); }
public static string GetString(string key, string defaultValue) { return axiPlayerPrefs.GetString(key, defaultValue); }
internal static void DeleteAll() { axiPlayerPrefs.DeleteAll(); }
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 71c6edecb09ea914b90fa115b491698d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,162 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public abstract class AxiPlayerPrefsFileBase : IAxiPlayerPrefs
{
protected static string AxiPlayerPrefsFilePath => AxiPlayerPrefs.SaveDataRootDirPath + "/AxiPlayerPrefs.dat";
Dictionary<string, AxiPlayerPrefsKeyValye> m_keyval = new Dictionary<string, AxiPlayerPrefsKeyValye>();
Func<Dictionary<string, AxiPlayerPrefsKeyValye>> m_LoadFunc;
Action<Dictionary<string, AxiPlayerPrefsKeyValye>> m_SaveFunc;
bool bDirty = false;
[Serializable]
public class AxiPlayerPrefsAllData
{
public int version;
public List<AxiPlayerPrefsKeyValye> datalist;
}
[Serializable]
public class AxiPlayerPrefsKeyValye
{
public string key;
public int intval;
public string strval;
public float floatval;
}
public AxiPlayerPrefsFileBase(Func<Dictionary<string, AxiPlayerPrefsKeyValye>> load, Action<Dictionary<string, AxiPlayerPrefsKeyValye>> save)
{
m_LoadFunc = load;
m_SaveFunc = save;
Load();
AxiPlayerPrefsMono.SetInvoke(Save, 15);
}
public static Dictionary<string, AxiPlayerPrefsKeyValye> JsonStrToData(string dataStr)
{
AxiPlayerPrefsAllData alldata = UnityEngine.JsonUtility.FromJson<AxiPlayerPrefsAllData>(dataStr);
Dictionary<string, AxiPlayerPrefsKeyValye> data = new Dictionary<string, AxiPlayerPrefsKeyValye>();
foreach (var item in alldata.datalist)
{
data.Add(item.key, item);
}
return data;
}
public static string DataToJsonStr(Dictionary<string, AxiPlayerPrefsKeyValye> data)
{
return UnityEngine.JsonUtility.ToJson(new AxiPlayerPrefsAllData() { version = 1, datalist = data.Values.ToList() });
}
AxiPlayerPrefsKeyValye GetByKey(string key, bool NonAutoCreate, out bool IsNew)
{
//Debug.Log($"GetByKey=>{key}");
if (!m_keyval.ContainsKey(key))
{
IsNew = true;
if (!NonAutoCreate)
return null;
m_keyval.Add(key, new AxiPlayerPrefsKeyValye() { key = key });
}
else
IsNew = false;
return m_keyval[key];
}
public void Load()
{
m_keyval = m_LoadFunc.Invoke();
}
public void Save()
{
if (bDirty)
{
Debug.Log("Auto AxiPlayerPrefs.");
bDirty = false;
m_SaveFunc.Invoke(m_keyval);
}
}
public float GetFloat(string key, float defaultValue)
{
AxiPlayerPrefsKeyValye kv = GetByKey(key, true, out bool IsNew);
if (IsNew)
kv.floatval = defaultValue;
return kv.floatval;
}
public int GetInt(string key, int defaultValue)
{
AxiPlayerPrefsKeyValye kv = GetByKey(key, true, out bool IsNew);
if (IsNew)
kv.intval = defaultValue;
return kv.intval;
}
public string GetString(string key, string defaultValue)
{
AxiPlayerPrefsKeyValye kv = GetByKey(key, true, out bool IsNew);
if (IsNew)
kv.strval = defaultValue;
return kv.strval;
}
public float GetFloat(string key)
{
AxiPlayerPrefsKeyValye kv = GetByKey(key, false, out bool _);
if (kv != null) return kv.floatval;
return default(float);
}
public int GetInt(string key)
{
AxiPlayerPrefsKeyValye kv = GetByKey(key, false, out bool _);
if (kv != null) return kv.intval;
return default(int);
}
public string GetString(string key)
{
AxiPlayerPrefsKeyValye kv = GetByKey(key, false, out bool _);
if (kv != null) return kv.strval;
return string.Empty;
}
public void SetInt(string key, int value)
{
AxiPlayerPrefsKeyValye kv = GetByKey(key, true, out bool _);
if (kv.intval == value)
return;
kv.intval = value;
bDirty = true;
}
public void SetString(string key, string value)
{
AxiPlayerPrefsKeyValye kv = GetByKey(key, true, out bool _);
if (string.Equals(kv.strval, value))
return;
kv.strval = value;
bDirty = true;
}
public void SetFloat(string key, float value)
{
AxiPlayerPrefsKeyValye kv = GetByKey(key, true, out bool _);
if (kv.floatval == value)
return;
kv.floatval = value;
bDirty = true;
}
public void DeleteAll()
{
m_keyval.Clear();
bDirty = true;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4085aa85cd82706448a25a172cd681a0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,48 @@
using System.Collections.Generic;
using UnityEngine;
public class AxiPlayerPrefsForFileSystem : AxiPlayerPrefsFileBase
{
public AxiPlayerPrefsForFileSystem() : base(LoadData, SaveData)
{
Debug.Log($"AxiPlayerPrefsForFileSystem Init");
}
protected static Dictionary<string, AxiPlayerPrefsKeyValye> LoadData()
{
if (!AxiIO.AxiIO.io.file_Exists(AxiPlayerPrefsFilePath))
return new Dictionary<string, AxiPlayerPrefsKeyValye>();
else
{
string outputData = string.Empty;
byte[] loadedData = AxiIO.AxiIO.io.file_ReadAllBytes(AxiPlayerPrefsFilePath);
if (loadedData != null && loadedData.Length != 0)
{
using (System.IO.MemoryStream stream = new System.IO.MemoryStream(loadedData))
{
using (System.IO.BinaryReader reader = new System.IO.BinaryReader(stream))
{
outputData = reader.ReadString();
}
}
}
if (string.IsNullOrEmpty(outputData))
return new Dictionary<string, AxiPlayerPrefsKeyValye>();
return AxiPlayerPrefsFileBase.JsonStrToData(outputData);
}
}
protected static void SaveData(Dictionary<string, AxiPlayerPrefsKeyValye> data)
{
string jsonStr = AxiPlayerPrefsFileBase.DataToJsonStr(data);
byte[] dataByteArray;
using (System.IO.MemoryStream stream = new System.IO.MemoryStream(jsonStr.Length * sizeof(char)))
{
System.IO.BinaryWriter binaryWriter = new System.IO.BinaryWriter(stream);
binaryWriter.Write(jsonStr);
dataByteArray = stream.GetBuffer();
stream.Close();
}
AxiIO.AxiIO.io.file_WriteAllBytes(AxiPlayerPrefsFilePath, dataByteArray, false);
}
}

View File

@ -0,0 +1,55 @@

using UnityEngine;
public class AxiPlayerPrefsForUnity : IAxiPlayerPrefs
{
public string GetString(string key, string defaultValue)
{
return PlayerPrefs.GetString(key, defaultValue);
}
public void SetString(string key, string value)
{
PlayerPrefs.SetString(key, value);
}
public int GetInt(string key, int defaultValue)
{
return PlayerPrefs.GetInt(key, defaultValue);
}
public void SetInt(string key, int value)
{
PlayerPrefs.SetInt(key, value);
}
public float GetFloat(string key, float defaultValue)
{
return PlayerPrefs.GetFloat(key, defaultValue);
}
public float GetFloat(string key)
{
return PlayerPrefs.GetFloat(key);
}
public int GetInt(string key)
{
return PlayerPrefs.GetInt(key);
}
public string GetString(string key)
{
return PlayerPrefs.GetString(key);
}
public void SetFloat(string key, float value)
{
PlayerPrefs.SetFloat(key,value);
}
public void DeleteAll()
{
PlayerPrefs.DeleteAll();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 94efbbb58793f1146b395c1ebfe19d33
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,39 @@
using System;
using UnityEngine;
public class AxiPlayerPrefsMono : MonoBehaviour
{
Action act;
float waittime;
float lastinvokeTime;
public static void SetInvoke(Action _act, int _waitsec)
{
GameObject gobj = GameObject.Find($"[{nameof(AxiPlayerPrefsMono)}]");
if (gobj == null)
{
gobj = new GameObject();
gobj.name = $"[{nameof(AxiPlayerPrefsMono)}]";
GameObject.DontDestroyOnLoad(gobj);
}
AxiPlayerPrefsMono com = gobj.GetComponent<AxiPlayerPrefsMono>();
if (com == null)
{
com = gobj.AddComponent<AxiPlayerPrefsMono>();
}
com.act = _act;
com.waittime = _waitsec;
}
public void OnEnable()
{
Debug.Log("AxiPlayerPrefsMono Enable");
}
public void Update()
{
if (Time.time - lastinvokeTime < waittime)
return;
lastinvokeTime = Time.time;
if (act != null)
act.Invoke();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8fff109e9498ef549a7d124a24894a98
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,13 @@
public interface IAxiPlayerPrefs
{
void DeleteAll();
float GetFloat(string key, float defaultValue);
float GetFloat(string key);
int GetInt(string key, int defaultValue);
int GetInt(string key);
string GetString(string key);
string GetString(string key, string defaultValue);
void SetFloat(string key, float value);
void SetInt(string key, int value);
void SetString(string key, string value);
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e194ccb9ac1dc984da8922b7c67ec879
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -14,9 +14,9 @@ namespace AxibugEmuOnline.Client.Settings
{
get
{
var color1 = PlayerPrefs.GetString($"{nameof(BgColorSettings)}.{nameof(CurrentColor)}.{nameof(CurrentColor.color1)}", null);
var color2 = PlayerPrefs.GetString($"{nameof(BgColorSettings)}.{nameof(CurrentColor)}.{nameof(CurrentColor.color2)}", null);
var name = PlayerPrefs.GetString($"{nameof(BgColorSettings)}.{nameof(CurrentColor)}.{nameof(CurrentColor.Name)}", null);
var color1 = AxiPlayerPrefs.GetString($"{nameof(BgColorSettings)}.{nameof(CurrentColor)}.{nameof(CurrentColor.color1)}", null);
var color2 = AxiPlayerPrefs.GetString($"{nameof(BgColorSettings)}.{nameof(CurrentColor)}.{nameof(CurrentColor.color2)}", null);
var name = AxiPlayerPrefs.GetString($"{nameof(BgColorSettings)}.{nameof(CurrentColor)}.{nameof(CurrentColor.Name)}", null);
if (string.IsNullOrWhiteSpace(color1) || string.IsNullOrWhiteSpace(color2) || string.IsNullOrWhiteSpace(name))
return DEFAULT;
else
@ -24,9 +24,9 @@ namespace AxibugEmuOnline.Client.Settings
}
set
{
PlayerPrefs.SetString($"{nameof(BgColorSettings)}.{nameof(CurrentColor)}.{nameof(CurrentColor.color1)}", $"#{ColorUtility.ToHtmlStringRGB(value.color1)}");
PlayerPrefs.SetString($"{nameof(BgColorSettings)}.{nameof(CurrentColor)}.{nameof(CurrentColor.color2)}", $"#{ColorUtility.ToHtmlStringRGB(value.color2)}");
PlayerPrefs.SetString($"{nameof(BgColorSettings)}.{nameof(CurrentColor)}.{nameof(CurrentColor.Name)}", value.Name);
AxiPlayerPrefs.SetString($"{nameof(BgColorSettings)}.{nameof(CurrentColor)}.{nameof(CurrentColor.color1)}", $"#{ColorUtility.ToHtmlStringRGB(value.color1)}");
AxiPlayerPrefs.SetString($"{nameof(BgColorSettings)}.{nameof(CurrentColor)}.{nameof(CurrentColor.color2)}", $"#{ColorUtility.ToHtmlStringRGB(value.color2)}");
AxiPlayerPrefs.SetString($"{nameof(BgColorSettings)}.{nameof(CurrentColor)}.{nameof(CurrentColor.Name)}", value.Name);
OnColorChanged?.Invoke(value);
}

View File

@ -25,7 +25,7 @@ namespace AxibugEmuOnline.Client.Settings
public FilterManager()
{
loadFilters();
var json = PlayerPrefs.GetString(nameof(FilterRomSetting));
var json = AxiPlayerPrefs.GetString(nameof(FilterRomSetting));
m_filterRomSetting = JsonUtility.FromJson<FilterRomSetting>(json) ?? new FilterRomSetting();
}
@ -152,7 +152,7 @@ namespace AxibugEmuOnline.Client.Settings
m_filterRomSetting.Setup(rom, filter, preset);
string json = m_filterRomSetting.ToJson();
PlayerPrefs.SetString(nameof(FilterRomSetting), json);
AxiPlayerPrefs.SetString(nameof(FilterRomSetting), json);
}
/// <summary>
@ -214,7 +214,7 @@ namespace AxibugEmuOnline.Client.Settings
private void loadPresets()
{
var json = PlayerPrefs.GetString($"Filter_{Name}_PresetList", string.Empty);
var json = AxiPlayerPrefs.GetString($"Filter_{Name}_PresetList", string.Empty);
var loadedPresets = JsonUtility.FromJson<FilterPresetList>(json);
if (loadedPresets == null) return;
else Presets = loadedPresets.presets;
@ -223,7 +223,7 @@ namespace AxibugEmuOnline.Client.Settings
public void SavePresets()
{
var json = JsonUtility.ToJson(new FilterPresetList(Presets));
PlayerPrefs.SetString($"Filter_{Name}_PresetList", json);
AxiPlayerPrefs.SetString($"Filter_{Name}_PresetList", json);
}
public MsgBool CreatePreset(string presetName, out FilterPreset newPreset)

View File

@ -14,8 +14,8 @@ namespace AxibugEmuOnline.Client.Settings
/// </summary>
public EnumScalerMode GlobalMode
{
get => (EnumScalerMode)PlayerPrefs.GetInt($"{nameof(ScreenScaler)}.GlobalMode", 0);
set => PlayerPrefs.SetInt($"{nameof(ScreenScaler)}.GlobalMode", (int)value);
get => (EnumScalerMode)AxiPlayerPrefs.GetInt($"{nameof(ScreenScaler)}.GlobalMode", 0);
set => AxiPlayerPrefs.SetInt($"{nameof(ScreenScaler)}.GlobalMode", (int)value);
}
/// <summary>
@ -25,7 +25,7 @@ namespace AxibugEmuOnline.Client.Settings
/// <returns></returns>
public EnumScalerMode GetMode(RomPlatformType platform)
{
int setVal = PlayerPrefs.GetInt($"{nameof(ScreenScaler)}.PlatMode.{platform}", -1);
int setVal = AxiPlayerPrefs.GetInt($"{nameof(ScreenScaler)}.PlatMode.{platform}", -1);
if (setVal == -1)
return GlobalMode;
else
@ -34,14 +34,14 @@ namespace AxibugEmuOnline.Client.Settings
public bool IsSetMode(RomPlatformType platform)
{
int setVal = PlayerPrefs.GetInt($"{nameof(ScreenScaler)}.PlatMode.{platform}", -1);
int setVal = AxiPlayerPrefs.GetInt($"{nameof(ScreenScaler)}.PlatMode.{platform}", -1);
return setVal != -1;
}
public void SetMode(RomPlatformType platform, EnumScalerMode? mode)
{
int setVal = mode == null ? -1 : (int)mode;
PlayerPrefs.SetInt($"{nameof(ScreenScaler)}.PlatMode.{platform}", setVal);
AxiPlayerPrefs.SetInt($"{nameof(ScreenScaler)}.PlatMode.{platform}", setVal);
}
/// <summary>