AxibugEmuOnline/AxibugEmuOnline.Client/Assets/Script/Manager/RomLib/RomLib.cs

65 lines
2.2 KiB
C#
Raw Normal View History

2024-08-13 18:35:20 +08:00
using AxibugEmuOnline.Client.ClientCore;
using System;
using System.Collections.Generic;
namespace AxibugEmuOnline.Client
{
public class RomLib
{
2024-08-14 13:09:22 +08:00
private Dictionary<int, RomFile> nesRomFileIdMapper = new Dictionary<int, RomFile>();
private Dictionary<string, RomFile> nesRomFileNameMapper = new Dictionary<string, RomFile>();
2024-08-13 18:35:20 +08:00
2024-08-14 13:09:22 +08:00
public RomFile GetNesRomFile(string romFileName)
2024-08-13 18:35:20 +08:00
{
2024-08-14 13:09:22 +08:00
nesRomFileNameMapper.TryGetValue(romFileName, out RomFile romFile);
return romFile;
}
public void GetNesRomFile(int page, int pageSize, Action<List<RomFile>> callback)
{
AppAxibugEmuOnline.httpAPI.GetNesRomList((romList) =>
2024-08-13 18:35:20 +08:00
{
2024-08-14 13:09:22 +08:00
if (romList == null)
2024-08-13 18:35:20 +08:00
{
2024-08-14 13:09:22 +08:00
callback.Invoke(null);
2024-08-13 18:35:20 +08:00
}
2024-08-14 13:09:22 +08:00
else
2024-08-13 18:35:20 +08:00
{
2024-08-14 13:09:22 +08:00
List<RomFile> result = new List<RomFile>();
for (int i = 0; i < romList.gameList.Count; i++)
2024-08-13 18:35:20 +08:00
{
2024-08-14 13:09:22 +08:00
var webData = romList.gameList[i];
nesRomFileIdMapper.TryGetValue(webData.id, out var targetRomFile);
if (targetRomFile == null)
2024-08-13 18:35:20 +08:00
{
2024-08-14 13:09:22 +08:00
targetRomFile = new RomFile(EnumPlatform.NES);
targetRomFile.SetWebData(webData);
nesRomFileIdMapper[webData.id] = targetRomFile;
nesRomFileNameMapper[targetRomFile.FileName] = targetRomFile;
2024-08-13 18:35:20 +08:00
}
2024-08-14 13:09:22 +08:00
result.Add(targetRomFile);
2024-08-13 18:35:20 +08:00
}
2024-08-14 13:09:22 +08:00
callback(result);
}
}, page, pageSize);
}
public static string CalcHash(byte[] data)
{
2024-08-14 13:20:52 +08:00
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"));
//}
2024-08-14 13:09:22 +08:00
2024-08-14 13:20:52 +08:00
//return sb.ToString();
2024-08-13 18:35:20 +08:00
}
}
}