From: David ‘Bombe’ Roden Date: Fri, 21 Jul 2006 23:42:25 +0000 (+0000) Subject: let users specify configuration file on the command line X-Git-Tag: 0.4.7~1 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=978a833ff2f68927ea0c376f9ad538069898f1e7;p=jSite.git let users specify configuration file on the command line --- diff --git a/src/de/todesbaum/jsite/main/Configuration.java b/src/de/todesbaum/jsite/main/Configuration.java index 9b43784..e4e0510 100644 --- a/src/de/todesbaum/jsite/main/Configuration.java +++ b/src/de/todesbaum/jsite/main/Configuration.java @@ -53,13 +53,21 @@ public class Configuration { private SimpleXML rootNode; public Configuration() { - filename = System.getProperty("user.home") + "/.jSite/config7"; - lockFilename = System.getProperty("user.home") + "/.jSite/lock7"; + this(System.getProperty("user.home") + "/.jSite/config7"); + } + + public Configuration(String filename) { + this(filename, filename + ".lock"); + } + + public Configuration(String filename, String lockFilename) { + this.filename = filename; + this.lockFilename = lockFilename; readConfiguration(); } private boolean createConfigDirectory() { - File configDirectory = new File(System.getProperty("user.home"), ".jSite"); + File configDirectory = new File(filename).getAbsoluteFile().getParentFile(); return (configDirectory.exists() && configDirectory.isDirectory()) || configDirectory.mkdirs(); } @@ -112,7 +120,7 @@ public class Configuration { public boolean save() { File configurationFile = new File(filename); if (!configurationFile.exists()) { - File configurationFilePath = configurationFile.getParentFile(); + File configurationFilePath = configurationFile.getAbsoluteFile().getParentFile(); if (!configurationFilePath.exists() && !configurationFilePath.mkdirs()) { return false; } diff --git a/src/de/todesbaum/jsite/main/Main.java b/src/de/todesbaum/jsite/main/Main.java index 76d456d..3a62d9a 100644 --- a/src/de/todesbaum/jsite/main/Main.java +++ b/src/de/todesbaum/jsite/main/Main.java @@ -64,7 +64,7 @@ import de.todesbaum.util.swing.WizardListener; public class Main implements ActionListener, ListSelectionListener, WizardListener, NodeManagerListener { private static boolean debug = false; - private Configuration configuration = new Configuration(); + private Configuration configuration; private Freenet7Interface freenetInterface = new Freenet7Interface(); protected Icon jSiteIcon; @@ -82,6 +82,15 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen private final Map pages = new HashMap(); private Main() { + this(null); + } + + private Main(String configFilename) { + if (configFilename != null) { + configuration = new Configuration(configFilename); + } else { + configuration = new Configuration(); + } Locale.setDefault(configuration.getLocale()); I18n.setLocale(configuration.getLocale()); if (!configuration.createLockFile()) { @@ -405,13 +414,37 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen // // MAIN METHOD // - public static void main(String[] args) { System.setProperty("swing.plaf.metal.userFont", "Tahoma"); System.setProperty("swing.plaf.metal.controlFont", "Tahoma"); System.setProperty("swing.aatext", "true"); - debug = (args.length > 0) && (args[0].equals("--debug")); - new Main(); + String configFilename = null; + boolean nextIsConfigFilename = false; + for (String argument: args) { + if (nextIsConfigFilename) { + configFilename = argument; + nextIsConfigFilename = false; + } + if ("--help".equals(argument)) { + printHelp(); + return; + } else if ("--debug".equals(argument)) { + debug = true; + } else if ("--config-file".equals(argument)) { + nextIsConfigFilename = true; + } + } + if (nextIsConfigFilename) { + System.out.println("--config-file needs parameter!"); + return; + } + new Main(configFilename); } + private static void printHelp() { + System.out.println("--help\tshows this cruft"); + System.out.println("--debug\tenables some debug output"); + System.out.println("--config-file \tuse specified configuration file"); + } + }