add psx db generation
This commit is contained in:
parent
95deb6f3f9
commit
66eba89a94
|
@ -35,6 +35,7 @@
|
||||||
<DefineConstants>TRACE;WINDOWS</DefineConstants>
|
<DefineConstants>TRACE;WINDOWS</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="CSharp-SQLite">
|
<Reference Include="CSharp-SQLite">
|
||||||
|
@ -46,6 +47,8 @@
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
<Reference Include="System.Web" />
|
<Reference Include="System.Web" />
|
||||||
<Reference Include="System.Windows.Forms" />
|
<Reference Include="System.Windows.Forms" />
|
||||||
|
<Reference Include="System.XML" />
|
||||||
|
<Reference Include="System.Xml.Linq" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="DB.cs" />
|
<Compile Include="DB.cs" />
|
||||||
|
@ -59,6 +62,7 @@
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="DiscHash.cs" />
|
<Compile Include="DiscHash.cs" />
|
||||||
|
<Compile Include="PsxDBJob.cs" />
|
||||||
<Compile Include="RomHasher.cs" />
|
<Compile Include="RomHasher.cs" />
|
||||||
<EmbeddedResource Include="DBMan_MainForm.resx">
|
<EmbeddedResource Include="DBMan_MainForm.resx">
|
||||||
<DependentUpon>DBMan_MainForm.cs</DependentUpon>
|
<DependentUpon>DBMan_MainForm.cs</DependentUpon>
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -12,14 +12,6 @@ namespace BizHawk.Client.DBMan
|
||||||
{
|
{
|
||||||
class DiscHash
|
class DiscHash
|
||||||
{
|
{
|
||||||
Job job;
|
|
||||||
public void Run(string[] args)
|
|
||||||
{
|
|
||||||
using (job = new Job())
|
|
||||||
{
|
|
||||||
MyRun(args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static List<string> FindExtensionsRecurse(string dir, string extUppercaseWithDot)
|
static List<string> FindExtensionsRecurse(string dir, string extUppercaseWithDot)
|
||||||
{
|
{
|
||||||
|
@ -48,13 +40,14 @@ namespace BizHawk.Client.DBMan
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyRun(string[] args)
|
public void Run(string[] args)
|
||||||
{
|
{
|
||||||
|
|
||||||
string indir = null;
|
string indir = null;
|
||||||
string dpTemp = null;
|
string dpTemp = null;
|
||||||
string fpOutfile = null;
|
string fpOutfile = null;
|
||||||
|
|
||||||
for(int i=0;;)
|
for (int i = 0; ; )
|
||||||
{
|
{
|
||||||
if (i == args.Length) break;
|
if (i == args.Length) break;
|
||||||
var arg = args[i++];
|
var arg = args[i++];
|
||||||
|
@ -66,7 +59,7 @@ namespace BizHawk.Client.DBMan
|
||||||
fpOutfile = args[i++];
|
fpOutfile = args[i++];
|
||||||
}
|
}
|
||||||
|
|
||||||
using(var outf = new StreamWriter(fpOutfile))
|
using (var outf = new StreamWriter(fpOutfile))
|
||||||
{
|
{
|
||||||
|
|
||||||
Dictionary<uint, string> FoundHashes = new Dictionary<uint, string>();
|
Dictionary<uint, string> FoundHashes = new Dictionary<uint, string>();
|
||||||
|
@ -118,127 +111,4 @@ namespace BizHawk.Client.DBMan
|
||||||
} //MyRun()
|
} //MyRun()
|
||||||
} //class PsxRedump
|
} //class PsxRedump
|
||||||
|
|
||||||
public enum JobObjectInfoType
|
|
||||||
{
|
|
||||||
AssociateCompletionPortInformation = 7,
|
|
||||||
BasicLimitInformation = 2,
|
|
||||||
BasicUIRestrictions = 4,
|
|
||||||
EndOfJobTimeInformation = 6,
|
|
||||||
ExtendedLimitInformation = 9,
|
|
||||||
SecurityLimitInformation = 5,
|
|
||||||
GroupInformation = 11
|
|
||||||
}
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public struct SECURITY_ATTRIBUTES
|
|
||||||
{
|
|
||||||
public int nLength;
|
|
||||||
public IntPtr lpSecurityDescriptor;
|
|
||||||
public int bInheritHandle;
|
|
||||||
}
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
struct JOBOBJECT_BASIC_LIMIT_INFORMATION
|
|
||||||
{
|
|
||||||
public Int64 PerProcessUserTimeLimit;
|
|
||||||
public Int64 PerJobUserTimeLimit;
|
|
||||||
public Int16 LimitFlags;
|
|
||||||
public UInt32 MinimumWorkingSetSize;
|
|
||||||
public UInt32 MaximumWorkingSetSize;
|
|
||||||
public Int16 ActiveProcessLimit;
|
|
||||||
public Int64 Affinity;
|
|
||||||
public Int16 PriorityClass;
|
|
||||||
public Int16 SchedulingClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
struct IO_COUNTERS
|
|
||||||
{
|
|
||||||
public UInt64 ReadOperationCount;
|
|
||||||
public UInt64 WriteOperationCount;
|
|
||||||
public UInt64 OtherOperationCount;
|
|
||||||
public UInt64 ReadTransferCount;
|
|
||||||
public UInt64 WriteTransferCount;
|
|
||||||
public UInt64 OtherTransferCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
struct JOBOBJECT_EXTENDED_LIMIT_INFORMATION
|
|
||||||
{
|
|
||||||
public JOBOBJECT_BASIC_LIMIT_INFORMATION BasicLimitInformation;
|
|
||||||
public IO_COUNTERS IoInfo;
|
|
||||||
public UInt32 ProcessMemoryLimit;
|
|
||||||
public UInt32 JobMemoryLimit;
|
|
||||||
public UInt32 PeakProcessMemoryUsed;
|
|
||||||
public UInt32 PeakJobMemoryUsed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Job : IDisposable
|
|
||||||
{
|
|
||||||
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
|
|
||||||
static extern IntPtr CreateJobObject(object a, string lpName);
|
|
||||||
|
|
||||||
[DllImport("kernel32.dll")]
|
|
||||||
static extern bool SetInformationJobObject(IntPtr hJob, JobObjectInfoType infoType, IntPtr lpJobObjectInfo, uint cbJobObjectInfoLength);
|
|
||||||
|
|
||||||
[DllImport("kernel32.dll", SetLastError = true)]
|
|
||||||
static extern bool AssignProcessToJobObject(IntPtr job, IntPtr process);
|
|
||||||
|
|
||||||
private IntPtr m_handle;
|
|
||||||
private bool m_disposed = false;
|
|
||||||
|
|
||||||
public Job()
|
|
||||||
{
|
|
||||||
m_handle = CreateJobObject(null, null);
|
|
||||||
|
|
||||||
JOBOBJECT_BASIC_LIMIT_INFORMATION info = new JOBOBJECT_BASIC_LIMIT_INFORMATION();
|
|
||||||
info.LimitFlags = 0x2000;
|
|
||||||
|
|
||||||
JOBOBJECT_EXTENDED_LIMIT_INFORMATION extendedInfo = new JOBOBJECT_EXTENDED_LIMIT_INFORMATION();
|
|
||||||
extendedInfo.BasicLimitInformation = info;
|
|
||||||
|
|
||||||
int length = Marshal.SizeOf(typeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION));
|
|
||||||
IntPtr extendedInfoPtr = Marshal.AllocHGlobal(length);
|
|
||||||
Marshal.StructureToPtr(extendedInfo, extendedInfoPtr, false);
|
|
||||||
|
|
||||||
if (!SetInformationJobObject(m_handle, JobObjectInfoType.ExtendedLimitInformation, extendedInfoPtr, (uint)length))
|
|
||||||
throw new Exception(string.Format("Unable to set information. Error: {0}", Marshal.GetLastWin32Error()));
|
|
||||||
}
|
|
||||||
|
|
||||||
#region IDisposable Members
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
Dispose(true);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
private void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (m_disposed)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (disposing) { }
|
|
||||||
|
|
||||||
Close();
|
|
||||||
m_disposed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
[DllImport("kernel32.dll", SetLastError = true)]
|
|
||||||
[return: MarshalAs(UnmanagedType.Bool)]
|
|
||||||
public static extern bool CloseHandle(IntPtr hObject);
|
|
||||||
public void Close()
|
|
||||||
{
|
|
||||||
CloseHandle(m_handle);
|
|
||||||
m_handle = IntPtr.Zero;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool AddProcess(IntPtr handle)
|
|
||||||
{
|
|
||||||
return AssignProcessToJobObject(m_handle, handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -111,6 +111,11 @@ namespace BizHawk.Client.DBMan
|
||||||
new DiscHash().Run(args.Skip(1).ToArray());
|
new DiscHash().Run(args.Skip(1).ToArray());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (args.Length > 0 && args[0] == "--psxdb")
|
||||||
|
{
|
||||||
|
new PsxDBJob().Run(args.Skip(1).ToArray());
|
||||||
|
return;
|
||||||
|
}
|
||||||
//if (args.Length > 0 && args[0] == "--disccmp")
|
//if (args.Length > 0 && args[0] == "--disccmp")
|
||||||
//{
|
//{
|
||||||
// new DiscCmp().Run(args.Skip(1).ToArray());
|
// new DiscCmp().Run(args.Skip(1).ToArray());
|
||||||
|
|
|
@ -0,0 +1,127 @@
|
||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.IO;
|
||||||
|
using System.Xml;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
|
||||||
|
using BizHawk.Common;
|
||||||
|
using BizHawk.Emulation.DiscSystem;
|
||||||
|
|
||||||
|
namespace BizHawk.Client.DBMan
|
||||||
|
{
|
||||||
|
class PsxDBJob
|
||||||
|
{
|
||||||
|
class HashRecord
|
||||||
|
{
|
||||||
|
public string name, bizhash, datahash;
|
||||||
|
public bool matched;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Run(string[] args)
|
||||||
|
{
|
||||||
|
string fpHash = null, fpRedump = null, fpOutfile = null;
|
||||||
|
for (int i = 0; ; )
|
||||||
|
{
|
||||||
|
if (i == args.Length) break;
|
||||||
|
var arg = args[i++];
|
||||||
|
if (arg == "--hashes")
|
||||||
|
fpHash = args[i++];
|
||||||
|
if (arg == "--redump")
|
||||||
|
fpRedump = args[i++];
|
||||||
|
if (arg == "--outfile")
|
||||||
|
fpOutfile = args[i++];
|
||||||
|
}
|
||||||
|
|
||||||
|
var hashes = new Dictionary<string, HashRecord>();
|
||||||
|
|
||||||
|
Console.WriteLine("Loading redump data");
|
||||||
|
RedumpPSX rdpsx = new RedumpPSX();
|
||||||
|
rdpsx.Load(fpRedump);
|
||||||
|
|
||||||
|
Console.WriteLine("Loading hash data");
|
||||||
|
var splitSlashes = new string[]{"//"};
|
||||||
|
foreach (var line in File.ReadAllLines(fpHash))
|
||||||
|
{
|
||||||
|
var parts = line.Split(splitSlashes, StringSplitOptions.None);
|
||||||
|
var hr = new HashRecord()
|
||||||
|
{
|
||||||
|
name = parts[1],
|
||||||
|
bizhash = parts[0].Substring(8, 8),
|
||||||
|
datahash = parts[0].Substring(26, 8),
|
||||||
|
};
|
||||||
|
hashes[hr.datahash] = hr;
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine("merging");
|
||||||
|
foreach (var rr in rdpsx.Records)
|
||||||
|
{
|
||||||
|
HashRecord hr;
|
||||||
|
if (!hashes.TryGetValue(rr.crc, out hr))
|
||||||
|
continue;
|
||||||
|
hr.matched = true;
|
||||||
|
//correct name to redump current
|
||||||
|
hr.name = rr.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine("writing results");
|
||||||
|
using (var outf = new StreamWriter(fpOutfile))
|
||||||
|
{
|
||||||
|
foreach (var hr in hashes.Values)
|
||||||
|
{
|
||||||
|
if (!hr.matched)
|
||||||
|
continue;
|
||||||
|
outf.WriteLine("{0}\tG\t{1}\tPSX\t\tdh={2}", hr.bizhash, hr.name, hr.datahash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RedumpPSX
|
||||||
|
{
|
||||||
|
public class RedumpRecord
|
||||||
|
{
|
||||||
|
public string name;
|
||||||
|
public string crc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<RedumpRecord> Records = new List<RedumpRecord>();
|
||||||
|
|
||||||
|
public void Load(string datpath)
|
||||||
|
{
|
||||||
|
var xd = XDocument.Load(datpath);
|
||||||
|
|
||||||
|
Dictionary<uint, string> knownHashes = new Dictionary<uint, string>();
|
||||||
|
var games = xd.Root.Descendants("game").ToArray();
|
||||||
|
for(int i=0;i<games.Length;i++)
|
||||||
|
{
|
||||||
|
var game = games[i];
|
||||||
|
if (i % 100 == 0)
|
||||||
|
Console.WriteLine("{0}/{1}", i, games.Length);
|
||||||
|
|
||||||
|
var name = game.Attribute("name").Value;
|
||||||
|
BizHawk.Emulation.DiscSystem.DiscHasher.SpecialCRC32 spec_crc_calc = new Emulation.DiscSystem.DiscHasher.SpecialCRC32();
|
||||||
|
spec_crc_calc.Current = 0;
|
||||||
|
foreach (var rom in game.Elements("rom"))
|
||||||
|
{
|
||||||
|
var ext = Path.GetExtension(rom.Attribute("name").Value).ToLower();
|
||||||
|
if (ext == ".cue") continue;
|
||||||
|
uint onecrc = uint.Parse(rom.Attribute("crc").Value, NumberStyles.HexNumber);
|
||||||
|
int size = int.Parse(rom.Attribute("size").Value);
|
||||||
|
spec_crc_calc.Incorporate(onecrc, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Console.WriteLine("{0:X8}", spec_crc_calc.Current);
|
||||||
|
Records.Add(new RedumpRecord()
|
||||||
|
{
|
||||||
|
name = name,
|
||||||
|
crc = spec_crc_calc.Current.ToString("X8")
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue