using AxibugEmuOnline.Client.ClientCore; using System; using System.Collections.Generic; 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) { return string.Empty; //todo : 等待远程仓库敲定hash算法 //var hashBytes = MD5.Create().ComputeHash(data); //StringBuilder sb = new StringBuilder(); //foreach (byte b in hashBytes) //{ // sb.Append(b.ToString("x2")); //} //return sb.ToString(); } } }