mirror of
https://github.com/processing/processing4.git
synced 2026-04-25 21:54:42 +02:00
adding licensing information to files, removing some tabs
This commit is contained in:
@@ -1,3 +1,28 @@
|
||||
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
PdeUpdater - self-updater code.. when was the last this worked?
|
||||
Part of the Processing project - http://Proce55ing.net
|
||||
|
||||
Copyright (c) 2001-03
|
||||
Ben Fry, Massachusetts Institute of Technology and
|
||||
Casey Reas, Interaction Design Institute Ivrea
|
||||
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
@@ -18,7 +43,7 @@ public class PdeUpdater {
|
||||
// this is a separate updater application
|
||||
boolean updateEnabled = true;
|
||||
//(new Boolean(properties.getProperty("update.enabled",
|
||||
// "false"))).booleanValue();
|
||||
// "false"))).booleanValue();
|
||||
|
||||
// check for updates from the server, if enabled
|
||||
//if (getBoolean("update.enabled", false)) {
|
||||
@@ -26,97 +51,97 @@ public class PdeUpdater {
|
||||
// open the update file to get the latest version
|
||||
long lastUpdate = 0;
|
||||
try {
|
||||
DataInputStream dis =
|
||||
new DataInputStream(new FileInputStream("lib/version"));
|
||||
lastUpdate = dis.readLong();
|
||||
//System.out.println("pde.jar timestamp is " + lastUpdate);
|
||||
DataInputStream dis =
|
||||
new DataInputStream(new FileInputStream("lib/version"));
|
||||
lastUpdate = dis.readLong();
|
||||
//System.out.println("pde.jar timestamp is " + lastUpdate);
|
||||
} catch (IOException e) { }
|
||||
|
||||
//String baseUrl = get("update.url");
|
||||
String baseUrl = properties.getProperty("update.url");
|
||||
|
||||
try {
|
||||
URL url = new URL(baseUrl + "version");
|
||||
URLConnection conn = url.openConnection();
|
||||
//conn.connect();
|
||||
URL url = new URL(baseUrl + "version");
|
||||
URLConnection conn = url.openConnection();
|
||||
//conn.connect();
|
||||
|
||||
//System.out.println("date of last update" + conn.getDate());
|
||||
long newDate = conn.getLastModified();
|
||||
//System.out.println("server timestamp is " + newDate);
|
||||
//System.out.println((newDate - lastUpdate) + "ms newer");
|
||||
if (newDate > lastUpdate) {
|
||||
System.out.println("new update available");
|
||||
//System.out.println("date of last update" + conn.getDate());
|
||||
long newDate = conn.getLastModified();
|
||||
//System.out.println("server timestamp is " + newDate);
|
||||
//System.out.println((newDate - lastUpdate) + "ms newer");
|
||||
if (newDate > lastUpdate) {
|
||||
System.out.println("new update available");
|
||||
|
||||
DataOutputStream vos =
|
||||
new DataOutputStream(new FileOutputStream("lib/version"));
|
||||
//new DataOutputStream(new FileOutputStream("lib/version.update"));
|
||||
vos.writeLong(newDate);
|
||||
vos.flush();
|
||||
vos.close();
|
||||
DataOutputStream vos =
|
||||
new DataOutputStream(new FileOutputStream("lib/version"));
|
||||
//new DataOutputStream(new FileOutputStream("lib/version.update"));
|
||||
vos.writeLong(newDate);
|
||||
vos.flush();
|
||||
vos.close();
|
||||
|
||||
url = new URL(baseUrl + "pde.jar");
|
||||
conn = url.openConnection();
|
||||
url = new URL(baseUrl + "pde.jar");
|
||||
conn = url.openConnection();
|
||||
|
||||
// move the old pde.jar file out of the way
|
||||
//File pdeJar = new File("lib/pde.jar");
|
||||
//pdeJar.renameTo("lib/pde.old.jar");
|
||||
// move the old pde.jar file out of the way
|
||||
//File pdeJar = new File("lib/pde.jar");
|
||||
//pdeJar.renameTo("lib/pde.old.jar");
|
||||
|
||||
// download the new pde.jar file
|
||||
//FileOutputStream os = new FileOutputStream("lib/pde.jar.update");
|
||||
FileOutputStream os = new FileOutputStream("lib/pde.jar");
|
||||
//Object object = conn.getContent();
|
||||
//System.out.println(object);
|
||||
InputStream is = conn.getInputStream();
|
||||
copyStream(is, os);
|
||||
os.close();
|
||||
// download the new pde.jar file
|
||||
//FileOutputStream os = new FileOutputStream("lib/pde.jar.update");
|
||||
FileOutputStream os = new FileOutputStream("lib/pde.jar");
|
||||
//Object object = conn.getContent();
|
||||
//System.out.println(object);
|
||||
InputStream is = conn.getInputStream();
|
||||
copyStream(is, os);
|
||||
os.close();
|
||||
|
||||
// if everything copied ok, rename new/old files
|
||||
// this probably needs to be way more bulletproof
|
||||
/*
|
||||
File file = new File("lib/version");
|
||||
if (file.exists())
|
||||
System.out.println(file.renameTo(new File("lib/version.old")));
|
||||
file = new File("lib/version.update");
|
||||
System.out.println(file.renameTo(new File("lib/version")));
|
||||
// if everything copied ok, rename new/old files
|
||||
// this probably needs to be way more bulletproof
|
||||
/*
|
||||
File file = new File("lib/version");
|
||||
if (file.exists())
|
||||
System.out.println(file.renameTo(new File("lib/version.old")));
|
||||
file = new File("lib/version.update");
|
||||
System.out.println(file.renameTo(new File("lib/version")));
|
||||
|
||||
file = new File("lib/pde.jar");
|
||||
file.delete();
|
||||
//System.out.println(file.renameTo(new File("lib/pde.jar.old")));
|
||||
file = new File("lib/pde.jar.update");
|
||||
System.out.println(file.renameTo(new File("lib/pde.jar")));
|
||||
*/
|
||||
file = new File("lib/pde.jar");
|
||||
file.delete();
|
||||
//System.out.println(file.renameTo(new File("lib/pde.jar.old")));
|
||||
file = new File("lib/pde.jar.update");
|
||||
System.out.println(file.renameTo(new File("lib/pde.jar")));
|
||||
*/
|
||||
|
||||
// restart or relaunch
|
||||
//System.out.println("done copying new version, restart");
|
||||
//System.exit(0);
|
||||
// restart or relaunch
|
||||
//System.out.println("done copying new version, restart");
|
||||
//System.exit(0);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
try {
|
||||
Class c = Class.forName("PdeApplication");
|
||||
Object o = c.newInstance();
|
||||
//PdeApplication.main(null);
|
||||
} catch (Exception e) {
|
||||
System.err.println("update failed");
|
||||
e.printStackTrace();
|
||||
}
|
||||
*/
|
||||
// mac mrj is not smart enough to exit the applicaiton here
|
||||
System.exit(0);
|
||||
/*
|
||||
try {
|
||||
Class c = Class.forName("PdeApplication");
|
||||
Object o = c.newInstance();
|
||||
//PdeApplication.main(null);
|
||||
} catch (Exception e) {
|
||||
System.err.println("update failed");
|
||||
e.printStackTrace();
|
||||
}
|
||||
*/
|
||||
// mac mrj is not smart enough to exit the applicaiton here
|
||||
System.exit(0);
|
||||
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
e1.printStackTrace();
|
||||
|
||||
//} catch (MalformedURLException e2) {
|
||||
//e2.printStackTrace();
|
||||
//} catch (MalformedURLException e2) {
|
||||
//e2.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static public void copyStream(InputStream input, OutputStream output
|
||||
/*int padding, long length*/)
|
||||
/*int padding, long length*/)
|
||||
throws IOException {
|
||||
byte[] buffer = new byte[4096];
|
||||
int count;
|
||||
@@ -138,12 +163,12 @@ public class PdeUpdater {
|
||||
count = input.read(buffer, 0, amount);
|
||||
//System.out.println("got " + count);
|
||||
if (count == -1)
|
||||
break;
|
||||
break;
|
||||
|
||||
output.write(buffer, 0, count);
|
||||
length -= count; // used to be amount... bug?
|
||||
length -= count; // used to be amount... bug?
|
||||
if (length == 0)
|
||||
break;
|
||||
break;
|
||||
}
|
||||
output.flush();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user