Commit fd2567ba authored by superblaubeere27's avatar superblaubeere27

Add Login

parent 83d53f8e
......@@ -11,12 +11,13 @@ import java.net.MalformedURLException;
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(final Exception e) {
try{
} catch (final Exception e) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(final Exception ignored) { }
} catch (final Exception ignored) {
}
}
// JavaFX installed check
......@@ -29,10 +30,10 @@ public class Main {
// return;
// }
try{
try {
final LiquidLauncher liquidLauncher = new LiquidLauncher();
liquidLauncher.start();
}catch(final MalformedURLException e) {
} catch (final MalformedURLException e) {
e.printStackTrace();
}
}
......
......@@ -37,15 +37,16 @@ public class AssetManager {
public void checkAssetsForVersion(final String version) {
LiquidLauncher.LOGGER.info("Checking assets for " + version);
try{
try{
if(!checkIndexFile(version)) {
if(!downloadIndexFile(version)) {
try {
try {
if (!checkIndexFile(version)) {
if (!downloadIndexFile(version)) {
LiquidLauncher.LOGGER.warning("Failed to update assets");
return;
}
}
}catch(Exception ignored) { }
} catch (Exception ignored) {
}
final List<Asset> assets = readAssetIndex(new String(Files.readAllBytes(new File(indecies, version + ".json").toPath())));
final int allAssets = assets.size();
......@@ -53,11 +54,11 @@ public class AssetManager {
LiquidLauncher.LOGGER.info("Missing " + assets.size() + "/" + allAssets + " assets");
int i = 0;
for(final Asset asset : assets) {
for (final Asset asset : assets) {
i++;
downloadAsset(asset, i, assets.size());
}
}catch(IOException e) {
} catch (IOException e) {
LiquidLauncher.LOGGER.severe("Failed to update assets: ");
e.printStackTrace();
}
......@@ -70,10 +71,10 @@ public class AssetManager {
private void filterMissingAssets(final List<Asset> assets) {
final List<Asset> remove = new ArrayList<>();
for(final Asset asset : assets) {
for (final Asset asset : assets) {
final File assetPath = new File(objects, asset.getAssetPath());
if(assetPath.exists())
if (assetPath.exists())
remove.add(asset);
}
......
......@@ -29,8 +29,8 @@ public class ClientBuild {
public static List<ClientBuild> getBuildsFromJson(JsonObject obj) {
final List<ClientBuild> result = new ArrayList<>();
for(String minecraftVersion : obj.keySet()) {
for(String liquidBounceVersion : obj.getAsJsonObject(minecraftVersion).keySet()) {
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();
......
......@@ -47,19 +47,19 @@ public class Library {
public static Library getFromJsonObject(final JsonObject obj) {
final MavenDependency dependency = MavenDependency.fromString(obj.get("name").getAsString());
String repoUrl = null;
if(obj.has("url"))
if (obj.has("url"))
repoUrl = obj.get("url").getAsString();
int size = -1;
String downloadUrl = null;
String sha1 = null;
if(obj.has("downloads") && obj.getAsJsonObject("downloads").has("artifact") && !obj.has("natives")) {
if (obj.has("downloads") && obj.getAsJsonObject("downloads").has("artifact") && !obj.has("natives")) {
final JsonObject artifact = obj.getAsJsonObject("downloads").getAsJsonObject("artifact");
if(artifact.has("size"))
if (artifact.has("size"))
size = artifact.get("size").getAsInt();
if(artifact.has("sha1"))
if (artifact.has("sha1"))
sha1 = artifact.get("sha1").getAsString();
if(artifact.has("url"))
if (artifact.has("url"))
downloadUrl = artifact.get("url").getAsString();
}
......@@ -85,28 +85,28 @@ public class Library {
}
boolean available = true;
if(obj.has("rules")) {
for(final JsonElement el : obj.getAsJsonArray("rules")) {
if (obj.has("rules")) {
for (final JsonElement el : obj.getAsJsonArray("rules")) {
final JsonObject rulesObj = el.getAsJsonObject();
if(rulesObj.get("action").getAsString().equals("disallow")) {
if (rulesObj.get("action").getAsString().equals("disallow")) {
available = false;
if(rulesObj.has("os"))
if(!rulesObj.getAsJsonObject("os").get("name").equals(osName))
if (rulesObj.has("os"))
if (!rulesObj.getAsJsonObject("os").get("name").equals(osName))
available = true;
if(!available)
if (!available)
break;
}else{
if(rulesObj.get("action").getAsString().equals("allow")) {
} else {
if (rulesObj.get("action").getAsString().equals("allow")) {
available = true;
if (rulesObj.has("os"))
if (!rulesObj.getAsJsonObject("os").get("name").equals(osName))
available = false;
if(!available)
if (!available)
break;
}
}
......@@ -114,7 +114,7 @@ public class Library {
}
String nativeName = "";
if(obj.has("natives")) {
if (obj.has("natives")) {
final StringBuilder archBuilder = new StringBuilder();
{ // OS Arch
......@@ -122,11 +122,11 @@ public class Library {
final Pattern pattern = Pattern.compile("[+-]?[0-9]+");
final Matcher matcher = pattern.matcher(osArch);
while(matcher.find())
while (matcher.find())
archBuilder.append(osArch.substring(matcher.start(), matcher.end()));
}
if(obj.getAsJsonObject("natives").get(osName) == null)
if (obj.getAsJsonObject("natives").get(osName) == null)
available = false;
else
nativeName = obj.getAsJsonObject("natives").get(osName).getAsString().replace("${arch}", archBuilder.toString());
......@@ -134,7 +134,7 @@ public class Library {
nativeName = "-" + nativeName;
}
if(!available)
if (!available)
LiquidLauncher.LOGGER.info(String.format("The library %s isnt supported for this OS.", dependency.toString())); // THE TWICH LIBRARY IS ONLY SUPPORTED FOR WINDOWS
if (dependency.getGroupId().equals("net.minecraftforge") && dependency.getArtifactId().equals("forge"))
......@@ -156,7 +156,7 @@ public class Library {
}
public String getRepositoryUrl() {
if(repoUrl == null || repoUrl.isEmpty())
if (repoUrl == null || repoUrl.isEmpty())
return "https://libraries.minecraft.net/";
if (!repoUrl.endsWith("/"))
......@@ -174,20 +174,20 @@ public class Library {
if (isNative && isAvailable() && new File(libaryFolder, dependency.getUrl(nativeSuffix)).exists()) {
LiquidLauncher.LOGGER.info("Extracting natives of " + getMavenLib());
try{
try {
final ZipFile zipFile = new ZipFile(new File(libaryFolder, dependency.getUrl(nativeSuffix)));
final Enumeration enumeration = zipFile.entries();
while(enumeration.hasMoreElements()) {
while (enumeration.hasMoreElements()) {
final ZipEntry entry = (ZipEntry) enumeration.nextElement();
if(entry.getName().startsWith("META-INF"))
if (entry.getName().startsWith("META-INF"))
continue;
final FileOutputStream outputStream = new FileOutputStream(new File(nativeFolder, entry.getName()));
ByteStreams.copy(zipFile.getInputStream(entry), outputStream);
outputStream.close();
}
}catch(Exception e) {
} catch (Exception e) {
throw new LaunchException("Failed to extract natives", e);
}
}
......@@ -210,28 +210,28 @@ public class Library {
final StringBuilder sb = new StringBuilder();
sb.append(dependency);
if(isNative()) {
if (isNative()) {
sb.append(" NATIVE");
if(isAvailable())
if (isAvailable())
sb.append("[").append(nativeSuffix).append("]");
}
if(!isAvailable())
if (!isAvailable())
sb.append("[NOT AVAILABLE]");
return sb.toString();
}
public void update(final File natives, final File libraryFolder) {
if(!available)
if (!available)
return;
final File libFile = new File(libraryFolder, dependency.getUrl(nativeSuffix));
if(!libFile.exists()) {
if (!libFile.exists()) {
LiquidLauncher.LOGGER.info("Updating library " + dependency);
try{
try {
NetworkUtils.downloadWithProgressBarUpdate("Waiting...", getLibraryDownload(), libFile, LiquidLauncher.menuInterface.progress, "Downloading " + dependency);
}catch(IOException e) {
} catch (IOException e) {
LiquidLauncher.LOGGER.warning("Failed to download library " + dependency);
}
}
......
......@@ -25,8 +25,8 @@ public class LibraryManager {
public static LibraryManager loadLibraries(final JsonArray... l) {
final List<Library> libs = new ArrayList<>();
for(JsonArray libaries : l)
for(JsonElement el : libaries)
for (JsonArray libaries : l)
for (JsonElement el : libaries)
libs.add(Library.getFromJsonObject(el.getAsJsonObject()));
return new LibraryManager(libs);
}
......@@ -36,7 +36,7 @@ public class LibraryManager {
}
public void updateLibraries(final File natives, final File libraryFolder) {
for(Library lib : getLibraries())
for (Library lib : getLibraries())
lib.update(natives, libraryFolder);
}
......@@ -44,11 +44,11 @@ public class LibraryManager {
final String separator = System.getProperty("path.separator");
final StringBuilder sb = new StringBuilder();
for(Library lib : libraries) {
if(lib.isNative() || !lib.isAvailable())
for (Library lib : libraries) {
if (lib.isNative() || !lib.isAvailable())
continue;
if(SystemUtils.getOS() == SystemUtils.OSType.WINDOWS)
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);
......
......@@ -20,15 +20,15 @@ public class MavenDependency {
public static MavenDependency fromString(final String s) throws NumberFormatException {
MavenDependency mavenDependency = null;
String[] split = s.split(":");
if(split.length == 3)
if (split.length == 3)
mavenDependency = new MavenDependency(split[0], split[1], split[2]);
split = s.split("/");
if(split.length == 3)
if (split.length == 3)
mavenDependency = new MavenDependency(split[0], split[1], split[2]);
if(mavenDependency == null)
if (mavenDependency == null)
throw new RuntimeException("The library " + s + " is not valid.");
return mavenDependency;
}
......
......@@ -12,7 +12,9 @@ import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.dnd.*;
import java.awt.event.*;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import java.net.URI;
......@@ -31,6 +33,13 @@ public class AddLiquidBounceDialog extends JDialog {
private JLabel dlLabel;
private String file = "";
{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
$$$setupUI$$$();
}
public AddLiquidBounceDialog(final String downloadLink, final String hash) {
this.hash = hash;
setContentPane(contentPane);
......@@ -43,25 +52,25 @@ public class AddLiquidBounceDialog extends JDialog {
public void dragEnter(DropTargetDragEvent dtde) {
final Transferable transferable = dtde.getTransferable();
boolean accept = false;
if(transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
try{
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) {
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
dtde.rejectDrag();
......@@ -126,10 +135,10 @@ 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 | URISyntaxException e) {
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
}
......@@ -137,7 +146,7 @@ public class AddLiquidBounceDialog extends JDialog {
browseButton.addActionListener(e -> {
String s = Utils.chooseFile(null, AddLiquidBounceDialog.this);
if(s != null)
if (s != null)
fileField.setText(s);
});
}
......@@ -160,20 +169,20 @@ 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;
}
file = fileField.getText();
dispose();
}catch(IOException e) {
} catch (IOException e) {
JOptionPane.showMessageDialog(this, e.toString(), "ERROR", JOptionPane.ERROR_MESSAGE);
}
}
......@@ -182,13 +191,6 @@ public class AddLiquidBounceDialog extends JDialog {
dispose();
}
{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
$$$setupUI$$$();
}
/**
* Method generated by IntelliJ IDEA GUI Designer
* >>> IMPORTANT!! <<<
......
......@@ -93,31 +93,29 @@
<text value="Login"/>
</properties>
</component>
<component id="8ddee" class="javax.swing.JLabel" binding="statusLabel">
<component id="b2f72" class="javax.swing.JLabel">
<constraints>
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="4" 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>
<properties>
<text value="Idle..."/>
<text value="Email:Password"/>
</properties>
</component>
<component id="d6f5e" class="javax.swing.JTextField" binding="emailPassword">
<component id="904c0" class="javax.swing.JLabel" binding="statusLabel">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
<grid row="8" 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>
<properties>
<text value=""/>
<text value="Idle..."/>
</properties>
</component>
<component id="b2f72" class="javax.swing.JLabel">
<component id="5df12" class="javax.swing.JTextField" binding="emailPassword">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<text value="Email:Password"/>
</properties>
<properties/>
</component>
</children>
</grid>
......
......@@ -22,14 +22,14 @@ public class Utils {
public static String chooseDirectory(final File currFolder, final Component parent) {
final JFileChooser chooser = new JFileChooser(currFolder);
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
if(chooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION)
if (chooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION)
return chooser.getSelectedFile().getAbsolutePath();
return null;
}
public static String chooseFile(final File currFolder, final Component parent) {
final JFileChooser chooser = new JFileChooser(currFolder);
if(chooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION)
if (chooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION)
return chooser.getSelectedFile().getAbsolutePath();
return null;
}
......
......@@ -17,7 +17,7 @@ public class LauncherFolderTreeTest {
@Test
public void testPaths() {
LauncherFolderTree tree = new LauncherFolderTree(new File("/ll"), new File("/mc"), new ClientBuild("eth", "", "", "1.8.8", "b26.2", ""));
LauncherFolderTree tree = new LauncherFolderTree(new File("/ll"), new ClientBuild("eth", "", "", "1.8.8", "b26.6", ""));
assertEquals("/ll/assets", tree.getAssets().getAbsolutePath());
assertEquals("/ll/versions/1.8.8", tree.getMinecraftVersionFolder().getAbsolutePath());
assertEquals("/ll/versions/1.8.8/1.8.8.json", tree.getMinecraftJson().getAbsolutePath());
......
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