From 2ab2e40a2bbee89b7f1ddf7d916268c50fcbb9f1 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Thu, 9 Mar 2017 08:04:30 +0100 Subject: [PATCH] Better cover support for 'local' (File) support - BasicSupport#getCover(..) now checks for absolute paths, too --- .../fanfix/supported/BasicSupport.java | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/be/nikiroo/fanfix/supported/BasicSupport.java b/src/be/nikiroo/fanfix/supported/BasicSupport.java index 0ee12fec..b230bc32 100644 --- a/src/be/nikiroo/fanfix/supported/BasicSupport.java +++ b/src/be/nikiroo/fanfix/supported/BasicSupport.java @@ -874,19 +874,35 @@ public abstract class BasicSupport { if (line != null) { // try for files - String path = null; if (source != null) { - path = new File(source.getFile()).getParent(); try { - String basePath = new File(new File(path), line.trim()) - .getAbsolutePath(); + + String relPath = null; + String absPath = null; + try { + String path = new File(source.getFile()).getParent(); + relPath = new File(new File(path), line.trim()) + .getAbsolutePath(); + } catch (Exception e) { + // Cannot be converted to path (one possibility to take + // into account: absolute path on Windows) + } + try { + absPath = new File(line.trim()).getAbsolutePath(); + } catch (Exception e) { + // Cannot be converted to path (at all) + } + for (String ext : getImageExt(true)) { - if (new File(basePath + ext).exists()) { - url = new File(basePath + ext).toURI().toURL(); + if (absPath != null && new File(absPath + ext).exists()) { + url = new File(absPath + ext).toURI().toURL(); + } else if (relPath != null + && new File(relPath + ext).exists()) { + url = new File(relPath + ext).toURI().toURL(); } } } catch (Exception e) { - // Nothing to do here + // Should not happen since we control the correct arguments } } -- 2.27.0