From 8379b2e4a5dd76fcbd344b7a152dc14629f64ae9 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Mon, 22 Sep 2014 16:55:49 +0200 Subject: [client] do commit the changes :) --- dozentenmodul/src/main/java/config/Config.java | 29 ++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'dozentenmodul/src/main/java/config/Config.java') diff --git a/dozentenmodul/src/main/java/config/Config.java b/dozentenmodul/src/main/java/config/Config.java index 95547b5f..547e0ad5 100644 --- a/dozentenmodul/src/main/java/config/Config.java +++ b/dozentenmodul/src/main/java/config/Config.java @@ -1,8 +1,10 @@ package config; + import java.io.File; import java.io.IOException; +import org.apache.log4j.Logger; import org.ini4j.Wini; /** @@ -13,6 +15,11 @@ import org.ini4j.Wini; public class Config { + /** + * Logger for this class + */ + private final static Logger LOGGER = Logger.getLogger(Config.class); + /** * The main configuration object is of type Wini * It contains the content of the config.ini as @@ -39,7 +46,7 @@ public class Config { // Determine OS String OSName = System.getProperty("os.name").toLowerCase(); - System.out.println("Machine's OS: " + OSName); + LOGGER.info("Machine's OS: " + OSName); if (OSName.contains("windows")) { // Windows machine. Use the environment variable 'APPDATA' which // should point to a path similar to: @@ -49,7 +56,7 @@ public class Config { configPath = appDataPath + "\\bwSuite\\config.ini"; } else { // APPDATA was empty, let's build it ourselves... - System.out.println("APPDATA ist leer."); + LOGGER.warn("APPDATA ist leer."); configPath = System.getProperty("user.home") + "\\AppData\\Roaming\\bwSuite\\config.ini"; } @@ -69,7 +76,7 @@ public class Config { // Check if the directory exists. if (!configFile.getParentFile().exists()) { - System.out.println("Ordner " + configFile.getParentFile() + " exisitiert nicht - lege ihn jetzt an."); + LOGGER.info("Ordner " + configFile.getParentFile() + " exisitiert nicht - lege ihn jetzt an."); // Does not, create it if (!configFile.getParentFile().mkdirs()) { throw new IOException("Konnte '" + configFile.getParentFile() + "' nicht erstellen."); @@ -84,7 +91,7 @@ public class Config { // Check if file is writeable if(configFile.canWrite()) { ini = new Wini(configFile); - System.out.println("Erzeuge '" + configFile + "'..."); + LOGGER.info("Erzeuge '" + configFile + "'..."); // write default configuration options and values ini.put("main", "BillOfRights", false); ini.put("main", "vmware", false); @@ -98,7 +105,7 @@ public class Config { throw new IOException("Konnte nicht in '" + configFile + "' schreiben. Haben Sie Rechte dazu?"); } } else { - System.out.println("'" + configFile + "' existiert bereits - keine weitere Aktion."); + LOGGER.info("'" + configFile + "' existiert bereits - keine weitere Aktion."); ini = new Wini(configFile); } } // end constructor. @@ -146,6 +153,17 @@ public class Config { return getString("main", "Letzter Uploadpfad", System.getProperty("user.home")); } + /** + * Query the path of the configuration file + * @return path to the configuration file + */ + public static String getPath() { + if (ini.getFile().getParentFile().isDirectory()) + return ini.getFile().getParentFile().toString(); + else + return null; + } + /** * Sets the value of 'BillOfRights' in the configuration file to 'value' * @return true if it succeeded, false otherwise @@ -199,7 +217,6 @@ public class Config { ini.store(); return true; } catch (IOException e) { - // TODO Auto-generated catch block e.printStackTrace(); return false; } -- cgit v1.2.3-55-g7522