01: /*
02: * LatestVersionPlugin.java - Latest Version Check Plugin
03: * Copyright (C) 1999, 2003 Slava Pestov
04: *
05: * This program is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU General Public License
07: * as published by the Free Software Foundation; either version 2
08: * of the License, or any later version.
09: *
10: * This program is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: * GNU General Public License for more details.
14: *
15: * You should have received a copy of the GNU General Public License
16: * along with this program; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18: */
19:
20: import javax.swing.JOptionPane;
21: import java.io.*;
22: import java.net.URL;
23: import org.gjt.sp.jedit.*;
24:
25: public class LatestVersionPlugin extends EditPlugin {
26: public static void doVersionCheck(View view) {
27: view.showWaitCursor();
28:
29: try {
30: URL url = new URL(jEdit.getProperty("version-check.url"));
31: InputStream in = url.openStream();
32: BufferedReader bin = new BufferedReader(
33: new InputStreamReader(in));
34:
35: String line;
36: String develBuild = null;
37: String stableBuild = null;
38: while ((line = bin.readLine()) != null) {
39: if (line.startsWith(".build"))
40: develBuild = line.substring(6).trim();
41: else if (line.startsWith(".stablebuild"))
42: stableBuild = line.substring(12).trim();
43: }
44:
45: bin.close();
46:
47: if (develBuild != null && stableBuild != null) {
48: doVersionCheck(view, stableBuild, develBuild);
49: }
50: } catch (IOException e) {
51: String[] args = { jEdit.getProperty("version-check.url"),
52: e.toString() };
53: GUIUtilities.error(view, "read-error", args);
54: }
55:
56: view.hideWaitCursor();
57: }
58:
59: public static void doVersionCheck(View view, String stableBuild,
60: String develBuild) {
61: String myBuild = jEdit.getBuild();
62: String pre = myBuild.substring(6, 7);
63: String variant;
64: String build;
65:
66: if (pre.equals("99")) {
67: variant = "stable";
68: build = stableBuild;
69: } else {
70: variant = "devel";
71: build = develBuild;
72: }
73:
74: // special case: no current development version
75: if (develBuild.compareTo(stableBuild) < 0)
76: variant += "-nodevel";
77:
78: int retVal = GUIUtilities
79: .confirm(view, "version-check." + variant,
80: new String[] {
81: MiscUtilities.buildToVersion(myBuild),
82: MiscUtilities
83: .buildToVersion(stableBuild),
84: MiscUtilities
85: .buildToVersion(develBuild) },
86: JOptionPane.YES_NO_OPTION,
87: JOptionPane.QUESTION_MESSAGE);
88: if (retVal == JOptionPane.YES_OPTION)
89: jEdit
90: .openFile(view, jEdit
91: .getProperty("version-check.url"));
92: }
93: }
|