/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ // Hello. // Wherever I messed with the code I put either: // "// ADDED", "// REMOVED", or "// CHANGED" // I hope I didn't mess up too much :D /* Part of the Processing project - http://processing.org Copyright (c) 2005-06 Ben Fry and Casey Reas 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 */ package processing.app; import java.awt.*; import java.awt.event.*; import java.io.*; import java.lang.reflect.*; import java.net.*; import java.util.*; import java.util.zip.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.text.*; import javax.swing.undo.*; import com.apple.mrj.*; import com.ice.jni.registry.*; import processing.core.*; /** * Threaded class to check for updates in the background. *
* This is the class that handles the mind control and stuff for * spying on our users and stealing their personal information. * A random ID number is generated for each user, and hits the server * to check for updates. Also included is the operating system and * its version and the version of Java being used to run Processing. *
* The ID number also helps provide us a general idea of how many * people are using Processing, which helps us when writing grant * proposals and that kind of thing so that we can keep Processing free. */ public class UpdateCheck implements Runnable { Editor editor; String downloadURL = "http://processing.org/download/latest.txt"; static final long ONE_DAY = 24 * 60 * 60 * 1000; public UpdateCheck(Editor editor) { this.editor = editor; Thread thread = new Thread(this); thread.start(); } public void run() { //System.out.println("checking for updates..."); // generate a random id in case none exists yet Random r = new Random(); long id = r.nextLong(); String idString = Preferences.get("update.id"); if (idString != null) { id = Long.parseLong(idString); } else { Preferences.set("update.id", String.valueOf(id)); } String info = URLEncoder.encode(id + "\t" + PApplet.nf(Base.VERSION, 4) + "\t" + System.getProperty("java.version") + "\t" + System.getProperty("java.vendor") + "\t" + System.getProperty("os.name") + "\t" + System.getProperty("os.version") + "\t" + System.getProperty("os.arch")); try { String latest_string = readString(downloadURL + "?" + info); int latest = Integer.parseInt(latest_string); String lastString = Preferences.get("update.last"); long now = System.currentTimeMillis(); if (lastString != null) { long when = Long.parseLong(lastString); if (now - when < ONE_DAY) { // don't annoy the shit outta people return; } } Preferences.set("update.last", String.valueOf(now)); String prompt = "A new version of Processing is available,\n" + "would you like to update?"; // ADDED //"would you like to visit the Processing download page?"; // REMOVED if (latest > Base.VERSION) { Object[] options = { "Yes", "No" }; int result = JOptionPane.showOptionDialog(editor, prompt, "Update", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (result == JOptionPane.YES_OPTION) { //Base.openURL("http://processing.org/download/"); // REMOVED extract("http://processing.org/download/processing-"+latest_string+".zip"); // ADDED //} else if (result == JOptionPane.NO_OPTION) { } } } catch (Exception e) { //e.printStackTrace(); //System.err.println("Error while trying to check for an update."); } } // ADDED protected String readString(String filename) throws Exception { URL url = new URL(filename); InputStream stream = url.openStream(); InputStreamReader isr = new InputStreamReader(stream); BufferedReader reader = new BufferedReader(isr); return reader.readLine(); } // CHANGED protected int readInt(String filename) throws Exception { return Integer.parseInt(readString(filename)); } // ADDED // Note: I have no clue if this method actually works... I don't have JDK // or whatever :P protected void extract(String input_file) { ZipFile z = new ZipFile(input_file); Enumeration e = z.entries(); while(e.hasMoreElements()) { ZipEntry ze = (ZipEntry) e.nextElement(); FileOutputStream out = new FileOutputStream(ze.getName()); InputStream in = z.getInputStream(ze); for(int c = in.read(); c != -1; c = in.read()) { out.write(c); } out.close(); in.close(); } } }