X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=src%2Ftim%2Fprune%2Ffunction%2FCheckVersionScreen.java;fp=src%2Ftim%2Fprune%2Ffunction%2FCheckVersionScreen.java;h=701937d4b5f23066586cbab4dc55727195544907;hp=0000000000000000000000000000000000000000;hb=ce6f2161b8596f7018d6a76bff79bc9e571f35fd;hpb=2d8cb72e84d5cc1089ce77baf1e34ea3ea2f8465 diff --git a/src/tim/prune/function/CheckVersionScreen.java b/src/tim/prune/function/CheckVersionScreen.java new file mode 100644 index 0000000..701937d --- /dev/null +++ b/src/tim/prune/function/CheckVersionScreen.java @@ -0,0 +1,113 @@ +package tim.prune.function; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Properties; +import javax.swing.JOptionPane; + +import tim.prune.App; +import tim.prune.GenericFunction; +import tim.prune.GpsPrune; +import tim.prune.I18nManager; +import tim.prune.function.browser.BrowserLauncher; + +/** + * Class to check the version of GpsPrune + * and show an appropriate dialog + */ +public class CheckVersionScreen extends GenericFunction +{ + /** + * Constructor + * @param inApp app object + */ + public CheckVersionScreen(App inApp) + { + super(inApp); + } + + /** + * Get the name key + */ + public String getNameKey() { + return "function.checkversion"; + } + + /** + * Show the check version dialog + */ + public void begin() + { + final String filePathStart = "https://activityworkshop.net/software/gpsprune/gpsprune_versioncheck_"; + final String filePathEnd = ".txt"; + String latestVer = null; + String nextVersion = null; + String releaseDate = null; + Properties props = new Properties(); + try + { + // Load properties from the url on the server + InputStream inStream = new URL(filePathStart + GpsPrune.VERSION_NUMBER + filePathEnd).openStream(); + props.load(inStream); + + // Extract the three fields we want, ignore others + latestVer = props.getProperty("prune.latestversion"); + nextVersion = props.getProperty("prune.nextversion"); + releaseDate = props.getProperty("prune.releasedate"); + } + catch (IOException ioe) { + System.err.println(ioe.getClass().getName() + " - " + ioe.getMessage()); + } + + if (latestVer == null) { + // Couldn't get version number, show error message + JOptionPane.showMessageDialog(_parentFrame, I18nManager.getText("dialog.checkversion.error"), + I18nManager.getText(getNameKey()), JOptionPane.ERROR_MESSAGE); + } + else if (latestVer.equals(GpsPrune.VERSION_NUMBER)) + { + // Version on the server is the same as this one + String displayMessage = I18nManager.getText("dialog.checkversion.uptodate"); + if (nextVersion != null && !nextVersion.equals("")) + { + displayMessage += "\n\n" + nextVersion; + } + // Show information message that the current version is already running + JOptionPane.showMessageDialog(_parentFrame, displayMessage, + I18nManager.getText(getNameKey()), JOptionPane.INFORMATION_MESSAGE); + } + else + { + // A new version is available! + String displayMessage = I18nManager.getText("dialog.checkversion.newversion1") + " " + latestVer + + " " + I18nManager.getText("dialog.checkversion.newversion2"); + try + { + if (releaseDate != null && !releaseDate.equals("")) { + displayMessage += "\n\n" + I18nManager.getText("dialog.checkversion.releasedate1") + " " + + DateFormat.getDateInstance(DateFormat.LONG).format(new SimpleDateFormat("y-M-d").parse(releaseDate)) + + " " + I18nManager.getText("dialog.checkversion.releasedate2"); + } + } + catch (ParseException pe) { + System.err.println("Oops, couldn't parse date: '" + releaseDate + "'"); + } + displayMessage += "\n\n" + I18nManager.getText("dialog.checkversion.download"); + + // Show information message to download the new version + Object[] buttonTexts = {I18nManager.getText("button.showwebpage"), I18nManager.getText("button.cancel")}; + if (JOptionPane.showOptionDialog(_parentFrame, displayMessage, + I18nManager.getText(getNameKey()), JOptionPane.YES_NO_OPTION, + JOptionPane.INFORMATION_MESSAGE, null, buttonTexts, buttonTexts[1]) + == JOptionPane.YES_OPTION) + { + // User selected to launch home page + BrowserLauncher.launchBrowser("https://activityworkshop.net/software/gpsprune/download.html"); + } + } + } +}