Ticket #6405: cachedir.2.patch

File cachedir.2.patch, 1.5 KB (added by bilbo, 14 years ago)

patch to allow absolute cache path, fixed version

  • src/org/openstreetmap/josm/data/imagery/WmsCache.java

     
    9595    private Map<CacheEntry, SoftReference<BufferedImage>> memoryCache = new HashMap<WmsCache.CacheEntry, SoftReference<BufferedImage>>();
    9696    private Set<ProjectionBounds> areaToCache;
    9797
     98    protected String cacheDirPath() {
     99        String cPath = PROP_CACHE_PATH.get();
     100        if (!(cPath.startsWith("/") || cPath.startsWith(":/",1))) {
     101            //Not an absolute path
     102            cPath = Main.pref.getPreferencesDir() + cPath;
     103        }
     104        return cPath;
     105    }
     106
    98107    public WmsCache(String url, int tileSize) {
    99         File globalCacheDir = new File(Main.pref.getPreferencesDir() + PROP_CACHE_PATH.get());
     108        File globalCacheDir = new File(cacheDirPath());
    100109        globalCacheDir.mkdirs();
    101110        cacheDir = new File(globalCacheDir, getCacheDirectory(url));
    102111        cacheDir.mkdirs();
     
    109118        OutputStream fos = null;
    110119        try {
    111120            Properties layersIndex = new Properties();
    112             File layerIndexFile = new File(Main.pref.getPreferencesDir() + PROP_CACHE_PATH.get(), LAYERS_INDEX_FILENAME);
     121            File layerIndexFile = new File(cacheDirPath(), LAYERS_INDEX_FILENAME);
    113122            try {
    114123                fis = new FileInputStream(layerIndexFile);
    115124                layersIndex.load(fis);