Menu

[01c4ec]: / CheckVersionThread.java  Maximize  Restore  History

Download this file

87 lines (80 with data), 2.9 kB

 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
/* Copyright (C) 2006-2010 Joan Queralt Molina
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
package biogenesis;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class CheckVersionThread extends Thread {
private JFrame parentFrame;
public static String translateVersion(String str) {
String zero = "000000"; //$NON-NLS-1$
String v;
int version, subversion, revision;
try {
v = zero.substring(0, 6 - str.length()) + str;
} catch (IndexOutOfBoundsException e) {
return str;
}
try {
version = Integer.parseInt(v.substring(0, 2));
subversion = Integer.parseInt(v.substring(2, 4));
revision = Integer.parseInt(v.substring(4, 6));
} catch (NumberFormatException e) {
return str;
}
String result;
if (revision == 0)
result = version + "." + subversion; //$NON-NLS-1$
else
result = version + "." + subversion + "." + revision; //$NON-NLS-1$ //$NON-NLS-2$
return result;
}
public CheckVersionThread(JFrame frame) {
parentFrame = frame;
}
@Override
public void run() {
URL url;
BufferedReader br = null;
try {
url = new URL("http://biogenesis.sourceforge.net/lastversion.txt"); //$NON-NLS-1$
InputStreamReader inr = new InputStreamReader(url.openStream());
br = new BufferedReader(inr);
String s = translateVersion(br.readLine());
JOptionPane.showMessageDialog(parentFrame,Messages.getString("T_YOUR_VERSION")+translateVersion(String.valueOf(Utils.VERSION))+"\n"+Messages.getString("T_LAST_VERSION")+s, //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
Messages.getString("T_VERSION_TITLE"), JOptionPane.INFORMATION_MESSAGE); //$NON-NLS-1$
br.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
JOptionPane.showMessageDialog(parentFrame,Messages.getString("T_CANT_CHECK_CURRENT_VERSION")+e.getLocalizedMessage(), //$NON-NLS-1$
Messages.getString("T_VERSION_TITLE"), JOptionPane.ERROR_MESSAGE); //$NON-NLS-1$
} finally {
if (br != null)
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.