diff --git a/pom.xml b/pom.xml index e838effd..0e0229f6 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.rarchives.ripme ripme jar - 1.0.3 + 1.0.4 ripme http://rip.rarchives.com diff --git a/src/main/java/com/rarchives/ripme/ui/MainWindow.java b/src/main/java/com/rarchives/ripme/ui/MainWindow.java index 49a8b42e..191a718b 100644 --- a/src/main/java/com/rarchives/ripme/ui/MainWindow.java +++ b/src/main/java/com/rarchives/ripme/ui/MainWindow.java @@ -19,6 +19,7 @@ import java.net.URL; import javax.swing.DefaultListModel; import javax.swing.JButton; +import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; @@ -80,10 +81,13 @@ public class MainWindow implements Runnable, RipStatusHandler { private static JPanel configurationPanel; private static JButton configUpdateButton; private static JLabel configUpdateLabel; + private static JTextField configTimeoutText; + private static JTextField configThreadsText; + private static JCheckBox configOverwriteCheckbox; // TODO Configuration components public MainWindow() { - mainFrame = new JFrame(WINDOW_TITLE); + mainFrame = new JFrame(WINDOW_TITLE + " v" + UpdateUtils.getThisJarVersion()); mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //mainFrame.setPreferredSize(new Dimension(400, 180)); //mainFrame.setResizable(false); @@ -196,15 +200,23 @@ public class MainWindow implements Runnable, RipStatusHandler { configurationPanel.setVisible(false); configurationPanel.setPreferredSize(new Dimension(300, 250)); // TODO Configuration components - JLabel configLabel = new JLabel("Version: " + UpdateUtils.getThisJarVersion()); configUpdateButton = new JButton("Check for updates"); - configUpdateLabel = new JLabel(""); - gbc.gridy = 0; configurationPanel.add(configLabel, gbc); - gbc.gridy = 1; configurationPanel.add(configUpdateButton, gbc); - gbc.ipady = 50; - gbc.gridy = 2; configurationPanel.add(configUpdateLabel, gbc); - gbc.ipady = 10; - + configUpdateLabel = new JLabel("Current version: " + UpdateUtils.getThisJarVersion(), JLabel.RIGHT); + JLabel configTimeoutLabel = new JLabel("Timeout (in milliseconds):", JLabel.RIGHT); + JLabel configThreadsLabel = new JLabel("Maximum download threads:", JLabel.RIGHT); + configTimeoutText = new JTextField(Integer.toString(Utils.getConfigInteger("download.timeout", 60000))); + configThreadsText = new JTextField(Integer.toString(Utils.getConfigInteger("threads.size", 3))); + configOverwriteCheckbox = new JCheckBox("Overwrite existing files?", Utils.getConfigBoolean("file.overwrite", false)); + configOverwriteCheckbox.setHorizontalAlignment(JCheckBox.RIGHT); + configOverwriteCheckbox.setHorizontalTextPosition(JCheckBox.LEFT); + gbc.gridy = 0; gbc.gridx = 0; configurationPanel.add(configUpdateLabel, gbc); + gbc.gridx = 1; configurationPanel.add(configUpdateButton, gbc); + gbc.gridy = 1; gbc.gridx = 0; configurationPanel.add(configTimeoutLabel, gbc); + gbc.gridx = 1; configurationPanel.add(configTimeoutText, gbc); + gbc.gridy = 2; gbc.gridx = 0; configurationPanel.add(configThreadsLabel, gbc); + gbc.gridx = 1; configurationPanel.add(configThreadsText, gbc); + gbc.gridy = 3; gbc.gridx = 0; configurationPanel.add(configOverwriteCheckbox, gbc); + gbc.gridy = 0; pane.add(ripPanel, gbc); gbc.gridy = 1; pane.add(statusPanel, gbc); gbc.gridy = 2; pane.add(progressPanel, gbc); @@ -295,12 +307,17 @@ public class MainWindow implements Runnable, RipStatusHandler { configUpdateButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { - UpdateUtils.updateProgram(configUpdateLabel); + Thread t = new Thread() { + @Override + public void run() { + UpdateUtils.updateProgram(configUpdateLabel); + } + }; + t.start(); } }); } - private void appendLog(final String text, final Color color) { SimpleAttributeSet sas = new SimpleAttributeSet(); StyleConstants.setForeground(sas, color); diff --git a/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java b/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java index 587c70f5..f971a5e9 100644 --- a/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java +++ b/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java @@ -5,6 +5,7 @@ import java.io.FileOutputStream; import java.io.IOException; import javax.swing.JLabel; +import javax.swing.JOptionPane; import org.apache.log4j.Logger; import org.json.JSONArray; @@ -16,7 +17,7 @@ import org.jsoup.nodes.Document; public class UpdateUtils { private static final Logger logger = Logger.getLogger(UpdateUtils.class); - private static final String DEFAULT_VERSION = "100.0.0"; + private static final String DEFAULT_VERSION = "1.0.4"; private static final String updateJsonURL = "http://rarchives.com/ripme.json"; private static final String updateJarURL = "http://rarchives.com/ripme.jar"; private static final String mainFileName = "ripme.jar"; @@ -32,7 +33,7 @@ public class UpdateUtils { } public static void updateProgram(JLabel configUpdateLabel) { - configUpdateLabel.setText("Checking for update...:"); + configUpdateLabel.setText("Checking for update..."); Document doc = null; try { @@ -40,32 +41,53 @@ public class UpdateUtils { .ignoreContentType(true) .get(); } catch (IOException e) { - configUpdateLabel.setText("Error while fetching update: " + e.getMessage()); logger.error("Error while fetching update: ", e); + JOptionPane.showMessageDialog(null, + "Error while fetching update: " + e.getMessage() + "", + "RipMe Updater", + JOptionPane.ERROR_MESSAGE); return; + } finally { + configUpdateLabel.setText("Current version: " + getThisJarVersion()); } String jsonString = doc.body().html().replaceAll(""", "\""); JSONObject json = new JSONObject(jsonString); JSONArray jsonChangeList = json.getJSONArray("changeList"); - configUpdateLabel.setText("Most recent changes:"); + StringBuilder changeList = new StringBuilder(); for (int i = 0; i < jsonChangeList.length(); i++) { String change = jsonChangeList.getString(i); - configUpdateLabel.setText(configUpdateLabel.getText() + "
+ " + change); + changeList.append("
+ " + change); } String latestVersion = json.getString("latestVersion"); if (UpdateUtils.isNewerVersion(latestVersion)) { - configUpdateLabel.setText("Newer version found!

" + configUpdateLabel.getText() + ""); + int result = JOptionPane.showConfirmDialog( + null, + "New version (" + latestVersion + ") is available!" + + "

Recent changes:" + changeList.toString() + + "

Do you want to download and run the newest version?", + "RipMe Updater", + JOptionPane.YES_NO_OPTION); + if (result != JOptionPane.YES_OPTION) { + configUpdateLabel.setText("Current Version: " + getThisJarVersion() + + "
Latest version: " + latestVersion + ""); + return; + } + configUpdateLabel.setText("Downloading new version..."); logger.info("New version found, downloading..."); try { UpdateUtils.downloadJarAndReplace(updateJarURL); } catch (IOException e) { - configUpdateLabel.setText("Error while updating: " + e.getMessage()); + JOptionPane.showMessageDialog(null, + "Error while updating: " + e.getMessage(), + "RipMe Updater", + JOptionPane.ERROR_MESSAGE); + configUpdateLabel.setText(""); logger.error("Error while updating: ", e); return; } } else { - configUpdateLabel.setText("Running latest version: " + UpdateUtils.getThisJarVersion()); + configUpdateLabel.setText("v" + UpdateUtils.getThisJarVersion() + " is the latest version"); logger.info("Running latest version: " + UpdateUtils.getThisJarVersion()); } }