X-Git-Url: https://gitweb.fperrin.net/?a=blobdiff_plain;f=src%2Ftim%2Fprune%2Ffunction%2Fsrtm%2FSrtmDiskCache.java;fp=src%2Ftim%2Fprune%2Ffunction%2Fsrtm%2FSrtmDiskCache.java;h=80159e0b33dffeb0c9d178107ea3f567f1679eac;hb=189a667821db055202dcb9f539ee26bd2af7ade4;hp=0000000000000000000000000000000000000000;hpb=2302358503c38817e19f6e529f6c9e530aac0e86;p=GpsPrune.git diff --git a/src/tim/prune/function/srtm/SrtmDiskCache.java b/src/tim/prune/function/srtm/SrtmDiskCache.java new file mode 100644 index 0000000..80159e0 --- /dev/null +++ b/src/tim/prune/function/srtm/SrtmDiskCache.java @@ -0,0 +1,49 @@ +package tim.prune.function.srtm; + +import java.io.File; + +import tim.prune.config.Config; +import tim.prune.I18nManager; + +public class SrtmDiskCache { + + private static boolean _cacheIsUsable = false; + private static File _cacheDir = null; + + public static boolean ensureCacheIsUsable() + { + + if (_cacheIsUsable) + { + return true; + } + // Check the cache is ok + String diskCachePath = Config.getConfigString(Config.KEY_DISK_CACHE); + if (diskCachePath == null) + { + return false; + } + File srtmDir = new File(diskCachePath, "srtm"); + if (!srtmDir.exists() && !srtmDir.mkdir()) { + // can't create the srtm directory + return false; + } + _cacheIsUsable = true; + _cacheDir = srtmDir; + return true; + } + + public static File getCacheDir(String inSourceName) + { + if (_cacheDir == null) + { + ensureCacheIsUsable(); + } + File cacheDir = new File(_cacheDir, inSourceName); + if (!cacheDir.exists() && !cacheDir.mkdir()) { + // can't create the srtm directory + return null; + } + return cacheDir; + } +}