1 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
2 // Licensed under the GNU General Public License version 2 ("the License").
3 // You may not use this file except in compliance with the License.
8 import org.ibex.util.*;
9 import org.ibex.crypto.*;
11 /** Manages access to ~/.ibex */
12 public class LocalStorage {
14 static String ibexDirName = System.getProperty("user.home") + java.io.File.separatorChar + ".ibex";
16 static java.io.File ibexDir = null;
17 static java.io.File cacheDir = null;
21 ibexDir = new java.io.File(ibexDirName);
22 if (!ibexDir.mkdirs()) ibexDir = null;
24 cacheDir = new java.io.File(ibexDirName + java.io.File.separatorChar + "cache");
25 if (!cacheDir.mkdirs()) cacheDir = null;
26 } catch (Exception e) {
27 Log.warn(LocalStorage.class, "unable to create cache directory " +
28 ibexDirName + java.io.File.separatorChar + "cache");
30 } catch (Exception e) {
31 Log.warn(LocalStorage.class, "unable to create ibex directory " + ibexDirName);
35 // FEATURE: we ought to be able to do stuff like sha1-checking and date checking on cached resources
36 public static class Cache {
38 private static void delTree(java.io.File f) throws IOException {
39 if (f.isDirectory()) {
40 String[] s = f.list();
41 for(int i=0; i<s.length; i++)
42 delTree(new java.io.File(f.getPath() + java.io.File.separatorChar + s[i]));
47 public static void flush() throws IOException {
52 public static java.io.File getCacheFileForKey(String key) {
53 // FEATURE: be smarter here
54 return new java.io.File(cacheDir.getPath() + File.separatorChar + new String(Base64.encode(key.getBytes())));