diff --git a/.gitignore b/.gitignore
index 557fffb9..4580c788 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,4 @@
ripme.log
rips/
.history
+ripme.jar.update
diff --git a/pom.xml b/pom.xml
index 7616b520..82dedb24 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
com.rarchives.ripme
ripme
jar
- 1.0
+ 1.0.2-beta1
ripme
http://rip.rarchives.com
@@ -52,6 +52,8 @@
com.rarchives.ripme.App
+ true
+ true
./config
diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/TwitterRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/TwitterRipper.java
index fb214a76..b92a3b59 100644
--- a/src/main/java/com/rarchives/ripme/ripper/rippers/TwitterRipper.java
+++ b/src/main/java/com/rarchives/ripme/ripper/rippers/TwitterRipper.java
@@ -17,7 +17,6 @@ import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import com.rarchives.ripme.ripper.AbstractRipper;
-import com.rarchives.ripme.ui.RipStatusMessage.STATUS;
import com.rarchives.ripme.utils.Utils;
public class TwitterRipper extends AbstractRipper {
diff --git a/src/main/java/com/rarchives/ripme/ui/MainWindow.java b/src/main/java/com/rarchives/ripme/ui/MainWindow.java
index f87fd5e3..60cbe3dd 100644
--- a/src/main/java/com/rarchives/ripme/ui/MainWindow.java
+++ b/src/main/java/com/rarchives/ripme/ui/MainWindow.java
@@ -78,6 +78,8 @@ public class MainWindow implements Runnable, RipStatusHandler {
// Configuration
private static JButton optionConfiguration;
private static JPanel configurationPanel;
+ private static JButton configUpdateButton;
+ private static JLabel configUpdateLabel;
// TODO Configuration components
public MainWindow() {
@@ -188,13 +190,22 @@ public class MainWindow implements Runnable, RipStatusHandler {
gbc.gridx = 2; historyButtonPanel.add(historyButtonRerip, gbc);
gbc.gridy = 1; gbc.gridx = 0;
historyPanel.add(historyButtonPanel, gbc);
-
+
configurationPanel = new JPanel(new GridBagLayout());
configurationPanel.setBorder(emptyBorder);
configurationPanel.setVisible(false);
configurationPanel.setPreferredSize(new Dimension(300, 250));
// TODO Configuration components
-
+ JLabel configLabel = new JLabel("Version: " + Utils.getConfigInteger("version.major", 0) + "." + Utils.getConfigInteger("version.minor", 0) + "." + Utils.getConfigInteger("version.build", 0));
+ configurationPanel.add(configLabel);
+ configUpdateButton = new JButton("Check for updates");
+ configUpdateLabel = new JLabel("");
+ gbc.ipady = 0;
+ gbc.gridy = 1;
+ configurationPanel.add(configUpdateButton, gbc);
+ gbc.gridy = 2;
+ configurationPanel.add(configUpdateLabel, gbc);
+
gbc.gridy = 0; pane.add(ripPanel, gbc);
gbc.gridy = 1; pane.add(statusPanel, gbc);
gbc.gridy = 2; pane.add(progressPanel, gbc);
@@ -282,8 +293,15 @@ public class MainWindow implements Runnable, RipStatusHandler {
new Thread(ripAllThread).start();
}
});
+ configUpdateButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ UpdateUtils.updateProgram(configUpdateLabel);
+ }
+ });
}
+
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
new file mode 100644
index 00000000..6fbed020
--- /dev/null
+++ b/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java
@@ -0,0 +1,117 @@
+package com.rarchives.ripme.ui;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import javax.swing.JLabel;
+
+import org.json.JSONArray;
+import org.json.JSONObject;
+import org.jsoup.Connection.Response;
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+
+public class UpdateUtils {
+
+ private static final String DEFAULT_VERSION = "1.0.0";
+ private static final String updateJsonURL = "http://rarchives.com/ripme.json";
+ private static final String updateJarURL = "http://rarchives.com/ripme.jar";
+
+ public static void updateProgram(JLabel configUpdateLabel) {
+ configUpdateLabel.setText("Checking for update...:");
+
+ Document doc = null;
+ try {
+ doc = Jsoup.connect(UpdateUtils.updateJsonURL)
+ .ignoreContentType(true)
+ .get();
+ } catch (IOException e) {
+ configUpdateLabel.setText("Error while fetching update: " + e.getMessage());
+ e.printStackTrace();
+ return;
+ }
+ String jsonString = doc.body().html().replaceAll(""", "\"");
+ JSONObject json = new JSONObject(jsonString);
+ JSONArray jsonChangeList = json.getJSONArray("changeList");
+ configUpdateLabel.setText("Most recent changes:");
+ for (int i = 0; i < jsonChangeList.length(); i++) {
+ String change = jsonChangeList.getString(i);
+ configUpdateLabel.setText(configUpdateLabel.getText() + "
+ " + change);
+ }
+
+ String latestVersion = json.getString("latestVersion");
+ if (UpdateUtils.isNewerVersion(latestVersion)) {
+ configUpdateLabel.setText("Newer version found!
" + configUpdateLabel.getText() + "");
+ try {
+ UpdateUtils.downloadJarAndReplace(updateJarURL);
+ } catch (IOException e) {
+ configUpdateLabel.setText("Error while updating: " + e.getMessage());
+ e.printStackTrace();
+ return;
+ }
+ } else {
+ configUpdateLabel.setText("Running latest version: " + UpdateUtils.getThisJarVersion());
+ }
+ }
+
+ private static void downloadJarAndReplace(String updateJarURL)
+ throws IOException {
+ String newFile = "ripme.jar.update";
+ Response response;
+ response = Jsoup.connect(updateJarURL)
+ .ignoreContentType(true)
+ .timeout(60000)
+ .maxBodySize(1024 * 1024 * 100)
+ .execute();
+ FileOutputStream out = new FileOutputStream(newFile);
+ out.write(response.bodyAsBytes());
+ out.close();
+ Runtime.getRuntime().exec(new String[] {"java", "-jar", newFile});
+ System.exit(0);
+ }
+
+ private static String getThisJarVersion() {
+ String thisVersion = UpdateUtils.class.getPackage().getImplementationVersion();
+ if (thisVersion == null) {
+ // Version is null if we're not running from the JAR
+ thisVersion = DEFAULT_VERSION; ; // Super-high version number
+ }
+ return thisVersion;
+ }
+
+ private static boolean isNewerVersion(String latestVersion) {
+ int[] oldVersions = versionStringToInt(getThisJarVersion());
+ int[] newVersions = versionStringToInt(latestVersion);
+ if (oldVersions.length < newVersions.length) {
+ System.err.println("Calculated: " + oldVersions + " < " + latestVersion);
+ return true;
+ }
+
+ for (int i = 0; i < oldVersions.length; i++) {
+ System.err.println("Calculating: " + newVersions[i] + " <> " + oldVersions[i]);
+ if (newVersions[i] > oldVersions[i]) {
+ return true;
+ }
+ else if (newVersions[i] < oldVersions[i]) {
+ return false;
+ }
+ else {
+ continue;
+ }
+ }
+
+ // At this point, the version numbers are exactly the same.
+ // Assume any additional changes to the version text means a new version
+ return !(latestVersion.equals(getThisJarVersion()));
+ }
+
+ private static int[] versionStringToInt(String version) {
+ String strippedVersion = version.split("-")[0];
+ String[] strVersions = strippedVersion.split("\\.");
+ int[] intVersions = new int[strVersions.length];
+ for (int i = 0; i < strVersions.length; i++) {
+ intVersions[i] = Integer.parseInt(strVersions[i]);
+ }
+ return intVersions;
+ }
+}
diff --git a/src/main/java/com/rarchives/ripme/utils/Utils.java b/src/main/java/com/rarchives/ripme/utils/Utils.java
index 318524ef..c52c7d7b 100644
--- a/src/main/java/com/rarchives/ripme/utils/Utils.java
+++ b/src/main/java/com/rarchives/ripme/utils/Utils.java
@@ -180,4 +180,10 @@ public class Utils {
}
return classes;
}
+
+ public static String getBuildVersion() {
+ return getConfigInteger("version.major", 0)
+ + "." + getConfigInteger("version.minor", 0)
+ + "." + getConfigInteger("version.build", 0);
+ }
}
\ No newline at end of file
diff --git a/src/main/resources/rip.properties b/src/main/resources/rip.properties
index add7fcf9..cb3240f8 100644
--- a/src/main/resources/rip.properties
+++ b/src/main/resources/rip.properties
@@ -1,3 +1,4 @@
+
# Download threads to use per ripper
threads.size = 5
diff --git a/src/test/java/com/rarchives/ripme/tst/ripper/rippers/RedditRipperTest.java b/src/test/java/com/rarchives/ripme/tst/ripper/rippers/RedditRipperTest.java
index d478a4b9..bed60fde 100644
--- a/src/test/java/com/rarchives/ripme/tst/ripper/rippers/RedditRipperTest.java
+++ b/src/test/java/com/rarchives/ripme/tst/ripper/rippers/RedditRipperTest.java
@@ -10,7 +10,7 @@ import com.rarchives.ripme.ripper.rippers.RedditRipper;
public class RedditRipperTest extends RippersTest {
public void testRedditAlbums() throws IOException {
- if (false && !DOWNLOAD_CONTENT) {
+ if (!DOWNLOAD_CONTENT) {
return;
}
List contentURLs = new ArrayList();