X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fload%2FMediaHelper.java;h=ab4f366d820967c67674e916c15985cddc5debb2;hb=4d5796d02a15808311c09448d79e6e7d1de9d636;hp=d14798270740a0525b0f56f8a7414bb82028dada;hpb=649c5da6ee1bbc590699e11a92316ece2ea8512d;p=GpsPrune.git diff --git a/tim/prune/load/MediaHelper.java b/tim/prune/load/MediaHelper.java index d147982..ab4f366 100644 --- a/tim/prune/load/MediaHelper.java +++ b/tim/prune/load/MediaHelper.java @@ -24,9 +24,10 @@ public abstract class MediaHelper * Construct a MediaObject for the given path * @param inZipFile path to archive file (if any) * @param inPath path to media file + * @param inSourceFile file from which data was loaded * @return either Photo or AudioClip object as appropriate, or null */ - public static MediaObject createMediaObject(File inZipFile, String inPath) + public static MediaObject createMediaObject(File inZipFile, String inPath, File inSourceFile) { if (inPath == null || inPath.length() < 5) return null; InputStream is = null; @@ -85,29 +86,33 @@ public abstract class MediaHelper } return null; } - else - // If we haven't got a result by now, try to just load plain file - return createMediaObject(inPath); + + // If we haven't got a result by now, try to load plain file + File file = new File(inPath); + if (inSourceFile != null && !file.isAbsolute()) { + file = new File(inSourceFile.getParent(), inPath); + } + // awkward construction because new File(startPath, absolutePath) doesn't work + return createMediaObject(file); } /** - * Construct a MediaObject for the given path - * @param inPath path to file + * Construct a MediaObject for the given file + * @param inFile file to load * @return either Photo or AudioClip object as appropriate, or null */ - private static MediaObject createMediaObject(String inPath) + private static MediaObject createMediaObject(File inFile) { - if (inPath == null) {return null;} - File file = new File(inPath); - if (!file.exists() || !file.canRead() || !file.isFile()) {return null;} + if (inFile == null) {return null;} + if (!inFile.exists() || !inFile.canRead() || !inFile.isFile()) {return null;} initFilters(); // Check if filename looks like a jpeg - if (_jpegFilter.acceptFilename(file.getName())) { - return JpegLoader.createPhoto(file); + if (_jpegFilter.acceptFilename(inFile.getName())) { + return JpegLoader.createPhoto(inFile); } // Check if filename looks like an audio clip - if (_audioFilter.acceptFilename(file.getName())) { - return new AudioClip(file); + if (_audioFilter.acceptFilename(inFile.getName())) { + return new AudioClip(inFile); } // Neither photo nor audio return null;