1 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 { 27 public static void doVersionCheck(View view) 28 { 29 view.showWaitCursor(); 30 31 try 32 { 33 URL url = new URL (jEdit.getProperty( 34 "version-check.url")); 35 InputStream in = url.openStream(); 36 BufferedReader bin = new BufferedReader( 37 new InputStreamReader(in)); 38 39 String line; 40 String develBuild = null; 41 String stableBuild = null; 42 while((line = bin.readLine()) != null) 43 { 44 if(line.startsWith(".build")) 45 develBuild = line.substring(6).trim(); 46 else if(line.startsWith(".stablebuild")) 47 stableBuild = line.substring(12).trim(); 48 } 49 50 bin.close(); 51 52 if(develBuild != null && stableBuild != null) 53 { 54 doVersionCheck(view,stableBuild,develBuild); 55 } 56 } 57 catch(IOException e) 58 { 59 String [] args = { jEdit.getProperty("version-check.url"), 60 e.toString() }; 61 GUIUtilities.error(view,"read-error",args); 62 } 63 64 view.hideWaitCursor(); 65 } 66 67 public static void doVersionCheck(View view, String stableBuild, 68 String develBuild) 69 { 70 String myBuild = jEdit.getBuild(); 71 String pre = myBuild.substring(6,7); 72 String variant; 73 String build; 74 75 if(pre.equals("99")) 76 { 77 variant = "stable"; 78 build = stableBuild; 79 } 80 else 81 { 82 variant = "devel"; 83 build = develBuild; 84 } 85 86 if(develBuild.compareTo(stableBuild) < 0) 88 variant += "-nodevel"; 89 90 int retVal = GUIUtilities.confirm(view,"version-check." + variant, 91 new String [] { MiscUtilities.buildToVersion(myBuild), 92 MiscUtilities.buildToVersion(stableBuild), 93 MiscUtilities.buildToVersion(develBuild) }, 94 JOptionPane.YES_NO_OPTION, 95 JOptionPane.QUESTION_MESSAGE); 96 if(retVal == JOptionPane.YES_OPTION) 97 jEdit.openFile(view,jEdit.getProperty("version-check.url")); 98 } 99 } 100 | Popular Tags |