From 9f160234f82eafc9a9cdd61f70c1ae67c4f86400 Mon Sep 17 00:00:00 2001 From: "sha..rd" Date: Sun, 17 Jul 2011 05:20:38 +0000 Subject: [PATCH] * Added case-sensitivity and other "asset name requirements" to ClasspathLocator to prevent Windows -> Linux porting issues git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7868 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../jme3/asset/plugins/ClasspathLocator.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/engine/src/desktop/com/jme3/asset/plugins/ClasspathLocator.java b/engine/src/desktop/com/jme3/asset/plugins/ClasspathLocator.java index 03970cd75..6d5e73ae0 100644 --- a/engine/src/desktop/com/jme3/asset/plugins/ClasspathLocator.java +++ b/engine/src/desktop/com/jme3/asset/plugins/ClasspathLocator.java @@ -34,10 +34,13 @@ package com.jme3.asset.plugins; import com.jme3.asset.*; import com.jme3.system.JmeSystem; +import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.net.URISyntaxException; import java.net.URL; import java.net.URLConnection; +import java.util.logging.Level; import java.util.logging.Logger; /** @@ -103,12 +106,33 @@ public class ClasspathLocator implements AssetLocator { if (url == null) return null; + if (url.getProtocol().equals("file")){ + try { + String path = new File(url.toURI()).getCanonicalPath(); + + // convert to / for windows + if (File.separatorChar == '\\'){ + path = path.replace('\\', '/'); + } + + // compare path + if (!path.endsWith(name)){ + throw new AssetNotFoundException("Asset name doesn't match requirements.\n"+ + "\"" + path + "\" doesn't match \"" + name + "\""); + } + } catch (URISyntaxException ex) { + throw new AssetLoadException("Error converting URL to URI", ex); + } catch (IOException ex){ + throw new AssetLoadException("Failed to get canonical path for " + url, ex); + } + } + try{ URLConnection conn = url.openConnection(); conn.setUseCaches(false); return new ClasspathAssetInfo(manager, key, conn); }catch (IOException ex){ - return null; + throw new AssetLoadException("Failed to read URL " + url, ex); } }