[gnome-games] local-cover: Make the basename check more strict
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] local-cover: Make the basename check more strict
- Date: Tue, 31 Mar 2020 10:39:14 +0000 (UTC)
commit 8f2706ef19750fc6cb0b5d491594472431035ffb
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Tue Mar 31 15:34:34 2020 +0500
local-cover: Make the basename check more strict
Currently we take the basename of a ROM, strip its extension, and look for
files that start with the same prefix. This breaks as soon as we have names
as following:
* Game.rom
* Game - Something Else.jpg
Obviously they both contain the prefix "Game", so the file gets picked as
the cover, which is incorrect. Instead, take prefix of both files and check
that the whole prefix matches and not just the beginning.
src/utils/local-cover.vala | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
---
diff --git a/src/utils/local-cover.vala b/src/utils/local-cover.vala
index e8b70feb..8e639439 100644
--- a/src/utils/local-cover.vala
+++ b/src/utils/local-cover.vala
@@ -45,6 +45,15 @@ public class Games.LocalCover : Object, Cover {
return null;
}
+ private string get_basename_prefix (string basename) {
+ var pos = basename.last_index_of_char ('.');
+
+ if (pos < 0)
+ return basename;
+
+ return basename.substring (0, pos);
+ }
+
private string? get_sibling_cover_path () throws Error {
var file = uri.to_file ();
var parent = file.get_parent ();
@@ -52,8 +61,7 @@ public class Games.LocalCover : Object, Cover {
return null;
var basename = file.get_basename ();
- var splitted_basename = basename.split (".");
- var prefix = splitted_basename.length == 1 ? basename : string.joinv (".",
splitted_basename[0:splitted_basename.length - 1]);
+ var prefix = get_basename_prefix (basename);
string cover_path = null;
var directory = new Directory (parent);
@@ -63,7 +71,8 @@ public class Games.LocalCover : Object, Cover {
if (sibling_basename == basename)
return false;
- if (!sibling_basename.has_prefix (prefix))
+ var sibling_prefix = get_basename_prefix (sibling_basename);
+ if (prefix != sibling_prefix)
return false;
var type = sibling.get_attribute_string (FileAttribute.STANDARD_FAST_CONTENT_TYPE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]