Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/coolgirl-multicart/coolgirl-multirom-builder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2022-11-09 10:36:28 +0300
committerAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2022-11-09 10:37:21 +0300
commitcad8bacdb39b2ee4065c542382bfe4ce5d58d825 (patch)
tree4d2ecb77d109870a4ccef0746e6fe4c3a2813baf
parent5a5fd2a775fe6dad34f454a4c640a350a48b990c (diff)
File format detection based in extension
-rw-r--r--tools_sources/CoolgirlCombiner/Game.cs32
1 files changed, 17 insertions, 15 deletions
diff --git a/tools_sources/CoolgirlCombiner/Game.cs b/tools_sources/CoolgirlCombiner/Game.cs
index 86318c5..a4e25a3 100644
--- a/tools_sources/CoolgirlCombiner/Game.cs
+++ b/tools_sources/CoolgirlCombiner/Game.cs
@@ -72,10 +72,10 @@ namespace com.clusterrr.Famicom.CoolGirl
{
}
- public Game(string fileName, string? menuName = null, Dictionary<string, GameFix>? fixes = null)
+ public Game(string filename, string? menuName = null, Dictionary<string, GameFix>? fixes = null)
{
// Separators
- if (fileName == "-")
+ if (filename == "-")
{
MenuName = (string.IsNullOrWhiteSpace(menuName) || menuName == "-") ? "" : menuName;
FileName = "";
@@ -83,12 +83,12 @@ namespace com.clusterrr.Famicom.CoolGirl
}
else
{
- Console.WriteLine($"Loading {Path.GetFileName(fileName)}...");
- FileName = fileName;
+ Console.WriteLine($"Loading {Path.GetFileName(filename)}...");
+ FileName = filename;
if (string.IsNullOrWhiteSpace(menuName))
{
// Menu name based on filename
- MenuName = Limit(Regex.Replace(Path.GetFileNameWithoutExtension(fileName), @"( ?\[.*?\])|( \(.\))", string.Empty).Replace("_", " ").ToUpper().Replace(", THE", "").Trim());
+ MenuName = Limit(Regex.Replace(Path.GetFileNameWithoutExtension(filename), @"( ?\[.*?\])|( \(.\))", string.Empty).Replace("_", " ").ToUpper().Replace(", THE", "").Trim());
}
else
{
@@ -97,9 +97,10 @@ namespace com.clusterrr.Famicom.CoolGirl
}
string crc32;
string md5;
- try
+ var ext = Path.GetExtension(filename);
+ if (ext == ".nes")
{
- var nesFile = new NesFile(fileName);
+ var nesFile = new NesFile(filename);
PRG = nesFile.PRG;
CHR = nesFile.CHR;
Battery = nesFile.Battery;
@@ -116,15 +117,15 @@ namespace com.clusterrr.Famicom.CoolGirl
var md5full = nesFile.CalculateMD5();
md5 = $"{md5full[8]:x02}{md5full[9]:x02}{md5full[10]:x02}{md5full[11]:x02}{md5full[12]:x02}{md5full[13]:x02}{md5full[14]:x02}{md5full[15]:x02}"; // lower 8 bytes of MD5
}
- catch (InvalidDataException)
+ else if (ext == ".unf" || ext == ".unif")
{
- var unifFile = new UnifFile(fileName);
+ var unifFile = new UnifFile(filename);
PRG = unifFile.Where(k => k.Key.StartsWith("PRG")).OrderBy(k => k.Key).SelectMany(i => i.Value).ToArray();
CHR = unifFile.Where(k => k.Key.StartsWith("CHR")).OrderBy(k => k.Key).SelectMany(i => i.Value).ToArray();
Battery = unifFile.Battery ?? false;
var mapper = unifFile.Mapper;
if (string.IsNullOrEmpty(mapper))
- throw new InvalidDataException($"Mapper is not set in {Path.GetFileName(fileName)}");
+ throw new InvalidDataException($"Mapper is not set in {Path.GetFileName(filename)}");
if (mapper.StartsWith("NES-") || mapper.StartsWith("UNL-") || mapper.StartsWith("HVC-") || mapper.StartsWith("BTL-") || mapper.StartsWith("BMC-"))
mapper = mapper.Substring(4);
Mapper = mapper;
@@ -134,6 +135,7 @@ namespace com.clusterrr.Famicom.CoolGirl
var md5full = unifFile.CalculateMD5();
md5 = $"{md5full[8]:x02}{md5full[9]:x02}{md5full[10]:x02}{md5full[11]:x02}{md5full[12]:x02}{md5full[13]:x02}{md5full[14]:x02}{md5full[15]:x02}"; // lower 8 bytes of MD5
}
+ else throw new InvalidDataException($"Unknown file extension: {ext}");
// Check for fixes database
if (fixes != null)
{
@@ -143,27 +145,27 @@ namespace com.clusterrr.Famicom.CoolGirl
if (!string.IsNullOrEmpty(fix.Mapper) && Mapper != fix.Mapper)
{
Mapper = fix.Mapper;
- Console.WriteLine($"Fix based on checksum: {Path.GetFileName(fileName)} has {fix.Mapper} mapper");
+ Console.WriteLine($"Fix based on checksum: {Path.GetFileName(filename)} has {fix.Mapper} mapper");
}
if (!string.IsNullOrEmpty(fix.Mirroring) && (Mapper.ToString() != fix.Mirroring))
{
Mirroring = Enum.Parse<MirroringType>(fix.Mirroring);
- Console.WriteLine($"Fix based on checksum: {Path.GetFileName(fileName)} has {fix.Mirroring} mirroring type");
+ Console.WriteLine($"Fix based on checksum: {Path.GetFileName(filename)} has {fix.Mirroring} mirroring type");
}
if (fix.PrgRamSize.HasValue && (PrgRamSize != fix.PrgRamSize * 1024))
{
PrgRamSize = (int?)(fix.PrgRamSize * 1024);
- Console.WriteLine($"Fix based on checksum: {Path.GetFileName(fileName)} has {fix.PrgRamSize}KB PRG RAM");
+ Console.WriteLine($"Fix based on checksum: {Path.GetFileName(filename)} has {fix.PrgRamSize}KB PRG RAM");
}
if (fix.ChrRamSize.HasValue && (ChrRamSize != fix.ChrRamSize * 1024))
{
ChrRamSize = (int?)(fix.ChrRamSize * 1024);
- Console.WriteLine($"Fix based on checksum: {Path.GetFileName(fileName)} has {fix.ChrRamSize}KB CHR RAM");
+ Console.WriteLine($"Fix based on checksum: {Path.GetFileName(filename)} has {fix.ChrRamSize}KB CHR RAM");
}
if (fix.Battery.HasValue && (Battery != fix.Battery.Value))
{
Battery = fix.Battery.Value;
- Console.WriteLine($"Fix based on checksum: {Path.GetFileName(fileName)} battery saves = {fix.Battery}");
+ Console.WriteLine($"Fix based on checksum: {Path.GetFileName(filename)} battery saves = {fix.Battery}");
}
if (fix.WillNotWorkOnPal)
{