From 469f4feb0a3d4478c9cbf9e72edb4ec18065c386 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Mon, 26 Nov 2018 12:36:48 -0800 Subject: [PATCH] Auto-create app dir if we have an appbase. We were already doing this for bootstrap.properties-based launches, but there's no reason to restrict it to that. If you run Getdown with an appbase and an appdir, it can create the app dir and download the app into it. This enables scenarios where getdown is installed to a shared location and users that run the app install it in their private storage area (or on a machine local file system, or who knows). Closes #163. --- CHANGELOG.md | 5 +++ .../threerings/getdown/data/EnvConfig.java | 37 ++++++++++++------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6133cd4..debff2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,14 @@ ## 1.8.1 - Unreleased +* If both an `appbase` and `appdir` are provided via some means (bootstrap properties file, system + property, etc.) and the app dir does not yet exist, Getdown will create it. + * Added `max_concurrent_downloads` setting to `getdown.txt`. Controls what you would expect. Defaults to two. +* Fixed issue with `appid` not being properly used when specified via command line arg. + * Fixed issue with running Getdown on single CPU systems (or virtual systems). It was attempting to create a thread pool of size zero, which failed. diff --git a/core/src/main/java/com/threerings/getdown/data/EnvConfig.java b/core/src/main/java/com/threerings/getdown/data/EnvConfig.java index 6fe28a7..68e988a 100644 --- a/core/src/main/java/com/threerings/getdown/data/EnvConfig.java +++ b/core/src/main/java/com/threerings/getdown/data/EnvConfig.java @@ -60,10 +60,6 @@ public final class EnvConfig { if (bundle.containsKey("appdir")) { appDir = bundle.getString("appdir"); appDir = appDir.replace(USER_HOME_KEY, System.getProperty("user.home")); - File appDirFile = new File(appDir); - if (!appDirFile.exists()) { - appDirFile.mkdirs(); - } appDirProv = "bootstrap.properties"; } if (bundle.containsKey("appid")) { @@ -137,17 +133,32 @@ public final class EnvConfig { return null; // caller will report problem to user } - // ensure that the appdir refers to a directory that exists - File appDirFile = new File(appDir); - if (!appDirFile.exists() || !appDirFile.isDirectory()) { - notes.add(Note.error("Invalid appdir '" + appDir + "'.")); - return null; - } - notes.add(Note.info("Using appdir from " + appDirProv + ": " + appDir)); if (appId != null) notes.add(Note.info("Using appid from " + appIdProv + ": " + appId)); - if (appBase != null) notes.add(Note.info("Using appbase from " + appBaseProv + ": " + - appBase)); + if (appBase != null) notes.add( + Note.info("Using appbase from " + appBaseProv + ": " + appBase)); + + // ensure that the appdir refers to a directory that exists + File appDirFile = new File(appDir); + if (!appDirFile.exists()) { + // if we have a bootstrap URL then we auto-create the app dir; this enables an + // installer to simply place a getdown.jar file somewhere and create an OS shortcut + // that runs getdown with an appdir and appbase specified, and have getdown create the + // appdir and download the app into it + if (!StringUtil.isBlank(appBase)) { + if (appDirFile.mkdirs()) { + notes.add(Note.info("Auto-created app directory '" + appDir + "'")); + } else { + notes.add(Note.warn("Unable to auto-create app dir: '" + appDir + "'")); + } + } else { + notes.add(Note.error("Invalid appdir '" + appDir + "': directory does not exist")); + return null; + } + } else if (!appDirFile.isDirectory()) { + notes.add(Note.error("Invalid appdir '" + appDir + "': refers to non-directory")); + return null; + } // pass along anything after the first two args as extra app args List appArgs = argv.length > 2 ?