Merge pull request #210 from Parabot/feature/alert-download

[FEATURE] Alert of new version
This commit is contained in:
Jeroen Ketelaar
2017-06-01 01:23:57 +02:00
committed by GitHub
3 changed files with 38 additions and 26 deletions
+4 -6
View File
@@ -1,7 +1,6 @@
package org.parabot; package org.parabot;
import org.parabot.api.translations.TranslationHelper; import org.parabot.api.translations.TranslationHelper;
import org.parabot.core.Configuration;
import org.parabot.core.Core; import org.parabot.core.Core;
import org.parabot.core.Directories; import org.parabot.core.Directories;
import org.parabot.core.forum.AccountManager; import org.parabot.core.forum.AccountManager;
@@ -10,13 +9,10 @@ import org.parabot.core.network.proxy.ProxySocket;
import org.parabot.core.network.proxy.ProxyType; import org.parabot.core.network.proxy.ProxyType;
import org.parabot.core.ui.BotUI; import org.parabot.core.ui.BotUI;
import org.parabot.core.ui.ServerSelector; import org.parabot.core.ui.ServerSelector;
import org.parabot.core.ui.utils.UILog;
import javax.swing.*; import javax.swing.*;
import java.awt.*;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URI;
/** /**
* Parabot v2.6 * Parabot v2.6
@@ -46,8 +42,10 @@ public final class Landing {
} }
if (!Core.inDebugMode() && Core.hasValidation() && !Core.isValid()) { if (!Core.inDebugMode() && Core.hasValidation() && !Core.isValid()) {
Core.downloadNewVersion(); if (Core.newVersionAlert() == JOptionPane.YES_OPTION) {
return; Core.downloadNewVersion();
return;
}
} }
Core.verbose(TranslationHelper.translate("VALIDATION_ACCOUNT_MANAGER")); Core.verbose(TranslationHelper.translate("VALIDATION_ACCOUNT_MANAGER"));
+13 -8
View File
@@ -14,13 +14,11 @@ import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Date;
/** /**
* The core of parabot * The core of parabot
@@ -36,7 +34,7 @@ public class Core {
private static boolean loadLocal; //Loads both local and public scripts/servers private static boolean loadLocal; //Loads both local and public scripts/servers
private static boolean validate = true; private static boolean validate = true;
private static boolean secure = true; private static boolean secure = true;
private static Version currentVersion = Configuration.BOT_VERSION; private static Version currentVersion = Configuration.BOT_VERSION;
@@ -141,11 +139,11 @@ public class Core {
File f = new File(Landing.class.getProtectionDomain().getCodeSource().getLocation().getFile()); File f = new File(Landing.class.getProtectionDomain().getCodeSource().getLocation().getFile());
if (f.isFile()) { if (f.isFile()) {
try { try {
MessageDigest md = MessageDigest.getInstance("MD5"); MessageDigest md = MessageDigest.getInstance("MD5");
File location = new File(Landing.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()); File location = new File(Landing.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
if (location.exists()) { if (location.exists()) {
FileInputStream fis = new FileInputStream(location); FileInputStream fis = new FileInputStream(location);
byte[] dataBytes = new byte[1024]; byte[] dataBytes = new byte[1024];
int nread; int nread;
@@ -185,7 +183,7 @@ public class Core {
try { try {
if (br != null) { if (br != null) {
JSONObject object = (JSONObject) WebUtil.getJsonParser().parse(br); JSONObject object = (JSONObject) WebUtil.getJsonParser().parse(br);
boolean latest = (Boolean) object.get("result"); boolean latest = (Boolean) object.get("result");
if (!latest) { if (!latest) {
Directories.clearCache(); Directories.clearCache();
} }
@@ -251,4 +249,11 @@ public class Core {
return true; return true;
} }
} }
/**
* Alerts the user that there is a new version
*/
public static int newVersionAlert() {
return UILog.alert("Parabot Update", "There's a new version of Parabot! \nDo you wish to download it?\n\nThe current version could have some problems!", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
}
} }
@@ -1,24 +1,33 @@
package org.parabot.core.ui.utils; package org.parabot.core.ui.utils;
import javax.swing.JOptionPane; import javax.swing.*;
/** /**
*
* Log messages to the log user interface which is attached to the bot user interface * Log messages to the log user interface which is attached to the bot user interface
* *
* @author Everel * @author Everel
*
*/ */
public class UILog { public class UILog {
public static void log(final String title, final String message) { public static void log(final String title, final String message) {
log(title, message, JOptionPane.INFORMATION_MESSAGE); log(title, message, JOptionPane.INFORMATION_MESSAGE);
} }
public static void log(final String title, final String message, public static void log(final String title, final String message,
int messageType) { int messageType) {
JOptionPane.showMessageDialog(null, message, title, JOptionPane.showMessageDialog(null, message, title,
messageType); messageType);
} }
public static int alert(final String title, final String message) {
return alert(title, message, JOptionPane.YES_NO_OPTION);
}
public static int alert(final String title, final String message, int option) {
return alert(title, message, option, JOptionPane.DEFAULT_OPTION);
}
public static int alert(final String title, final String message, int optionType, int messageType) {
return JOptionPane.showConfirmDialog(null, message, title, optionType, messageType);
}
} }