From afebe6dbdac4fa8e5d6e74fd50aa50203a9c94ba Mon Sep 17 00:00:00 2001 From: Max Weber Date: Mon, 30 Apr 2018 01:26:37 -0600 Subject: [PATCH] runelite-client: Cleanup cli arguments --- .../net/runelite/client/ClientLoader.java | 34 +++++++------- .../java/net/runelite/client/RuneLite.java | 47 +++++++++++-------- .../net/runelite/client/UpdateCheckMode.java | 33 +++++++++++++ 3 files changed, 78 insertions(+), 36 deletions(-) create mode 100644 runelite-client/src/main/java/net/runelite/client/UpdateCheckMode.java diff --git a/runelite-client/src/main/java/net/runelite/client/ClientLoader.java b/runelite-client/src/main/java/net/runelite/client/ClientLoader.java index 9978fa8eb5..ef657e5bdf 100644 --- a/runelite-client/src/main/java/net/runelite/client/ClientLoader.java +++ b/runelite-client/src/main/java/net/runelite/client/ClientLoader.java @@ -28,33 +28,34 @@ import java.applet.Applet; import java.io.IOException; import java.net.URL; import java.net.URLClassLoader; -import java.util.Optional; import lombok.extern.slf4j.Slf4j; import net.runelite.http.api.updatecheck.UpdateCheckClient; @Slf4j public class ClientLoader { - public Optional loadRs(boolean disableUpdateCheck) + public Applet loadRs(UpdateCheckMode updateMode) { - boolean isOutdated = false; - - if (!disableUpdateCheck) + if (updateMode == UpdateCheckMode.AUTO) { final UpdateCheckClient updateCheck = new UpdateCheckClient(); - isOutdated = updateCheck.isOutdated(); + updateMode = updateCheck.isOutdated() ? + UpdateCheckMode.VANILLA : + UpdateCheckMode.RUNELITE; } try { - if (isOutdated) + switch (updateMode) { - log.info("RuneLite is outdated - fetching vanilla client"); - return Optional.of(loadVanilla()); + case RUNELITE: + return loadRuneLite(); + default: + case VANILLA: + return loadVanilla(); + case NONE: + return null; } - - log.debug("RuneLite is up to date"); - return Optional.of(loadRuneLite()); } catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException e) { @@ -66,7 +67,8 @@ public class ClientLoader } log.error("Error loading RS!", e); - return Optional.empty(); + System.exit(-1); + return null; } } @@ -102,9 +104,9 @@ public class ClientLoader // Must set parent classloader to null, or it will pull from // this class's classloader first URLClassLoader classloader = new URLClassLoader(new URL[] - { - url - }, null); + { + url + }, null); Class clientClass = classloader.loadClass(initialClass); Applet rs = (Applet) clientClass.newInstance(); diff --git a/runelite-client/src/main/java/net/runelite/client/RuneLite.java b/runelite-client/src/main/java/net/runelite/client/RuneLite.java index 94a0322be5..5c65ebfa96 100644 --- a/runelite-client/src/main/java/net/runelite/client/RuneLite.java +++ b/runelite-client/src/main/java/net/runelite/client/RuneLite.java @@ -34,10 +34,11 @@ import com.google.inject.Injector; import com.google.inject.Provider; import java.applet.Applet; import java.io.File; -import java.util.Optional; import javax.inject.Singleton; +import joptsimple.ArgumentAcceptingOptionSpec; import joptsimple.OptionParser; import joptsimple.OptionSet; +import joptsimple.util.EnumConverter; import lombok.extern.slf4j.Slf4j; import net.runelite.api.Client; import net.runelite.client.account.SessionManager; @@ -119,12 +120,29 @@ public class RuneLite public static void main(String[] args) throws Exception { OptionParser parser = new OptionParser(); - parser.accepts("developer-mode"); - parser.accepts("no-rs"); - parser.accepts("debug"); - parser.accepts("disable-update-check"); + parser.accepts("developer-mode", "Enable developer tools"); + parser.accepts("debug", "Show extra debugging output"); + ArgumentAcceptingOptionSpec updateMode = parser.accepts("rs", "Select client type") + .withRequiredArg() + .ofType(UpdateCheckMode.class) + .defaultsTo(UpdateCheckMode.AUTO) + .withValuesConvertedBy(new EnumConverter(UpdateCheckMode.class) + { + @Override + public UpdateCheckMode convert(String v) + { + return super.convert(v.toUpperCase()); + } + }); + parser.accepts("help", "Show this text").forHelp(); setOptions(parser.parse(args)); + if (getOptions().has("help")) + { + parser.printHelpOn(System.out); + System.exit(0); + } + PROFILES_DIR.mkdirs(); // Setup logger @@ -137,26 +155,15 @@ public class RuneLite } setInjector(Guice.createInjector(new RuneLiteModule())); - injector.getInstance(RuneLite.class).start(); + injector.getInstance(RuneLite.class).start(getOptions().valueOf(updateMode)); } - public void start() throws Exception + public void start(UpdateCheckMode updateMode) throws Exception { // Load RuneLite or Vanilla client - final boolean hasRs = !getOptions().has("no-rs"); - final boolean disableUpdateCheck = getOptions().has("disable-update-check"); - final Optional optionalClient = hasRs - ? new ClientLoader().loadRs(disableUpdateCheck) - : Optional.empty(); + final Applet client = new ClientLoader().loadRs(updateMode); - if (!optionalClient.isPresent() && hasRs) - { - System.exit(-1); - return; - } - - final Applet client = optionalClient.orElse(null); - final boolean isOutdated = client == null || !(client instanceof Client); + final boolean isOutdated = !(client instanceof Client); if (!isOutdated) { diff --git a/runelite-client/src/main/java/net/runelite/client/UpdateCheckMode.java b/runelite-client/src/main/java/net/runelite/client/UpdateCheckMode.java new file mode 100644 index 0000000000..06abaaa07d --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/UpdateCheckMode.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018 Abex + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client; + +public enum UpdateCheckMode +{ + AUTO, + NONE, + VANILLA, + RUNELITE +}