完善AxiIO为Switch可用且健壮的代码
This commit is contained in:
parent
7b40e190d0
commit
20b3d2e8ef
@ -64,6 +64,10 @@ namespace AxibugEmuOnline.Client.ClientCore
|
|||||||
#else
|
#else
|
||||||
Application.persistentDataPath;
|
Application.persistentDataPath;
|
||||||
#endif
|
#endif
|
||||||
|
public static string PersistentDataRootPath()
|
||||||
|
{
|
||||||
|
return s_persistentRoot;
|
||||||
|
}
|
||||||
|
|
||||||
public static string PersistentDataPath(RomPlatformType emuPlatform)
|
public static string PersistentDataPath(RomPlatformType emuPlatform)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,19 +1,20 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace AxiIO
|
namespace AxiIO
|
||||||
{
|
{
|
||||||
|
|
||||||
public static class AxiIO
|
public static class AxiIO
|
||||||
{
|
{
|
||||||
static IAxiIO m_io;
|
static IAxiIO m_io;
|
||||||
public static IAxiIO io
|
public static IAxiIO io
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
//Debug.Log("[AxiIO]");
|
||||||
if (m_io == null)
|
if (m_io == null)
|
||||||
{
|
{
|
||||||
#if UNITY_SWITCH && !UNITY_EDITOR
|
#if UNITY_SWITCH && !UNITY_EDITOR
|
||||||
m_io = new NSwitchIO();
|
m_io = new NSwitchIO();
|
||||||
#else
|
#else
|
||||||
m_io = new CSharpIO();
|
m_io = new CSharpIO();
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -1,2 +1,11 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 32f63f62398d8184590292135b011084
|
guid: 32f63f62398d8184590292135b011084
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
|||||||
@ -5,8 +5,12 @@ using System.IO;
|
|||||||
namespace AxiIO
|
namespace AxiIO
|
||||||
{
|
{
|
||||||
public class CSharpIO : IAxiIO
|
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);
|
System.IO.Directory.CreateDirectory(dirpath);
|
||||||
}
|
}
|
||||||
@ -72,5 +76,6 @@ namespace AxiIO
|
|||||||
{
|
{
|
||||||
return System.IO.Directory.GetFiles(path);
|
return System.IO.Directory.GetFiles(path);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -1,2 +1,11 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: f01df62ce36a4da4f9a20b4758d59102
|
guid: f01df62ce36a4da4f9a20b4758d59102
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
|||||||
@ -23,5 +23,6 @@ namespace AxiIO
|
|||||||
int file_ReadBytesToArr(string filePath, byte[] readToArr, int start, int len);
|
int file_ReadBytesToArr(string filePath, byte[] readToArr, int start, int len);
|
||||||
string[] dir_GetDirectories(string path);
|
string[] dir_GetDirectories(string path);
|
||||||
string[] dir_GetFiles(string path);
|
string[] dir_GetFiles(string path);
|
||||||
};
|
void Ping();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
@ -1,2 +1,11 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 588eae2a7e121cc40907d8ac6f4250d4
|
guid: 588eae2a7e121cc40907d8ac6f4250d4
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
|||||||
@ -1,89 +1,127 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace AxiIO
|
namespace AxiIO
|
||||||
{
|
{
|
||||||
public class NSwitchIO : IAxiIO
|
public class NSwitchIO : IAxiIO
|
||||||
{
|
{
|
||||||
public NSwitchIO()
|
public NSwitchIO()
|
||||||
{
|
{
|
||||||
AxiNS.instance.Init();
|
Debug.Log($"NSwitchIO Init");
|
||||||
}
|
//return;
|
||||||
public void dir_CreateDirectory(string dirpath)
|
AxiNS.instance.Init();
|
||||||
{
|
}
|
||||||
AxiNS.instance.io.CreateDir(dirpath);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void dir_Delete(string path, bool recursive)
|
public void Ping()
|
||||||
{
|
{
|
||||||
AxiNS.instance.io.DeletePathFile(path);
|
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)
|
public void dir_Delete(string path, bool recursive)
|
||||||
{
|
{
|
||||||
return AxiNS.instance.io.EnumerateFiles(path, searchPattern);
|
//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)
|
public IEnumerable<string> dir_EnumerateFiles(string path, string searchPattern)
|
||||||
{
|
{
|
||||||
return AxiNS.instance.io.CheckPathExists(dirpath);
|
//Debug.Log($"dir_EnumerateFiles path=>{path} searchPattern=>{searchPattern}");
|
||||||
}
|
//return default;
|
||||||
|
return AxiNS.instance.io.EnumerateFiles(path, searchPattern);
|
||||||
|
}
|
||||||
|
|
||||||
public string[] dir_GetDirectories(string path)
|
public bool dir_Exists(string dirpath)
|
||||||
{
|
{
|
||||||
if (!AxiNS.instance.io.GetDirectoryDirs(path, out string[] result))
|
//Debug.Log($"dir_Exists path=>{dirpath}");
|
||||||
{
|
//return default;
|
||||||
return new string[0];
|
return AxiNS.instance.io.CheckPathExists(dirpath);
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string[] dir_GetFiles(string path)
|
public string[] dir_GetDirectories(string path)
|
||||||
{
|
{
|
||||||
if (!AxiNS.instance.io.GetDirectoryFiles(path, out string[] result))
|
//Debug.Log($"dir_GetDirectories path=>{path}");
|
||||||
{
|
//return default;
|
||||||
return new string[0];
|
if (!AxiNS.instance.io.GetDirectoryDirs(path, out string[] result))
|
||||||
}
|
{
|
||||||
return result;
|
return new string[0];
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public void file_Delete(string filePath)
|
public string[] dir_GetFiles(string path)
|
||||||
{
|
{
|
||||||
AxiNS.instance.io.DeletePathFile(filePath);
|
//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)
|
public void file_Delete(string filePath)
|
||||||
{
|
{
|
||||||
return AxiNS.instance.io.CheckPathExists(filePath);
|
//Debug.Log($"file_Delete path=>{filePath}");
|
||||||
}
|
//return;
|
||||||
|
AxiNS.instance.io.DeletePathFile(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
public byte[] file_ReadAllBytes(string filePath)
|
public bool file_Exists(string filePath)
|
||||||
{
|
{
|
||||||
return AxiNS.instance.io.LoadSwitchDataFile(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)
|
public byte[] file_ReadAllBytes(string filePath)
|
||||||
{
|
{
|
||||||
byte[] bytes = file_ReadAllBytes(filePath);
|
//Debug.Log($"file_ReadAllBytes path=>{filePath}");
|
||||||
int templen = Math.Min(len, bytes.Length);
|
//return default;
|
||||||
Array.Copy(readToArr, readToArr, len);
|
return AxiNS.instance.io.LoadSwitchDataFile(filePath);
|
||||||
return templen;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
public int file_ReadBytesToArr(string filePath, byte[] readToArr, int start, int len)
|
||||||
///
|
{
|
||||||
/// </summary>
|
//Debug.Log($"file_ReadBytesToArr filePath=>{filePath},readToArr.Length=>{readToArr.Length},start=>{start},len=>{len}");
|
||||||
/// <param name="filePath"></param>
|
//return default;
|
||||||
/// <param name="data"></param>
|
byte[] bytes = file_ReadAllBytes(filePath);
|
||||||
/// <param name="immediatelyCommit">是否立即Commit到物理存储</param>
|
int templen = Math.Min(len, bytes.Length);
|
||||||
public void file_WriteAllBytes(string filePath, byte[] data, bool immediatelyCommit = true)
|
Array.Copy(readToArr, readToArr, len);
|
||||||
{
|
return templen;
|
||||||
AxiNS.instance.io.FileToSaveWithCreate(filePath, data);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void file_WriteAllBytes(string filePath, System.IO.MemoryStream ms)
|
/// <summary>
|
||||||
{
|
///
|
||||||
AxiNS.instance.io.FileToSaveWithCreate(filePath, ms);
|
/// </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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -1,2 +1,11 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 3da9b14bf7568f34989774dc5f5fbcf4
|
guid: 3da9b14bf7568f34989774dc5f5fbcf4
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
|||||||
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a68ab2d5a12fb19428369238ea0fe27f
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -14,9 +14,9 @@ namespace AxibugEmuOnline.Client.Settings
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var color1 = PlayerPrefs.GetString($"{nameof(BgColorSettings)}.{nameof(CurrentColor)}.{nameof(CurrentColor.color1)}", null);
|
var color1 = AxiPlayerPrefs.GetString($"{nameof(BgColorSettings)}.{nameof(CurrentColor)}.{nameof(CurrentColor.color1)}", null);
|
||||||
var color2 = PlayerPrefs.GetString($"{nameof(BgColorSettings)}.{nameof(CurrentColor)}.{nameof(CurrentColor.color2)}", null);
|
var color2 = AxiPlayerPrefs.GetString($"{nameof(BgColorSettings)}.{nameof(CurrentColor)}.{nameof(CurrentColor.color2)}", null);
|
||||||
var name = PlayerPrefs.GetString($"{nameof(BgColorSettings)}.{nameof(CurrentColor)}.{nameof(CurrentColor.Name)}", null);
|
var name = AxiPlayerPrefs.GetString($"{nameof(BgColorSettings)}.{nameof(CurrentColor)}.{nameof(CurrentColor.Name)}", null);
|
||||||
if (string.IsNullOrWhiteSpace(color1) || string.IsNullOrWhiteSpace(color2) || string.IsNullOrWhiteSpace(name))
|
if (string.IsNullOrWhiteSpace(color1) || string.IsNullOrWhiteSpace(color2) || string.IsNullOrWhiteSpace(name))
|
||||||
return DEFAULT;
|
return DEFAULT;
|
||||||
else
|
else
|
||||||
@ -24,9 +24,9 @@ namespace AxibugEmuOnline.Client.Settings
|
|||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
PlayerPrefs.SetString($"{nameof(BgColorSettings)}.{nameof(CurrentColor)}.{nameof(CurrentColor.color1)}", $"#{ColorUtility.ToHtmlStringRGB(value.color1)}");
|
AxiPlayerPrefs.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)}");
|
AxiPlayerPrefs.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.Name)}", value.Name);
|
||||||
|
|
||||||
OnColorChanged?.Invoke(value);
|
OnColorChanged?.Invoke(value);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,7 +25,7 @@ namespace AxibugEmuOnline.Client.Settings
|
|||||||
public FilterManager()
|
public FilterManager()
|
||||||
{
|
{
|
||||||
loadFilters();
|
loadFilters();
|
||||||
var json = PlayerPrefs.GetString(nameof(FilterRomSetting));
|
var json = AxiPlayerPrefs.GetString(nameof(FilterRomSetting));
|
||||||
m_filterRomSetting = JsonUtility.FromJson<FilterRomSetting>(json) ?? new FilterRomSetting();
|
m_filterRomSetting = JsonUtility.FromJson<FilterRomSetting>(json) ?? new FilterRomSetting();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ namespace AxibugEmuOnline.Client.Settings
|
|||||||
m_filterRomSetting.Setup(rom, filter, preset);
|
m_filterRomSetting.Setup(rom, filter, preset);
|
||||||
|
|
||||||
string json = m_filterRomSetting.ToJson();
|
string json = m_filterRomSetting.ToJson();
|
||||||
PlayerPrefs.SetString(nameof(FilterRomSetting), json);
|
AxiPlayerPrefs.SetString(nameof(FilterRomSetting), json);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -214,7 +214,7 @@ namespace AxibugEmuOnline.Client.Settings
|
|||||||
|
|
||||||
private void loadPresets()
|
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);
|
var loadedPresets = JsonUtility.FromJson<FilterPresetList>(json);
|
||||||
if (loadedPresets == null) return;
|
if (loadedPresets == null) return;
|
||||||
else Presets = loadedPresets.presets;
|
else Presets = loadedPresets.presets;
|
||||||
@ -223,7 +223,7 @@ namespace AxibugEmuOnline.Client.Settings
|
|||||||
public void SavePresets()
|
public void SavePresets()
|
||||||
{
|
{
|
||||||
var json = JsonUtility.ToJson(new FilterPresetList(Presets));
|
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)
|
public MsgBool CreatePreset(string presetName, out FilterPreset newPreset)
|
||||||
|
|||||||
@ -14,8 +14,8 @@ namespace AxibugEmuOnline.Client.Settings
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public EnumScalerMode GlobalMode
|
public EnumScalerMode GlobalMode
|
||||||
{
|
{
|
||||||
get => (EnumScalerMode)PlayerPrefs.GetInt($"{nameof(ScreenScaler)}.GlobalMode", 0);
|
get => (EnumScalerMode)AxiPlayerPrefs.GetInt($"{nameof(ScreenScaler)}.GlobalMode", 0);
|
||||||
set => PlayerPrefs.SetInt($"{nameof(ScreenScaler)}.GlobalMode", (int)value);
|
set => AxiPlayerPrefs.SetInt($"{nameof(ScreenScaler)}.GlobalMode", (int)value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -25,7 +25,7 @@ namespace AxibugEmuOnline.Client.Settings
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public EnumScalerMode GetMode(RomPlatformType platform)
|
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)
|
if (setVal == -1)
|
||||||
return GlobalMode;
|
return GlobalMode;
|
||||||
else
|
else
|
||||||
@ -34,14 +34,14 @@ namespace AxibugEmuOnline.Client.Settings
|
|||||||
|
|
||||||
public bool IsSetMode(RomPlatformType platform)
|
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;
|
return setVal != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetMode(RomPlatformType platform, EnumScalerMode? mode)
|
public void SetMode(RomPlatformType platform, EnumScalerMode? mode)
|
||||||
{
|
{
|
||||||
int setVal = mode == null ? -1 : (int)mode;
|
int setVal = mode == null ? -1 : (int)mode;
|
||||||
PlayerPrefs.SetInt($"{nameof(ScreenScaler)}.PlatMode.{platform}", setVal);
|
AxiPlayerPrefs.SetInt($"{nameof(ScreenScaler)}.PlatMode.{platform}", setVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user