Skip to content

Commit

Permalink
Fix + improve launch method (MeteorDevelopment#3983)
Browse files Browse the repository at this point in the history
Paddyk45 authored Aug 21, 2023
1 parent 9ffca3f commit d752b5b
Showing 1 changed file with 22 additions and 52 deletions.
74 changes: 22 additions & 52 deletions launch/src/main/java/meteordevelopment/meteorclient/Main.java
Original file line number Diff line number Diff line change
@@ -6,9 +6,11 @@
package meteordevelopment.meteorclient;

import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.util.Locale;

@@ -20,28 +22,40 @@ public static void main(String[] args) throws UnsupportedLookAndFeelException, C
null,
"To install Meteor Client you need to put it in your mods folder and run Fabric for latest Minecraft version.",
"Meteor Client",
JOptionPane.YES_NO_OPTION,
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.ERROR_MESSAGE,
null,
new String[] { "Open Wiki", "Open Mods Folder" },
new String[] { "Open Wiki", "Open Mods Folder", "Join our Discord" },
null
);

switch (option) {
case 0: getOS().open("https://meteorclient.com/installation"); break;
case 0: {
try {
Desktop.getDesktop().browse(URI.create("https://meteorclient.com/faq/installation"));
} catch (IOException ignored) {}
break;
}
case 1: {
String path;

switch (getOS()) {
case WINDOWS: path = System.getenv("AppData") + "/.minecraft/mods"; break;
case OSX: path = System.getProperty("user.home") + "/Library/Application Support/minecraft/mods"; break;
default: path = System.getProperty("user.home") + "/.minecraft"; break;
default: path = System.getProperty("user.home") + "/.minecraft/mods"; break;
}

File mods = new File(path);
if (!mods.exists()) mods.mkdirs();

getOS().open(mods);
try {
Desktop.getDesktop().open(mods);
} catch (IOException ignored) {}
break;
}
case 2: {
try {
Desktop.getDesktop().browse(URI.create("https://discord.com/invite/bBGQZvd"));
} catch (IOException ignored) {}
break;
}
}
@@ -59,52 +73,8 @@ private static OperatingSystem getOS() {

private enum OperatingSystem {
LINUX,
WINDOWS {
@Override
protected String[] getURLOpenCommand(URL url) {
return new String[] { "rundll32", "url.dll,FileProtocolHandler", url.toString() };
}
},
OSX {
@Override
protected String[] getURLOpenCommand(URL url) {
return new String[] { "open", url.toString() };
}
},
WINDOWS,
OSX,
UNKNOWN;

public void open(URL url) {
try {
Runtime.getRuntime().exec(getURLOpenCommand(url));
} catch (IOException e) {
e.printStackTrace();
}
}

public void open(String url) {
try {
open(new URL(url));
} catch (MalformedURLException e) {
e.printStackTrace();
}
}

public void open(File file) {
try {
open(file.toURI().toURL());
} catch (MalformedURLException e) {
e.printStackTrace();
}
}

protected String[] getURLOpenCommand(URL url) {
String string = url.toString();

if ("file".equals(url.getProtocol())) {
string = string.replace("file:", "file://");
}

return new String[] { "xdg-open", string };
}
}
}

0 comments on commit d752b5b

Please sign in to comment.