Fix Forge installer for 1.7.10

This commit is contained in:
BuildTools 2023-06-28 20:33:48 +03:00
parent 85b3a42dd3
commit 09be377919
5 changed files with 29 additions and 6 deletions

View File

@ -1 +1 @@
1687691695288
1687971356220

View File

@ -11,6 +11,7 @@ import java.awt.event.WindowEvent;
import java.lang.instrument.Instrumentation;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import javax.swing.AbstractButton;
import javax.swing.JDialog;
@ -20,6 +21,8 @@ public class Agent implements AWTEventListener {
private boolean forgeWindowHandled = false;
private final boolean suppressProfileCreation;
private final Timer componentTimer = new Timer();
public Agent(boolean ps) {
this.suppressProfileCreation = ps;
}
@ -30,15 +33,20 @@ public class Agent implements AWTEventListener {
Window window = windowEvent.getWindow();
if(windowEvent.getID() == WindowEvent.WINDOW_OPENED) {
if(!forgeWindowHandled) { // false at startup, so we will handle the first window as the Forge one
handleForgeWindow(window);
forgeWindowHandled = true;
forgeWindowHandled = handleForgeWindow(window);
if(forgeWindowHandled) {
componentTimer.cancel();
componentTimer.purge();
}else{
componentTimer.schedule(new ComponentTimeoutTask(), 30000);
}
}else if(window instanceof JDialog) { // expecting a new dialog
handleDialog(window);
}
}
}
public void handleForgeWindow(Window window) {
public boolean handleForgeWindow(Window window) {
List<Component> components = new ArrayList<>();
insertAllComponents(components, window, new MainWindowFilter());
AbstractButton okButton = null;
@ -56,11 +64,13 @@ public class Agent implements AWTEventListener {
}
}
if(okButton == null) {
System.out.println("Failed to set all the UI components.");
System.out.println("Failed to set all the UI components, wil try again in the next window");
System.exit(17);
return false;
}else{
ProfileFixer.storeProfile();
EventQueue.invokeLater(okButton::doClick); // do that after forge actually builds its window, otherwise we set the path too fast
return true;
}
}
@ -70,6 +80,7 @@ public class Agent implements AWTEventListener {
if(components.size() == 1) {
// another common trait of them - they only have one option pane in them,
// so we can discard the rest of the dialog structure
// also allows us to discard dialogs with progress bars which older installers use
JOptionPane optionPane = (JOptionPane) components.get(0);
if(optionPane.getMessageType() == JOptionPane.INFORMATION_MESSAGE) { // forge doesn't emit information messages for other reasons yet
System.out.println("The install was successful!");

View File

@ -0,0 +1,11 @@
package git.artdeell.forgeinstaller;
import java.util.TimerTask;
public class ComponentTimeoutTask extends TimerTask {
@Override
public void run() {
System.out.println("Initialization timed out!");
System.exit(17);
}
}

View File

@ -6,6 +6,7 @@ import java.awt.*;
public class DialogFilter implements ComponentFilter{
@Override
public boolean checkComponent(Component component) {
return component instanceof JOptionPane;
return component instanceof JOptionPane
|| component instanceof JProgressBar;
}
}