From 945a0f30aaf3595cd0411521b0596073aca445c0 Mon Sep 17 00:00:00 2001
From: str4d <str4d@mail.i2p>
Date: Mon, 23 Jul 2012 10:39:11 +0000
Subject: [PATCH] If the theme set for snark doesn't exist, use the default
 instead

---
 .../src/org/klomp/snark/SnarkManager.java     | 24 ++++++++++++-------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java b/apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java
index 25a0f9a031..d4733cd533 100644
--- a/apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java
+++ b/apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java
@@ -289,14 +289,7 @@ public class SnarkManager implements Snark.CompleteListener {
         if (!_config.containsKey(PROP_STARTUP_DELAY))
             _config.setProperty(PROP_STARTUP_DELAY, Integer.toString(DEFAULT_STARTUP_DELAY));
         // Fetch theme
-        Properties themeProps = _context.readConfigFile(THEME_CONFIG_FILE);
-        _theme = themeProps.getProperty(PROP_THEME);
-        // Ensure that theme config line exists in config file
-        if (_theme == null) {
-            _theme = DEFAULT_THEME;
-            themeProps.put(PROP_THEME, _theme);
-            _context.writeConfigFile(THEME_CONFIG_FILE, themeProps);
-        }
+        _theme = getTheme();
         updateConfig();
     }
     /**
@@ -305,7 +298,20 @@ public class SnarkManager implements Snark.CompleteListener {
      * @return String -- the current theme
      */
     public String getTheme() {
-        _theme = _context.readConfigFile(THEME_CONFIG_FILE).getProperty(PROP_THEME, DEFAULT_THEME);
+        Properties themeProps = _context.readConfigFile(THEME_CONFIG_FILE);
+        _theme = themeProps.getProperty(PROP_THEME);
+        // 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, _theme);
+            _context.writeConfigFile(THEME_CONFIG_FILE, themeProps);
+        }
         return _theme;
     }
 
-- 
GitLab