Commit 83d53f8e authored by superblaubeere27's avatar superblaubeere27

Merge branch 'master' of http://git.liquidbounce.net/CCBlueX/LiquidLauncherV2

# Conflicts:
#	src/main/java/net/ccbluex/LiquidLauncher/ui/MenuInterface.java
parents d3e4052b d6b3760e
package net.ccbluex.LiquidLauncher;
import javax.swing.*;
import java.net.MalformedURLException;
/**
* Project: LiquidLauncher
* Copyright © 2015 - 2017 | CCBlueX | All rights reserved.
* <p>
* Exrief - $ By CCBlueX(superblaubeere27)
* Created by: Marco_MC & superblaubeere27
*/
public class Main {
public static void main(String args[]) {
try {
try{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel"); // NECESSARY FOR LINUX COMPUTERS
} catch (Exception e) {
try {
}catch(final Exception e) {
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e1) {
}
}catch(final Exception ignored) { }
}
// JavaFX installed check
// try {
// Class.forName("com.sun.javafx.application.PlatformImpl");
......@@ -31,11 +28,11 @@ public class Main {
// System.exit(-1);
// return;
// }
LiquidLauncher liquidLauncher = null;
try {
liquidLauncher = new LiquidLauncher();
try{
final LiquidLauncher liquidLauncher = new LiquidLauncher();
liquidLauncher.start();
} catch (MalformedURLException e) {
}catch(final MalformedURLException e) {
e.printStackTrace();
}
}
......
......@@ -13,9 +13,9 @@ import java.util.List;
import java.util.Map;
/**
* Project: LiquidLauncher
* Copyright © 2015 - 2017 | CCBlueX | All rights reserved.
* <p>
* LiquidLauncher - $ By CCBlueX(superblaubeere27)
* Created by: Marco_MC & superblaubeere27
*/
public class AssetManager {
private File assetDir;
......@@ -33,68 +33,57 @@ public class AssetManager {
assetDir.mkdirs();
indecies.mkdirs();
objects.mkdirs();
}
public void checkAssetsForVersion(String version) {
LiquidLauncher.liquidLauncher.LOGGER.info("Checking assets for " + version);
try {
try {
if (!checkIndexFile(version)) {
if (!downloadIndexFile(version)) {
LiquidLauncher.liquidLauncher.LOGGER.warning("Failed to update assets");
public void checkAssetsForVersion(final String version) {
LiquidLauncher.LOGGER.info("Checking assets for " + version);
try{
try{
if(!checkIndexFile(version)) {
if(!downloadIndexFile(version)) {
LiquidLauncher.LOGGER.warning("Failed to update assets");
return;
}
}
} catch (Exception e) {
}catch(Exception ignored) { }
}
List<Asset> assets = readAssetIndex(new String(Files.readAllBytes(new File(indecies, version + ".json").toPath())));
int allAssets = assets.size();
final List<Asset> assets = readAssetIndex(new String(Files.readAllBytes(new File(indecies, version + ".json").toPath())));
final int allAssets = assets.size();
filterMissingAssets(assets);
LiquidLauncher.liquidLauncher.LOGGER.info("Missing " + assets.size() + "/" + allAssets + " assets");
LiquidLauncher.LOGGER.info("Missing " + assets.size() + "/" + allAssets + " assets");
int i = 0;
for (Asset asset :
assets) {
}
for (Asset asset :
assets) {
for(final Asset asset : assets) {
i++;
downloadAsset(asset, i, assets.size());
}
} catch (IOException e) {
LiquidLauncher.liquidLauncher.LOGGER.severe("Failed to update assets: ");
}catch(IOException e) {
LiquidLauncher.LOGGER.severe("Failed to update assets: ");
e.printStackTrace();
}
LiquidLauncher.liquidLauncher.menuInterface.progress.setString("Waiting...");
LiquidLauncher.menuInterface.progress.setString("Waiting...");
}
private void downloadAsset(Asset asset, int minor, int major) throws IOException {
NetworkUtils.downloadWithProgressBarUpdate("Updating assets", "http://resources.download.minecraft.net/" + asset.getAssetPath(), new File(objects, asset.getAssetPath()), LiquidLauncher.liquidLauncher.menuInterface.progress, "[" + minor + "/" + major + "] Downloading " + asset.getName());
}
private void filterMissingAssets(List<Asset> assets) {
int j = 0;
List<Asset> remove = new ArrayList<>();
for (int i = 0; i < assets.size(); i++) {
Asset asset = assets.get(i);
File assetPath = new File(objects, asset.getAssetPath());
if (assetPath.exists()) {
private void filterMissingAssets(final List<Asset> assets) {
final List<Asset> remove = new ArrayList<>();
for(final Asset asset : assets) {
final File assetPath = new File(objects, asset.getAssetPath());
if(assetPath.exists())
remove.add(asset);
j++;
}
}
for (Asset asset1 :
remove) {
assets.remove(asset1);
}
assets.removeAll(remove);
}
private List<Asset> readAssetIndex(String s) {
List<Asset> assets = new ArrayList<>();
JsonObject objects = LiquidLauncher.liquidLauncher.jsonParser.parse(s).getAsJsonObject().get("objects").getAsJsonObject();
for (Map.Entry<String, JsonElement> asset :
objects.entrySet()) {
private List<Asset> readAssetIndex(final String s) {
final List<Asset> assets = new ArrayList<>();
final JsonObject objects = LiquidLauncher.liquidLauncher.jsonParser.parse(s).getAsJsonObject().get("objects").getAsJsonObject();
for (Map.Entry<String, JsonElement> asset : objects.entrySet()) {
JsonObject assetInfo = asset.getValue().getAsJsonObject();
assets.add(new Asset(assetInfo.get("size").getAsInt(), assetInfo.get("hash").getAsString(), asset.getKey()));
}
......@@ -110,12 +99,12 @@ public class AssetManager {
}
private class Asset {
private final int size;
private final String assetPath;
private final String hash;
private final String name;
public Asset(int size, String hash, String name) {
this.size = size;
this.hash = hash;
......@@ -124,7 +113,6 @@ public class AssetManager {
}
public int getSize() {
return size;
}
......
......@@ -6,9 +6,9 @@ import java.util.ArrayList;
import java.util.List;
/**
* Project: LiquidLauncher
* Copyright © 2015 - 2017 | CCBlueX | All rights reserved.
* <p>
* Exrief - $ By CCBlueX(superblaubeere27)
* Created by: Marco_MC & superblaubeere27
*/
public class ClientBuild {
private String forgeVersion;
......@@ -18,7 +18,7 @@ public class ClientBuild {
private String liquidBounceVersion;
private String liquidBounceHash;
public ClientBuild(String forgeVersion, String optifineDownload, String liquidBounceDownload, String minecraftVersion, String liquidBounceVersion, String liquidBounceHash) {
public ClientBuild(final String forgeVersion, final String optifineDownload, final String liquidBounceDownload, final String minecraftVersion, final String liquidBounceVersion, final String liquidBounceHash) {
this.forgeVersion = forgeVersion;
this.optifineDownload = optifineDownload;
this.liquidBounceDownload = liquidBounceDownload;
......@@ -28,16 +28,14 @@ public class ClientBuild {
}
public static List<ClientBuild> getBuildsFromJson(JsonObject obj) {
List<ClientBuild> result = new ArrayList<>();
for (String minecraftVersion :
obj.keySet()) {
for (String liquidBounceVersion :
obj.getAsJsonObject(minecraftVersion).keySet()) {
JsonObject version = obj.getAsJsonObject(minecraftVersion).getAsJsonObject(liquidBounceVersion);
String forge = version.get("forge").getAsString();
String optifine = version.get("optifine").getAsString();
String liquidBounce = version.get("liquidBounce").getAsString();
String liquidBounceHash = version.get("liquidBounceHash").getAsString();
final List<ClientBuild> result = new ArrayList<>();
for(String minecraftVersion : obj.keySet()) {
for(String liquidBounceVersion : obj.getAsJsonObject(minecraftVersion).keySet()) {
final JsonObject version = obj.getAsJsonObject(minecraftVersion).getAsJsonObject(liquidBounceVersion);
final String forge = version.get("forge").getAsString();
final String optifine = version.get("optifine").getAsString();
final String liquidBounce = version.get("liquidBounce").getAsString();
final String liquidBounceHash = version.get("liquidBounceHash").getAsString();
result.add(new ClientBuild(forge, optifine, liquidBounce, minecraftVersion, liquidBounceVersion, liquidBounceHash));
}
}
......
......@@ -8,16 +8,16 @@ import java.io.InputStreamReader;
import java.util.regex.Pattern;
/**
* Project: LiquidLauncher
* Copyright © 2015 - 2017 | CCBlueX | All rights reserved.
* <p>
* LiquidLauncher - $ By CCBlueX(Marco)
* Created by: Marco_MC & superblaubeere27
*/
public class GameProcess {
private static final Pattern clazzPattern = Pattern.compile("byCCBlueX+[.][\\w\\\\.$]+");
private Process process;
public GameProcess(Process process) {
public GameProcess(final Process process) {
this.process = process;
new Thread(() -> {
......@@ -25,9 +25,8 @@ public class GameProcess {
final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = bufferedReader.readLine()) != null) {
LiquidLauncher.liquidLauncher.LOGGER.info(censor(line));
}
while ((line = bufferedReader.readLine()) != null)
LiquidLauncher.LOGGER.info(censor(line));
} catch (final IOException e) {
e.printStackTrace();
}
......@@ -38,18 +37,16 @@ public class GameProcess {
final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String line;
while ((line = bufferedReader.readLine()) != null) {
LiquidLauncher.liquidLauncher.LOGGER.warning(censor(line));
}
while ((line = bufferedReader.readLine()) != null)
LiquidLauncher.LOGGER.warning(censor(line));
} catch (final IOException e) {
e.printStackTrace();
}
}).start();
}
private String censor(String line) {
private String censor(final String line) {
return clazzPattern.matcher(line).replaceAll("<CENSORED>");
// return line;
}
public Process getProcess() {
......
......@@ -3,24 +3,24 @@ package net.ccbluex.LiquidLauncher.launch;
import java.io.File;
/**
* Project: LiquidLauncher
* Copyright © 2015 - 2017 | CCBlueX | All rights reserved.
* <p>
* LiquidLauncher - $ By CCBlueX(Marco)
* Created by: Marco_MC & superblaubeere27
*/
public class GameProcessBuilder {
private final StringBuilder argumentsBuilder = new StringBuilder();
private File directory;
public GameProcessBuilder(String javaPath) {
public GameProcessBuilder(final String javaPath) {
argumentsBuilder.append(javaPath);
}
public void appendArgument(String argument) {
public void appendArgument(final String argument) {
argumentsBuilder.append(" ").append(argument);
}
public void appendArgument(String key, String value) {
public void appendArgument(final String key, final String value) {
argumentsBuilder.append(" ").append(key).append(" ").append(value);
}
......
......@@ -8,6 +8,7 @@ import java.io.File;
* Exrief - $ By CCBlueX(superblaubeere27)
*/
public class LauncherFolderTree {
private File assets;
private File minecraftVersionFolder;
private File minecraftJson;
......@@ -22,7 +23,7 @@ public class LauncherFolderTree {
private File forgeJar;
private File modsFolder;
public LauncherFolderTree(File liquidLauncherFolder, File minecraftFolder, ClientBuild build) {
public LauncherFolderTree(final File liquidLauncherFolder, final ClientBuild build) {
assets = new File(liquidLauncherFolder, "assets"); // /assets
minecraftVersionFolder = new File(liquidLauncherFolder, "versions" + File.separator + build.getMinecraftVersion() + File.separator);
versionDir = new File(new File(liquidLauncherFolder, "versions" + File.separator + build.getMinecraftVersion()), build.getLiquidBounceVersion());
......
......@@ -11,26 +11,23 @@ import java.util.List;
/**
* Project: LiquidLauncher
* Copyright © 2015 - 2017 | CCBlueX | All rights reserved.
* <p>
* Exrief - $ By CCBlueX(superblaubeere27)
* Created by: Marco_MC & superblaubeere27
*/
public class LibraryManager {
private final List<Library> libraries;
public LibraryManager(List<Library> libraries) {
public LibraryManager(final List<Library> libraries) {
this.libraries = libraries;
}
public static LibraryManager loadLibraries(JsonArray... l) {
List<Library> libs = new ArrayList<>();
for (JsonArray libaries :
l) {
for (JsonElement el :
libaries) {
public static LibraryManager loadLibraries(final JsonArray... l) {
final List<Library> libs = new ArrayList<>();
for(JsonArray libaries : l)
for(JsonElement el : libaries)
libs.add(Library.getFromJsonObject(el.getAsJsonObject()));
}
}
return new LibraryManager(libs);
}
......@@ -38,30 +35,25 @@ public class LibraryManager {
return libraries;
}
public void buildCP() {
}
public void updateLibraries(File natives, File libraryFolder) {
for (Library lib :
getLibraries())
public void updateLibraries(final File natives, final File libraryFolder) {
for(Library lib : getLibraries())
lib.update(natives, libraryFolder);
}
public String getCPList(File libraryFolder) {
public String getCPList(final File libraryFolder) {
final String separator = System.getProperty("path.separator");
StringBuilder sb = new StringBuilder();
for (Library lib :
libraries) {
if (lib.isNative() || !lib.isAvailable()) {
final StringBuilder sb = new StringBuilder();
for(Library lib : libraries) {
if(lib.isNative() || !lib.isAvailable())
continue;
}
if (SystemUtils.getOS() == SystemUtils.OSType.WINDOWS) {
sb.append("\"" + new File(libraryFolder, lib.getMavenLib().getUrl(lib.getNativeSuffix())).getAbsolutePath() + "\"").append(separator);
} else {
if(SystemUtils.getOS() == SystemUtils.OSType.WINDOWS)
sb.append("\"").append(new File(libraryFolder, lib.getMavenLib().getUrl(lib.getNativeSuffix())).getAbsolutePath()).append("\"").append(separator);
else
sb.append(Utils.unixPathReplacer(new File(libraryFolder, lib.getMavenLib().getUrl(lib.getNativeSuffix())).getAbsolutePath())).append(separator);
}
}
return sb.toString();
}
}
package net.ccbluex.LiquidLauncher.launch;
/**
* Project: LiquidLauncher
* Copyright © 2015 - 2017 | CCBlueX | All rights reserved.
* <p>
* Exrief - $ By CCBlueX(superblaubeere27)
* Created by: Marco_MC & superblaubeere27
*/
public class MavenDependency {
private String groupId;
private String artifactId;
private String version;
public MavenDependency(String groupId, String artifactId, String version) {
public MavenDependency(final String groupId, final String artifactId, final String version) {
this.groupId = groupId;
this.artifactId = artifactId;
this.version = version;
}
public static MavenDependency fromString(String s) throws NumberFormatException {
MavenDependency dep = null;
public static MavenDependency fromString(final String s) throws NumberFormatException {
MavenDependency mavenDependency = null;
String[] split = s.split(":");
if (split.length == 3) {
dep = new MavenDependency(split[0], split[1], split[2]);
}
if(split.length == 3)
mavenDependency = new MavenDependency(split[0], split[1], split[2]);
split = s.split("/");
if (split.length == 3) {
dep = new MavenDependency(split[0], split[1], split[2]);
}
if (dep == null) {
if(split.length == 3)
mavenDependency = new MavenDependency(split[0], split[1], split[2]);
if(mavenDependency == null)
throw new RuntimeException("The library " + s + " is not valid.");
}
return dep;
return mavenDependency;
}
public String getGroupId() {
......@@ -53,10 +54,10 @@ public class MavenDependency {
return getUrl("");
}
public String getUrl(String suffix) {
String g = groupId.replace(".", "/");
String a = artifactId;
String version = getVersion();
public String getUrl(final String suffix) {
final String g = groupId.replace(".", "/");
final String a = artifactId;
final String version = getVersion();
return g + "/" + a + "/" + version + "/" + a + "-" + version + suffix + ".jar";
}
}
package net.ccbluex.LiquidLauncher.launch;
/**
* Project: LiquidLauncher
* Copyright © 2015 - 2017 | CCBlueX | All rights reserved.
* <p>
* Exrief - $ By CCBlueX(superblaubeere27)
* Created by: Marco_MC & superblaubeere27
*/
public class MinecraftArguments {
private String argumentsString;
public MinecraftArguments(String argumentsString) {
public MinecraftArguments(final String argumentsString) {
this.argumentsString = argumentsString;
}
public String getArguments(MinecraftArgumentInfo info) {
public String getArguments(final MinecraftArgumentInfo info) {
String s = argumentsString;
s = s.replace("${auth_player_name}", info.username);
s = s.replace("${version_name}", info.version);
......@@ -27,6 +28,7 @@ public class MinecraftArguments {
}
public static class MinecraftArgumentInfo {
private final String username;
private final String version;
private final String gameDir;
......@@ -84,11 +86,10 @@ public class MinecraftArguments {
public String getUserType() {
return userType;
}
}
public static class MinecraftArgumentInfoBuilder {
private String username;
private String version;
private String gameDir;
......
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="net.ccbluex.LiquidLauncher.inerfaces.AddLiquidBounceDialog">
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="net.ccbluex.LiquidLauncher.ui.AddLiquidBounceDialog">
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
......@@ -57,7 +57,7 @@
<properties/>
<border type="none"/>
<children>
<component id="d3b96" class="javax.swing.JLabel" binding="dl">
<component id="d3b96" class="javax.swing.JLabel" binding="dlLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
......
package net.ccbluex.LiquidLauncher.inerfaces;
package net.ccbluex.LiquidLauncher.ui;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
......@@ -21,48 +21,50 @@ import java.nio.file.Files;
import java.util.List;
public class AddLiquidBounceDialog extends JDialog {
private final String hash;
private JPanel contentPane;
private JButton buttonOK;
private JButton buttonCancel;
private JTextField fileField;
private JButton browseButton;
private JLabel dl;
private JLabel dlLabel;
private String file = "";
public AddLiquidBounceDialog(String downloadLink, String hash) {
public AddLiquidBounceDialog(final String downloadLink, final String hash) {
this.hash = hash;
setContentPane(contentPane);
setModal(true);
setTitle("Add LiquidBounce");
pack();
dl.setText(dl.getText().replace("%download%", downloadLink));
dlLabel.setText(dlLabel.getText().replace("%download%", downloadLink));
DropTarget target = new DropTarget(this, new DropTargetListener() {
@Override
public void dragEnter(DropTargetDragEvent dtde) {
Transferable t = dtde.getTransferable();
final Transferable transferable = dtde.getTransferable();
boolean accept = false;
if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
try {
Object td = t.getTransferData(DataFlavor.javaFileListFlavor);
if (td instanceof List) {
for (Object value : ((List) td)) {
if (value instanceof File) {
if(transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
try{
final Object obj = transferable.getTransferData(DataFlavor.javaFileListFlavor);
if(obj instanceof List) {
for(Object value : ((List) obj)) {
if(value instanceof File) {
File file = (File) value;
String name = file.getName().toLowerCase();
accept = true;
}
}
}
} catch (UnsupportedFlavorException | IOException ex) {
}catch(UnsupportedFlavorException | IOException ex) {
ex.printStackTrace();
}
}
if (accept) {
if(accept)
dtde.acceptDrag(DnDConstants.ACTION_COPY);
} else {
else
dtde.rejectDrag();
}
}
@Override
......@@ -123,27 +125,20 @@ public class AddLiquidBounceDialog extends JDialog {
// call onCancel() on ESCAPE
contentPane.registerKeyboardAction(e -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
if (Desktop.isDesktopSupported()) {
try {
if(Desktop.isDesktopSupported()) {
try{
Desktop.getDesktop().browse(new URI(downloadLink));
} catch (IOException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
}catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
}
browseButton.addActionListener(new ActionListener() {
/**
* Invoked when an action occurs.
*
* @param e
*/
@Override
public void actionPerformed(ActionEvent e) {
String s = Utils.chooseFile(null, AddLiquidBounceDialog.this);
if (s != null)
fileField.setText(s);
}
browseButton.addActionListener(e -> {
String s = Utils.chooseFile(null, AddLiquidBounceDialog.this);
if(s != null)
fileField.setText(s);
});
}
......@@ -165,25 +160,25 @@ public class AddLiquidBounceDialog extends JDialog {
}
private void onOK() {
if (!new File(fileField.getText()).exists()) {
if(!new File(fileField.getText()).exists()) {
JOptionPane.showMessageDialog(this, "This file is not valid!", "ERROR", JOptionPane.ERROR_MESSAGE);
return;
}
try {
if (!DigestUtils.md5Hex(Files.readAllBytes(new File(fileField.getText()).toPath())).equals(hash)) {
try{
if(!DigestUtils.md5Hex(Files.readAllBytes(new File(fileField.getText()).toPath())).equals(hash)) {
JOptionPane.showMessageDialog(this, "<html>Invalid file, please do <strong>NOT</strong> extract the file</html>", "ERROR", JOptionPane.ERROR_MESSAGE);
return;
}