]> gitweb.fperrin.net Git - GpsPrune.git/blob - src/tim/prune/function/srtm/SrtmDiskCache.java
Use SRTM 1deg data from NASA servers
[GpsPrune.git] / src / tim / prune / function / srtm / SrtmDiskCache.java
1 package tim.prune.function.srtm;
2
3 import java.io.File;
4
5 import tim.prune.config.Config;
6 import tim.prune.I18nManager;
7
8 public class SrtmDiskCache {
9
10         private static boolean _cacheIsUsable = false;
11         private static File _cacheDir = null;
12
13         public static boolean ensureCacheIsUsable()
14         {
15
16                 if (_cacheIsUsable)
17                 {
18                         return true;
19                 }
20                 // Check the cache is ok
21                 String diskCachePath = Config.getConfigString(Config.KEY_DISK_CACHE);
22                 if (diskCachePath == null)
23                 {
24                         return false;
25                 }
26                 File srtmDir = new File(diskCachePath, "srtm");
27                 if (!srtmDir.exists() && !srtmDir.mkdir()) {
28                         // can't create the srtm directory
29                         return false;
30                 }
31                 _cacheIsUsable = true;
32                 _cacheDir = srtmDir;
33                 return true;
34         }
35
36         public static File getCacheDir(String inSourceName)
37         {
38                 if (_cacheDir == null)
39                 {
40                         ensureCacheIsUsable();
41                 }
42                 File cacheDir = new File(_cacheDir, inSourceName);
43                 if (!cacheDir.exists() && !cacheDir.mkdir()) {
44                         // can't create the srtm directory
45                         return null;
46                 }
47                 return cacheDir;
48         }
49 }