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

github.com/ClusterM/hakchi2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Apps/FdsGame.cs4
-rw-r--r--Apps/NesGame.cs6
-rw-r--r--Apps/NesMiniApplication.cs40
-rw-r--r--Apps/SnesGame.cs2
-rw-r--r--MainForm.cs11
-rw-r--r--WorkerForm.cs20
6 files changed, 55 insertions, 28 deletions
diff --git a/Apps/FdsGame.cs b/Apps/FdsGame.cs
index 1a32ed39..acb656c1 100644
--- a/Apps/FdsGame.cs
+++ b/Apps/FdsGame.cs
@@ -41,7 +41,7 @@ namespace com.clusterrr.hakchi_gui
Args = Args; // To update exec path if need
}
- public static FdsGame Import(string fdsFileName, byte[] rawRomData = null)
+ public static FdsGame Import(string fdsFileName, string sourceFileName, byte[] rawRomData = null)
{
if (rawRomData == null)
rawRomData = File.ReadAllBytes(fdsFileName);
@@ -63,7 +63,7 @@ namespace com.clusterrr.hakchi_gui
game.Name = Regex.Replace(game.Name, @" ?\(.*?\)", string.Empty).Trim();
game.Name = Regex.Replace(game.Name, @" ?\[.*?\]", string.Empty).Trim();
game.Name = game.Name.Replace("_", " ").Replace(" ", " ").Trim();
- game.FindCover(fdsFileName, Resources.blank_fds, crc32);
+ game.FindCover(fdsFileName, sourceFileName, Resources.blank_fds, crc32);
game.Args = DefaultArgs;
game.Save();
return game;
diff --git a/Apps/NesGame.cs b/Apps/NesGame.cs
index 187cc89c..cebcbd28 100644
--- a/Apps/NesGame.cs
+++ b/Apps/NesGame.cs
@@ -76,7 +76,7 @@ namespace com.clusterrr.hakchi_gui
Args = Args; // To update exec path if need
}
- public static NesMiniApplication Import(string nesFileName, bool? ignoreMapper, ref bool? needPatch, NeedPatchDelegate needPatchCallback = null, Form parentForm = null, byte[] rawRomData = null)
+ public static NesMiniApplication Import(string nesFileName, string sourceFileName, bool? ignoreMapper, ref bool? needPatch, NeedPatchDelegate needPatchCallback = null, Form parentForm = null, byte[] rawRomData = null)
{
NesFile nesFile;
try
@@ -88,7 +88,7 @@ namespace com.clusterrr.hakchi_gui
}
catch
{
- return NesMiniApplication.Import(nesFileName, rawRomData);
+ return NesMiniApplication.Import(nesFileName, sourceFileName, rawRomData);
}
nesFile.CorrectRom();
var crc32 = nesFile.CRC32;
@@ -151,7 +151,7 @@ namespace com.clusterrr.hakchi_gui
game.Name = Regex.Replace(game.Name, @" ?\(.*?\)", string.Empty).Trim();
game.Name = Regex.Replace(game.Name, @" ?\[.*?\]", string.Empty).Trim();
game.Name = game.Name.Replace("_", " ").Replace(" ", " ");
- game.FindCover(nesFileName, (game.region == "Japan") ? Resources.blank_jp : Resources.blank_nes, crc32);
+ game.FindCover(nesFileName, sourceFileName, (game.region == "Japan") ? Resources.blank_jp : Resources.blank_nes, crc32);
game.Args = DefaultArgs;
game.Save();
return game;
diff --git a/Apps/NesMiniApplication.cs b/Apps/NesMiniApplication.cs
index 2f2f9c8f..f80ff69e 100644
--- a/Apps/NesMiniApplication.cs
+++ b/Apps/NesMiniApplication.cs
@@ -1,6 +1,8 @@
using com.clusterrr.hakchi_gui.Properties;
using SevenZip;
using System;
+using System.Collections;
+using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
@@ -126,7 +128,7 @@ namespace com.clusterrr.hakchi_gui
return new NesMiniApplication(path, ignoreEmptyConfig);
}
- public static NesMiniApplication Import(string fileName, byte[] rawRomData = null)
+ public static NesMiniApplication Import(string fileName, string sourceFile = null, byte[] rawRomData = null)
{
var extension = Path.GetExtension(fileName).ToLower();
if (extension == ".desktop")
@@ -136,17 +138,17 @@ namespace com.clusterrr.hakchi_gui
var appinfo = AppTypeCollection.GetAppByExtension(extension);
if (appinfo != null)
{
- var import = appinfo.Class.GetMethod("Import", new Type[] { typeof(string), typeof(byte[]) });
+ var import = appinfo.Class.GetMethod("Import", new Type[] { typeof(string), typeof(string), typeof(byte[]) });
if (import != null)
- return (NesMiniApplication)import.Invoke(null, new object[] { fileName, rawRomData });
+ return (NesMiniApplication)import.Invoke(null, new object[] { fileName, sourceFile, rawRomData });
else
- return Import(fileName, rawRomData, appinfo.Prefix, appinfo.DefaultApp, appinfo.DefaultCover, ConfigIni.Compress);
+ return Import(fileName, sourceFile, rawRomData, appinfo.Prefix, appinfo.DefaultApp, appinfo.DefaultCover, ConfigIni.Compress);
}
string application = extension.Length > 2 ? ("/bin/" + extension.Substring(1)) : DefaultApp;
- return Import(fileName, rawRomData, DefaultPrefix, application, DefaultCover);
+ return Import(fileName, sourceFile, rawRomData, DefaultPrefix, application, DefaultCover);
}
- private static NesMiniApplication Import(string fileName, byte[] rawRomData, char prefixCode, string application, Image defaultCover, bool compress = false)
+ private static NesMiniApplication Import(string fileName, string sourceFile, byte[] rawRomData, char prefixCode, string application, Image defaultCover, bool compress = false)
{
var crc32 = CRC32(rawRomData);
var code = GenerateCode(crc32, prefixCode);
@@ -191,7 +193,7 @@ namespace com.clusterrr.hakchi_gui
game.Name = Regex.Replace(game.Name, @" ?\(.*?\)", string.Empty).Trim();
game.Name = Regex.Replace(game.Name, @" ?\[.*?\]", string.Empty).Trim();
game.Name = game.Name.Replace("_", " ").Replace(" ", " ").Trim();
- game.FindCover(fileName, defaultCover, crc32);
+ game.FindCover(fileName, sourceFile, defaultCover, crc32);
game.Command = string.Format("{0} /usr/share/games/nes/kachikachi/{1}/{2}", application, code, romName);
game.Save();
return NesMiniApplication.FromDirectory(gamePath);
@@ -353,12 +355,21 @@ namespace com.clusterrr.hakchi_gui
outImageSmall.Save(SmallIconPath, ImageFormat.Png);
}
- internal bool FindCover(string romFileName, Image defaultCover, uint crc32 = 0)
+ internal bool FindCover(string romFileName, string sourceFileName, Image defaultCover, uint crc32 = 0)
{
// Trying to find cover file
Image cover = null;
if (!string.IsNullOrEmpty(romFileName))
{
+ if (!string.IsNullOrEmpty(sourceFileName) && sourceFileName != romFileName)
+ {
+ var archImagePath = Path.Combine(Path.GetDirectoryName(sourceFileName), Path.GetFileNameWithoutExtension(romFileName) + ".png");
+ if (File.Exists(archImagePath))
+ cover = LoadBitmap(archImagePath);
+ archImagePath = Path.Combine(Path.GetDirectoryName(sourceFileName), Path.GetFileNameWithoutExtension(romFileName) + ".jpg");
+ if (File.Exists(archImagePath))
+ cover = LoadBitmap(archImagePath);
+ }
var imagePath = Path.Combine(Path.GetDirectoryName(romFileName), Path.GetFileNameWithoutExtension(romFileName) + ".png");
if (File.Exists(imagePath))
cover = LoadBitmap(imagePath);
@@ -531,6 +542,19 @@ namespace com.clusterrr.hakchi_gui
arch.Read(result, 0, result.Length);
return result;
}
+
+ public class NesMiniAppEqualityComparer : IEqualityComparer<NesMiniApplication>
+ {
+ public bool Equals(NesMiniApplication x, NesMiniApplication y)
+ {
+ return x.Code == y.Code;
+ }
+
+ public int GetHashCode(NesMiniApplication obj)
+ {
+ return obj.Code.GetHashCode();
+ }
+ }
}
}
diff --git a/Apps/SnesGame.cs b/Apps/SnesGame.cs
index c5048786..2ff7cb99 100644
--- a/Apps/SnesGame.cs
+++ b/Apps/SnesGame.cs
@@ -10,7 +10,7 @@ namespace com.clusterrr.hakchi_gui
{
get
{
- return "(snes | super famicom)";
+ return "(snes | super nintendo)";
}
}
diff --git a/MainForm.cs b/MainForm.cs
index 5b5880ca..80e937f9 100644
--- a/MainForm.cs
+++ b/MainForm.cs
@@ -678,10 +678,13 @@ namespace com.clusterrr.hakchi_gui
if (addedApps != null)
{
// Add games, only new ones
- var oldApps = from app in checkedListBoxGames.Items.Cast<object>().ToArray()
- where app is NesMiniApplication
- select (app as NesMiniApplication).Code;
- var newApps = from app in addedApps where !oldApps.Contains(app.Code) select app;
+ var newApps = addedApps.Distinct(new NesMiniApplication.NesMiniAppEqualityComparer());
+ var newCodes = from app in newApps select app.Code;
+ var oldAppsReplaced = from app in checkedListBoxGames.Items.Cast<object>().ToArray()
+ where (app is NesMiniApplication) && newCodes.Contains((app as NesMiniApplication).Code)
+ select app;
+ foreach (var replaced in oldAppsReplaced)
+ checkedListBoxGames.Items.Remove(replaced);
checkedListBoxGames.Items.AddRange(newApps.ToArray());
var first = checkedListBoxGames.Items[0];
bool originalChecked = (checkedListBoxGames.CheckedItems.Contains(first));
diff --git a/WorkerForm.cs b/WorkerForm.cs
index 4f32e910..6dd2fa5e 100644
--- a/WorkerForm.cs
+++ b/WorkerForm.cs
@@ -899,20 +899,20 @@ namespace com.clusterrr.hakchi_gui
YesForAllPatches = false;
int count = 0;
SetStatus(Resources.AddingGames);
- foreach (var file in files)
+ foreach (var sourceFileName in files)
{
NesMiniApplication app = null;
try
{
- var fileName = file;
- var ext = Path.GetExtension(file).ToLower();
+ var fileName = sourceFileName;
+ var ext = Path.GetExtension(sourceFileName).ToLower();
bool? needPatch = YesForAllPatches ? (bool?)true : null;
byte[] rawData = null;
string tmp = null;
if (ext == ".7z" || ext == ".zip" || ext == ".rar")
{
SevenZipExtractor.SetLibraryPath(Path.Combine(baseDirectory, IntPtr.Size == 8 ? @"tools\7z64.dll" : @"tools\7z.dll"));
- using (var szExtractor = new SevenZipExtractor(file))
+ using (var szExtractor = new SevenZipExtractor(sourceFileName))
{
var filesInArchive = new List<string>();
var nesFilesInArchive = new List<string>();
@@ -933,7 +933,7 @@ namespace com.clusterrr.hakchi_gui
if (r == DialogResult.OK)
fileName = selectedFile;
else if (r == DialogResult.Ignore)
- fileName = file;
+ fileName = sourceFileName;
else continue;
}
else if (filesInArchive.Count == 1) // No NES files but only one another file
@@ -946,10 +946,10 @@ namespace com.clusterrr.hakchi_gui
if (r == DialogResult.OK)
fileName = selectedFile;
else if (r == DialogResult.Ignore)
- fileName = file;
+ fileName = sourceFileName;
else continue;
}
- if (fileName != file)
+ if (fileName != sourceFileName)
{
var o = new MemoryStream();
if (Path.GetExtension(fileName).ToLower() == ".desktop" // App in archive, need the whole directory
@@ -975,7 +975,7 @@ namespace com.clusterrr.hakchi_gui
{
try
{
- app = NesGame.Import(fileName, YesForAllUnsupportedMappers ? (bool?)true : null, ref needPatch, needPatchCallback, this, rawData);
+ app = NesGame.Import(fileName, sourceFileName, YesForAllUnsupportedMappers ? (bool?)true : null, ref needPatch, needPatchCallback, this, rawData);
// Trying to import Game Genie codes
var lGameGeniePath = Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName) + ".xml");
@@ -1000,7 +1000,7 @@ namespace com.clusterrr.hakchi_gui
if (r == DialogResult.Abort)
YesForAllUnsupportedMappers = true;
if (r == DialogResult.Yes || r == DialogResult.Abort || r == DialogResult.Retry)
- app = NesGame.Import(fileName, true, ref needPatch, needPatchCallback, this, rawData);
+ app = NesGame.Import(fileName, sourceFileName, true, ref needPatch, needPatchCallback, this, rawData);
else
continue;
}
@@ -1009,7 +1009,7 @@ namespace com.clusterrr.hakchi_gui
}
else
{
- app = NesMiniApplication.Import(fileName, rawData);
+ app = NesMiniApplication.Import(fileName, sourceFileName, rawData);
}
if (!string.IsNullOrEmpty(tmp) && Directory.Exists(tmp)) Directory.Delete(tmp, true);
ConfigIni.SelectedGames += ";" + app.Code;