|
24 | 24 |
|
25 | 25 | // We enter in java 8 so we can display a nice error message if things don't work |
26 | 26 | public class Main { |
27 | | - public static void main(String[] args) { |
28 | | - try { |
29 | | - // Only use CLI mode if there are any arguments or we have a headless JVM |
30 | | - if (GraphicsEnvironment.isHeadless() || args.length != 0) { |
31 | | - MethodHandles.lookup() |
32 | | - .findStatic(Class.forName("org.quiltmc.installer.CliInstaller"), "run", MethodType.methodType(void.class, String[].class)) |
33 | | - .invokeExact(args); |
34 | | - } else { |
35 | | - MethodHandles.lookup() |
36 | | - .findStatic(Class.forName("org.quiltmc.installer.gui.swing.SwingInstaller"), "run", MethodType.methodType(void.class)) |
37 | | - .invokeExact(); |
38 | | - } |
39 | | - } catch (UnsupportedClassVersionError error) { |
40 | | - if (GraphicsEnvironment.isHeadless() || args.length != 0) { |
41 | | - System.out.println("Quilt Installer requires Java 17 to run."); |
42 | | - System.exit(1); |
43 | | - } else { |
44 | | - try { |
45 | | - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |
46 | | - } catch (ClassNotFoundException | UnsupportedLookAndFeelException | IllegalAccessException | |
47 | | - InstantiationException e) { |
48 | | - // oh well |
49 | | - e.printStackTrace(); |
50 | | - } |
| 27 | + public static void main(String[] args) { |
| 28 | + try { |
| 29 | + // Only use CLI mode if there are any arguments or we have a headless JVM |
| 30 | + if (GraphicsEnvironment.isHeadless() || args.length != 0) { |
| 31 | + MethodHandles.lookup() |
| 32 | + .findStatic(Class.forName("org.quiltmc.installer.CliInstaller"), "run", MethodType.methodType(void.class, String[].class)) |
| 33 | + .invokeExact(args); |
| 34 | + } else { |
| 35 | + MethodHandles.lookup() |
| 36 | + .findStatic(Class.forName("org.quiltmc.installer.gui.swing.SwingInstaller"), "run", MethodType.methodType(void.class)) |
| 37 | + .invokeExact(); |
| 38 | + } |
| 39 | + } catch (UnsupportedClassVersionError error) { |
| 40 | + if (GraphicsEnvironment.isHeadless() || args.length != 0) { |
| 41 | + System.out.println("Quilt Installer requires Java 17 to run."); |
| 42 | + System.exit(1); |
| 43 | + } else { |
| 44 | + try { |
| 45 | + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |
| 46 | + } catch (ClassNotFoundException | UnsupportedLookAndFeelException | IllegalAccessException | |
| 47 | + InstantiationException e) { |
| 48 | + // oh well |
| 49 | + e.printStackTrace(); |
| 50 | + } |
51 | 51 |
|
52 | 52 |
|
53 | | - showPopup("Ornithe Installer crashed!", "<html>Ornithe Installer needs Java 17 to run.<br><br>" + |
54 | | - "Install the latest LTS release of Java from <a href=\"https://adoptium.net/\">Eclipse Adoptium</a> and try again." + |
55 | | - "<br><br>If you need help, ask" + |
56 | | - " in the <a href=\"https://discord.gg/JbRbRf62pn\">Ornithe Discord server</a>.</html>", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE); |
57 | | - System.exit(1); |
58 | | - } |
59 | | - } catch (Throwable t) { |
60 | | - throw new RuntimeException(t); |
61 | | - } |
62 | | - } |
| 53 | + showPopup("Ornithe Installer crashed!", "<html>Ornithe Installer needs Java 17 to run.<br><br>" + |
| 54 | + "Install the latest LTS release of Java from <a href=\"https://adoptium.net/\">Eclipse Adoptium</a> and try again." + |
| 55 | + "<br><br>If you need help, ask" + |
| 56 | + " in the <a href=\"https://discord.gg/JbRbRf62pn\">Ornithe Discord server</a>.</html>", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE); |
| 57 | + System.exit(1); |
| 58 | + } |
| 59 | + } catch (Throwable t) { |
| 60 | + throw new RuntimeException(t); |
| 61 | + } |
| 62 | + } |
63 | 63 |
|
64 | | - // Copied from AbstractPanel |
65 | | - protected static boolean showPopup(String title, String description, int optionType, int messageType) { |
66 | | - JEditorPane pane = new JEditorPane("text/html", |
67 | | - "<html><body style=\"" + buildEditorPaneStyle() + "\">" + description + "</body></html>"); |
68 | | - pane.setEditable(false); |
69 | | - pane.addHyperlinkListener(e -> { |
70 | | - try { |
71 | | - if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { |
72 | | - if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { |
73 | | - Desktop.getDesktop().browse(e.getURL().toURI()); |
74 | | - } else { |
75 | | - throw new UnsupportedOperationException("Failed to open " + e.getURL().toString()); |
76 | | - } |
77 | | - } |
78 | | - } catch (Throwable throwable) { |
79 | | - // Oh well |
80 | | - throwable.printStackTrace(); |
81 | | - } |
82 | | - }); |
83 | | - return JOptionPane.showOptionDialog(null, pane, title, optionType, messageType, null, null, null) == 0; |
84 | | - } |
| 64 | + // Copied from AbstractPanel |
| 65 | + protected static boolean showPopup(String title, String description, int optionType, int messageType) { |
| 66 | + JEditorPane pane = new JEditorPane("text/html", |
| 67 | + "<html><body style=\"" + buildEditorPaneStyle() + "\">" + description + "</body></html>"); |
| 68 | + pane.setEditable(false); |
| 69 | + pane.addHyperlinkListener(e -> { |
| 70 | + try { |
| 71 | + if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { |
| 72 | + if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { |
| 73 | + Desktop.getDesktop().browse(e.getURL().toURI()); |
| 74 | + } else { |
| 75 | + throw new UnsupportedOperationException("Failed to open " + e.getURL().toString()); |
| 76 | + } |
| 77 | + } |
| 78 | + } catch (Throwable throwable) { |
| 79 | + // Oh well |
| 80 | + throwable.printStackTrace(); |
| 81 | + } |
| 82 | + }); |
| 83 | + return JOptionPane.showOptionDialog(null, pane, title, optionType, messageType, null, null, null) == 0; |
| 84 | + } |
85 | 85 |
|
86 | | - private static String buildEditorPaneStyle() { |
87 | | - JLabel label = new JLabel(); |
88 | | - Font font = label.getFont(); |
89 | | - Color color = label.getBackground(); |
| 86 | + private static String buildEditorPaneStyle() { |
| 87 | + JLabel label = new JLabel(); |
| 88 | + Font font = label.getFont(); |
| 89 | + Color color = label.getBackground(); |
90 | 90 |
|
91 | | - return String.format( |
92 | | - "font-family:%s;font-weight:%s;font-size:%dpt;background-color: rgb(%d,%d,%d);", |
93 | | - font.getFamily(), (font.isBold() ? "bold" : "normal"), font.getSize(), color.getRed(), color.getGreen(), color.getBlue() |
94 | | - ); |
95 | | - } |
| 91 | + return String.format( |
| 92 | + "font-family:%s;font-weight:%s;font-size:%dpt;background-color: rgb(%d,%d,%d);", |
| 93 | + font.getFamily(), (font.isBold() ? "bold" : "normal"), font.getSize(), color.getRed(), color.getGreen(), color.getBlue() |
| 94 | + ); |
| 95 | + } |
96 | 96 | } |
0 commit comments