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:
authorAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2017-02-27 21:47:58 +0300
committerAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2017-02-27 21:47:58 +0300
commit3990def525e77466768a87436dfe5cb7c2dbf634 (patch)
tree01f6407cc425c9e2398ddd26e61ea58c3e6781e0 /Apps/NesMiniApplication.cs
parentb471b9e755119e7495b62f82701e10c37cedcd02 (diff)
Minor fixes
Diffstat (limited to 'Apps/NesMiniApplication.cs')
-rw-r--r--Apps/NesMiniApplication.cs40
1 files changed, 32 insertions, 8 deletions
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();
+ }
+ }
}
}