From 38427cbc1ee47a572f3fc1290c704f8c6a7dbfd5 Mon Sep 17 00:00:00 2001 From: gropp_volker Date: Mon, 17 Sep 2018 13:04:19 +0200 Subject: [PATCH] load bootstrap.properties from resource bundle --- .../getdown/launcher/GetdownApp.java | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/launcher/src/main/java/com/threerings/getdown/launcher/GetdownApp.java b/launcher/src/main/java/com/threerings/getdown/launcher/GetdownApp.java index 2dbb507..356fac2 100644 --- a/launcher/src/main/java/com/threerings/getdown/launcher/GetdownApp.java +++ b/launcher/src/main/java/com/threerings/getdown/launcher/GetdownApp.java @@ -24,6 +24,8 @@ import java.security.cert.X509Certificate; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.MissingResourceException; +import java.util.ResourceBundle; import javax.swing.JFrame; import javax.swing.WindowConstants; @@ -40,6 +42,9 @@ import static com.threerings.getdown.Log.log; */ public class GetdownApp { + + private static final String USER_HOME = "${user.home}"; + public static void main (String[] argv) { try { @@ -62,11 +67,16 @@ public class GetdownApp // check for app dir in a sysprop and then via argv String adarg = SysProps.appDir(); if (StringUtil.isBlank(adarg)) { - if (args.isEmpty()) { + loadBootstrapResource(); + if (args.isEmpty() && SysProps.appDir() == null) { System.err.println("Usage: java -jar getdown.jar app_dir [app_id] [app args]"); System.exit(-1); } - adarg = args.get(aidx++); + if (!args.isEmpty()) { + adarg = args.get(aidx++); + } else { + adarg = SysProps.appDir(); + } } // check for an app identifier in a sysprop and then via argv @@ -260,4 +270,25 @@ public class GetdownApp app.start(); return app; } + + private static void loadBootstrapResource() { + try { + ResourceBundle bundle = ResourceBundle.getBundle("bootstrap"); + if (bundle.containsKey("appbase")) { + System.setProperty("appbase", bundle.getString("appbase")); + } + if (bundle.containsKey("appdir")) { + String appDir = bundle.getString("appdir"); + appDir = appDir.replace(USER_HOME, System.getProperty("user.home")); + File appDirFile = new File(appDir); + if (!appDirFile.exists()) { + appDirFile.mkdirs(); + } + System.setProperty("appdir", appDir); + } + log.info("bootstrap.properties found using:", "_appdir", System.getProperty("appdir"), "appbase", System.getProperty("appbase")); + } catch (MissingResourceException e) { + log.info("bootstrap.properties not found in resource bundle, starting without bootstrapping"); + } + } }