using AxibugEmuOnline.Client.ClientCore; using System; using System.Collections.Generic; using System.Security.Cryptography; using System.Text; using UnityEngine; namespace AxibugEmuOnline.Client { public class RomLib { private Dictionary nesRomFileIdMapper = new Dictionary(); private Dictionary nesRomFileNameMapper = new Dictionary(); public RomFile GetNesRomFile(string romFileName) { nesRomFileNameMapper.TryGetValue(romFileName, out RomFile romFile); return romFile; } public void GetNesRomFile(int page, int pageSize, Action> callback) { AppAxibugEmuOnline.httpAPI.GetNesRomList((romList) => { if (romList == null) { callback.Invoke(null); } else { List result = new List(); for (int i = 0; i < romList.gameList.Count; i++) { var webData = romList.gameList[i]; nesRomFileIdMapper.TryGetValue(webData.id, out var targetRomFile); if (targetRomFile == null) { targetRomFile = new RomFile(EnumPlatform.NES); targetRomFile.SetWebData(webData); nesRomFileIdMapper[webData.id] = targetRomFile; nesRomFileNameMapper[targetRomFile.FileName] = targetRomFile; } result.Add(targetRomFile); } callback(result); } }, page, pageSize); } public static string CalcHash(byte[] data) { var hashBytes = MD5.Create().ComputeHash(data); StringBuilder sb = new StringBuilder(); foreach (byte b in hashBytes) { sb.Append(b.ToString("x2")); } return sb.ToString(); } } }