From 3d69d2bf63ac7a6faa5243092f2651cfc5e8e683 Mon Sep 17 00:00:00 2001 From: str4d <str4d@mail.i2p> Date: Tue, 31 Jul 2012 12:56:23 +0000 Subject: [PATCH] If the theme set for susidns doesn't exist, use the default instead --- .../src/java/src/i2p/susi/dns/BaseBean.java | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/apps/susidns/src/java/src/i2p/susi/dns/BaseBean.java b/apps/susidns/src/java/src/i2p/susi/dns/BaseBean.java index e157c745a3..a58d49602d 100644 --- a/apps/susidns/src/java/src/i2p/susi/dns/BaseBean.java +++ b/apps/susidns/src/java/src/i2p/susi/dns/BaseBean.java @@ -49,8 +49,14 @@ public class BaseBean // Fetch theme Properties themeProps = _context.readConfigFile(THEME_CONFIG_FILE); _theme = themeProps.getProperty(PROP_THEME_NAME); - // Ensure that theme config line exists in config file - if (_theme == null) { + // Ensure that theme config line exists in config file, and theme exists + String[] themes = getThemes(); + boolean themeExists = false; + for (int i = 0; i < themes.length; i++) { + if (themes[i].equals(_theme)) + themeExists = true; + } + if (_theme == null || !themeExists) { _theme = DEFAULT_THEME; themeProps.put(PROP_THEME_NAME, _theme); _context.writeConfigFile(THEME_CONFIG_FILE, themeProps); @@ -75,4 +81,26 @@ public class BaseBean url += _theme + "/"; return url; } + + /** + * Get all themes + * @return String[] -- Array of all the themes found. + * @since 0.9.2 + */ + public String[] getThemes() { + String[] themes = null; + // "docs/themes/susidns/" + File dir = new File(_context.getBaseDir(), "docs/themes/susidns"); + FileFilter fileFilter = new FileFilter() { public boolean accept(File file) { return file.isDirectory(); } }; + // Walk the themes dir, collecting the theme names, and append them to the map + File[] dirnames = dir.listFiles(fileFilter); + if (dirnames != null) { + themes = new String[dirnames.length]; + for(int i = 0; i < dirnames.length; i++) { + themes[i] = dirnames[i].getName(); + } + } + // return the map. + return themes; + } } -- GitLab