除了核心之外的,已经包装了区分Switch和普通的IO

This commit is contained in:
sin365 2025-04-24 11:27:35 +08:00
parent ee9d54386b
commit d7fe849bb1
17 changed files with 3106 additions and 116 deletions

View File

@ -3,7 +3,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using UnityEditor; using UnityEditor;
@ -20,7 +19,17 @@ namespace AxibugEmuOnline.Editors
static Dictionary<string, string> tools = new Dictionary<string, string>(); static Dictionary<string, string> tools = new Dictionary<string, string>();
static string prodKeysPath; static string prodKeysPath;
[MenuItem("Axibug盧濂묏야/Switch/AxibugNSPTools/RepackNSP(쏭路劤뭐쉔NPS")] static void InitToolPath()
{
#region
// 获取环境变量(需要添加环境变量检查)
string sdkRoot = Environment.GetEnvironmentVariable("NINTENDO_SDK_ROOT");
tools["authoringTool"] = Path.Combine(sdkRoot, "Tools/CommandLineTools/AuthoringTool/AuthoringTool.exe");
tools["hacPack"] = Path.Combine(hacpack_root, "hacpack");
#endregion
}
[MenuItem("Axibug移植工具/Switch/AxibugNSPTools/RepackNSP(仅重新构建NSP")]
static void RepackNSP() static void RepackNSP()
{ {
if (!CheckEnvironmentVariable()) if (!CheckEnvironmentVariable())
@ -38,7 +47,29 @@ namespace AxibugEmuOnline.Editors
RepackNSP(path); RepackNSP(path);
} }
[MenuItem("Axibug盧濂묏야/Switch/AxibugNSPTools/Build With RepackNSP(댔관NSP깻路劤뭐쉔NPS")]
//[MenuItem("Axibug移植工具/Switch/AxibugNSPTools/UnpackNSP(解包工具)")]
//static void UnpackNSP()
//{
// InitToolPath();
// if (!CheckEnvironmentVariable())
// return;
// string nspFilePath = EditorUtility.OpenFilePanel(
// title: "选择 .nsp 文件",
// directory: Path.Combine(Application.dataPath, ".."), // 默认路径为项目 Assets 目录
// extension: "nsp" // 限制文件类型为 .nsp
// );
// if (string.IsNullOrEmpty(nspFilePath))
// return;
// string nspParentDir = Path.GetDirectoryName(nspFilePath);
// string extractPath = Path.Combine(nspParentDir, "repacker_extract");
// ExecuteCommand($"{tools["authoringTool"]} extract -o \"{extractPath}\" \"{nspFilePath}\"", nspParentDir);
//}
[MenuItem("Axibug移植工具/Switch/AxibugNSPTools/Build With RepackNSP(打包NSP并重新构建NSP")]
public static void BuildWithRepackNSP() public static void BuildWithRepackNSP()
{ {
if (!CheckEnvironmentVariable()) if (!CheckEnvironmentVariable())
@ -121,12 +152,7 @@ namespace AxibugEmuOnline.Editors
static void RepackNSP(string nspFile) static void RepackNSP(string nspFile)
{ {
#region InitToolPath();
// 삿혤뻔쓱긴좆(矜狼警속뻔쓱긴좆쇱꿴)
string sdkRoot = Environment.GetEnvironmentVariable("NINTENDO_SDK_ROOT");
tools["authoringTool"] = Path.Combine(sdkRoot, "Tools/CommandLineTools/AuthoringTool/AuthoringTool.exe");
tools["hacPack"] = Path.Combine(hacpack_root, "hacpack");
#endregion
#region ´¦ÀíNSPÎļþ·¾ #region ´¦ÀíNSPÎļþ·¾
string nspFilePath = nspFile; string nspFilePath = nspFile;

View File

@ -0,0 +1,3 @@
{
"name": "AxiNSApi"
}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: c8ad600c72d635843bd8aeb9d8aebfb8
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -62,6 +62,8 @@ public class AxiNSIO
#endif #endif
} }
/// <summary> /// <summary>
/// 保存并创建文件(如果目录不存在回先自动创建目录) /// 保存并创建文件(如果目录不存在回先自动创建目录)
/// </summary> /// </summary>
@ -208,7 +210,13 @@ public class AxiNSIO
AxiNS.instance.wait.AddWait(wait); AxiNS.instance.wait.AddWait(wait);
return wait; return wait;
} }
public bool LoadSwitchDataFile(string filename, ref System.IO.MemoryStream ms) public byte[] LoadSwitchDataFile(string filename)
{
LoadSwitchDataFile(filename, out byte[] outputData);
return outputData;
}
public bool LoadSwitchDataFile(string filename, ref System.IO.MemoryStream ms)
{ {
if (LoadSwitchDataFile(filename, out byte[] outputData)) if (LoadSwitchDataFile(filename, out byte[] outputData))
{ {

View File

@ -5,7 +5,7 @@ using AxibugProtobuf;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; //using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using UnityEngine; using UnityEngine;
using static AxibugEmuOnline.Client.HttpAPI; using static AxibugEmuOnline.Client.HttpAPI;
@ -130,8 +130,10 @@ namespace AxibugEmuOnline.Client.ClientCore
private static void PSP2Init() private static void PSP2Init()
{ {
//PSVita最好手动创建目录 //PSVita最好手动创建目录
if (!Directory.Exists("ux0:data/AxibugEmu")) if (!AxiIO.Directory.Exists("ux0:data/AxibugEmu"))
Directory.CreateDirectory("ux0:data/AxibugEmu"); AxiIO.Directory.CreateDirectory("ux0:data/AxibugEmu");
//if (!Directory.Exists("ux0:data/AxibugEmu"))
// Directory.CreateDirectory("ux0:data/AxibugEmu");
#if UNITY_PSP2 #if UNITY_PSP2
//创建PSV弹窗UI //创建PSV弹窗UI

View File

@ -1,8 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO.Compression;
using System.IO.Compression;
using System.Net; using System.Net;
using System.Net.Security; using System.Net.Security;
using System.Net.Sockets; using System.Net.Sockets;
@ -162,7 +161,7 @@ public static class AxiHttp
public string fileName; public string fileName;
public float DownLoadPr => public float DownLoadPr =>
NeedloadedLenght <= 0 ? -1 : (float)loadedLenght / NeedloadedLenght; NeedloadedLenght <= 0 ? -1 : (float)loadedLenght / NeedloadedLenght;
public BinaryWriter binaryWriter; public System.IO.BinaryWriter binaryWriter;
} }
public static IPAddress GetDnsIP(string str) public static IPAddress GetDnsIP(string str)
@ -268,7 +267,7 @@ public static class AxiHttp
var ipEndPoint = new IPEndPoint(ip, port); var ipEndPoint = new IPEndPoint(ip, port);
using (Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) using (Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
using (MemoryStream memoryStream = new MemoryStream()) using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
{ {
client.Connect(ipEndPoint); client.Connect(ipEndPoint);
if (!client.Connected) if (!client.Connected)
@ -497,7 +496,7 @@ public static class AxiHttp
// 使用Uri类解析URL // 使用Uri类解析URL
Uri uri = new Uri(url); Uri uri = new Uri(url);
respinfo.fileName = Path.GetFileName(uri.LocalPath); respinfo.fileName = System.IO.Path.GetFileName(uri.LocalPath);
} }
else else
{ {
@ -567,7 +566,7 @@ public static class AxiHttp
//using (Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) //using (Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
//using (TcpClient tcpclient = new TcpClient()) //using (TcpClient tcpclient = new TcpClient())
using (MemoryStream memoryStream = new MemoryStream()) using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
{ {
//client.Connect(ipEndPoint); //client.Connect(ipEndPoint);
@ -780,7 +779,7 @@ public static class AxiHttp
// 使用Uri类解析URL // 使用Uri类解析URL
Uri uri = new Uri(url); Uri uri = new Uri(url);
respinfo.fileName = Path.GetFileName(uri.LocalPath); respinfo.fileName = System.IO.Path.GetFileName(uri.LocalPath);
} }
else else
{ {
@ -865,9 +864,9 @@ public static class AxiHttp
{ {
string str = ""; string str = "";
MemoryStream ms = new MemoryStream(data, 0, len); System.IO.MemoryStream ms = new System.IO.MemoryStream(data, 0, len);
GZipStream gs = new GZipStream(ms, CompressionMode.Decompress); GZipStream gs = new GZipStream(ms, CompressionMode.Decompress);
MemoryStream outbuf = new MemoryStream(); System.IO.MemoryStream outbuf = new System.IO.MemoryStream();
byte[] block = new byte[1024]; byte[] block = new byte[1024];
try try
@ -904,9 +903,9 @@ public static class AxiHttp
public static byte[] unGzipBytes(byte[] data, int len) public static byte[] unGzipBytes(byte[] data, int len)
{ {
MemoryStream ms = new MemoryStream(data, 0, len); System.IO.MemoryStream ms = new System.IO.MemoryStream(data, 0, len);
GZipStream gs = new GZipStream(ms, CompressionMode.Decompress); GZipStream gs = new GZipStream(ms, CompressionMode.Decompress);
MemoryStream outbuf = new MemoryStream(); System.IO.MemoryStream outbuf = new System.IO.MemoryStream();
byte[] block = new byte[1024]; byte[] block = new byte[1024];
byte[] result; byte[] result;
try try

View File

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

View File

@ -0,0 +1,190 @@
using DG.Tweening.Plugins.Core.PathCore;
using System;
using System.Collections.Generic;
using System.IO;
using Unity.Android.Gradle.Manifest;
using UnityEngine;
using static UnityEngine.Analytics.IAnalytic;
namespace AxiIO
{
public interface IAxiIO
{
bool dir_Exists(string dirpath);
void dir_CreateDirectory(string dirpath);
IEnumerable<string> dir_EnumerateFiles(string path, string searchPattern);
void dir_Delete(string path, bool recursive);
byte[] file_ReadAllBytes(string filePath);
bool file_Exists(string filePath);
void file_Delete(string filePath);
void file_WriteAllBytes(string filePath, byte[] data);
void file_WriteAllBytes(string filePath, System.IO.MemoryStream ms);
};
public class CSharpIO : IAxiIO
{
public void dir_CreateDirectory(string dirpath)
{
System.IO.Directory.CreateDirectory(dirpath);
}
public void dir_Delete(string path, bool recursive)
{
System.IO.Directory.Delete(path, recursive);
}
public IEnumerable<string> dir_EnumerateFiles(string path, string searchPattern)
{
return System.IO.Directory.EnumerateFiles(path, searchPattern);
}
public bool dir_Exists(string dirpath)
{
return System.IO.Directory.Exists(dirpath);
}
public void file_WriteAllBytes(string filePath, byte[] data)
{
System.IO.File.WriteAllBytes(filePath, data);
}
public void file_WriteAllBytes(string filePath, MemoryStream ms)
{
System.IO.File.WriteAllBytes(filePath, ms.ToArray());
}
public void file_Delete(string filePath)
{
System.IO.File.Delete(filePath);
}
public bool file_Exists(string filePath)
{
return System.IO.File.Exists(filePath);
}
public byte[] file_ReadAllBytes(string filePath)
{
return System.IO.File.ReadAllBytes(filePath);
}
}
public class NintendoSwitchIO : IAxiIO
{
public NintendoSwitchIO()
{
AxiNS.instance.Init();
}
public void dir_CreateDirectory(string dirpath)
{
AxiNS.instance.io.CreateDir(dirpath);
}
public void dir_Delete(string path, bool recursive)
{
AxiNS.instance.io.DeletePathFile(path);
}
public IEnumerable<string> dir_EnumerateFiles(string path, string searchPattern)
{
throw new NotImplementedException();
}
public bool dir_Exists(string dirpath)
{
return AxiNS.instance.io.CheckPathExists(dirpath);
}
public void file_Delete(string filePath)
{
AxiNS.instance.io.DeletePathFile(filePath);
}
public bool file_Exists(string filePath)
{
return AxiNS.instance.io.CheckPathExists(filePath);
}
public byte[] file_ReadAllBytes(string filePath)
{
return AxiNS.instance.io.LoadSwitchDataFile(filePath);
}
public void file_WriteAllBytes(string filePath, byte[] data)
{
AxiNS.instance.io.FileToSaveWithCreate(filePath, data);
}
public void file_WriteAllBytes(string filePath, MemoryStream ms)
{
AxiNS.instance.io.FileToSaveWithCreate(filePath,ms);
}
}
public static class AxiIO
{
static IAxiIO m_io;
public static IAxiIO io
{
get
{
if (m_io == null)
{
if (UnityEngine.Application.platform == RuntimePlatform.Switch)
m_io = new NintendoSwitchIO();
else
m_io = new CSharpIO();
}
return m_io;
}
}
}
public static class File
{
internal static void Delete(string filePath)
{
AxiIO.io.file_Delete(filePath);
}
internal static bool Exists(string filePath)
{
return AxiIO.io.file_Exists(filePath);
}
internal static byte[] ReadAllBytes(string filePath)
{
return AxiIO.io.file_ReadAllBytes(filePath);
}
internal static void WriteAllBytes(string path, byte[] data)
{
AxiIO.io.file_WriteAllBytes(path, data);
}
internal static void WriteAllBytesFromStream(string path, MemoryStream ms)
{
AxiIO.io.file_WriteAllBytes(path, ms);
}
}
public static class Directory
{
public static bool Exists(string dirpath)
{
return AxiIO.io.dir_Exists(dirpath);
}
public static void CreateDirectory(string dirpath)
{
AxiIO.io.dir_CreateDirectory(dirpath);
}
public static IEnumerable<string> EnumerateFiles(string path, string searchPattern)
{
return AxiIO.io.dir_EnumerateFiles(path, searchPattern);
}
internal static void Delete(string cacheDirPath, bool v)
{
AxiIO.io.dir_Delete(cacheDirPath, v);
}
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 32f63f62398d8184590292135b011084

View File

@ -1,4 +1,4 @@
{ {
"name": "AxibugEmuOnline.Client", "name": "AxibugEmuOnline.Client",
"rootNamespace": "", "rootNamespace": "",
"references": [ "references": [
@ -7,8 +7,9 @@
"UIEffect2018", "UIEffect2018",
"Mame.Core", "Mame.Core",
"Essgee.Unity", "Essgee.Unity",
"StoicGooseUnity", "StoicGooseUnity",
"Unity.InputSystem" "Unity.InputSystem",
"AxiNSApi"
], ],
"includePlatforms": [], "includePlatforms": [],
"excludePlatforms": [], "excludePlatforms": [],

View File

@ -1,6 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; //using System.IO;
using System.IO.Compression; using System.IO.Compression;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
@ -26,7 +26,7 @@ namespace AxibugEmuOnline.Client.Common
public static byte[] CompressByteArray(byte[] bytesToCompress) public static byte[] CompressByteArray(byte[] bytesToCompress)
{ {
using (var compressedMemoryStream = new MemoryStream()) using (var compressedMemoryStream = new System.IO.MemoryStream())
using (var gzipStream = new GZipStream(compressedMemoryStream, CompressionMode.Compress)) using (var gzipStream = new GZipStream(compressedMemoryStream, CompressionMode.Compress))
{ {
gzipStream.Write(bytesToCompress, 0, bytesToCompress.Length); gzipStream.Write(bytesToCompress, 0, bytesToCompress.Length);
@ -37,35 +37,35 @@ namespace AxibugEmuOnline.Client.Common
public static byte[] DecompressByteArray(byte[] compressedBytes) public static byte[] DecompressByteArray(byte[] compressedBytes)
{ {
using (var compressedMemoryStream = new MemoryStream(compressedBytes)) using (var compressedMemoryStream = new System.IO.MemoryStream(compressedBytes))
using (var gzipStream = new GZipStream(compressedMemoryStream, CompressionMode.Decompress)) using (var gzipStream = new GZipStream(compressedMemoryStream, CompressionMode.Decompress))
using (var resultMemoryStream = new MemoryStream()) using (var resultMemoryStream = new System.IO.MemoryStream())
{ {
gzipStream.CopyTo(resultMemoryStream); gzipStream.CopyTo(resultMemoryStream);
return resultMemoryStream.ToArray(); return resultMemoryStream.ToArray();
} }
} }
public static string FileMD5Hash(string filePath) //public static string FileMD5Hash(string filePath)
{ //{
using (var md5 = MD5.Create()) // using (var md5 = MD5.Create())
{ // {
using (var stream = File.OpenRead(filePath)) // using (var stream = File.OpenRead(filePath))
{ // {
var hash = md5.ComputeHash(stream); // var hash = md5.ComputeHash(stream);
var sb = new StringBuilder(hash.Length * 2); // var sb = new StringBuilder(hash.Length * 2);
foreach (var b in hash) // foreach (var b in hash)
sb.AppendFormat("{0:x2}", b); // sb.AppendFormat("{0:x2}", b);
return sb.ToString(); // return sb.ToString();
} // }
} // }
} //}
static byte[] FileMD5HashByte(byte[] data) static byte[] FileMD5HashByte(byte[] data)
{ {
using (var md5 = MD5.Create()) using (var md5 = MD5.Create())
{ {
using (var stream = new MemoryStream(data)) using (var stream = new System.IO.MemoryStream(data))
{ {
return md5.ComputeHash(stream); return md5.ComputeHash(stream);
} }

View File

@ -2,7 +2,7 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; //using System.IO;
using UnityEngine; using UnityEngine;
namespace AxibugEmuOnline.Client namespace AxibugEmuOnline.Client
@ -20,8 +20,8 @@ namespace AxibugEmuOnline.Client
/// <summary> 移除文件缓存 </summary> /// <summary> 移除文件缓存 </summary>
public void ClearCaches() public void ClearCaches()
{ {
if (Directory.Exists(CacheDirPath)) if (AxiIO.Directory.Exists(CacheDirPath))
Directory.Delete(CacheDirPath, true); AxiIO.Directory.Delete(CacheDirPath, true);
} }
IEnumerator DownloadFromURL(string url, string path, Action<byte[]> callback) IEnumerator DownloadFromURL(string url, string path, Action<byte[]> callback)
@ -38,8 +38,8 @@ namespace AxibugEmuOnline.Client
if (!request.downloadHandler.bHadErr) if (!request.downloadHandler.bHadErr)
{ {
Directory.CreateDirectory(path); AxiIO.Directory.CreateDirectory(path);
File.WriteAllBytes($"{path}/{url.GetHashCode()}", request.downloadHandler.data); AxiIO.File.WriteAllBytes($"{path}/{url.GetHashCode()}", request.downloadHandler.data);
callback.Invoke(request.downloadHandler.data); callback.Invoke(request.downloadHandler.data);
} }
else else
@ -78,9 +78,9 @@ namespace AxibugEmuOnline.Client
byte[] rawData = null; byte[] rawData = null;
var filePath = $"{path}/{fileName}"; var filePath = $"{path}/{fileName}";
if (File.Exists(filePath)) if (AxiIO.File.Exists(filePath))
{ {
rawData = File.ReadAllBytes(filePath); rawData = AxiIO.File.ReadAllBytes(filePath);
var @out = RawDataConvert<T>(rawData); var @out = RawDataConvert<T>(rawData);
cachesInMemory[url] = @out; cachesInMemory[url] = @out;
callback.Invoke(@out, url); callback.Invoke(@out, url);

View File

@ -5,7 +5,7 @@ using ICSharpCode.SharpZipLib.Zip;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; //using System.IO;
using UnityEngine; using UnityEngine;
namespace AxibugEmuOnline.Client namespace AxibugEmuOnline.Client
@ -208,9 +208,9 @@ namespace AxibugEmuOnline.Client
if (App.FileDownloader.GetDownloadProgress(webData.url) == null) if (App.FileDownloader.GetDownloadProgress(webData.url) == null)
{ {
if (MultiFileRom) if (MultiFileRom)
m_hasLocalFile = Directory.Exists(LocalFilePath); m_hasLocalFile = AxiIO.Directory.Exists(LocalFilePath);
else else
m_hasLocalFile = File.Exists(LocalFilePath); m_hasLocalFile = AxiIO.File.Exists(LocalFilePath);
} }
} }
@ -242,7 +242,7 @@ namespace AxibugEmuOnline.Client
{ {
Dictionary<string, byte[]> unzipFiles = new Dictionary<string, byte[]>(); Dictionary<string, byte[]> unzipFiles = new Dictionary<string, byte[]>();
//多rom文件的平台,下载下来的数据直接解压放入文件夹内 //多rom文件的平台,下载下来的数据直接解压放入文件夹内
var zip = new ZipInputStream(new MemoryStream(bytes)); var zip = new ZipInputStream(new System.IO.MemoryStream(bytes));
List<string> depth0Files = new List<string>(); List<string> depth0Files = new List<string>();
while (true) while (true)
@ -253,7 +253,7 @@ namespace AxibugEmuOnline.Client
if (currentEntry.IsDirectory) continue; if (currentEntry.IsDirectory) continue;
var buffer = new byte[1024]; var buffer = new byte[1024];
MemoryStream output = new MemoryStream(); System.IO.MemoryStream output = new System.IO.MemoryStream();
while (true) while (true)
{ {
var size = zip.Read(buffer, 0, buffer.Length); var size = zip.Read(buffer, 0, buffer.Length);
@ -275,16 +275,16 @@ namespace AxibugEmuOnline.Client
{ {
var path = rootDirName != null ? item.Key.Substring(0, rootDirName.Length + 1) : item.Key; var path = rootDirName != null ? item.Key.Substring(0, rootDirName.Length + 1) : item.Key;
var data = item.Value; var data = item.Value;
Directory.CreateDirectory(Path.GetDirectoryName(path)); AxiIO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(path));
File.WriteAllBytes(path, data); AxiIO.File.WriteAllBytes(path, data);
} }
} }
else else
{ {
var directPath = Path.GetDirectoryName(LocalFilePath); var directPath = System.IO.Path.GetDirectoryName(LocalFilePath);
Directory.CreateDirectory(directPath); AxiIO.Directory.CreateDirectory(directPath);
File.WriteAllBytes(LocalFilePath, bytes); AxiIO.File.WriteAllBytes(LocalFilePath, bytes);
} }
Eventer.Instance.PostEvent(EEvent.OnRomFileDownloaded, ID); Eventer.Instance.PostEvent(EEvent.OnRomFileDownloaded, ID);
OnDownloadOver?.Invoke(this); OnDownloadOver?.Invoke(this);
@ -297,10 +297,10 @@ namespace AxibugEmuOnline.Client
if (webData == null) throw new Exception("Not Valid Rom"); if (webData == null) throw new Exception("Not Valid Rom");
if (!RomReady) throw new Exception("Rom File Not Downloaded"); if (!RomReady) throw new Exception("Rom File Not Downloaded");
var bytes = File.ReadAllBytes(LocalFilePath); var bytes = AxiIO.File.ReadAllBytes(LocalFilePath);
if (Path.GetExtension(LocalFilePath).ToLower() == ".zip") if (System.IO.Path.GetExtension(LocalFilePath).ToLower() == ".zip")
{ {
var zip = new ZipInputStream(new MemoryStream(bytes)); var zip = new ZipInputStream(new System.IO.MemoryStream(bytes));
while (true) while (true)
{ {
var currentEntry = zip.GetNextEntry(); var currentEntry = zip.GetNextEntry();
@ -310,7 +310,7 @@ namespace AxibugEmuOnline.Client
if (!currentEntry.Name.ToLower().EndsWith(FileExtentionName)) continue; if (!currentEntry.Name.ToLower().EndsWith(FileExtentionName)) continue;
var buffer = new byte[1024]; var buffer = new byte[1024];
MemoryStream output = new MemoryStream(); System.IO.MemoryStream output = new System.IO.MemoryStream();
while (true) while (true)
{ {
var size = zip.Read(buffer, 0, buffer.Length); var size = zip.Read(buffer, 0, buffer.Length);
@ -332,7 +332,7 @@ namespace AxibugEmuOnline.Client
public void SetWebData(HttpAPI.Resp_RomInfo resp_RomInfo) public void SetWebData(HttpAPI.Resp_RomInfo resp_RomInfo)
{ {
webData = resp_RomInfo; webData = resp_RomInfo;
FileName = MultiFileRom ? Path.GetFileNameWithoutExtension(webData.url) : Path.GetFileName(webData.url); FileName = MultiFileRom ? System.IO.Path.GetFileNameWithoutExtension(webData.url) : System.IO.Path.GetFileName(webData.url);
FileName = System.Net.WebUtility.UrlDecode(FileName); FileName = System.Net.WebUtility.UrlDecode(FileName);
//收集依赖Rom //收集依赖Rom

View File

@ -4,7 +4,7 @@ using AxibugEmuOnline.Client.Event;
using AxibugProtobuf; using AxibugProtobuf;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; //using System.IO;
using System.Linq; using System.Linq;
using static AxibugEmuOnline.Client.HttpAPI; using static AxibugEmuOnline.Client.HttpAPI;
@ -62,14 +62,14 @@ namespace AxibugEmuOnline.Client
public void ClearRomFile() public void ClearRomFile()
{ {
var path = $"{App.PersistentDataPath(m_platform)}/RemoteRoms"; var path = $"{App.PersistentDataPath(m_platform)}/RemoteRoms";
if (Directory.Exists(path)) Directory.Delete(path, true); if (AxiIO.Directory.Exists(path)) AxiIO.Directory.Delete(path, true);
} }
/// <summary> 移除一个已下载的Rom </summary> /// <summary> 移除一个已下载的Rom </summary>
public void RemoveOneRomFile(RomFile romFile) public void RemoveOneRomFile(RomFile romFile)
{ {
if (romFile.RomReady) if (romFile.RomReady)
File.Delete(romFile.LocalFilePath); AxiIO.File.Delete(romFile.LocalFilePath);
} }
/// <summary> /// <summary>

View File

@ -1,9 +1,9 @@
using AxibugEmuOnline.Client.ClientCore; using AxibugEmuOnline.Client.ClientCore;
using AxibugEmuOnline.Client.Tools; using AxibugEmuOnline.Client.Tools;
using AxibugProtobuf; using AxibugProtobuf;
using MAME.Core;
using System; using System;
using System.IO;
//using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace AxibugEmuOnline.Client namespace AxibugEmuOnline.Client
@ -32,7 +32,7 @@ namespace AxibugEmuOnline.Client
var path = App.UserPersistenDataPath(EmuPlatform); var path = App.UserPersistenDataPath(EmuPlatform);
path = $"{path}/Slot/{RomID}"; path = $"{path}/Slot/{RomID}";
Directory.CreateDirectory(path); AxiIO.Directory.CreateDirectory(path);
var filePath = $"{path}/slot{SlotIndex}.SlotSav"; var filePath = $"{path}/slot{SlotIndex}.SlotSav";
return filePath; return filePath;
@ -80,25 +80,37 @@ namespace AxibugEmuOnline.Client
FSM.AddState<SyncedState>(); FSM.AddState<SyncedState>();
FSM.OnStateChanged += FSM_OnStateChanged; FSM.OnStateChanged += FSM_OnStateChanged;
IsEmpty = !File.Exists(FilePath); IsEmpty = !AxiIO.File.Exists(FilePath);
if (IsEmpty) Sequecen = 0; if (IsEmpty) Sequecen = 0;
else //从文件头读取存储序号 else //从文件头读取存储序号
{ {
byte[] saveOrderData = new byte[4]; byte[] saveOrderData = new byte[4];
var streaming = File.OpenRead(FilePath);
int res = streaming.Read(saveOrderData, 0, 4); //FileStream streaming = System.IO.File.OpenRead(FilePath);
if (res != 4) //无效的存档文件 //int res = streaming.Read(saveOrderData, 0, 4);
//if (res != 4) //无效的存档文件
//{
// IsEmpty = true;
// File.Delete(FilePath);
//}
//else
//{
// Sequecen = BitConverter.ToUInt32(saveOrderData, 0);
//}
//streaming.Dispose();
byte[] bytes = AxiIO.File.ReadAllBytes(FilePath);
if (bytes.Length < 4) //无效的存档文件
{ {
IsEmpty = true; IsEmpty = true;
File.Delete(FilePath); AxiIO.File.Delete(FilePath);
} }
else else
{ {
Array.Copy(bytes, 0, saveOrderData, 0, 4);
Sequecen = BitConverter.ToUInt32(saveOrderData, 0); Sequecen = BitConverter.ToUInt32(saveOrderData, 0);
} }
streaming.Dispose();
} }
FSM.ChangeState<IdleState>(); FSM.ChangeState<IdleState>();
@ -138,9 +150,9 @@ namespace AxibugEmuOnline.Client
savData = null; savData = null;
screenShotData = null; screenShotData = null;
if (!File.Exists(FilePath)) return; if (!AxiIO.File.Exists(FilePath)) return;
var raw = File.ReadAllBytes(FilePath); var raw = AxiIO.File.ReadAllBytes(FilePath);
int headerSize = Marshal.SizeOf(typeof(Header)); int headerSize = Marshal.SizeOf(typeof(Header));
if (raw.Length < headerSize) if (raw.Length < headerSize)
@ -199,7 +211,7 @@ namespace AxibugEmuOnline.Client
Array.Copy(savData, 0, raw, headerSize, savData.Length); Array.Copy(savData, 0, raw, headerSize, savData.Length);
Array.Copy(screenShotData, 0, raw, headerSize + savData.Length, screenShotData.Length); Array.Copy(screenShotData, 0, raw, headerSize + savData.Length, screenShotData.Length);
File.WriteAllBytes(filePath, raw); AxiIO.File.WriteAllBytes(filePath, raw);
Sequecen = sequence; Sequecen = sequence;
m_headerCache = header; m_headerCache = header;

View File

@ -1,7 +1,7 @@
using AxibugEmuOnline.Client.ClientCore; using AxibugEmuOnline.Client.ClientCore;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; //using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using UnityEngine; using UnityEngine;
@ -103,9 +103,9 @@ namespace AxibugEmuOnline.Client
string GetSavePath() string GetSavePath()
{ {
string dir = $"{App.PersistentDataPath(App.emu.Core.Platform)}/AxiSoundRecord"; string dir = $"{App.PersistentDataPath(App.emu.Core.Platform)}/AxiSoundRecord";
if (!Directory.Exists(dir)) if (!AxiIO.Directory.Exists(dir))
{ {
Directory.CreateDirectory(dir); AxiIO.Directory.CreateDirectory(dir);
} }
return $"{dir}/{App.tick.GetDateTimeStr()}"; return $"{dir}/{App.tick.GetDateTimeStr()}";
} }
@ -132,13 +132,21 @@ namespace AxibugEmuOnline.Client
OverlayManager.PopTip("没有录音数据"); OverlayManager.PopTip("没有录音数据");
return; return;
} }
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
using (FileStream file = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
{ {
file.Write(waveHeader.GetBytes(), 0, (int)waveHeader.Length()); ms.Write(waveHeader.GetBytes(), 0, (int)waveHeader.Length());
file.Write(formatChunk.GetBytes(), 0, (int)formatChunk.Length()); ms.Write(formatChunk.GetBytes(), 0, (int)formatChunk.Length());
file.Write(dataChunk.GetBytes(), 0, (int)dataChunk.Length()); ms.Write(dataChunk.GetBytes(), 0, (int)dataChunk.Length());
AxiIO.File.WriteAllBytesFromStream(filename, ms);
} }
//using (FileStream file = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
//{
// file.Write(waveHeader.GetBytes(), 0, (int)waveHeader.Length());
// file.Write(formatChunk.GetBytes(), 0, (int)formatChunk.Length());
// file.Write(dataChunk.GetBytes(), 0, (int)dataChunk.Length());
//}
IsRecording = false; IsRecording = false;
OverlayManager.PopTip("录音结束"); OverlayManager.PopTip("录音结束");
} }