diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_PluginPreferenceActivity.java b/mobile/src/com/cradle/iitc_mobile/IITC_PluginPreferenceActivity.java index 02ac8ddd..78736a9e 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_PluginPreferenceActivity.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_PluginPreferenceActivity.java @@ -21,6 +21,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Scanner; @@ -193,29 +194,12 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity { void addPluginPreference(String src, String plugin_key, boolean user) { - // now parse plugin name, description and category - String header = src.substring(src.indexOf("==UserScript=="), - src.indexOf("==/UserScript==")); - // remove new line comments and replace with space - // this way we get double spaces instead of newline + double slash - header = header.replace("\n//", " "); - // get a list of key-value...split on multiple spaces - String[] attributes = header.split(" +"); - String plugin_name = "not found"; - String plugin_desc = "not found"; - String plugin_cat = "Misc"; - for (int j = 0; j < attributes.length; j++) { - // search for name and use the value - if (attributes[j].equals("@name")) { - plugin_name = attributes[j + 1]; - } - if (attributes[j].equals("@description")) { - plugin_desc = attributes[j + 1]; - } - if (attributes[j].equals("@category")) { - plugin_cat = attributes[j + 1]; - } - } + // parse plugin name, description and category + // we need default versions here otherwise iitcm may crash + HashMap info = IITC_WebViewClient.getScriptInfo(src); + String plugin_name = info.get("name"); + String plugin_cat = info.get("category"); + String plugin_desc = info.get("description"); // remove IITC plugin prefix from plugin_name plugin_name = plugin_name.replace("IITC Plugin: ", ""); diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java index 38f3e5ba..1749b3a9 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java @@ -56,7 +56,8 @@ public class IITC_WebViewClient extends WebViewClient { return map.get("version"); } - public HashMap getScriptInfo(String js) { + // static method because we use it in IITC_PluginPreferenceActivity too + public static HashMap getScriptInfo(String js) { HashMap map = new HashMap(); String header = ""; if (js != null) { @@ -67,7 +68,12 @@ public class IITC_WebViewClient extends WebViewClient { header = header.replace("\n//", " "); // get a list of key-value String[] attributes = header.split(" +"); - String iitc_version = "not found"; + // add default values + map.put("version", "not found"); + map.put("name", "unknown"); + map.put("description", ""); + map.put("category", "Misc"); + // add parsed values for (int i = 0; i < attributes.length; i++) { // search for attributes and use the value if (attributes[i].equals("@version")) { @@ -79,6 +85,9 @@ public class IITC_WebViewClient extends WebViewClient { if (attributes[i].equals("@description")) { map.put("description", attributes[i + 1]); } + if (attributes[i].equals("@category")) { + map.put("category", attributes[i + 1]); + } } return map; }