public AssetInfo locate(AssetManager manager, AssetKey key) { String name = key.getName(); File file = (root != null) ? new File(root, name) : new File(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); } AssetInfo fileAssetInfo = new AssetInfoFile(manager, key, file); return UncompressedAssetInfo.create(fileAssetInfo); } else { return null; } }
public void setRootPath(String rootPath) { if (rootPath == null) { throw new IllegalArgumentException("rootPath is required: use '\' to register any file"); } else if (rootPath == "/") { // any file is okay root = null; return; } try { root = new File(rootPath).getCanonicalFile(); if (!root.isDirectory()) { throw new IllegalArgumentException("Given root path \"" + root + "\" is not a directory"); } } catch (IOException ex) { throw new AssetLoadException("Root path is invalid", ex); } }