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
path: root/Apps
diff options
context:
space:
mode:
authordaPhie79 <33412188+daPhie79@users.noreply.github.com>2017-12-05 07:58:50 +0300
committerdaPhie79 <33412188+daPhie79@users.noreply.github.com>2017-12-05 07:58:50 +0300
commitff7f200496cd031761ea7fb2f03acbf8726972f7 (patch)
treeacebe986c3b8a6f2a9eac26af7ffd46048582891 /Apps
parentbb815358c0697969cef65bb0d0dd221b13bbc141 (diff)
expand search in FindCovers to allow more cover art matches (subdirectories and fuzzy bidirectional search)
Diffstat (limited to 'Apps')
-rw-r--r--Apps/NesMiniApplication.cs48
1 files changed, 36 insertions, 12 deletions
diff --git a/Apps/NesMiniApplication.cs b/Apps/NesMiniApplication.cs
index 874d8ef4..ceeb9f62 100644
--- a/Apps/NesMiniApplication.cs
+++ b/Apps/NesMiniApplication.cs
@@ -470,24 +470,48 @@ namespace com.clusterrr.hakchi_gui
Directory.CreateDirectory(artDirectory);
if (!string.IsNullOrEmpty(inputFileName))
{
+ string name = System.IO.Path.GetFileNameWithoutExtension(inputFileName);
if (crc32 != 0)
{
var covers = Directory.GetFiles(artDirectory, string.Format("{0:X8}*.*", crc32), SearchOption.AllDirectories);
if (covers.Length > 0)
cover = LoadBitmap(covers[0]);
}
- var imagePath = System.IO.Path.Combine(artDirectory, System.IO.Path.GetFileNameWithoutExtension(inputFileName) + ".png");
- if (File.Exists(imagePath))
- cover = LoadBitmap(imagePath);
- imagePath = System.IO.Path.Combine(artDirectory, System.IO.Path.GetFileNameWithoutExtension(inputFileName) + ".jpg");
- if (File.Exists(imagePath))
- cover = LoadBitmap(imagePath);
- imagePath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(inputFileName), System.IO.Path.GetFileNameWithoutExtension(inputFileName) + ".png");
- if (File.Exists(imagePath))
- cover = LoadBitmap(imagePath);
- imagePath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(inputFileName), System.IO.Path.GetFileNameWithoutExtension(inputFileName) + ".jpg");
- if (File.Exists(imagePath))
- cover = LoadBitmap(imagePath);
+ if (cover == null)
+ {
+ // priority to inputFileName directory
+ var imagePath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(inputFileName), name + ".jpg");
+ if (File.Exists(imagePath))
+ cover = LoadBitmap(imagePath);
+ imagePath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(inputFileName), name + ".png");
+ if (File.Exists(imagePath))
+ cover = LoadBitmap(imagePath);
+ }
+ if( cover == null )
+ {
+ // do a bidirectional search on sanitized filenames to allow minor variance in filenames, also allows subdirectories
+ Regex rgx = new Regex("[^a-zA-Z0-9]", RegexOptions.Compiled);
+ var sanitizedName = rgx.Replace(name, string.Empty).ToLower();
+
+ var covers = Directory.GetFiles(artDirectory, "*.*", SearchOption.AllDirectories);
+ foreach(var file in covers)
+ {
+ var sanitized = rgx.Replace(System.IO.Path.GetFileNameWithoutExtension(file), "").ToLower();
+ if (sanitizedName.StartsWith(sanitized) || sanitized.StartsWith(sanitizedName))
+ {
+ cover = LoadBitmap(file);
+ break;
+ }
+ }
+ /*
+ var imagePath = System.IO.Path.Combine(artDirectory, System.IO.Path.GetFileNameWithoutExtension(inputFileName) + ".png");
+ if (File.Exists(imagePath))
+ cover = LoadBitmap(imagePath);
+ imagePath = System.IO.Path.Combine(artDirectory, System.IO.Path.GetFileNameWithoutExtension(inputFileName) + ".jpg");
+ if (File.Exists(imagePath))
+ cover = LoadBitmap(imagePath);
+ */
+ }
}
if (cover == null)
{