From 15fbe27d13fa853e96dccc4bed8296367fd49aca Mon Sep 17 00:00:00 2001 From: "sha..rd" Date: Sun, 17 Jul 2011 05:27:55 +0000 Subject: [PATCH] * Now added "asset name requirements" to FileLocator to prevent Windows -> Linux porting issues git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7869 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../com/jme3/asset/plugins/ClasspathLocator.java | 4 ---- .../com/jme3/asset/plugins/FileLocator.java | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/engine/src/desktop/com/jme3/asset/plugins/ClasspathLocator.java b/engine/src/desktop/com/jme3/asset/plugins/ClasspathLocator.java index 6d5e73ae0..299ec70e1 100644 --- a/engine/src/desktop/com/jme3/asset/plugins/ClasspathLocator.java +++ b/engine/src/desktop/com/jme3/asset/plugins/ClasspathLocator.java @@ -40,7 +40,6 @@ 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; /** @@ -134,8 +133,5 @@ public class ClasspathLocator implements AssetLocator { }catch (IOException ex){ throw new AssetLoadException("Failed to read URL " + url, ex); } - } - - } diff --git a/engine/src/desktop/com/jme3/asset/plugins/FileLocator.java b/engine/src/desktop/com/jme3/asset/plugins/FileLocator.java index 63bcf86da..0456aec8c 100644 --- a/engine/src/desktop/com/jme3/asset/plugins/FileLocator.java +++ b/engine/src/desktop/com/jme3/asset/plugins/FileLocator.java @@ -34,11 +34,14 @@ package com.jme3.asset.plugins; import com.jme3.asset.AssetInfo; import com.jme3.asset.AssetKey; +import com.jme3.asset.AssetLoadException; import com.jme3.asset.AssetLocator; import com.jme3.asset.AssetManager; +import com.jme3.asset.AssetNotFoundException; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.IOException; import java.io.InputStream; /** @@ -82,6 +85,19 @@ public class FileLocator implements AssetLocator { String name = key.getName(); File file = new File(root, name); if (file.exists() && file.isFile()){ + try { + // Now, check asset name requirements + String canonical = file.getCanonicalPath(); + String absolute = file.getAbsolutePath(); + if (!canonical.endsWith(absolute)){ + throw new AssetNotFoundException("Asset name doesn't match requirements.\n"+ + "\"" + canonical + "\" doesn't match \"" + absolute + "\""); + } + } catch (IOException ex) { + throw new AssetLoadException("Failed to get file canonical path " + file, ex); + } + + return new AssetInfoFile(manager, key, file); }else{ return null;