From 36b614c4a7980e54167cbaa8cf868d615f3bd90d Mon Sep 17 00:00:00 2001 From: sin365 <353374337@qq.com> Date: Thu, 24 Apr 2025 16:34:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BB=E9=A1=B9=E7=9B=AE=E5=92=8CVirtualNES.?= =?UTF-8?q?Core=E6=A0=B8=E5=BF=83=20NS=E4=B8=8B=E4=B8=8D=E5=86=8D=E4=BE=9D?= =?UTF-8?q?=E8=B5=96system.io=E8=BF=9B=E8=A1=8C=E6=96=87=E4=BB=B6=E8=AF=BB?= =?UTF-8?q?=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Assets/Script/AppMain/App.cs | 1 - .../Assets/Script/AppMain/AxiIO/AxiIO.cs | 5 +- .../Assets/Script/AppMain/Common/Helper.cs | 1 - .../Emulator/EssgeeEmulator/UEssgee.cs | 50 +++++----- .../UEssgeeInterface/UEGSoundPlayer.cs | 3 - .../AppMain/Emulator/MameEmulator/UMAME.cs | 13 ++- .../Emulator/NesEmulator/CoreSupporter.cs | 33 +++---- .../Emulator/NesEmulator/NesEmulator.cs | 3 +- .../Handle/DatabaseHandler.cs | 9 +- .../StoicGooseEmulator/UStoicGoose.cs | 99 +++++++++++-------- .../Script/AppMain/Manager/CacheManager.cs | 1 - .../Script/AppMain/Manager/RomLib/RomFile.cs | 1 - .../Script/AppMain/Manager/RomLib/RomLib.cs | 1 - .../Manager/SaveSlotManager/SaveFile.cs | 2 - .../Assets/Script/AppMain/MonoCom/AudioMgr.cs | 1 - .../Assets/VirtualNes.Core/NES.cs | 7 +- .../Assets/VirtualNes.Core/ROM.cs | 5 +- .../VirtualNes.Core/State/StateBuffer.cs | 9 +- .../VirtualNes.Core/Supporter/Supporter.cs | 10 +- 19 files changed, 125 insertions(+), 129 deletions(-) diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/App.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/App.cs index 080a4155..93b73829 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/App.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/App.cs @@ -5,7 +5,6 @@ using AxibugProtobuf; using System; using System.Collections; using System.Collections.Generic; -//using System.IO; using System.Threading.Tasks; using UnityEngine; using static AxibugEmuOnline.Client.HttpAPI; diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiIO/AxiIO.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiIO/AxiIO.cs index 9266b3a8..344a83de 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiIO/AxiIO.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiIO/AxiIO.cs @@ -1,10 +1,7 @@ -using DG.Tweening.Plugins.Core.PathCore; -using System; +using System; using System.Collections.Generic; using System.IO; -using Unity.Android.Gradle.Manifest; using UnityEngine; -using static UnityEngine.Analytics.IAnalytic; namespace AxiIO { diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Common/Helper.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Common/Helper.cs index f6ea7d1f..be9bd9f0 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Common/Helper.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Common/Helper.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -//using System.IO; using System.IO.Compression; using System.Security.Cryptography; using System.Text; diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgee.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgee.cs index aeca7de5..81a5abf6 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgee.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgee.cs @@ -11,7 +11,7 @@ using Essgee.Metadata; using Essgee.Utilities; using System; using System.Collections.Generic; -using System.IO; +//using System.IO; using System.Linq; using System.Text; using UnityEngine; @@ -189,29 +189,29 @@ public class UEssgee : MonoBehaviour, IEmuCore EmuStandInfo.ProductName = "AxibugEmu"; EmuStandInfo.ProductVersion = ""; - EmuStandInfo.programDataDirectory = Path.Combine(CustonDataDir, EmuStandInfo.ProductName); - EmuStandInfo.programConfigPath = Path.Combine(EmuStandInfo.programDataDirectory, EmuStandInfo.jsonConfigFileName); + EmuStandInfo.programDataDirectory = System.IO.Path.Combine(CustonDataDir, EmuStandInfo.ProductName); + EmuStandInfo.programConfigPath = System.IO.Path.Combine(EmuStandInfo.programDataDirectory, EmuStandInfo.jsonConfigFileName); - EmuStandInfo.ShaderPath = Path.Combine(CustonDataDir, "Assets", "Shaders"); - EmuStandInfo.SaveDataPath = Path.Combine(EmuStandInfo.programDataDirectory, EmuStandInfo.saveDataDirectoryName); - EmuStandInfo.ScreenshotPath = Path.Combine(EmuStandInfo.programDataDirectory, EmuStandInfo.screenshotDirectoryName); - EmuStandInfo.SaveStatePath = Path.Combine(EmuStandInfo.programDataDirectory, EmuStandInfo.saveStateDirectoryName); - EmuStandInfo.ExtraDataPath = Path.Combine(EmuStandInfo.programDataDirectory, EmuStandInfo.extraDataDirectoryName); + EmuStandInfo.ShaderPath = System.IO.Path.Combine(CustonDataDir, "Assets", "Shaders"); + EmuStandInfo.SaveDataPath = System.IO.Path.Combine(EmuStandInfo.programDataDirectory, EmuStandInfo.saveDataDirectoryName); + EmuStandInfo.ScreenshotPath = System.IO.Path.Combine(EmuStandInfo.programDataDirectory, EmuStandInfo.screenshotDirectoryName); + EmuStandInfo.SaveStatePath = System.IO.Path.Combine(EmuStandInfo.programDataDirectory, EmuStandInfo.saveStateDirectoryName); + EmuStandInfo.ExtraDataPath = System.IO.Path.Combine(EmuStandInfo.programDataDirectory, EmuStandInfo.extraDataDirectoryName); LoadConfiguration(); - if (!Directory.Exists(EmuStandInfo.SaveDataPath)) - Directory.CreateDirectory(EmuStandInfo.SaveDataPath); + if (!AxiIO.Directory.Exists(EmuStandInfo.SaveDataPath)) + AxiIO.Directory.CreateDirectory(EmuStandInfo.SaveDataPath); - if (!Directory.Exists(EmuStandInfo.ScreenshotPath)) - Directory.CreateDirectory(EmuStandInfo.ScreenshotPath); + if (!AxiIO.Directory.Exists(EmuStandInfo.ScreenshotPath)) + AxiIO.Directory.CreateDirectory(EmuStandInfo.ScreenshotPath); - if (!Directory.Exists(EmuStandInfo.SaveStatePath)) - Directory.CreateDirectory(EmuStandInfo.SaveStatePath); + if (!AxiIO.Directory.Exists(EmuStandInfo.SaveStatePath)) + AxiIO.Directory.CreateDirectory(EmuStandInfo.SaveStatePath); - if (!Directory.Exists(EmuStandInfo.ExtraDataPath)) - Directory.CreateDirectory(EmuStandInfo.ExtraDataPath); + if (!AxiIO.Directory.Exists(EmuStandInfo.ExtraDataPath)) + AxiIO.Directory.CreateDirectory(EmuStandInfo.ExtraDataPath); if (AppEnvironment.EnableLogger) { @@ -756,13 +756,13 @@ public class UEssgee : MonoBehaviour, IEmuCore } /* Generate filename/path */ - var filePrefix = $"{Path.GetFileNameWithoutExtension(lastGameMetadata.FileName)} ({e.Description}{(includeDateTime ? $" {DateTime.Now:yyyy-MM-dd HH-mm-ss})" : ")")}"; - var filePath = Path.Combine(EmuStandInfo.ExtraDataPath, $"{filePrefix}.{extension}"); + var filePrefix = $"{System.IO.Path.GetFileNameWithoutExtension(lastGameMetadata.FileName)} ({e.Description}{(includeDateTime ? $" {DateTime.Now:yyyy-MM-dd HH-mm-ss})" : ")")}"; + var filePath = System.IO.Path.Combine(EmuStandInfo.ExtraDataPath, $"{filePrefix}.{extension}"); if (!allowOverwrite) { - var existingFiles = Directory.EnumerateFiles(EmuStandInfo.ExtraDataPath, $"{filePrefix}*{extension}"); + var existingFiles = AxiIO.Directory.EnumerateFiles(EmuStandInfo.ExtraDataPath, $"{filePrefix}*{extension}"); if (existingFiles.Contains(filePath)) - for (int i = 2; existingFiles.Contains(filePath = Path.Combine(EmuStandInfo.ExtraDataPath, $"{filePrefix} ({i}).{extension}")); i++) { } + for (int i = 2; existingFiles.Contains(filePath = System.IO.Path.Combine(EmuStandInfo.ExtraDataPath, $"{filePrefix} ({i}).{extension}")); i++) { } } /* Handle data */ @@ -777,10 +777,12 @@ public class UEssgee : MonoBehaviour, IEmuCore else if (e.Data is byte[] raw) { /* Raw bytes */ - using (var file = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite)) - { - file.Write(raw, 0, raw.Length); - } + //using (var file = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite)) + //{ + // file.Write(raw, 0, raw.Length); + //} + + AxiIO.File.WriteAllBytes(filePath, raw); } } diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/UEGSoundPlayer.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/UEGSoundPlayer.cs index d559ee90..ac555e6f 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/UEGSoundPlayer.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/UEGSoundPlayer.cs @@ -1,9 +1,6 @@ using AxibugEmuOnline.Client.ClientCore; using System; using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; using UnityEngine; public class UEGSoundPlayer : MonoBehaviour diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/MameEmulator/UMAME.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/MameEmulator/UMAME.cs index 950fea83..5799338f 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/MameEmulator/UMAME.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/MameEmulator/UMAME.cs @@ -5,7 +5,6 @@ using AxiReplay; using MAME.Core; using System; using System.Collections.Generic; -using System.IO; using System.Text; using UnityEngine; using UnityEngine.UI; @@ -197,11 +196,11 @@ public class UMAME : MonoBehaviour, IEmuCore } byte[] SaveState() { - if (!Directory.Exists(SavePath)) - Directory.CreateDirectory(SavePath); + if (!AxiIO.Directory.Exists(SavePath)) + AxiIO.Directory.CreateDirectory(SavePath); - MemoryStream ms = new MemoryStream(); - BinaryWriter bw = new BinaryWriter(ms); + System.IO.MemoryStream ms = new System.IO.MemoryStream(); + System.IO.BinaryWriter bw = new System.IO.BinaryWriter(ms); emu.SaveState(bw); byte[] data = ms.ToArray(); bw.Close(); @@ -218,8 +217,8 @@ public class UMAME : MonoBehaviour, IEmuCore } void LoadState(byte[] data) { - MemoryStream fs = new MemoryStream(data); - BinaryReader br = new BinaryReader(fs); + System.IO.MemoryStream fs = new System.IO.MemoryStream(data); + System.IO.BinaryReader br = new System.IO.BinaryReader(fs); emu.LoadState(br); br.Close(); fs.Close(); diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/NesEmulator/CoreSupporter.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/NesEmulator/CoreSupporter.cs index ad097133..4d46cac3 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/NesEmulator/CoreSupporter.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/NesEmulator/CoreSupporter.cs @@ -2,7 +2,6 @@ using AxibugProtobuf; using AxiReplay; using System; -using System.IO; using System.Runtime.InteropServices; using UnityEngine; using VirtualNes.Core; @@ -17,14 +16,14 @@ namespace AxibugEmuOnline.Client m_controllerMapper = conMapper; } - public Stream OpenRom(string fname) + public System.IO.Stream OpenRom(string fname) { try { var romFile = App.GetRomLib(RomPlatformType.Nes).GetRomFile(fname); var bytes = romFile.GetRomFileData(); Debug.Log($"Open {romFile.Alias}"); - return new MemoryStream(bytes); + return new System.IO.MemoryStream(bytes); } catch (Exception ex) { @@ -39,34 +38,34 @@ namespace AxibugEmuOnline.Client UnityEngine.Debug.Assert(romFile != null); fullPath = romFile.LocalFilePath; - directPath = Path.GetDirectoryName(fullPath); + directPath = System.IO.Path.GetDirectoryName(fullPath); } - public Stream OpenFile_DISKSYS() + public System.IO.Stream OpenFile_DISKSYS() { - return new MemoryStream(Resources.Load("NES/Disksys.rom").bytes); + return new System.IO.MemoryStream(Resources.Load("NES/Disksys.rom").bytes); } public void SaveSRAMToFile(byte[] sramContent, string romName) { string sramDirectoryPath = $"{App.PersistentDataPath(AxibugProtobuf.RomPlatformType.Nes)}/{Config.path.szSavePath}"; - Directory.CreateDirectory(sramDirectoryPath); - romName = Path.GetFileNameWithoutExtension(romName); - File.WriteAllBytes($"{sramDirectoryPath}/{romName}.sav", sramContent); + AxiIO.Directory.CreateDirectory(sramDirectoryPath); + romName = System.IO.Path.GetFileNameWithoutExtension(romName); + AxiIO.File.WriteAllBytes($"{sramDirectoryPath}/{romName}.sav", sramContent); } public void SaveDISKToFile(byte[] diskFileContent, string romName) { string diskFileDirectoryPath = $"{App.PersistentDataPath(AxibugProtobuf.RomPlatformType.Nes)}/dsv"; - Directory.CreateDirectory(diskFileDirectoryPath); - romName = Path.GetFileNameWithoutExtension(romName); - File.WriteAllBytes($"{diskFileDirectoryPath}/{romName}.dsv", diskFileContent); + AxiIO.Directory.CreateDirectory(diskFileDirectoryPath); + romName = System.IO.Path.GetFileNameWithoutExtension(romName); + AxiIO.File.WriteAllBytes($"{diskFileDirectoryPath}/{romName}.dsv", diskFileContent); } public EmulatorConfig Config { get; private set; } = new EmulatorConfig(); public void PrepareDirectory(string directPath) { - Directory.CreateDirectory($"{App.PersistentDataPath(AxibugProtobuf.RomPlatformType.Nes)}/{directPath}"); + AxiIO.Directory.CreateDirectory($"{App.PersistentDataPath(AxibugProtobuf.RomPlatformType.Nes)}/{directPath}"); } public void SaveFile(byte[] fileData, string directPath, string fileName) @@ -74,17 +73,17 @@ namespace AxibugEmuOnline.Client PrepareDirectory(directPath); var fileFullpath = $"{App.PersistentDataPath(AxibugProtobuf.RomPlatformType.Nes)}/{directPath}/{fileName}"; - File.WriteAllBytes(fileFullpath, fileData); + AxiIO.File.WriteAllBytes(fileFullpath, fileData); } - public Stream OpenFile(string directPath, string fileName) + public System.IO.Stream OpenFile(string directPath, string fileName) { try { var path = $"{App.PersistentDataPath(AxibugProtobuf.RomPlatformType.Nes)}/{directPath}/{fileName}"; - var data = File.ReadAllBytes(path); + var data = AxiIO.File.ReadAllBytes(path); if (data == null) return null; - return new MemoryStream(data); + return new System.IO.MemoryStream(data); } catch { diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/NesEmulator/NesEmulator.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/NesEmulator/NesEmulator.cs index 399cb2fb..5421409f 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/NesEmulator/NesEmulator.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/NesEmulator/NesEmulator.cs @@ -3,7 +3,6 @@ using AxibugProtobuf; using System; using System.Diagnostics; using System.Globalization; -using System.IO; using System.Xml.Linq; using UnityEngine; using UnityEngine.UI; @@ -178,7 +177,7 @@ namespace AxibugEmuOnline.Client var db = Resources.Load("NES/ROMDB"); db.Clear(); - var xmlStr = File.ReadAllText("nes20db.xml"); + var xmlStr = System.IO.File.ReadAllText("nes20db.xml"); var xml = XDocument.Parse(xmlStr); var games = xml.Element("nes20db")?.Elements("game"); System.Diagnostics.Debug.Assert(games != null, nameof(games) + " != null"); diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/StoicGooseEmulator/Handle/DatabaseHandler.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/StoicGooseEmulator/Handle/DatabaseHandler.cs index 01953a32..26779e16 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/StoicGooseEmulator/Handle/DatabaseHandler.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/StoicGooseEmulator/Handle/DatabaseHandler.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Xml; using System.Xml.Serialization; @@ -16,24 +15,24 @@ public sealed class DatabaseHandler { string wsc = "Bandai - WonderSwan Color.dat"; GetDatBytes(wsc, out byte[] loadedData); - using (MemoryStream stream = new MemoryStream(loadedData)) + using (System.IO.MemoryStream stream = new System.IO.MemoryStream(loadedData)) { var root = new XmlRootAttribute("datafile") { IsNullable = true }; var serializer = new XmlSerializer(typeof(DatFile), root); var reader = XmlReader.Create(stream, new() { DtdProcessing = DtdProcessing.Ignore }); - datFiles.Add(Path.GetFileName(wsc), (DatFile)serializer.Deserialize(reader)); + datFiles.Add(System.IO.Path.GetFileName(wsc), (DatFile)serializer.Deserialize(reader)); } } { string ws = "Bandai - WonderSwan.dat"; GetDatBytes(ws, out byte[] loadedData); - using (MemoryStream stream = new MemoryStream(loadedData)) + using (System.IO.MemoryStream stream = new System.IO.MemoryStream(loadedData)) { var root = new XmlRootAttribute("datafile") { IsNullable = true }; var serializer = new XmlSerializer(typeof(DatFile), root); var reader = XmlReader.Create(stream, new() { DtdProcessing = DtdProcessing.Ignore }); - datFiles.Add(Path.GetFileName(ws), (DatFile)serializer.Deserialize(reader)); + datFiles.Add(System.IO.Path.GetFileName(ws), (DatFile)serializer.Deserialize(reader)); } } diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/StoicGooseEmulator/UStoicGoose.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/StoicGooseEmulator/UStoicGoose.cs index f749ac88..37758fd7 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/StoicGooseEmulator/UStoicGoose.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/StoicGooseEmulator/UStoicGoose.cs @@ -5,7 +5,6 @@ using StoicGoose.Common.Utilities; using StoicGoose.Core.Machines; using System; using System.Collections.Generic; -using System.IO; using System.IO.Compression; using System.Linq; using UnityEngine; @@ -22,7 +21,7 @@ public class UStoicGoose : MonoBehaviour, IEmuCore readonly static int maxRecentFiles = 15; readonly static int statusIconSize = 12; - readonly static List<(string description, string extension, Func streamReadFunc)> supportedFileInformation = new() + readonly static List<(string description, string extension, Func streamReadFunc)> supportedFileInformation = new() { ("WonderSwan ROMs", ".ws", GetStreamFromFile), ("WonderSwan Color ROMs", ".wsc", GetStreamFromFile), @@ -312,7 +311,7 @@ public class UStoicGoose : MonoBehaviour, IEmuCore // graphicsHandler.DrawFrame(); //}; - internalEepromPath = Path.Combine(Program.InternalDataPath, $"{machineType.Name}.eep"); + internalEepromPath = System.IO.Path.Combine(Program.InternalDataPath, $"{machineType.Name}.eep"); } //private void InitializeWindows() @@ -408,11 +407,14 @@ public class UStoicGoose : MonoBehaviour, IEmuCore if (!emulatorHandler.IsRunning) { - if (File.Exists(filename)) + if (AxiIO.File.Exists(filename)) { - using var stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); - var data = new byte[stream.Length]; - stream.Read(data, 0, data.Length); + //using var stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); + //var data = new byte[stream.Length]; + //stream.Read(data, 0, data.Length); + + var data = AxiIO.File.ReadAllBytes(filename); + emulatorHandler.Machine.LoadBootstrap(data); } emulatorHandler.Machine.UseBootstrap = Program.Configuration.General.UseBootstrap; @@ -421,23 +423,31 @@ public class UStoicGoose : MonoBehaviour, IEmuCore private void LoadInternalEeprom() { - if (!emulatorHandler.IsRunning && File.Exists(internalEepromPath)) + if (!emulatorHandler.IsRunning && AxiIO.File.Exists(internalEepromPath)) { - using var stream = new FileStream(internalEepromPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); - var data = new byte[stream.Length]; - stream.Read(data, 0, data.Length); + //using var stream = new FileStream(internalEepromPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); + //var data = new byte[stream.Length]; + //stream.Read(data, 0, data.Length); + + var data = AxiIO.File.ReadAllBytes(internalEepromPath); + emulatorHandler.Machine.LoadInternalEeprom(data); } } - private static Stream GetStreamFromFile(string filename) + private static System.IO.Stream GetStreamFromFile(string filename) { - return new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); + //return new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); + byte[] data = AxiIO.File.ReadAllBytes(filename); + return new System.IO.MemoryStream(data); } - private static Stream GetStreamFromFirstZippedFile(string filename) + private static System.IO.Stream GetStreamFromFirstZippedFile(string filename) { - return new ZipArchive(new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)).Entries.FirstOrDefault()?.Open(); + //return new ZipArchive(new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)).Entries.FirstOrDefault()?.Open(); + + byte[] data = AxiIO.File.ReadAllBytes(filename); + return new ZipArchive(new System.IO.MemoryStream(data)).Entries.FirstOrDefault()?.Open(); } private bool LoadAndRunCartridge(string filename) @@ -450,8 +460,8 @@ public class UStoicGoose : MonoBehaviour, IEmuCore emulatorHandler.Shutdown(); } - using var inputStream = supportedFileInformation.FirstOrDefault(x => x.extension == Path.GetExtension(filename)).streamReadFunc(filename) ?? GetStreamFromFile(filename); - using var stream = new MemoryStream(); + using var inputStream = supportedFileInformation.FirstOrDefault(x => x.extension == System.IO.Path.GetExtension(filename)).streamReadFunc(filename) ?? GetStreamFromFile(filename); + using var stream = new System.IO.MemoryStream(); inputStream.CopyTo(stream); stream.Position = 0; @@ -462,7 +472,7 @@ public class UStoicGoose : MonoBehaviour, IEmuCore graphicsHandler.IsVerticalOrientation = isVerticalOrientation = emulatorHandler.Machine.Cartridge.Metadata.Orientation == CartridgeMetadata.Orientations.Vertical; inputHandler.SetVerticalOrientation(isVerticalOrientation); - CurrRomName = Path.GetFileName(filename); + CurrRomName = System.IO.Path.GetFileName(filename); LoadRam(); @@ -490,12 +500,15 @@ public class UStoicGoose : MonoBehaviour, IEmuCore private void LoadRam() { //var path = Path.Combine(Program.SaveDataPath, $"{Path.GetFileNameWithoutExtension(Program.Configuration.General.RecentFiles.First())}.sav"); - var path = Path.Combine(Program.SaveDataPath, $"{CurrRomName}.sav"); - if (!File.Exists(path)) return; + var path = System.IO.Path.Combine(Program.SaveDataPath, $"{CurrRomName}.sav"); + //if (!File.Exists(path)) return; + if (!AxiIO.File.Exists(path)) return; - using var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); - var data = new byte[stream.Length]; - stream.Read(data, 0, data.Length); + //using var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); + //var data = new byte[stream.Length]; + //stream.Read(data, 0, data.Length); + + var data = AxiIO.File.ReadAllBytes(path); if (data.Length != 0) emulatorHandler.Machine.LoadSaveData(data); } @@ -511,8 +524,10 @@ public class UStoicGoose : MonoBehaviour, IEmuCore var data = emulatorHandler.Machine.GetInternalEeprom(); if (data.Length == 0) return; - using var stream = new FileStream(internalEepromPath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite); - stream.Write(data, 0, data.Length); + //using var stream = new FileStream(internalEepromPath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite); + //stream.Write(data, 0, data.Length); + + AxiIO.File.WriteAllBytes(internalEepromPath, data); } private void SaveRam() @@ -521,10 +536,12 @@ public class UStoicGoose : MonoBehaviour, IEmuCore if (data.Length == 0) return; //var path = Path.Combine(Program.SaveDataPath, $"{Path.GetFileNameWithoutExtension(Program.Configuration.General.RecentFiles.First())}.sav"); - var path = Path.Combine(Program.SaveDataPath, $"{CurrRomName}.sav"); + var path = System.IO.Path.Combine(Program.SaveDataPath, $"{CurrRomName}.sav"); - using var stream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.ReadWrite); - stream.Write(data, 0, data.Length); + //using var stream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.ReadWrite); + //stream.Write(data, 0, data.Length); + + AxiIO.File.WriteAllBytes(path, data); } @@ -603,25 +620,25 @@ static class Program shaderDirectoryName = "Shaders"; noIntroDatDirectoryName = "No-Intro"; mutexName = $"Unity_{GetVersionDetails()}"; - programDataDirectory = Path.Combine(CustonDataDir, "AxibugEmu"); - programConfigPath = Path.Combine(programDataDirectory, jsonConfigFileName); + programDataDirectory = System.IO.Path.Combine(CustonDataDir, "AxibugEmu"); + programConfigPath = System.IO.Path.Combine(programDataDirectory, jsonConfigFileName); Configuration = LoadConfiguration(programConfigPath); - Log.WriteLine(Path.Combine(programDataDirectory, logFileName)); + Log.WriteLine(System.IO.Path.Combine(programDataDirectory, logFileName)); programApplicationDirectory = AppDomain.CurrentDomain.BaseDirectory; - programAssetsDirectory = Path.Combine(programApplicationDirectory, assetsDirectoryName); - Directory.CreateDirectory(DataPath = programDataDirectory); - Directory.CreateDirectory(InternalDataPath = Path.Combine(programDataDirectory, internalDataDirectoryName)); - Directory.CreateDirectory(SaveDataPath = Path.Combine(programDataDirectory, saveDataDirectoryName)); - Directory.CreateDirectory(CheatsDataPath = Path.Combine(programDataDirectory, cheatDataDirectoryName)); - Directory.CreateDirectory(DebuggingDataPath = Path.Combine(programDataDirectory, debuggingDataDirectoryName)); + programAssetsDirectory = System.IO.Path.Combine(programApplicationDirectory, assetsDirectoryName); + AxiIO.Directory.CreateDirectory(DataPath = programDataDirectory); + AxiIO.Directory.CreateDirectory(InternalDataPath = System.IO.Path.Combine(programDataDirectory, internalDataDirectoryName)); + AxiIO.Directory.CreateDirectory(SaveDataPath = System.IO.Path.Combine(programDataDirectory, saveDataDirectoryName)); + AxiIO.Directory.CreateDirectory(CheatsDataPath = System.IO.Path.Combine(programDataDirectory, cheatDataDirectoryName)); + AxiIO.Directory.CreateDirectory(DebuggingDataPath = System.IO.Path.Combine(programDataDirectory, debuggingDataDirectoryName)); //if (!Directory.Exists(ShaderPath = Path.Combine(programAssetsDirectory, shaderDirectoryName))) // throw new DirectoryNotFoundException("Shader directory missing"); - if (!Directory.Exists(NoIntroDatPath = Path.Combine(programAssetsDirectory, noIntroDatDirectoryName))) - throw new DirectoryNotFoundException("No-Intro .dat directory missing"); + if (!AxiIO.Directory.Exists(NoIntroDatPath = System.IO.Path.Combine(programAssetsDirectory, noIntroDatDirectoryName))) + throw new Exception("No-Intro .dat directory missing"); } - catch (DirectoryNotFoundException e) + catch (Exception e) { } } @@ -674,7 +691,7 @@ static class Program private static Configuration LoadConfiguration(string filename) { - Directory.CreateDirectory(Path.GetDirectoryName(filename)); + AxiIO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(filename)); Configuration configuration; //if (!File.Exists(filename) || (configuration = filename.DeserializeFromFile()) == null) diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/CacheManager.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/CacheManager.cs index 27721dfd..19d5f9df 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/CacheManager.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/CacheManager.cs @@ -2,7 +2,6 @@ using System; using System.Collections; using System.Collections.Generic; -//using System.IO; using UnityEngine; namespace AxibugEmuOnline.Client diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/RomFile.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/RomFile.cs index 8a67f54f..b6a5f12f 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/RomFile.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/RomFile.cs @@ -5,7 +5,6 @@ using ICSharpCode.SharpZipLib.Zip; using System; using System.Collections; using System.Collections.Generic; -//using System.IO; using UnityEngine; namespace AxibugEmuOnline.Client diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/RomLib.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/RomLib.cs index 6b7c4fa9..5da6d78a 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/RomLib.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/RomLib.cs @@ -4,7 +4,6 @@ using AxibugEmuOnline.Client.Event; using AxibugProtobuf; using System; using System.Collections.Generic; -//using System.IO; using System.Linq; using static AxibugEmuOnline.Client.HttpAPI; diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/SaveSlotManager/SaveFile.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/SaveSlotManager/SaveFile.cs index 603d4fb3..bcd01ff4 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/SaveSlotManager/SaveFile.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/SaveSlotManager/SaveFile.cs @@ -2,8 +2,6 @@ using AxibugEmuOnline.Client.Tools; using AxibugProtobuf; using System; - -//using System.IO; using System.Runtime.InteropServices; namespace AxibugEmuOnline.Client diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/MonoCom/AudioMgr.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/MonoCom/AudioMgr.cs index 90e61684..2a9a83f5 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/MonoCom/AudioMgr.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/MonoCom/AudioMgr.cs @@ -1,7 +1,6 @@ using AxibugEmuOnline.Client.ClientCore; using System; using System.Collections.Generic; -//using System.IO; using System.Linq; using System.Text; using UnityEngine; diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/NES.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/NES.cs index 8c07370e..47eca7bb 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/NES.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/NES.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.IO; using System.Text; using VirtualNes.Core.Debug; @@ -28,13 +27,13 @@ namespace VirtualNes.Core private int m_nNsfSongMode; private bool m_bMoviePlay; private bool m_bMovieRec; - private Stream m_fpMovie; + private System.IO.Stream m_fpMovie; private uint m_MovieControl; private int m_MovieStepTotal; private int m_MovieStep; private bool m_bTapePlay; private bool m_bTapeRec; - private Stream m_fpTape; + private System.IO.Stream m_fpTape; private double m_TapeCycles; private byte m_TapeIn; private byte m_TapeOut; @@ -1110,7 +1109,7 @@ namespace VirtualNes.Core return; int i = 0; - Stream fp = null; + System.IO.Stream fp = null; DISKFILEHDR ifh; byte[] lpDisk = rom.GetPROM(); byte[] lpWrite = rom.GetDISK(); diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/ROM.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/ROM.cs index addb70d6..ee38757d 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/ROM.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/ROM.cs @@ -1,5 +1,4 @@ using System; -using System.IO; using VirtualNes.Core.Debug; namespace VirtualNes.Core @@ -29,7 +28,7 @@ namespace VirtualNes.Core public ROM(string fname) { - Stream fp = null; + System.IO.Stream fp = null; byte[] temp = null; byte[] bios = null; long FileSize = 0; @@ -218,7 +217,7 @@ namespace VirtualNes.Core } Supporter.S.GetRomPathInfo(fname, out fullpath, out path); - name = Path.GetFileNameWithoutExtension(fullpath); + name = System.IO.Path.GetFileNameWithoutExtension(fullpath); if (!bNSF) { mapper = (header.control1 >> 4) | (header.control2 & 0xF0); diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/StateBuffer.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/StateBuffer.cs index a419ed20..6e8b4e01 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/StateBuffer.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/StateBuffer.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.IO; using System.Text; namespace VirtualNes.Core @@ -84,22 +83,22 @@ namespace VirtualNes.Core } public class StateReader { - private MemoryStream m_dataStream; + private System.IO.MemoryStream m_dataStream; public long Remain => m_dataStream.Length - 1 - m_dataStream.Position; public StateReader(byte[] bytes) { - m_dataStream = new MemoryStream(bytes); + m_dataStream = new System.IO.MemoryStream(bytes); } public void Skip(uint count) { - m_dataStream.Seek(count, SeekOrigin.Current); + m_dataStream.Seek(count, System.IO.SeekOrigin.Current); } public void Skip(long count) { - m_dataStream.Seek(count, SeekOrigin.Current); + m_dataStream.Seek(count, System.IO.SeekOrigin.Current); } public byte[] Read_bytes(int length) diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Supporter/Supporter.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Supporter/Supporter.cs index 3287ab8f..43438ef6 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Supporter/Supporter.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Supporter/Supporter.cs @@ -1,6 +1,4 @@ -using System.IO; - -namespace VirtualNes.Core +namespace VirtualNes.Core { public static class Supporter { @@ -15,15 +13,15 @@ namespace VirtualNes.Core public interface ISupporterImpl { - Stream OpenRom(string fname); + System.IO.Stream OpenRom(string fname); void GetRomPathInfo(string fname, out string fullPath, out string directPath); - Stream OpenFile_DISKSYS(); + System.IO.Stream OpenFile_DISKSYS(); void SaveSRAMToFile(byte[] sramContent, string romName); void SaveDISKToFile(byte[] diskFileContent, string romName); EmulatorConfig Config { get; } void PrepareDirectory(string directPath); void SaveFile(byte[] fileData, string directPath, string fileName); - Stream OpenFile(string directPath, string fileName); + System.IO.Stream OpenFile(string directPath, string fileName); bool TryGetMapperNo(ROM rom, out int mapperNo); ControllerState GetControllerState(); void SampleInput(uint frameCount);