From 84f361641d265e9d3318ce36beb424d1c29c2293 Mon Sep 17 00:00:00 2001 From: Downforce Agent Date: Fri, 12 Jul 2024 16:49:04 -0500 Subject: [PATCH] autoupdater finished --- firestar/src/main/java/Ernie.java | 27 +++++++++++++++++++++++---- firestar/src/main/java/Main.java | 4 ++-- firestar/src/main/java/MissPiggy.java | 8 ++++++-- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/firestar/src/main/java/Ernie.java b/firestar/src/main/java/Ernie.java index 973f44b..9e69e51 100644 --- a/firestar/src/main/java/Ernie.java +++ b/firestar/src/main/java/Ernie.java @@ -19,6 +19,8 @@ import java.awt.Desktop; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; import java.awt.image.BufferedImage; import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; @@ -43,7 +45,7 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -public class Ernie implements ActionListener, Runnable { +public class Ernie implements ActionListener { // Base URL for Gitea API public static final String gitapi = "https://git.worlio.com/api/v1/repos/bonkmaykr/firestar"; public static final String changelog = "https://bonkmaykr.worlio.com/http/firestar/changelog.htm"; @@ -61,14 +63,17 @@ public class Ernie implements ActionListener, Runnable { public boolean backgroundDone = false; private BufferedImage windowIcon; - public void run() { + private JFrame parent; + + public Ernie(JFrame parent) { + this.parent = parent; try { windowIcon = ImageIO.read(Main.class.getResourceAsStream("/titleIcon.png")); frame.setIconImage(windowIcon); } catch (IOException e) { System.out.println("ERROR: Failed to find /resources/titleIcon.png. Window will not have an icon."); } - byte[] urlraw = new Ernie().getFile(gitapi+"/releases?draft=false&pre-release=false"); + byte[] urlraw = getFile(gitapi+"/releases?draft=false&pre-release=false"); if (urlraw.length <= 0) { JOptionPane.showMessageDialog(frame, "Internal Error: Couldn't check for updates.", "Fatal Error", JOptionPane.ERROR_MESSAGE); } else { @@ -89,6 +94,16 @@ public class Ernie implements ActionListener, Runnable { frame.setResizable(false); frame.setLocationRelativeTo(null); frame.setAlwaysOnTop(true); + frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); + parent.setEnabled(false); + frame.addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) + { + parent.setEnabled(true); + e.getWindow().dispose(); + } + }); frame.setVisible(true); } else { System.out.println("Updater: No updates."); } } catch (IOException ex) { @@ -101,12 +116,16 @@ public class Ernie implements ActionListener, Runnable { @Override public void actionPerformed(ActionEvent actionEvent) { - if (actionEvent.getSource() == notnowbtn) {frame.dispose();} else + if (actionEvent.getSource() == notnowbtn) { + parent.setEnabled(true); + frame.dispose(); + } else if (actionEvent.getSource() == surebtn) { if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { String releasepage = "https://git.worlio.com/bonkmaykr/firestar/releases"; try { Desktop.getDesktop().browse(new URI(releasepage)); + parent.setEnabled(true); frame.dispose(); } catch (Exception ex) { JOptionPane.showMessageDialog(frame, "Couldn't open your web browser!\nYou can check out the latest release at the URL below:\n"+releasepage, "Error", JOptionPane.ERROR_MESSAGE); diff --git a/firestar/src/main/java/Main.java b/firestar/src/main/java/Main.java index 402f0f3..d7f08ae 100644 --- a/firestar/src/main/java/Main.java +++ b/firestar/src/main/java/Main.java @@ -42,7 +42,7 @@ public class Main { public static boolean repatch; //are we in compat mode? public static boolean windows; //True = windows public static int confvint = vint; - public static boolean checkUpdates; + public static boolean checkUpdates = true; //public static String psarc; //sdk location public enum ArcTarget { // install target for 2048, type used by downloader @@ -138,7 +138,7 @@ public class Main { container.put("HDpath", "TODO"); // proposed hd/fury support for ps3, will use very simplified Fast Mode due to less difficulty installing container.put("safemode", repatch); container.put("isWin32", windows); - container.put("checkUpdates", checkUpdates); + container.put("checkUpdates", checkUpdates); container.put("currentPlaylist", "TODO"); // proposed feature: store separate mod lists in lists/ to load/save later? try { diff --git a/firestar/src/main/java/MissPiggy.java b/firestar/src/main/java/MissPiggy.java index 0a7d007..5712655 100644 --- a/firestar/src/main/java/MissPiggy.java +++ b/firestar/src/main/java/MissPiggy.java @@ -312,8 +312,12 @@ public class MissPiggy implements ActionListener { } private void StartErnie() { - Ernie e = new Ernie(); - new Thread(e).start(); + new Thread(new Runnable() { + @Override + public void run() { + new Ernie(frame); // changed away from runnable in order to pass params to constructor -bonk + } + }).start(); } private ListSelectionListener whenItemSelected() {