forked from sin365/AxibugEmuOnline
tools 归档
This commit is contained in:
parent
8858c43468
commit
e782fa2eb2
@ -11,6 +11,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VirtualNes.Core", "Core\Vir
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AxibugEmuOnline.GameScreenConvert", "AxibugEmuOnline.GameScreenConvert\AxibugEmuOnline.GameScreenConvert.csproj", "{A70AD410-E2F2-4792-AEC1-A0DB83392E52}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{516B4BC8-EC46-484F-A83A-01493A480FB1}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CheckFilesExist", "Tools\CheckFilesExist\CheckFilesExist.csproj", "{39F90FC2-0EE9-4663-97CF-985FAEBB91A2}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HtmlTable", "Tools\HtmlTable\HtmlTable.csproj", "{A29088C4-FAFA-4F8D-B9CC-57BB8CF454CB}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MAMEHashTool", "Tools\MAMEHashTool\MAMEHashTool.csproj", "{FA3B23B9-B8A5-422F-BC85-64069174A99D}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -33,10 +41,27 @@ Global
|
||||
{A70AD410-E2F2-4792-AEC1-A0DB83392E52}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A70AD410-E2F2-4792-AEC1-A0DB83392E52}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A70AD410-E2F2-4792-AEC1-A0DB83392E52}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{39F90FC2-0EE9-4663-97CF-985FAEBB91A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{39F90FC2-0EE9-4663-97CF-985FAEBB91A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{39F90FC2-0EE9-4663-97CF-985FAEBB91A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{39F90FC2-0EE9-4663-97CF-985FAEBB91A2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A29088C4-FAFA-4F8D-B9CC-57BB8CF454CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A29088C4-FAFA-4F8D-B9CC-57BB8CF454CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A29088C4-FAFA-4F8D-B9CC-57BB8CF454CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A29088C4-FAFA-4F8D-B9CC-57BB8CF454CB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{FA3B23B9-B8A5-422F-BC85-64069174A99D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{FA3B23B9-B8A5-422F-BC85-64069174A99D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FA3B23B9-B8A5-422F-BC85-64069174A99D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FA3B23B9-B8A5-422F-BC85-64069174A99D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{39F90FC2-0EE9-4663-97CF-985FAEBB91A2} = {516B4BC8-EC46-484F-A83A-01493A480FB1}
|
||||
{A29088C4-FAFA-4F8D-B9CC-57BB8CF454CB} = {516B4BC8-EC46-484F-A83A-01493A480FB1}
|
||||
{FA3B23B9-B8A5-422F-BC85-64069174A99D} = {516B4BC8-EC46-484F-A83A-01493A480FB1}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {979933DC-FDAB-4ED1-974D-61FC7F814963}
|
||||
EndGlobalSection
|
||||
|
6
Tools/CheckFilesExist/App.config
Normal file
6
Tools/CheckFilesExist/App.config
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
|
||||
</startup>
|
||||
</configuration>
|
54
Tools/CheckFilesExist/CheckFilesExist.csproj
Normal file
54
Tools/CheckFilesExist/CheckFilesExist.csproj
Normal file
@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{39F90FC2-0EE9-4663-97CF-985FAEBB91A2}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>CheckFilesExist</RootNamespace>
|
||||
<AssemblyName>CheckFilesExist</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
28
Tools/CheckFilesExist/Program.cs
Normal file
28
Tools/CheckFilesExist/Program.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace CheckFilesExist
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
string[] checklist = File.ReadAllLines("checkfiles.txt");
|
||||
|
||||
List<string> dontExist = new List<string>();
|
||||
Console.WriteLine("不存在列表:");
|
||||
foreach (var item in checklist)
|
||||
{
|
||||
var path = System.Net.WebUtility.UrlDecode(item);
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
Console.WriteLine(path);
|
||||
dontExist.Add(path);
|
||||
}
|
||||
}
|
||||
Console.WriteLine($"完毕,共{dontExist.Count}个不存在");
|
||||
Console.ReadLine();
|
||||
}
|
||||
}
|
||||
}
|
33
Tools/CheckFilesExist/Properties/AssemblyInfo.cs
Normal file
33
Tools/CheckFilesExist/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 有关程序集的一般信息由以下
|
||||
// 控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("CheckFilesExist")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("CheckFilesExist")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2025")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 将 ComVisible 设置为 false 会使此程序集中的类型
|
||||
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
|
||||
//请将此类型的 ComVisible 特性设置为 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||
[assembly: Guid("39f90fc2-0ee9-4663-97cf-985faebb91a2")]
|
||||
|
||||
// 程序集的版本信息由下列四个值组成:
|
||||
//
|
||||
// 主版本
|
||||
// 次版本
|
||||
// 生成号
|
||||
// 修订号
|
||||
//
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
62
Tools/HtmlTable/FileHelper.cs
Normal file
62
Tools/HtmlTable/FileHelper.cs
Normal file
@ -0,0 +1,62 @@
|
||||
using System.Text;
|
||||
|
||||
namespace HtmlTable
|
||||
{
|
||||
public class FileHelper
|
||||
{
|
||||
public static bool LoadFile(string FilePath, out byte[] data)
|
||||
{
|
||||
using (FileStream fs = new FileStream(FilePath, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] buffur = new byte[fs.Length];
|
||||
fs.Read(buffur, 0, (int)fs.Length);
|
||||
fs.Close();
|
||||
data = buffur;
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
data = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static string[] GetDirFile(string Path)
|
||||
{
|
||||
return Directory.GetFiles(Path);
|
||||
}
|
||||
|
||||
public static byte[] String2Byte(string value)
|
||||
{
|
||||
return Encoding.Default.GetBytes(value);
|
||||
}
|
||||
public static bool SaveFile(string FilePath, byte[] buffer)
|
||||
{
|
||||
try
|
||||
{
|
||||
//创建一个文件流
|
||||
using (FileStream wfs = new FileStream(FilePath, FileMode.Create))
|
||||
{
|
||||
//将byte数组写入文件中
|
||||
wfs.Write(buffer, 0, buffer.Length);
|
||||
//所有流类型都要关闭流,否则会出现内存泄露问题
|
||||
wfs.Close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void SaveFile(string FilePath, string[] strArr)
|
||||
{
|
||||
System.IO.File.WriteAllLines(FilePath, strArr);
|
||||
}
|
||||
}
|
||||
}
|
14
Tools/HtmlTable/HtmlTable.csproj
Normal file
14
Tools/HtmlTable/HtmlTable.csproj
Normal file
@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.11.61" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
142
Tools/HtmlTable/Program.cs
Normal file
142
Tools/HtmlTable/Program.cs
Normal file
@ -0,0 +1,142 @@
|
||||
using HtmlAgilityPack;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
|
||||
namespace HtmlTable
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static string loc = Path.GetDirectoryName(AppContext.BaseDirectory) + "\\";
|
||||
const string InDir = "Input";
|
||||
const string OutDir = "Out";
|
||||
static void Main(string[] args)
|
||||
{
|
||||
if (!Directory.Exists(loc + InDir))
|
||||
{
|
||||
Console.WriteLine("Input文件不存在");
|
||||
Console.ReadLine();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Directory.Exists(loc + OutDir))
|
||||
{
|
||||
Console.WriteLine("Out文件不存在");
|
||||
Console.ReadLine();
|
||||
return;
|
||||
}
|
||||
|
||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||
string[] files = FileHelper.GetDirFile(loc + InDir);
|
||||
Console.WriteLine($"共{files.Length}个文件,是否处理? (y/n)");
|
||||
|
||||
string yn = Console.ReadLine();
|
||||
if (yn.ToLower() != "y")
|
||||
return;
|
||||
|
||||
int index = 0;
|
||||
int errcount = 0;
|
||||
List<string> outline = new List<string>();
|
||||
for (int i = 0; i < files.Length; i++)
|
||||
{
|
||||
string FileName = files[i].Substring(files[i].LastIndexOf("\\"));
|
||||
|
||||
if (!FileName.ToLower().Contains(".htm"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
index++;
|
||||
|
||||
Console.WriteLine($">>>>>>>>>>>>>>开始处理 第{index}个文件 {FileName}<<<<<<<<<<<<<<<<<<<");
|
||||
outline.AddRange(GetToData(File.ReadAllText(files[i],System.Text.Encoding.GetEncoding("gb2312"))));
|
||||
Console.WriteLine($">>>>>>>>>>>>>>成功处理 第{index}个");
|
||||
}
|
||||
|
||||
string newfileName = "out.csv";
|
||||
string outstring = loc + OutDir + "\\" + newfileName;
|
||||
FileHelper.SaveFile(outstring, outline.ToArray());
|
||||
|
||||
|
||||
Console.WriteLine($"已处理{files.Length}个文件,其中{errcount}个失败");
|
||||
|
||||
Console.ReadLine();
|
||||
}
|
||||
|
||||
static List<string> GetToData(string html)
|
||||
{
|
||||
List<string> result = new List<string>();
|
||||
HtmlDocument doc = new HtmlDocument();
|
||||
doc.LoadHtml(html);
|
||||
|
||||
// 假设table的XPath已经给出,但这里我们直接使用根table(因为示例中只有一个)
|
||||
HtmlNode table = doc.DocumentNode.SelectSingleNode("//table[@width='100%' and @border='1']");
|
||||
|
||||
if (table != null)
|
||||
{
|
||||
var all = table.SelectNodes("tr");
|
||||
|
||||
int Idx = 0;
|
||||
// 遍历除了标题行之外的所有行
|
||||
foreach (HtmlNode row in all) // 跳过标题行
|
||||
{
|
||||
Idx++;
|
||||
if (Idx == 1)
|
||||
continue;
|
||||
// 提取游戏名称和游戏链接
|
||||
HtmlNode gameNameNode = row.SelectSingleNode("td");
|
||||
|
||||
|
||||
|
||||
if (gameNameNode != null)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
HtmlNode gameNode1 = row.SelectSingleNode("td[1]/div");
|
||||
if(gameNode1 == null) gameNode1 = row.SelectSingleNode("td[1]");
|
||||
string gameName = gameNode1.InnerText.Trim();
|
||||
string gameUrl = gameNode1.SelectSingleNode("a").GetAttributeValue("href", null);
|
||||
|
||||
HtmlNode gameNode2 = row.SelectSingleNode("td[2]/div");
|
||||
if (gameNode2 == null) gameNode2 = row.SelectSingleNode("td[2]");
|
||||
string imgUrl = gameNode2.SelectSingleNode("a").GetAttributeValue("href", null);
|
||||
|
||||
HtmlNode gameNode3 = row.SelectSingleNode("td[3]/div");
|
||||
if (gameNode3 == null) gameNode3 = row.SelectSingleNode("td[3]");
|
||||
string gameType = gameNode3.InnerText.Trim();
|
||||
|
||||
HtmlNode gameNode4 = row.SelectSingleNode("td[4]/div");
|
||||
if (gameNode4 == null) gameNode4 = row.SelectSingleNode("td[4]");
|
||||
string description = gameNode4.InnerText.Trim();
|
||||
|
||||
//// 假设图片URL、游戏类型和说明分别在第二个、第三个和第四个<td>中
|
||||
//HtmlNode imgNode = row.SelectSingleNode("td:nth-child(2) img");
|
||||
//string imgUrl = imgNode?.GetAttributeValue("src", null);
|
||||
|
||||
//HtmlNode gameTypeNode = row.SelectSingleNode("td:nth-child(3)");
|
||||
//string gameType = gameTypeNode?.InnerText.Trim();
|
||||
|
||||
//HtmlNode descriptionNode = row.SelectSingleNode("td:nth-child(4)");
|
||||
//string description = descriptionNode?.InnerText.Trim();
|
||||
|
||||
string outline = $"\"{gameName}\",\"{gameUrl}\",\"{imgUrl}\",\"{gameType}\",\"{description}\"";
|
||||
// 输出信息
|
||||
Console.WriteLine(outline);
|
||||
|
||||
result.Add(outline);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("未找到指定的table元素");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
16
Tools/MAMEHashTool/MAMEHashTool.csproj
Normal file
16
Tools/MAMEHashTool/MAMEHashTool.csproj
Normal file
@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="mame.xml">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
297
Tools/MAMEHashTool/Program.cs
Normal file
297
Tools/MAMEHashTool/Program.cs
Normal file
@ -0,0 +1,297 @@
|
||||
using System.Globalization;
|
||||
using System.IO.Compression;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace MAMEHashTool
|
||||
{
|
||||
|
||||
class roomHashInfo
|
||||
{
|
||||
public int RomID { get; set; }
|
||||
public string RomDirName { get; set; }
|
||||
public string RomAllFileHash { get; set; }
|
||||
public string ParentName { get; set; }
|
||||
public int ParentID { get; set; }
|
||||
public string desc { get; set; }
|
||||
public string board { get; set; }
|
||||
public string year { get; set; }
|
||||
public string manufacturer { get; set; }
|
||||
}
|
||||
|
||||
internal class Program
|
||||
{
|
||||
static Dictionary<int, roomHashInfo> dict = new Dictionary<int, roomHashInfo>();
|
||||
static Dictionary<string, int> dictName2RomID = new Dictionary<string, int>();
|
||||
static string romRootDir = "G:\\MAME.Core\\roms";
|
||||
static HashSet<string> NoInDB = new HashSet<string>();
|
||||
static HashSet<string> NotfindParent = new HashSet<string>();
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int RoomSeed = 10000;
|
||||
MAMEDBHelper.LoadROMXML(File.ReadAllText("./mame.xml"));
|
||||
// 获取当前程序所在目录
|
||||
string currentDirectory = romRootDir;
|
||||
|
||||
// 列出当前目录下的所有文件夹
|
||||
string[] directories = Directory.GetDirectories(currentDirectory);
|
||||
|
||||
// 文件夹名称
|
||||
foreach (string directory in directories)
|
||||
{
|
||||
// 使用Path.GetFileName来获取文件夹名称(不包含路径)
|
||||
string directoryName = Path.GetFileName(directory);
|
||||
Console.WriteLine($"正在处理,{RoomSeed}|{directoryName}");
|
||||
|
||||
|
||||
string[] files = Directory.GetFiles(directory);
|
||||
List<byte[]> filedatas = new List<byte[]>();
|
||||
foreach (string file in files)
|
||||
{
|
||||
filedatas.Add(File.ReadAllBytes(file));
|
||||
}
|
||||
|
||||
if (!RomInfo.dictName2Rom.ContainsKey(directoryName))
|
||||
{
|
||||
if (!NoInDB.Contains(directoryName))
|
||||
NoInDB.Add(directoryName);
|
||||
|
||||
Console.WriteLine($"数据库中不存在|{directoryName}");
|
||||
continue;
|
||||
}
|
||||
RomInfo xmlinfo = RomInfo.dictName2Rom[directoryName];
|
||||
roomHashInfo hashrom = new roomHashInfo()
|
||||
{
|
||||
RomID = RoomSeed,
|
||||
ParentName = xmlinfo.Parent,
|
||||
RomDirName = directoryName,
|
||||
RomAllFileHash = FileMD5Hash(filedatas),
|
||||
board = xmlinfo.Board,
|
||||
desc = xmlinfo.Description,
|
||||
manufacturer = xmlinfo.Manufacturer,
|
||||
year = xmlinfo.Year,
|
||||
};
|
||||
dict[RoomSeed] = hashrom;
|
||||
dictName2RomID[hashrom.RomDirName] = RoomSeed;
|
||||
//StartZip(romRootDir, directory);
|
||||
RoomSeed++;
|
||||
}
|
||||
|
||||
foreach (var rom in dict.Values)
|
||||
{
|
||||
if (string.IsNullOrEmpty(rom.ParentName))
|
||||
continue;
|
||||
if (!dictName2RomID.ContainsKey(rom.ParentName))
|
||||
{
|
||||
Console.WriteLine($"父级{rom.ParentName}无法找到");
|
||||
if (!NotfindParent.Contains(rom.ParentName))
|
||||
NotfindParent.Add(rom.ParentName);
|
||||
continue;
|
||||
}
|
||||
rom.ParentID = dictName2RomID[rom.ParentName];
|
||||
}
|
||||
|
||||
List<string> tempOutInfoList = new List<string>();
|
||||
foreach (var rom in dict.Values)
|
||||
{
|
||||
string ParentID = rom.ParentID == 0 ? "" : rom.ParentID.ToString();
|
||||
tempOutInfoList.Add($"{rom.RomID}|{rom.RomDirName}|{rom.board}|{rom.year}|{rom.manufacturer}|{rom.desc}|{rom.RomAllFileHash}|{ParentID}");
|
||||
}
|
||||
|
||||
Console.WriteLine($"共{NoInDB.Count}个数据库中不存在");
|
||||
tempOutInfoList.Add($"共{NoInDB.Count}个数据库中不存在");
|
||||
foreach (var name in NoInDB)
|
||||
{
|
||||
tempOutInfoList.Add(name);
|
||||
}
|
||||
Console.WriteLine($"共{NotfindParent.Count}个父级没找到");
|
||||
tempOutInfoList.Add($"共{NotfindParent.Count}个父级没找到");
|
||||
foreach (var name in NotfindParent)
|
||||
{
|
||||
tempOutInfoList.Add(name);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
File.WriteAllLines(romRootDir + "//axiromInfolist.txt", tempOutInfoList);
|
||||
Console.WriteLine($"写入文件完毕");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"写入文件失败:{ex}");
|
||||
}
|
||||
|
||||
Console.ReadLine();
|
||||
}
|
||||
|
||||
static void StartZip(string rootPath, string subDirectory)
|
||||
{
|
||||
Console.WriteLine($"压缩{subDirectory}");
|
||||
string subDirectoryName = Path.GetFileName(subDirectory); // 获取子文件夹名称
|
||||
string zipFileName = Path.Combine(rootPath, subDirectoryName + ".zip"); // 构建ZIP文件名
|
||||
|
||||
// 创建ZIP文件
|
||||
using (FileStream zipStream = new FileStream(zipFileName, FileMode.Create))
|
||||
using (ZipArchive archive = new ZipArchive(zipStream, ZipArchiveMode.Create))
|
||||
{
|
||||
// 遍历子文件夹中的所有文件,并将它们添加到ZIP文件中
|
||||
foreach (string filePath in Directory.GetFiles(subDirectory, "*.*", SearchOption.AllDirectories))
|
||||
{
|
||||
// 获取相对于子文件夹的路径,以便在ZIP文件中保持正确的目录结构
|
||||
string relativePath = filePath.Substring(subDirectory.Length + 1); // +1 是为了排除子文件夹路径末尾的反斜杠
|
||||
|
||||
// 创建ZIP条目,使用相对于子文件夹的路径作为条目名称
|
||||
ZipArchiveEntry entry = archive.CreateEntry(relativePath, CompressionLevel.SmallestSize);
|
||||
|
||||
// 打开ZIP条目以进行写入
|
||||
using (Stream entryStream = entry.Open())
|
||||
{
|
||||
// 读取文件内容并写入ZIP条目
|
||||
using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
fileStream.CopyTo(entryStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine($"Compressed {subDirectoryName} to {zipFileName}");
|
||||
}
|
||||
|
||||
static byte[] FileMD5HashByte(byte[] data)
|
||||
{
|
||||
using (var md5 = MD5.Create())
|
||||
{
|
||||
using (var stream = new MemoryStream(data))
|
||||
{
|
||||
return md5.ComputeHash(stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 单个文件hash
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public static string FileMD5Hash(byte[] data)
|
||||
{
|
||||
byte[] hash = FileMD5HashByte(data);
|
||||
var sb = new StringBuilder(hash.Length * 2);
|
||||
foreach (var b in hash)
|
||||
sb.AppendFormat("{0:x2}", b);
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 多文件总hash (顺序不影响结果)
|
||||
/// </summary>
|
||||
/// <param name="dataList"></param>
|
||||
/// <returns></returns>
|
||||
public static string FileMD5Hash(List<byte[]> dataList)
|
||||
{
|
||||
string allhash = string.Empty;
|
||||
List<string> temp = new List<string>();
|
||||
for (int i = 0; i < dataList.Count; i++)
|
||||
{
|
||||
if (dataList[i] == null)
|
||||
continue;
|
||||
temp.Add(FileMD5Hash(dataList[i]));
|
||||
}
|
||||
temp.Sort();
|
||||
var sb = new StringBuilder();
|
||||
for (int i = 0; i < temp.Count; i++)
|
||||
{
|
||||
sb.AppendLine(temp[i].ToString());
|
||||
}
|
||||
|
||||
//这里用Ascll
|
||||
return FileMD5Hash(Encoding.ASCII.GetBytes(sb.ToString()));
|
||||
}
|
||||
}
|
||||
public class MAMEDBHelper
|
||||
{
|
||||
public static void LoadROMXML(string xmbString)
|
||||
{
|
||||
XElement xe = XElement.Parse(xmbString);
|
||||
IEnumerable<XElement> elements = from ele in xe.Elements("game") select ele;
|
||||
showInfoByElements(elements);
|
||||
}
|
||||
|
||||
static void showInfoByElements(IEnumerable<XElement> elements)
|
||||
{
|
||||
RomInfo.romList = new List<RomInfo>();
|
||||
RomInfo.dictName2Rom = new Dictionary<string, RomInfo>();
|
||||
foreach (var ele in elements)
|
||||
{
|
||||
RomInfo rom = new RomInfo();
|
||||
rom.Name = ele.Attribute("name").Value;
|
||||
rom.Board = ele.Attribute("board").Value;
|
||||
rom.Parent = ele.Element("parent").Value;
|
||||
rom.Direction = ele.Element("direction").Value;
|
||||
rom.Description = ele.Element("description").Value;
|
||||
rom.Year = ele.Element("year").Value;
|
||||
rom.Manufacturer = ele.Element("manufacturer").Value;
|
||||
RomInfo.romList.Add(rom);
|
||||
RomInfo.dictName2Rom[rom.Name] = rom;
|
||||
//loadform.listView1.Items.Add(new ListViewItem(new string[] { rom.Description, rom.Year, rom.Name, rom.Parent, rom.Direction, rom.Manufacturer, rom.Board }));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public class RomInfo
|
||||
{
|
||||
public static List<RomInfo> romList = new List<RomInfo>();
|
||||
public static Dictionary<string, RomInfo> dictName2Rom = new Dictionary<string, RomInfo>();
|
||||
public static RomInfo Rom;
|
||||
public string Name, Board;
|
||||
public string Parent;
|
||||
public string Direction;
|
||||
public string Description;
|
||||
public string Year;
|
||||
public string Manufacturer;
|
||||
public string M1Default, M1Stop, M1Min, M1Max, M1Subtype;
|
||||
public static ushort IStop;
|
||||
public RomInfo()
|
||||
{
|
||||
|
||||
}
|
||||
public static RomInfo GetRomByName(string s1)
|
||||
{
|
||||
if (!dictName2Rom.TryGetValue(s1, out RomInfo info))
|
||||
return null;
|
||||
return info;
|
||||
}
|
||||
public static string GetParent(string s1)
|
||||
{
|
||||
string sParent = "";
|
||||
foreach (RomInfo ri in romList)
|
||||
{
|
||||
if (s1 == ri.Name)
|
||||
{
|
||||
sParent = ri.Parent;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return sParent;
|
||||
}
|
||||
public static List<string> GetParents(string s1)
|
||||
{
|
||||
string sChild, sParent;
|
||||
List<string> ls1 = new List<string>();
|
||||
sChild = s1;
|
||||
while (sChild != "")
|
||||
{
|
||||
ls1.Add(sChild);
|
||||
sParent = GetParent(sChild);
|
||||
sChild = sParent;
|
||||
}
|
||||
return ls1;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
https://go.microsoft.com/fwlink/?LinkID=208121.
|
||||
-->
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Any CPU</Platform>
|
||||
<PublishDir>bin\Release\net9.0\publish\</PublishDir>
|
||||
<PublishProtocol>FileSystem</PublishProtocol>
|
||||
<_TargetId>Folder</_TargetId>
|
||||
</PropertyGroup>
|
||||
</Project>
|
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
https://go.microsoft.com/fwlink/?LinkID=208121.
|
||||
-->
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<History>True|2025-01-23T09:13:53.2850370Z||;</History>
|
||||
<LastFailureDetails />
|
||||
</PropertyGroup>
|
||||
</Project>
|
8046
Tools/MAMEHashTool/mame.xml
Normal file
8046
Tools/MAMEHashTool/mame.xml
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user