client: add session and config file arguments
This commit is contained in:
@@ -33,6 +33,7 @@ import com.google.inject.Injector;
|
||||
import java.io.File;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.RuntimeMXBean;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Locale;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Provider;
|
||||
@@ -41,6 +42,8 @@ import javax.swing.SwingUtilities;
|
||||
import joptsimple.ArgumentAcceptingOptionSpec;
|
||||
import joptsimple.OptionParser;
|
||||
import joptsimple.OptionSet;
|
||||
import joptsimple.ValueConversionException;
|
||||
import joptsimple.ValueConverter;
|
||||
import joptsimple.util.EnumConverter;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -52,12 +55,12 @@ import net.runelite.client.chat.CommandManager;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.discord.DiscordService;
|
||||
import net.runelite.client.eventbus.EventBus;
|
||||
import net.runelite.client.externalplugins.ExternalPluginManager;
|
||||
import net.runelite.client.game.ClanManager;
|
||||
import net.runelite.client.game.ItemManager;
|
||||
import net.runelite.client.game.LootManager;
|
||||
import net.runelite.client.game.chatbox.ChatboxPanelManager;
|
||||
import net.runelite.client.menus.MenuManager;
|
||||
import net.runelite.client.externalplugins.ExternalPluginManager;
|
||||
import net.runelite.client.plugins.PluginManager;
|
||||
import net.runelite.client.rs.ClientLoader;
|
||||
import net.runelite.client.rs.ClientUpdateCheckMode;
|
||||
@@ -85,6 +88,8 @@ public class RuneLite
|
||||
public static final File PROFILES_DIR = new File(RUNELITE_DIR, "profiles");
|
||||
public static final File SCREENSHOT_DIR = new File(RUNELITE_DIR, "screenshots");
|
||||
public static final File LOGS_DIR = new File(RUNELITE_DIR, "logs");
|
||||
public static final String DEFAULT_SESSION_FILE = "session";
|
||||
public static final String DEFAULT_CONFIG_FILE = "settings.properties";
|
||||
|
||||
@Getter
|
||||
private static Injector injector;
|
||||
@@ -173,6 +178,14 @@ public class RuneLite
|
||||
parser.accepts("developer-mode", "Enable developer tools");
|
||||
parser.accepts("debug", "Show extra debugging output");
|
||||
|
||||
final ArgumentAcceptingOptionSpec<File> sessionfile = parser.accepts("sessionfile", "Use a specified session file")
|
||||
.withRequiredArg().defaultsTo(DEFAULT_SESSION_FILE)
|
||||
.withValuesConvertedBy(new ConfigFileConverter());
|
||||
|
||||
final ArgumentAcceptingOptionSpec<File> configfile = parser.accepts("config", "Use a specified config file")
|
||||
.withRequiredArg().defaultsTo(DEFAULT_CONFIG_FILE)
|
||||
.withValuesConvertedBy(new ConfigFileConverter());
|
||||
|
||||
final ArgumentAcceptingOptionSpec<ClientUpdateCheckMode> updateMode = parser
|
||||
.accepts("rs", "Select client type")
|
||||
.withRequiredArg()
|
||||
@@ -246,7 +259,9 @@ public class RuneLite
|
||||
|
||||
injector = Guice.createInjector(new RuneLiteModule(
|
||||
clientLoader,
|
||||
developerMode));
|
||||
developerMode,
|
||||
options.valueOf(sessionfile),
|
||||
options.valueOf(configfile)));
|
||||
|
||||
injector.getInstance(RuneLite.class).start();
|
||||
|
||||
@@ -363,4 +378,43 @@ public class RuneLite
|
||||
{
|
||||
RuneLite.injector = injector;
|
||||
}
|
||||
|
||||
private static class ConfigFileConverter implements ValueConverter<File>
|
||||
{
|
||||
@Override
|
||||
public File convert(String fileName)
|
||||
{
|
||||
final File file;
|
||||
|
||||
if (Paths.get(fileName).isAbsolute()
|
||||
|| fileName.startsWith("./")
|
||||
|| fileName.startsWith(".\\"))
|
||||
{
|
||||
file = new File(fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
file = new File(RuneLite.RUNELITE_DIR, fileName);
|
||||
}
|
||||
|
||||
if (file.exists() && (!file.isFile() || !file.canWrite()))
|
||||
{
|
||||
throw new ValueConversionException(String.format("File %s is not accessible", file.getAbsolutePath()));
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends File> valueType()
|
||||
{
|
||||
return File.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String valuePattern()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,17 +61,23 @@ public class RuneLiteModule extends AbstractModule
|
||||
|
||||
private final Supplier<Applet> clientLoader;
|
||||
private final boolean developerMode;
|
||||
private final File sessionfile;
|
||||
private final File config;
|
||||
|
||||
public RuneLiteModule(Supplier<Applet> clientLoader, boolean developerMode)
|
||||
public RuneLiteModule(Supplier<Applet> clientLoader, boolean developerMode, File sessionfile, File config)
|
||||
{
|
||||
this.clientLoader = clientLoader;
|
||||
this.developerMode = developerMode;
|
||||
this.sessionfile = sessionfile;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure()
|
||||
{
|
||||
bindConstant().annotatedWith(Names.named("developerMode")).to(developerMode);
|
||||
bind(File.class).annotatedWith(Names.named("sessionfile")).toInstance(sessionfile);
|
||||
bind(File.class).annotatedWith(Names.named("config")).toInstance(config);
|
||||
bind(ScheduledExecutorService.class).toInstance(new ExecutorServiceExceptionLogger(Executors.newSingleThreadScheduledExecutor()));
|
||||
bind(OkHttpClient.class).toInstance(RuneLiteAPI.CLIENT.newBuilder()
|
||||
.cache(new Cache(new File(RuneLite.CACHE_DIR, "okhttp"), MAX_OKHTTP_CACHE_SIZE))
|
||||
|
||||
@@ -33,15 +33,15 @@ import java.io.InputStreamReader;
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.client.events.SessionClose;
|
||||
import net.runelite.client.events.SessionOpen;
|
||||
import net.runelite.client.RuneLite;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.eventbus.EventBus;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
import net.runelite.client.events.SessionClose;
|
||||
import net.runelite.client.events.SessionOpen;
|
||||
import net.runelite.client.util.LinkBrowser;
|
||||
import net.runelite.client.ws.WSClient;
|
||||
import net.runelite.http.api.account.AccountClient;
|
||||
@@ -52,27 +52,32 @@ import net.runelite.http.api.ws.messages.LoginResponse;
|
||||
@Slf4j
|
||||
public class SessionManager
|
||||
{
|
||||
private static final File SESSION_FILE = new File(RuneLite.RUNELITE_DIR, "session");
|
||||
|
||||
@Getter
|
||||
private AccountSession accountSession;
|
||||
|
||||
private final EventBus eventBus;
|
||||
private final ConfigManager configManager;
|
||||
private final WSClient wsClient;
|
||||
private final File sessionFile;
|
||||
|
||||
@Inject
|
||||
private SessionManager(ConfigManager configManager, EventBus eventBus, WSClient wsClient)
|
||||
private SessionManager(
|
||||
@Named("sessionfile") File sessionfile,
|
||||
ConfigManager configManager,
|
||||
EventBus eventBus,
|
||||
WSClient wsClient)
|
||||
{
|
||||
this.configManager = configManager;
|
||||
this.eventBus = eventBus;
|
||||
this.wsClient = wsClient;
|
||||
this.sessionFile = sessionfile;
|
||||
|
||||
eventBus.register(this);
|
||||
}
|
||||
|
||||
public void loadSession()
|
||||
{
|
||||
if (!SESSION_FILE.exists())
|
||||
if (!sessionFile.exists())
|
||||
{
|
||||
log.info("No session file exists");
|
||||
return;
|
||||
@@ -80,7 +85,7 @@ public class SessionManager
|
||||
|
||||
AccountSession session;
|
||||
|
||||
try (FileInputStream in = new FileInputStream(SESSION_FILE))
|
||||
try (FileInputStream in = new FileInputStream(sessionFile))
|
||||
{
|
||||
session = new Gson().fromJson(new InputStreamReader(in), AccountSession.class);
|
||||
|
||||
@@ -110,11 +115,11 @@ public class SessionManager
|
||||
return;
|
||||
}
|
||||
|
||||
try (FileWriter fw = new FileWriter(SESSION_FILE))
|
||||
try (FileWriter fw = new FileWriter(sessionFile))
|
||||
{
|
||||
new Gson().toJson(accountSession, fw);
|
||||
|
||||
log.debug("Saved session to {}", SESSION_FILE);
|
||||
log.debug("Saved session to {}", sessionFile);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
@@ -124,7 +129,7 @@ public class SessionManager
|
||||
|
||||
private void deleteSession()
|
||||
{
|
||||
SESSION_FILE.delete();
|
||||
sessionFile.delete();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -61,6 +61,7 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.api.coords.WorldPoint;
|
||||
@@ -77,7 +78,6 @@ import net.runelite.http.api.config.Configuration;
|
||||
@Slf4j
|
||||
public class ConfigManager
|
||||
{
|
||||
private static final String SETTINGS_FILE_NAME = "settings.properties";
|
||||
private static final DateFormat TIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
|
||||
|
||||
@Inject
|
||||
@@ -92,11 +92,15 @@ public class ConfigManager
|
||||
private final ConfigInvocationHandler handler = new ConfigInvocationHandler(this);
|
||||
private final Properties properties = new Properties();
|
||||
private final Map<String, String> pendingChanges = new HashMap<>();
|
||||
private final File settingsFileInput;
|
||||
|
||||
@Inject
|
||||
public ConfigManager(ScheduledExecutorService scheduledExecutorService)
|
||||
public ConfigManager(
|
||||
@Named("config") File config,
|
||||
ScheduledExecutorService scheduledExecutorService)
|
||||
{
|
||||
this.executor = scheduledExecutorService;
|
||||
this.settingsFileInput = config;
|
||||
this.propertiesFile = getPropertiesFile();
|
||||
|
||||
executor.scheduleWithFixedDelay(this::sendConfig, 30, 30, TimeUnit.SECONDS);
|
||||
@@ -125,7 +129,7 @@ public class ConfigManager
|
||||
|
||||
private File getLocalPropertiesFile()
|
||||
{
|
||||
return new File(RuneLite.RUNELITE_DIR, SETTINGS_FILE_NAME);
|
||||
return settingsFileInput;
|
||||
}
|
||||
|
||||
private File getPropertiesFile()
|
||||
@@ -138,7 +142,7 @@ public class ConfigManager
|
||||
else
|
||||
{
|
||||
File profileDir = new File(RuneLite.PROFILES_DIR, session.getUsername().toLowerCase());
|
||||
return new File(profileDir, SETTINGS_FILE_NAME);
|
||||
return new File(profileDir, RuneLite.DEFAULT_CONFIG_FILE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,7 +335,7 @@ public class ConfigManager
|
||||
|
||||
parent.mkdirs();
|
||||
|
||||
File tempFile = new File(parent, SETTINGS_FILE_NAME + ".tmp");
|
||||
File tempFile = new File(parent, RuneLite.DEFAULT_CONFIG_FILE + ".tmp");
|
||||
|
||||
try (FileOutputStream out = new FileOutputStream(tempFile))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user