diff options
| author | Jonathan Bauer | 2014-09-12 13:28:29 +0200 |
|---|---|---|
| committer | Jonathan Bauer | 2014-09-12 13:28:29 +0200 |
| commit | 71bf305f6a2ff6c7a688472d034cccb9457492d8 (patch) | |
| tree | 1372dfd6de9d88205c5d4f61d5bf9657735f899b /dozentenmodul/src/main/java/config/config_file.java | |
| parent | [client] Fix jface dependency, generate build number in MANIFEST.MF (still to... (diff) | |
| download | tutor-module-71bf305f6a2ff6c7a688472d034cccb9457492d8.tar.gz tutor-module-71bf305f6a2ff6c7a688472d034cccb9457492d8.tar.xz tutor-module-71bf305f6a2ff6c7a688472d034cccb9457492d8.zip | |
java style name for Config class ...
Diffstat (limited to 'dozentenmodul/src/main/java/config/config_file.java')
| -rw-r--r-- | dozentenmodul/src/main/java/config/config_file.java | 129 |
1 files changed, 0 insertions, 129 deletions
diff --git a/dozentenmodul/src/main/java/config/config_file.java b/dozentenmodul/src/main/java/config/config_file.java deleted file mode 100644 index 3d562b35..00000000 --- a/dozentenmodul/src/main/java/config/config_file.java +++ /dev/null @@ -1,129 +0,0 @@ -package config; - -import java.io.File; -import java.io.IOException; - -import org.ini4j.Wini; - -public class config_file { - - // Nur die Wini als member - private static Wini ini = null; - - // Konstruktor ermittelt der Pfad zur Konfigurationsdatei. - // Unterscheidet dabei Windows/Linux - public static void init() throws IOException { - - // Hauptvariablen nur lokal notwendig - String configPath = null; - File configFile = null; - // Unterscheide zwischen Windows/Unix - String OSName = System.getProperty("os.name").toLowerCase(); - System.out.println("Machine's OS: " + OSName); - if (OSName.contains("windows")) { - // Windows machine. Use the environment variable 'APPDATA' which - // should point to a path similar to: - // C:\Users\<user>\AppData\Roaming - String appDataPath = System.getenv("APPDATA"); - if (!appDataPath.isEmpty()) { - configPath = appDataPath + "\\bwSuite\\config.ini"; - } else { - // APPDATA was empty, let's build it ourselves... - System.out.println("APPDATA ist leer."); - configPath = System.getProperty("user.home") + "\\AppData\\Roaming\\bwSuite\\config.ini"; - } - - } else if (OSName.contains("linux")) { - configPath=System.getProperty("user.home") + "/.config/bwSuite/config.ini"; - } else { - // Nicht Windows oder Linux, TODO MacOS Support? - configPath = null; - } - - //File fuer den Ordner erzeugen - if (!(configPath.isEmpty()||configPath == null)) { - configFile = new File(configPath); - } else { - throw new IOException("Konnte kein Pfad für die Konfigurationsdatei ermitteln."); - } - - // Checke, ob der Ordner existiert. - if (!configFile.getParentFile().exists()) { - System.out.println("Ordner " + configFile.getParentFile() + " exisitiert nicht - lege ihn jetzt an."); - // Wenn nicht, erzeuge Ordner - if (!configFile.getParentFile().mkdirs()) { - throw new IOException("Konnte '" + configFile.getParentFile() + "' nicht erstellen."); - } - } - - // Pruefen, ob Datei schon existiert - if (!configFile.exists()) { - // Erzeuge eine neue Datei - configFile.createNewFile(); - - // Wenn in die Datei geschrieben werden kann - if(configFile.canWrite()) { - ini = new Wini(configFile); - System.out.println("Erzeuge '" + configFile + "'..."); - //Schreibe Config - ini.put("main", "BillOfRights", false); - ini.put("main", "vmware", false); - ini.put("main", "Benutzername speichern", false); - ini.put("main", "Benutzername", ""); - ini.put("main", "Letzter Downloadpfad", ""); - ini.put("main", "Letzter Uploadpfad", ""); - ini.store(); - - } else { - throw new IOException("Konnte nicht in '" + configFile + "' schreiben. Haben Sie Rechte dazu?"); - } - } else { - System.out.println("'" + configFile + "' existiert bereits - keine weitere Aktion."); - ini = new Wini(configFile); - } - } - // Ende Konstruktor. - - // Public funktion zur Abfrage der Boolean-Werte - // Gibt Wert von Attribut 'key' in Sektion 'section', falls es existiert. - // Sonst gibt es 'defaultValue' zurück. - // - // Usage: getBoolean(<section>, <key>, <defaultValue>) - // Ex.: getBoolean("main", "Benutzername", "NichtGesetzt"); - public static boolean getBoolean(String section, String key, Boolean defaultValue) { - if (ini.containsKey(section) && ini.get(section).containsKey(key)) { - return ini.get(section, key, Boolean.class); - } else { - return defaultValue; - } - } - - // Public funktion zur Abfrage der String-Werte - // Usage: getBoolean(<key>) - public static String getString(String section, String key, String defaultValue) { - if (ini.containsKey(section) && ini.get(section).containsKey(key)) { - return ini.get(section, key); - } else { - return defaultValue; - } - } - - public static boolean setBoolean(String section, String key, Boolean value) { - return ini.put(section, key, value) != null; - } - - public static boolean setString(String section, String key, String value) { - return ini.put(section, key, value) != null; - } - - public static boolean store() { - try { - ini.store(); - return true; - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - return false; - } - } -} |
