Some interface deconcretization, and changed config parsing so that we only
complain if you actually provide an unparseable rect or color. If you don't provide one at all, we'll use the default. I want people to be able to configure Getdown with just: ui.name = My Project and get a no-frills, but usable interface that displays download and installation progress. Previously, this resulted in a bunch of warnings when they tried to generate their digest.txt because they failed to supply cryptic things like "ui.progress = 17, 321, 458, 22". I'd rather that be optional. I may add some sort of "spurious config" warning, so that if you provide "ui.progres = 17, 321, 458, 22" and you're wondering why things aren't working, you don't spend hours pulling your hair out.
This commit is contained in:
@@ -57,8 +57,8 @@ import java.util.HashMap;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@@ -421,7 +421,7 @@ public class Application
|
|||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
// parse our configuration file
|
// parse our configuration file
|
||||||
HashMap<String,Object> cdata = null;
|
Map<String,Object> cdata = null;
|
||||||
try {
|
try {
|
||||||
cdata = ConfigUtil.parseConfig(_config, checkPlatform);
|
cdata = ConfigUtil.parseConfig(_config, checkPlatform);
|
||||||
} catch (FileNotFoundException fnfe) {
|
} catch (FileNotFoundException fnfe) {
|
||||||
@@ -602,7 +602,7 @@ public class Application
|
|||||||
ui.progressBar = parseColor(cdata, "ui.progress_bar", ui.progressBar);
|
ui.progressBar = parseColor(cdata, "ui.progress_bar", ui.progressBar);
|
||||||
ui.status = parseRect(cdata, "ui.status", ui.status);
|
ui.status = parseRect(cdata, "ui.status", ui.status);
|
||||||
ui.statusText = parseColor(cdata, "ui.status_text", ui.statusText);
|
ui.statusText = parseColor(cdata, "ui.status_text", ui.statusText);
|
||||||
ui.textShadow = parseColor(cdata, "ui.text_shadow", ui.textShadow, false);
|
ui.textShadow = parseColor(cdata, "ui.text_shadow", ui.textShadow);
|
||||||
ui.backgroundImage = (String)cdata.get("ui.background_image");
|
ui.backgroundImage = (String)cdata.get("ui.background_image");
|
||||||
if (ui.backgroundImage == null) { // support legacy format
|
if (ui.backgroundImage == null) { // support legacy format
|
||||||
ui.backgroundImage = (String)cdata.get("ui.background");
|
ui.backgroundImage = (String)cdata.get("ui.background");
|
||||||
@@ -1343,8 +1343,8 @@ public class Application
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Used to parse resources with the specified name. */
|
/** Used to parse resources with the specified name. */
|
||||||
protected void parseResources (HashMap<String,Object> cdata, String name, boolean unpack,
|
protected void parseResources (Map<String,Object> cdata, String name, boolean unpack,
|
||||||
ArrayList<Resource> list)
|
List<Resource> list)
|
||||||
{
|
{
|
||||||
String[] rsrcs = ConfigUtil.getMultiValue(cdata, name);
|
String[] rsrcs = ConfigUtil.getMultiValue(cdata, name);
|
||||||
if (rsrcs == null) {
|
if (rsrcs == null) {
|
||||||
@@ -1360,51 +1360,35 @@ public class Application
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Used to parse rectangle specifications from the config file. */
|
/** Used to parse rectangle specifications from the config file. */
|
||||||
protected Rectangle parseRect (HashMap<String,Object> cdata, String name, Rectangle def)
|
protected Rectangle parseRect (Map<String,Object> cdata, String name, Rectangle def)
|
||||||
{
|
{
|
||||||
String value = (String)cdata.get(name);
|
String value = (String)cdata.get(name);
|
||||||
Rectangle rect = parseRect(value);
|
Rectangle rect = parseRect(name, value);
|
||||||
if (rect == null) {
|
return (rect == null) ? def : rect;
|
||||||
log.warning("Ignoring invalid '" + name + "' config '" + value + "'.");
|
|
||||||
} else {
|
|
||||||
return rect;
|
|
||||||
}
|
|
||||||
return def;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes a comma-separated String of four integers and returns a rectangle using those ints as
|
* Takes a comma-separated String of four integers and returns a rectangle using those ints as
|
||||||
* the its x, y, width, and height.
|
* the its x, y, width, and height.
|
||||||
*/
|
*/
|
||||||
public static Rectangle parseRect (String value)
|
public static Rectangle parseRect (String name, String value)
|
||||||
{
|
{
|
||||||
if (!StringUtil.isBlank(value)) {
|
if (!StringUtil.isBlank(value)) {
|
||||||
int[] v = StringUtil.parseIntArray(value);
|
int[] v = StringUtil.parseIntArray(value);
|
||||||
if (v != null && v.length == 4) {
|
if (v != null && v.length == 4) {
|
||||||
return new Rectangle(v[0], v[1], v[2], v[3]);
|
return new Rectangle(v[0], v[1], v[2], v[3]);
|
||||||
}
|
}
|
||||||
|
log.warning("Ignoring invalid '" + name + "' config '" + value + "'.");
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Used to parse color specifications from the config file. */
|
/** Used to parse color specifications from the config file. */
|
||||||
protected Color parseColor (HashMap<String, Object> cdata, String name, Color def)
|
protected Color parseColor (Map<String, Object> cdata, String name, Color def)
|
||||||
{
|
|
||||||
return parseColor(cdata, name, def, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Used to parse color specifications from the config file. */
|
|
||||||
protected Color parseColor (HashMap<String, Object> cdata, String name, Color def,
|
|
||||||
boolean required)
|
|
||||||
{
|
{
|
||||||
String value = (String)cdata.get(name);
|
String value = (String)cdata.get(name);
|
||||||
Color color = parseColor(value);
|
Color color = parseColor(value);
|
||||||
if (color == null && required) {
|
return (color == null) ? def : color;
|
||||||
log.warning("Ignoring invalid '" + name + "' config '" + value + "'.");
|
|
||||||
} else {
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
return def;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1424,7 +1408,7 @@ public class Application
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Parses a list of strings from the config file. */
|
/** Parses a list of strings from the config file. */
|
||||||
protected String[] parseList (HashMap<String, Object> cdata, String name)
|
protected String[] parseList (Map<String, Object> cdata, String name)
|
||||||
{
|
{
|
||||||
String value = (String)cdata.get(name);
|
String value = (String)cdata.get(name);
|
||||||
return (value == null) ? new String[0] : StringUtil.parseStringArray(value);
|
return (value == null) ? new String[0] : StringUtil.parseStringArray(value);
|
||||||
@@ -1482,16 +1466,15 @@ public class Application
|
|||||||
protected int _javaVersion;
|
protected int _javaVersion;
|
||||||
protected String _javaLocation;
|
protected String _javaLocation;
|
||||||
|
|
||||||
protected ArrayList<Resource> _codes = new ArrayList<Resource>();
|
protected List<Resource> _codes = new ArrayList<Resource>();
|
||||||
protected ArrayList<Resource> _resources = new ArrayList<Resource>();
|
protected List<Resource> _resources = new ArrayList<Resource>();
|
||||||
|
|
||||||
protected ArrayList<String> _auxgroups = new ArrayList<String>();
|
protected List<String> _auxgroups = new ArrayList<String>();
|
||||||
protected HashMap<String,ArrayList<Resource>> _auxrsrcs =
|
protected Map<String,ArrayList<Resource>> _auxrsrcs = new HashMap<String,ArrayList<Resource>>();
|
||||||
new HashMap<String,ArrayList<Resource>>();
|
protected Map<String,Boolean> _auxactive = new HashMap<String,Boolean>();
|
||||||
protected HashMap<String,Boolean> _auxactive = new HashMap<String,Boolean>();
|
|
||||||
|
|
||||||
protected ArrayList<String> _jvmargs = new ArrayList<String>();
|
protected List<String> _jvmargs = new ArrayList<String>();
|
||||||
protected ArrayList<String> _appargs = new ArrayList<String>();
|
protected List<String> _appargs = new ArrayList<String>();
|
||||||
|
|
||||||
protected String[] _baseJvmArgs = new String[0];
|
protected String[] _baseJvmArgs = new String[0];
|
||||||
protected String[] _baseAppArgs = new String[0];
|
protected String[] _baseAppArgs = new String[0];
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ import java.net.URL;
|
|||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.Map;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
@@ -282,7 +282,7 @@ public abstract class Getdown extends Thread
|
|||||||
File pfile = _app.getLocalPath("proxy.txt");
|
File pfile = _app.getLocalPath("proxy.txt");
|
||||||
if (pfile.exists()) {
|
if (pfile.exists()) {
|
||||||
try {
|
try {
|
||||||
HashMap<String, Object> pconf = ConfigUtil.parseConfig(pfile, false);
|
Map<String, Object> pconf = ConfigUtil.parseConfig(pfile, false);
|
||||||
setProxyProperties((String)pconf.get("host"), (String)pconf.get("port"));
|
setProxyProperties((String)pconf.get("host"), (String)pconf.get("port"));
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
@@ -546,7 +546,7 @@ public abstract class Getdown extends Thread
|
|||||||
reportTrackingEvent("jvm_start", -1);
|
reportTrackingEvent("jvm_start", -1);
|
||||||
|
|
||||||
updateStatus("m.downloading_java");
|
updateStatus("m.downloading_java");
|
||||||
ArrayList<Resource> list = new ArrayList<Resource>();
|
List<Resource> list = new ArrayList<Resource>();
|
||||||
list.add(vmjar);
|
list.add(vmjar);
|
||||||
download(list);
|
download(list);
|
||||||
|
|
||||||
@@ -598,7 +598,7 @@ public abstract class Getdown extends Thread
|
|||||||
// attempt to download the patch files
|
// attempt to download the patch files
|
||||||
Resource patch = _app.getPatchResource(null);
|
Resource patch = _app.getPatchResource(null);
|
||||||
if (patch != null) {
|
if (patch != null) {
|
||||||
ArrayList<Resource> list = new ArrayList<Resource>();
|
List<Resource> list = new ArrayList<Resource>();
|
||||||
list.add(patch);
|
list.add(patch);
|
||||||
|
|
||||||
// add the auxiliary group patch files for activated groups
|
// add the auxiliary group patch files for activated groups
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ public class GetdownAppletConfig
|
|||||||
// This allows us to configure the status panel from applet parameters in case something
|
// This allows us to configure the status panel from applet parameters in case something
|
||||||
// goes horribly wrong before we get a chance to read getdown.txt (like when the user
|
// goes horribly wrong before we get a chance to read getdown.txt (like when the user
|
||||||
// rejects write permission for the applet)
|
// rejects write permission for the applet)
|
||||||
statusBounds = Application.parseRect(getParameter("ui.status"));
|
statusBounds = Application.parseRect("ui.status", getParameter("ui.status"));
|
||||||
statusColor = Application.parseColor(getParameter("ui.status_text"));
|
statusColor = Application.parseColor(getParameter("ui.status_text"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import java.io.Reader;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import com.samskivert.util.StringUtil;
|
import com.samskivert.util.StringUtil;
|
||||||
|
|
||||||
@@ -82,10 +83,10 @@ public class ConfigUtil
|
|||||||
* @return a map from keys to values, where a value will be an array of strings if more than
|
* @return a map from keys to values, where a value will be an array of strings if more than
|
||||||
* one key/value pair in the config file was associated with the same key.
|
* one key/value pair in the config file was associated with the same key.
|
||||||
*/
|
*/
|
||||||
public static HashMap<String, Object> parseConfig (File config, boolean checkPlatform)
|
public static Map<String, Object> parseConfig (File config, boolean checkPlatform)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
HashMap<String, Object> data = new HashMap<String, Object>();
|
Map<String, Object> data = new HashMap<String, Object>();
|
||||||
|
|
||||||
// I thought that we could use HashMap<String, String[]> and put new String[] {pair[1]} for
|
// I thought that we could use HashMap<String, String[]> and put new String[] {pair[1]} for
|
||||||
// the null case, but it mysteriously dies on launch, so leaving it as HashMap<String,
|
// the null case, but it mysteriously dies on launch, so leaving it as HashMap<String,
|
||||||
@@ -112,7 +113,7 @@ public class ConfigUtil
|
|||||||
* Massages a single string into an array and leaves existing array values as is. Simplifies
|
* Massages a single string into an array and leaves existing array values as is. Simplifies
|
||||||
* access to parameters that are expected to be arrays.
|
* access to parameters that are expected to be arrays.
|
||||||
*/
|
*/
|
||||||
public static String[] getMultiValue (HashMap<String, Object> data, String name)
|
public static String[] getMultiValue (Map<String, Object> data, String name)
|
||||||
{
|
{
|
||||||
Object value = data.get(name);
|
Object value = data.get(name);
|
||||||
if (value instanceof String) {
|
if (value instanceof String) {
|
||||||
|
|||||||
Reference in New Issue
Block a user