[Mathlib-commitlog] SF.net SVN: mathlib:[860] JMathLib/trunk/src/jmathlib/toolbox/jmathlib/ system
Status: Beta
Brought to you by:
st_mueller
|
From: <st_...@us...> - 2009-02-21 17:49:26
|
Revision: 860
http://mathlib.svn.sourceforge.net/mathlib/?rev=860&view=rev
Author: st_mueller
Date: 2009-02-21 17:49:12 +0000 (Sat, 21 Feb 2009)
Log Message:
-----------
renamed MathLibOutput into JMathLibOutput and added a new method: setStatusText in order to show some status message in the GUI
Modified Paths:
--------------
JMathLib/trunk/src/jmathlib/toolbox/jmathlib/system/checkforupdates.java
JMathLib/trunk/src/jmathlib/toolbox/jmathlib/system/update.java
Modified: JMathLib/trunk/src/jmathlib/toolbox/jmathlib/system/checkforupdates.java
===================================================================
--- JMathLib/trunk/src/jmathlib/toolbox/jmathlib/system/checkforupdates.java 2009-02-21 17:48:39 UTC (rev 859)
+++ JMathLib/trunk/src/jmathlib/toolbox/jmathlib/system/checkforupdates.java 2009-02-21 17:49:12 UTC (rev 860)
@@ -16,9 +16,6 @@
import java.net.*;
import java.util.*;
-// OPEN: Also send current information about toolboxes and
-// installed version to server
-
/**An external function for checking for updates over the network*/
public class checkforupdates extends ExternalFunction
{
@@ -32,14 +29,22 @@
String s = "";
String lineFile = "";
- String updateSiteS = "http://www.jmathlib.de/updates/";
boolean silentB = false;
+ // check the information of the primary update site
+ String updateSiteS = "http://www.jmathlib.de/updates/";
s = globals.getProperty("update.site.primary");
+
+ // if update-site information is not available try the secondary site
+ if (s==null)
+ s = globals.getProperty("update.site.secondary");
+
+ // if primary update site or secondary site information is available
+ // take it
if (s != null)
updateSiteS = s;
-
-
+
+ // check the arguments
if (getNArgIn(operands) == 1)
{
if ((operands[0] instanceof CharToken))
@@ -52,43 +57,39 @@
}
else
{
+ // argument is maybe a different update site URL
updateSiteS = st;
globals.getInterpreter().displayText("New Update Site "+updateSiteS);
}
}
}
+ // inform the user about checking the update site
if (!silentB)
globals.getInterpreter().displayText("Checking for Updates at "+updateSiteS);
-
+ // check the last date when an update has been performed
String[] lastUpdateS = globals.getProperty("update.date.last").split("/");
int year = Integer.parseInt(lastUpdateS[0]);
int month = Integer.parseInt(lastUpdateS[1])-1;
int day = Integer.parseInt(lastUpdateS[2]);
//getInterpreter().displayText("check:"+year+"/"+month+"/"+day);
+ // read the interval between updates
int intervall = Integer.parseInt(globals.getProperty("update.intervall"));
+ // get the current date
GregorianCalendar calFile = new GregorianCalendar(year,month,day);
GregorianCalendar calCur = new GregorianCalendar();
- //getInterpreter().displayText("check: "+calCur.toString());
-
- //getInterpreter().displayText("check: "+calFile.toString());
-
+ // add update-interval to the current date
calFile.add(Calendar.DATE,intervall);
- //getInterpreter().displayText("check: "+calFile.toString());
-
- //getInterpreter().displayText("calFile "+calFile);
- //getInterpreter().displayText("calCur "+calCur);
-
-
if (silentB)
{
- if (calCur.after(calFile))
+ // if silent-mode is active only check for updates when update intervall has been reached
+ if (calCur.after(calFile) )
{
checkForUpdatesThread ch = new checkForUpdatesThread(updateSiteS, silentB);
}
@@ -99,8 +100,9 @@
}
return null;
- }
+ } // end evaluate
+
// create separate thread for checking the update site, because this may take
// some time
public class checkForUpdatesThread extends Thread
@@ -234,11 +236,17 @@
checkForUpdates(site)
checkForUpdates("-silent")
@DOC
+This functions checks via network if the current
+installation of JMathLib is up to date.
+
+This functions is also called during startup of JMathLib's GUI.
@EXAMPLE
+checkforupdates()
@NOTES
This functions checks via network if the current
installation of JMathLib is up to date.
This functions is also called during startup of JMathLib's GUI.
@SEE
+update
*/
Modified: JMathLib/trunk/src/jmathlib/toolbox/jmathlib/system/update.java
===================================================================
--- JMathLib/trunk/src/jmathlib/toolbox/jmathlib/system/update.java 2009-02-21 17:48:39 UTC (rev 859)
+++ JMathLib/trunk/src/jmathlib/toolbox/jmathlib/system/update.java 2009-02-21 17:49:12 UTC (rev 860)
@@ -8,6 +8,8 @@
*/
package jmathlib.toolbox.jmathlib.system;
+import java.awt.FileDialog;
+import java.awt.Frame;
import java.io.*;
import java.net.*;
import java.util.Properties;
@@ -73,17 +75,20 @@
// reaction on the response from the update server
if (updateActionS.equals("VERSION_UNKNOWN"))
{
+ // the server does not recognize the local version of JMathLib
globals.getInterpreter().displayText("Your version of JMathLib is not known by the update server.");
return null;
}
else if (updateVersionS.equals("NO_UPDATE_AVAILABLE") ||
updateActionS.equals("NO_ACTION") )
{
+ // there is no update available on the server
globals.getInterpreter().displayText("No update available right now.");
return null;
}
else if (updateActionS.equals("FULL_DOWNLOAD_REQUIRED"))
{
+ // the updates requires to do a full download of a new version of JMathLib
globals.getInterpreter().displayText("\n");
globals.getInterpreter().displayText("Full download required in order to update!");
globals.getInterpreter().displayText("Please visit www.jmathlib.de for details.");
@@ -96,30 +101,45 @@
if ((urlS==null) || (fileS==null))
return null;
-
- // put a message box here
+ // open a file dialog to choose the download directory and download filename
+ Frame f = new Frame();
+ FileDialog theFileDialog = new FileDialog(f, "Save to ...", FileDialog.SAVE);
+ theFileDialog.setFile(fileS);
+ theFileDialog.setVisible(true);
+ String downloadDirS = theFileDialog.getDirectory();
+ fileS = theFileDialog.getFile();
+ if (downloadDirS==null)
+ throwMathLibException("download directory error");
+
+ if (fileS==null)
+ throwMathLibException("download file error");
+
+ globals.getInterpreter().setStatusText("You selected "+downloadDirS+" as download directory.");
+
// open URL to file on update server
try
{
- globals.getInterpreter().displayText("Downloading ...");
+ globals.getInterpreter().displayText("Downloading ... (please wait some minutes)");
URL fileURL = new URL(urlS);
InputStream in = fileURL.openStream();
- // open file on local disc
- File file = new File(globals.getWorkingDirectory(),fileS);
+ // open file on local disc and download the new version of JMathLib
+ File file = new File(downloadDirS, fileS);
OutputStream out = new FileOutputStream(file);
byte[] cbuf = new byte[4096];
int len = -1;
-
+ int x = 0;
while ((len = in.read(cbuf)) != -1)
{
out.write(cbuf,0,len);
+ x+= len;
+ globals.getInterpreter().setStatusText("downloaded "+new Integer(x).toString()+" bytes");
}
in.close();
out.close();
- globals.getInterpreter().displayText("Downloading done.");
+ globals.getInterpreter().setStatusText("Downloading done.");
}
catch (Exception e)
{
@@ -132,7 +152,7 @@
try
{
globals.getInterpreter().displayText("Running installer ...");
- Runtime.getRuntime().exec(fileS);
+ Runtime.getRuntime().exec(downloadDirS+fileS);
globals.getInterpreter().displayText("Please exit JMathLib");
}
catch(IOException exception)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|