From 69b7d7ead7f8d6905a72675be536968fc57f8e04 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 31 Jan 2013 10:01:55 -0800 Subject: [PATCH] Read guacamole.properties from home directory first. --- .../properties/GuacamoleProperties.java | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/guacamole-common/src/main/java/net/sourceforge/guacamole/properties/GuacamoleProperties.java b/guacamole-common/src/main/java/net/sourceforge/guacamole/properties/GuacamoleProperties.java index a0e98b667..2706fa7bb 100644 --- a/guacamole-common/src/main/java/net/sourceforge/guacamole/properties/GuacamoleProperties.java +++ b/guacamole-common/src/main/java/net/sourceforge/guacamole/properties/GuacamoleProperties.java @@ -37,6 +37,8 @@ package net.sourceforge.guacamole.properties; * * ***** END LICENSE BLOCK ***** */ +import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Properties; @@ -83,9 +85,36 @@ public class GuacamoleProperties { try { - InputStream stream = GuacamoleProperties.class.getResourceAsStream("/guacamole.properties"); - if (stream == null) - throw new IOException("Resource /guacamole.properties not found."); + // Attempt to find Guacamole home + File guacHome; + + // Get explicitly specified directory, if any + String desiredDir = System.getProperty("guacamole.home"); + if (desiredDir != null) + guacHome = new File(desiredDir); + + // If not explicitly-define directory, use ~/.guacamole + else + guacHome = new File(System.getProperty("user.home"), ".guacamole"); + + InputStream stream; + + // If not a directory, load from classpath + if (!guacHome.isDirectory()) { + + // Read from classpath + stream = GuacamoleProperties.class.getResourceAsStream("/guacamole.properties"); + if (stream == null) + throw new IOException( + "guacamole.properties not loaded from " + guacHome + + " (not a directory), and guacamole.properties could" + + " not be found as a resource in the classpath."); + + } + + // Otherwise, try to load from file + else + stream = new FileInputStream(new File(guacHome, "guacamole.properties")); // Load properties, always close stream try { properties.load(stream); }