Commit c232f572 authored by superblaubeere27's avatar superblaubeere27

Setting system + JRE Finder

parent 3788015f
......@@ -11,4 +11,4 @@ Well, as you can see, LiquidLauncher is open-source. That means anyone can look
**But who guarantees that you're using the same code in the actual launcher?**
The actual .jar file isn't obfuscated. Just use a decompiler like (http://jd.benow.ca)[JD-GUI] to see its source.
\ No newline at end of file
The actual .jar file isn't obfuscated. Just use a decompiler like [JD-GUI](http://jd.benow.ca) to see its source.
\ No newline at end of file
......@@ -122,6 +122,12 @@
<artifactId>forms_rt</artifactId>
<version>7.0.3</version>
</dependency>
<dependency>
<groupId>com.github.jponge</groupId>
<artifactId>lzma-java</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
......
......@@ -6,6 +6,7 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import net.ccbluex.LiquidLauncher.config.Settings;
import net.ccbluex.LiquidLauncher.launch.*;
import net.ccbluex.LiquidLauncher.ui.AddLiquidBounceDialog;
import net.ccbluex.LiquidLauncher.ui.MenuInterface;
......@@ -46,6 +47,7 @@ public class LiquidLauncher {
public static final String LAUNCHER_VERSION_STRING = "v" + LAUNCHER_VERSION + "-SNAPSHOT";
public static LiquidLauncher liquidLauncher;
public static MenuInterface menuInterface;
private static File configFile;
static {
if (DEVEL_VERSION)
......@@ -94,7 +96,22 @@ public class LiquidLauncher {
public static void fatalError(String s) {
JOptionPane.showMessageDialog(menuInterface, s, "Error", JOptionPane.ERROR_MESSAGE);
System.exit(-1);
if (!DEVEL_VERSION) {
System.exit(-1);
}
}
public static void stop() {
LOGGER.info("Stopping LiquidLauncher...");
LOGGER.info("Saving settings...");
try {
Settings.save(configFile);
} catch (Exception e) {
e.printStackTrace();
}
LOGGER.info("Saved");
LOGGER.info("Stopped LiquidLauncher.");
return; // <---- To prevent bugs
}
public void start() {
......@@ -164,6 +181,7 @@ public class LiquidLauncher {
}
LOGGER.info("LiquidLauncher directory: " + launcherDirectory.getAbsolutePath());
configFile = new File(launcherDirectory, "config.lls");
if (!launcherDirectory.exists())
launcherDirectory.mkdirs();
......@@ -178,16 +196,21 @@ public class LiquidLauncher {
}
LOGGER.info(clientBuilds.size() + " versions were loaded.");
} catch (Exception e) {
if (DEVEL_VERSION) {
clientBuilds = new ArrayList<>();
clientBuilds.add(new ClientBuild("", "", "", "100.200", "b18.88", ""));
}
fatalError("Failed to load LiquidBounce versions: " + e);
}
assetManager = new AssetManager(launcherDirectory);
statusLabel.setText("Checking for updates...");
checkForUpdate();
Runtime.getRuntime().addShutdownHook(new Thread(LiquidLauncher::stop));
statusLabel.setText("Showing Menu...");
// TODO: Other init stuff
LOGGER.info("Show menu.");
menuInterface = new MenuInterface();
Settings.load(configFile);
menuInterface.setVisible(true);
LOGGER.info("Ready");
startScreen.dispose();
......@@ -195,6 +218,9 @@ public class LiquidLauncher {
public List<String> getMinecraftVersions() {
final List<String> mcVersions = new ArrayList<>();
if (clientBuilds == null) {
return mcVersions;
}
for (final ClientBuild build : clientBuilds)
if (!mcVersions.contains(build.getMinecraftVersion()))
mcVersions.add(build.getMinecraftVersion());
......@@ -411,4 +437,27 @@ public class LiquidLauncher {
}).start();
}
public String findJRE() {
File JVM_PATH = new File(System.getProperty("java.home"), "bin");
File file = new File(JVM_PATH, "java.exe");
if (file.exists()) {
return file.getAbsolutePath();
}
file = new File(JVM_PATH, "java");
if (file.exists()) {
return file.getAbsolutePath();
}
File[] files = JVM_PATH.listFiles();
if (files != null) {
for (File f :
files) {
if (f.getName().startsWith("java.")) {
return f.getPath();
}
}
}
// File path = new File();
JOptionPane.showMessageDialog(menuInterface, "Failed to find the launcher JRE", "Warning", JOptionPane.WARNING_MESSAGE);
return "java";
}
}
package net.ccbluex.LiquidLauncher.config;
import com.google.common.io.ByteStreams;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import net.ccbluex.LiquidLauncher.LiquidLauncher;
import net.ccbluex.LiquidLauncher.ui.MenuInterface;
import net.ccbluex.LiquidLauncher.utils.AuthenticationUtils;
import java.io.*;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
/**
* Copyright © 2015 - 2017 | CCBlueX | All rights reserved.
* <p>
* LiquidLauncher - By CCBlueX(superblaubeere27)
*/
public class Settings {
private final static String RES_X = "resolutionX";
private final static String RES_Y = "resolutionY";
private final static String AUTOSCROLL = "auto_scroll";
private final static String JVM_ARGS = "jvm_args";
private final static String THEME = "theme";
private final static String MC_VERSION = "minecraftVersion";
private final static String CLIENT_VERSION = "clientVersion";
private final static String KEEP_OPEN = "keepLauncherOpen";
private final static String REMEMBER_ME = "rememberme";
private final static String ACCOUNT = "account";
private final static String LATEST_VERSION = "latestVersion";
private final static String JVM_PATH = "jvmPath";
public static void save(final File file) {
final MenuInterface menuInterface = LiquidLauncher.liquidLauncher.menuInterface;
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
final JsonObject jsonObject = new JsonObject();
jsonObject.addProperty(RES_X, (Integer) menuInterface.getClientWidth().getValue());
jsonObject.addProperty(RES_Y, (Integer) menuInterface.getClientHeight().getValue());
jsonObject.addProperty(KEEP_OPEN, menuInterface.getKeepOpen().isSelected());
jsonObject.addProperty(AUTOSCROLL, menuInterface.getAutoScroll().isSelected());
jsonObject.addProperty(JVM_ARGS, menuInterface.getJvmArgumentsField().getText());
jsonObject.addProperty(MC_VERSION, (String) menuInterface.getMinecraftVersion().getSelectedItem());
jsonObject.addProperty(CLIENT_VERSION, (String) menuInterface.getClientVersion().getSelectedItem());
jsonObject.addProperty(REMEMBER_ME, menuInterface.getRememberMeCheckBox().isSelected());
jsonObject.addProperty(LATEST_VERSION, menuInterface.getAlwaysLatest().isSelected());
jsonObject.addProperty(JVM_PATH, menuInterface.getJvmPath().getText());
if (menuInterface.getRememberMeCheckBox().isSelected()) {
// TODO Only save session
final JsonObject accountObject = new JsonObject();
accountObject.addProperty("USERNAME", LiquidLauncher.liquidLauncher.account[0]);
accountObject.addProperty("PASSWORD", LiquidLauncher.liquidLauncher.account[1]);
jsonObject.add(ACCOUNT, accountObject);
}
try {
GZIPOutputStream outStream = new GZIPOutputStream(new FileOutputStream(file));
ByteStreams.copy(new ByteArrayInputStream(jsonObject.toString().getBytes()), outStream);
outStream.close();
// Files.write(file.toPath(), jsonObject.toString().getBytes());
} catch (final IOException e) {
LiquidLauncher.liquidLauncher.LOGGER.severe("Failed to save settings:");
e.printStackTrace();
}
}
public static void load(final File file) {
final MenuInterface menuInterface = LiquidLauncher.liquidLauncher.menuInterface;
try {
if (!file.exists())
return;
JsonElement el = new JsonParser().parse(new InputStreamReader(new GZIPInputStream(new FileInputStream(file))));
if (el == null) {
return;
}
final JsonObject jsonObject = el.getAsJsonObject();
if (jsonObject.has(RES_X))
menuInterface.getClientWidth().setValue(jsonObject.get(RES_X).getAsInt());
if (jsonObject.has(RES_Y))
menuInterface.getClientHeight().setValue(jsonObject.get(RES_Y).getAsInt());
if (jsonObject.has(AUTOSCROLL))
menuInterface.getAutoScroll().setSelected(jsonObject.get(AUTOSCROLL).getAsBoolean());
if (jsonObject.has(KEEP_OPEN))
menuInterface.getKeepOpen().setSelected(jsonObject.get(KEEP_OPEN).getAsBoolean());
if (jsonObject.has(JVM_ARGS))
menuInterface.getJvmArgumentsField().setText(jsonObject.get(JVM_ARGS).getAsString());
if (jsonObject.has(JVM_PATH))
menuInterface.getJvmPath().setText(jsonObject.get(JVM_PATH).getAsString());
if (jsonObject.has(MC_VERSION)) {
final String selectedMinecraftVersion = jsonObject.get(MC_VERSION).getAsString();
for (int i = 0; i < menuInterface.getMinecraftVersion().getModel().getSize(); i++) {
final String currentMinecraftVersion = (String) menuInterface.getMinecraftVersion().getModel().getElementAt(i);
if (currentMinecraftVersion.equals(selectedMinecraftVersion)) {
menuInterface.getMinecraftVersion().setSelectedItem(currentMinecraftVersion);
break;
}
}
}
if (jsonObject.has(LATEST_VERSION)) {
menuInterface.getAlwaysLatest().setSelected(jsonObject.get(LATEST_VERSION).getAsBoolean());
menuInterface.updateLatestVersion();
}
menuInterface.updateMCVersion();
if (jsonObject.has(CLIENT_VERSION)) {
final String selectedClientVersion = jsonObject.get(CLIENT_VERSION).getAsString();
for (int i = 0; i < menuInterface.getClientVersion().getModel().getSize(); i++) {
final String clientVersion = (String) menuInterface.getClientVersion().getModel().getElementAt(i);
if (clientVersion.equals(selectedClientVersion)) {
menuInterface.getClientVersion().setSelectedItem(clientVersion);
break;
}
}
}
menuInterface.getRememberMeCheckBox().setSelected(jsonObject.get(REMEMBER_ME).getAsBoolean());
if (jsonObject.has(ACCOUNT)) {
// TODO: LOAD SESSION
final JsonObject accountObject = jsonObject.get(ACCOUNT).getAsJsonObject();
final String username = accountObject.get("USERNAME").getAsString();
final JsonElement passwordObject = accountObject.get("PASSWORD");
if (passwordObject.isJsonNull() || passwordObject.getAsString().isEmpty())
LiquidLauncher.liquidLauncher.account = AuthenticationUtils.login(username);
else
LiquidLauncher.liquidLauncher.account = new String[]{username, passwordObject.getAsString()};
}
} catch (Exception e) {
LiquidLauncher.liquidLauncher.LOGGER.severe("Failed to load settings: ");
e.printStackTrace();
}
}
}
......@@ -3,7 +3,7 @@
<grid id="27dc6" binding="payne" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="401"/>
<xy x="20" y="20" width="539" height="409"/>
</constraints>
<properties/>
<border type="none"/>
......@@ -17,7 +17,7 @@
<properties/>
<border type="none"/>
<children>
<grid id="e43c8" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="e43c8" binding="newsPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<tabbedpane title="News"/>
......@@ -231,7 +231,7 @@
</component>
<component id="afb7b" class="javax.swing.JTextField" binding="jvmPath">
<constraints>
<grid row="8" column="0" row-span="1" col-span="4" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<grid row="8" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
......@@ -247,6 +247,14 @@
<text value="JVM-Path:"/>
</properties>
</component>
<component id="d9145" class="javax.swing.JButton" binding="useLauncherJREButton" default-binding="true">
<constraints>
<grid row="8" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Use launcher JRE"/>
</properties>
</component>
</children>
</grid>
<grid id="d6117" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment