Merge remote-tracking branch 'abex/cli-args' into next

This commit is contained in:
Adam
2018-05-01 21:24:05 -04:00
3 changed files with 78 additions and 36 deletions

View File

@@ -28,33 +28,34 @@ import java.applet.Applet;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import java.util.Optional;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.runelite.http.api.updatecheck.UpdateCheckClient; import net.runelite.http.api.updatecheck.UpdateCheckClient;
@Slf4j @Slf4j
public class ClientLoader public class ClientLoader
{ {
public Optional<Applet> loadRs(boolean disableUpdateCheck) public Applet loadRs(UpdateCheckMode updateMode)
{ {
boolean isOutdated = false; if (updateMode == UpdateCheckMode.AUTO)
if (!disableUpdateCheck)
{ {
final UpdateCheckClient updateCheck = new UpdateCheckClient(); final UpdateCheckClient updateCheck = new UpdateCheckClient();
isOutdated = updateCheck.isOutdated(); updateMode = updateCheck.isOutdated() ?
UpdateCheckMode.VANILLA :
UpdateCheckMode.RUNELITE;
} }
try try
{ {
if (isOutdated) switch (updateMode)
{ {
log.info("RuneLite is outdated - fetching vanilla client"); case RUNELITE:
return Optional.of(loadVanilla()); 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) catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException e)
{ {
@@ -66,7 +67,8 @@ public class ClientLoader
} }
log.error("Error loading RS!", e); 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 // Must set parent classloader to null, or it will pull from
// this class's classloader first // this class's classloader first
URLClassLoader classloader = new URLClassLoader(new URL[] URLClassLoader classloader = new URLClassLoader(new URL[]
{ {
url url
}, null); }, null);
Class<?> clientClass = classloader.loadClass(initialClass); Class<?> clientClass = classloader.loadClass(initialClass);
Applet rs = (Applet) clientClass.newInstance(); Applet rs = (Applet) clientClass.newInstance();

View File

@@ -34,10 +34,11 @@ import com.google.inject.Injector;
import com.google.inject.Provider; import com.google.inject.Provider;
import java.applet.Applet; import java.applet.Applet;
import java.io.File; import java.io.File;
import java.util.Optional;
import javax.inject.Singleton; import javax.inject.Singleton;
import joptsimple.ArgumentAcceptingOptionSpec;
import joptsimple.OptionParser; import joptsimple.OptionParser;
import joptsimple.OptionSet; import joptsimple.OptionSet;
import joptsimple.util.EnumConverter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.client.account.SessionManager; import net.runelite.client.account.SessionManager;
@@ -119,12 +120,29 @@ public class RuneLite
public static void main(String[] args) throws Exception public static void main(String[] args) throws Exception
{ {
OptionParser parser = new OptionParser(); OptionParser parser = new OptionParser();
parser.accepts("developer-mode"); parser.accepts("developer-mode", "Enable developer tools");
parser.accepts("no-rs"); parser.accepts("debug", "Show extra debugging output");
parser.accepts("debug"); ArgumentAcceptingOptionSpec<UpdateCheckMode> updateMode = parser.accepts("rs", "Select client type")
parser.accepts("disable-update-check"); .withRequiredArg()
.ofType(UpdateCheckMode.class)
.defaultsTo(UpdateCheckMode.AUTO)
.withValuesConvertedBy(new EnumConverter<UpdateCheckMode>(UpdateCheckMode.class)
{
@Override
public UpdateCheckMode convert(String v)
{
return super.convert(v.toUpperCase());
}
});
parser.accepts("help", "Show this text").forHelp();
setOptions(parser.parse(args)); setOptions(parser.parse(args));
if (getOptions().has("help"))
{
parser.printHelpOn(System.out);
System.exit(0);
}
PROFILES_DIR.mkdirs(); PROFILES_DIR.mkdirs();
// Setup logger // Setup logger
@@ -137,26 +155,15 @@ public class RuneLite
} }
setInjector(Guice.createInjector(new RuneLiteModule())); 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 // Load RuneLite or Vanilla client
final boolean hasRs = !getOptions().has("no-rs"); final Applet client = new ClientLoader().loadRs(updateMode);
final boolean disableUpdateCheck = getOptions().has("disable-update-check");
final Optional<Applet> optionalClient = hasRs
? new ClientLoader().loadRs(disableUpdateCheck)
: Optional.empty();
if (!optionalClient.isPresent() && hasRs) final boolean isOutdated = !(client instanceof Client);
{
System.exit(-1);
return;
}
final Applet client = optionalClient.orElse(null);
final boolean isOutdated = client == null || !(client instanceof Client);
if (!isOutdated) if (!isOutdated)
{ {

View File

@@ -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
}