File: CheckVersionScreen.java

package info (click to toggle)
gpsprune 13.4-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,008 kB
  • sloc: java: 28,802; sh: 25; makefile: 17; python: 15
file content (113 lines) | stat: -rw-r--r-- 3,734 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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 = "http://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("http://activityworkshop.net/software/gpsprune/download.html");
			}
		}
	}
}