From: <ka...@us...> - 2011-01-22 18:08:28
|
Revision: 3474 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3474&view=rev Author: kappa1 Date: 2011-01-22 18:08:21 +0000 (Sat, 22 Jan 2011) Log Message: ----------- AppletLoader - Fix for a crash on some platforms before the permissions dialog appears, this is because the relevant part of the code needed to be run on the EDT. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-01-22 13:26:07 UTC (rev 3473) +++ trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-01-22 18:08:21 UTC (rev 3474) @@ -35,6 +35,7 @@ import java.applet.AppletStub; import java.awt.BorderLayout; import java.awt.Color; +import java.awt.EventQueue; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Image; @@ -765,10 +766,18 @@ setLWJGLProperties(); // switch to LWJGL Applet - switchApplet(); - - setState(STATE_DONE); - repaint(); + EventQueue.invokeAndWait(new Runnable() { + public void run() { + try { + switchApplet(); + } catch (Exception e) { + fatalErrorOccured("This occurred while '" + getDescriptionForState() + "'", e); + } + setState(STATE_DONE); + repaint(); + } + }); + } catch (AccessControlException ace) { fatalErrorOccured(ace.getMessage(), ace); certificateRefused = true; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2011-01-24 22:35:18
|
Revision: 3476 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3476&view=rev Author: kappa1 Date: 2011-01-24 22:35:11 +0000 (Mon, 24 Jan 2011) Log Message: ----------- AppletLoader: add support for using multiple native jars Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-01-23 07:48:50 UTC (rev 3475) +++ trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-01-24 22:35:11 UTC (rev 3476) @@ -223,6 +223,9 @@ /** Sizes of files to download */ protected int[] fileSizes; + + /** Number of native jars */ + protected int nativeJarCount; /** whether to use caching system, only download files that have changed */ protected boolean cacheEnabled; @@ -598,68 +601,73 @@ // jars to load String jarList = getParameter("al_jars"); - - jarList = trimExtensionByCapabilities(jarList); - - StringTokenizer jar = new StringTokenizer(jarList, ", "); - - int jarCount = jar.countTokens() + 1; - - urlList = new URL[jarCount]; - - URL path = getCodeBase(); - - // set jars urls - for (int i = 0; i < jarCount - 1; i++) { - urlList[i] = new URL(path, jar.nextToken()); - } - - // native jar url - String osName = System.getProperty("os.name"); - String nativeJar = null; - + String nativeJarList = null; + + String osName = System.getProperty("os.name"); + if (osName.startsWith("Win")) { // check if arch specific natives have been specified if (System.getProperty("os.arch").endsWith("64")) { - nativeJar = getParameter("al_windows64"); + nativeJarList = getParameter("al_windows64"); } else { - nativeJar = getParameter("al_windows32"); + nativeJarList = getParameter("al_windows32"); } - if (nativeJar == null) { - nativeJar = getParameter("al_windows"); + if (nativeJarList == null) { + nativeJarList = getParameter("al_windows"); } } else if (osName.startsWith("Linux")) { // check if arch specific natives have been specified if (System.getProperty("os.arch").endsWith("64")) { - nativeJar = getParameter("al_linux64"); + nativeJarList = getParameter("al_linux64"); } else { - nativeJar = getParameter("al_linux32"); + nativeJarList = getParameter("al_linux32"); } - if (nativeJar == null) { - nativeJar = getParameter("al_linux"); + if (nativeJarList == null) { + nativeJarList = getParameter("al_linux"); } } else if (osName.startsWith("Mac")) { - nativeJar = getParameter("al_mac"); + nativeJarList = getParameter("al_mac"); } else if (osName.startsWith("Solaris") || osName.startsWith("SunOS")) { - nativeJar = getParameter("al_solaris"); + nativeJarList = getParameter("al_solaris"); } else if (osName.startsWith("FreeBSD")) { - nativeJar = getParameter("al_freebsd"); + nativeJarList = getParameter("al_freebsd"); } else { fatalErrorOccured("OS (" + osName + ") not supported", null); + return; } + + if (nativeJarList == null) { + fatalErrorOccured("no lwjgl natives files found", null); + return; + } + + jarList = trimExtensionByCapabilities(jarList); + StringTokenizer jars = new StringTokenizer(jarList, ", "); - if (nativeJar == null) { - fatalErrorOccured("no lwjgl natives files found", null); - } else { - nativeJar = trimExtensionByCapabilities(nativeJar); - urlList[jarCount - 1] = new URL(path, nativeJar); + nativeJarList = trimExtensionByCapabilities(nativeJarList); + StringTokenizer nativeJars = new StringTokenizer(nativeJarList, ", "); + + int jarCount = jars.countTokens(); + nativeJarCount = nativeJars.countTokens(); + + urlList = new URL[jarCount+nativeJarCount]; + + URL path = getCodeBase(); + + // set jars urls + for (int i = 0; i < jarCount; i++) { + urlList[i] = new URL(path, jars.nextToken()); } + + for (int i = jarCount; i < jarCount+nativeJarCount; i++) { + urlList[i] = new URL(path, nativeJars.nextToken()); + } } /** @@ -1357,19 +1365,15 @@ * @throws Exception if it fails to extract files */ protected void extractNatives(String path) throws Exception { + + setState(STATE_EXTRACTING_PACKAGES); - // if no new native jar was downloaded, no extracting needed - if (fileSizes[fileSizes.length-1] == -2) { - return; + // create native folder + File nativeFolder = new File(path + "natives"); + if (!nativeFolder.exists()) { + nativeFolder.mkdir(); } - - setState(STATE_EXTRACTING_PACKAGES); - - int initialPercentage = percentage; - - // get name of jar file with natives from urlList, it will be the last url - String nativeJar = getJarName(urlList[urlList.length - 1]); - + // get the current certificate to compare against native files Certificate[] certificate = AppletLoader.class.getProtectionDomain().getCodeSource().getCertificates(); @@ -1382,88 +1386,96 @@ jurl.setDefaultUseCaches(true); certificate = jurl.getCertificates(); } - - // create native folder - File nativeFolder = new File(path + "natives"); - if (!nativeFolder.exists()) { - nativeFolder.mkdir(); - } - - // open jar file - JarFile jarFile = new JarFile(path + nativeJar, true); - - // get list of files in jar - Enumeration entities = jarFile.entries(); - - totalSizeExtract = 0; - - // calculate the size of the files to extract for progress bar - while (entities.hasMoreElements()) { - JarEntry entry = (JarEntry) entities.nextElement(); - - // skip directories and anything in directories - // conveniently ignores the manifest - if (entry.isDirectory() || entry.getName().indexOf('/') != -1) { + + for (int i = fileSizes.length - nativeJarCount; i < fileSizes.length; i++) { + + int initialPercentage = percentage; + + // if a new native jar was not downloaded, no extracting needed + if (fileSizes[i] == -2) { continue; } - totalSizeExtract += entry.getSize(); - } - - currentSizeExtract = 0; - - // reset point to begining by getting list of file again - entities = jarFile.entries(); - - // extract all files from the jar - while (entities.hasMoreElements()) { - JarEntry entry = (JarEntry) entities.nextElement(); - - // skip directories and anything in directories - // conveniently ignores the manifest - if (entry.isDirectory() || entry.getName().indexOf('/') != -1) { - continue; + + // get name of jar file with natives from urlList + String nativeJar = getJarName(urlList[i]); + + // open jar file + JarFile jarFile = new JarFile(path + nativeJar, true); + + // get list of files in jar + Enumeration entities = jarFile.entries(); + + totalSizeExtract = 0; + + // calculate the size of the files to extract for progress bar + while (entities.hasMoreElements()) { + JarEntry entry = (JarEntry) entities.nextElement(); + + // skip directories and anything in directories + // conveniently ignores the manifest + if (entry.isDirectory() || entry.getName().indexOf('/') != -1) { + continue; + } + totalSizeExtract += entry.getSize(); } - - // check if native file already exists if so delete it to make room for new one - // useful when using the reload button on the browser - File f = new File(path + "natives" + File.separator + entry.getName()); - if (f.exists()) { - if (!f.delete()) { - continue; // unable to delete file, it is in use, skip extracting it + + currentSizeExtract = 0; + + // reset point to begining by getting list of file again + entities = jarFile.entries(); + + // extract all files from the jar + while (entities.hasMoreElements()) { + JarEntry entry = (JarEntry) entities.nextElement(); + + // skip directories and anything in directories + // conveniently ignores the manifest + if (entry.isDirectory() || entry.getName().indexOf('/') != -1) { + continue; } + + // check if native file already exists if so delete it to make room for new one + // useful when using the reload button on the browser + File f = new File(path + "natives" + File.separator + entry.getName()); + if (f.exists()) { + if (!f.delete()) { + continue; // unable to delete file, it is in use, skip extracting it + } + } + + debug_sleep(1000); + + InputStream in = jarFile.getInputStream(jarFile.getEntry(entry.getName())); + OutputStream out = new FileOutputStream(path + "natives" + File.separator + entry.getName()); + + int bufferSize; + byte buffer[] = new byte[65536]; + + while ((bufferSize = in.read(buffer, 0, buffer.length)) != -1) { + debug_sleep(10); + out.write(buffer, 0, bufferSize); + currentSizeExtract += bufferSize; + + // update progress bar + percentage = initialPercentage + ((currentSizeExtract * 20) / totalSizeExtract); + subtaskMessage = "Extracting: " + entry.getName() + " " + ((currentSizeExtract * 100) / totalSizeExtract) + "%"; + } + + // validate if the certificate for native file is correct + validateCertificateChain(certificate, entry.getCertificates()); + + in.close(); + out.close(); } - - debug_sleep(1000); - - InputStream in = jarFile.getInputStream(jarFile.getEntry(entry.getName())); - OutputStream out = new FileOutputStream(path + "natives" + File.separator + entry.getName()); - - int bufferSize; - byte buffer[] = new byte[65536]; - - while ((bufferSize = in.read(buffer, 0, buffer.length)) != -1) { - debug_sleep(10); - out.write(buffer, 0, bufferSize); - currentSizeExtract += bufferSize; - - // update progress bar - percentage = initialPercentage + ((currentSizeExtract * 20) / totalSizeExtract); - subtaskMessage = "Extracting: " + entry.getName() + " " + ((currentSizeExtract * 100) / totalSizeExtract) + "%"; - } - - // validate if the certificate for native file is correct - validateCertificateChain(certificate, entry.getCertificates()); - - in.close(); - out.close(); + subtaskMessage = ""; + + jarFile.close(); + + // delete native jar as it is no longer needed + File f = new File(path + nativeJar); + f.delete(); + } - subtaskMessage = ""; - - jarFile.close(); - - // delete native jar as it is no longer needed - File f = new File(path + nativeJar); - f.delete(); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2011-01-25 01:29:29
|
Revision: 3477 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3477&view=rev Author: kappa1 Date: 2011-01-25 01:29:22 +0000 (Tue, 25 Jan 2011) Log Message: ----------- AppletLoader - fix progress bar when extracting from multiple native jars Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-01-24 22:35:11 UTC (rev 3476) +++ trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-01-25 01:29:22 UTC (rev 3477) @@ -1367,7 +1367,9 @@ protected void extractNatives(String path) throws Exception { setState(STATE_EXTRACTING_PACKAGES); - + + float percentageParts = 20f/nativeJarCount; // parts for each native jar from 20% + // create native folder File nativeFolder = new File(path + "natives"); if (!nativeFolder.exists()) { @@ -1387,9 +1389,7 @@ certificate = jurl.getCertificates(); } - for (int i = fileSizes.length - nativeJarCount; i < fileSizes.length; i++) { - - int initialPercentage = percentage; + for (int i = urlList.length - nativeJarCount; i < urlList.length; i++) { // if a new native jar was not downloaded, no extracting needed if (fileSizes[i] == -2) { @@ -1406,7 +1406,8 @@ Enumeration entities = jarFile.entries(); totalSizeExtract = 0; - + int jarNum = i - (urlList.length - nativeJarCount); // used for progressbar + // calculate the size of the files to extract for progress bar while (entities.hasMoreElements()) { JarEntry entry = (JarEntry) entities.nextElement(); @@ -1457,7 +1458,7 @@ currentSizeExtract += bufferSize; // update progress bar - percentage = initialPercentage + ((currentSizeExtract * 20) / totalSizeExtract); + percentage = 65 + (int)(percentageParts * (jarNum + currentSizeExtract/(float)totalSizeExtract)); subtaskMessage = "Extracting: " + entry.getName() + " " + ((currentSizeExtract * 100) / totalSizeExtract) + "%"; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ma...@us...> - 2011-01-25 06:43:35
|
Revision: 3478 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3478&view=rev Author: matzon Date: 2011-01-25 06:43:28 +0000 (Tue, 25 Jan 2011) Log Message: ----------- propagate darwin check to applet loader too Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-01-25 01:29:22 UTC (rev 3477) +++ trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-01-25 06:43:28 UTC (rev 3478) @@ -631,7 +631,7 @@ nativeJarList = getParameter("al_linux"); } - } else if (osName.startsWith("Mac")) { + } else if (osName.startsWith("Mac") || osName.startsWith("Darwin")) { nativeJarList = getParameter("al_mac"); } else if (osName.startsWith("Solaris") || osName.startsWith("SunOS")) { nativeJarList = getParameter("al_solaris"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2011-01-28 23:06:16
|
Revision: 3482 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3482&view=rev Author: kappa1 Date: 2011-01-28 23:06:06 +0000 (Fri, 28 Jan 2011) Log Message: ----------- AppletLoader - added support for gzip files Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-01-28 21:55:16 UTC (rev 3481) +++ trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-01-28 23:06:06 UTC (rev 3482) @@ -79,6 +79,7 @@ import java.util.jar.JarFile; import java.util.jar.JarOutputStream; import java.util.jar.Pack200; +import java.util.zip.GZIPInputStream; import sun.security.util.SecurityConstants; @@ -1295,7 +1296,41 @@ // delete LZMA file, as it is no longer needed f.delete(); } + + /** + * Extract GZip File + * @param in Input path to pack file + * @param out output path to resulting file + * @throws Exception if any errors occur + */ + protected void extractGZip(String in, String out) throws Exception { + File f = new File(in); + FileInputStream fileInputHandle = new FileInputStream(f); + + InputStream inputHandle = new GZIPInputStream(fileInputHandle); + + OutputStream outputHandle; + outputHandle = new FileOutputStream(out); + + byte [] buffer = new byte [1<<14]; + + int ret = inputHandle.read(buffer); + while (ret >= 1) { + outputHandle.write(buffer,0,ret); + ret = inputHandle.read(buffer); + } + + inputHandle.close(); + outputHandle.close(); + + outputHandle = null; + inputHandle = null; + + // delete GZip file, as it is no longer needed + f.delete(); + } + /** * Extract Pack File * @param in Input path to pack file @@ -1316,7 +1351,7 @@ } /** - * Extract all jars from any lzma/pack files + * Extract all jars from any lzma/gz/pack files * * @param path output path * @throws Exception if any errors occur @@ -1325,7 +1360,7 @@ setState(STATE_EXTRACTING_PACKAGES); float increment = (float) 10.0 / urlList.length; - // extract all lzma and pack.lzma files + // extract all gz, lzma, pack.gz and pack.lzma files for (int i = 0; i < urlList.length; i++) { // if file has not changed, skip it @@ -1333,7 +1368,7 @@ percentage = 55 + (int) (increment * (i+1)); String filename = getFileName(urlList[i]); - + if (filename.endsWith(".pack.lzma")) { subtaskMessage = "Extracting: " + filename + " to " + filename.replaceAll(".lzma", ""); debug_sleep(1000); @@ -1343,6 +1378,15 @@ debug_sleep(1000); extractPack(path + filename.replaceAll(".lzma", ""), path + filename.replaceAll(".pack.lzma", "")); } + else if (filename.endsWith(".pack.gz")) { + subtaskMessage = "Extracting: " + filename + " to " + filename.replaceAll(".gz", ""); + debug_sleep(1000); + extractGZip(path + filename, path + filename.replaceAll(".gz", "")); + + subtaskMessage = "Extracting: " + filename.replaceAll(".gz", "") + " to " + filename.replaceAll(".pack.gz", ""); + debug_sleep(1000); + extractPack(path + filename.replaceAll(".gz", ""), path + filename.replaceAll(".pack.gz", "")); + } else if (filename.endsWith(".pack")) { subtaskMessage = "Extracting: " + filename + " to " + filename.replace(".pack", ""); debug_sleep(1000); @@ -1353,6 +1397,11 @@ debug_sleep(1000); extractLZMA(path + filename, path + filename.replace(".lzma", "")); } + else if (filename.endsWith(".gz")) { + subtaskMessage = "Extracting: " + filename + " to " + filename.replace(".gz", ""); + debug_sleep(1000); + extractGZip(path + filename, path + filename.replace(".gz", "")); + } } } @@ -1546,10 +1595,14 @@ if (fileName.endsWith(".pack.lzma")) { fileName = fileName.replaceAll(".pack.lzma", ""); + } else if (fileName.endsWith(".pack.gz")) { + fileName = fileName.replaceAll(".pack.gz", ""); } else if (fileName.endsWith(".pack")) { fileName = fileName.replaceAll(".pack", ""); } else if (fileName.endsWith(".lzma")) { fileName = fileName.replaceAll(".lzma", ""); + } else if (fileName.endsWith(".gz")) { + fileName = fileName.replaceAll(".gz", ""); } return fileName.substring(fileName.lastIndexOf('/') + 1); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2011-02-02 22:29:24
|
Revision: 3483 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3483&view=rev Author: kappa1 Date: 2011-02-02 22:29:18 +0000 (Wed, 02 Feb 2011) Log Message: ----------- AppletLoader - tweak image loading to fix cases where it doesn't work Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-01-28 23:06:06 UTC (rev 3482) +++ trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-02-02 22:29:18 UTC (rev 3483) @@ -774,7 +774,7 @@ // set lwjgl properties setLWJGLProperties(); - // switch to LWJGL Applet + // make applet switch on EDT as an AWT/Swing permission dialog could be called EventQueue.invokeAndWait(new Runnable() { public void run() { try { @@ -1556,11 +1556,11 @@ */ protected Image getImage(String s) { try { - URL url = Thread.currentThread().getContextClassLoader().getResource("/"+s); - - // if image not found in jar, look outside it + URL url = url = new URL(getCodeBase(), s); + + // if image failed to load, try another method if (url == null) { - url = new URL(getCodeBase(), s); + Thread.currentThread().getContextClassLoader().getResource(s); } Image image = super.getImage(url); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2011-02-03 09:35:07
|
Revision: 3484 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3484&view=rev Author: kappa1 Date: 2011-02-03 09:35:00 +0000 (Thu, 03 Feb 2011) Log Message: ----------- AppletLoader - added small bit of missing code (doh), thx to arielsan for spotting it Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-02-02 22:29:18 UTC (rev 3483) +++ trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-02-03 09:35:00 UTC (rev 3484) @@ -1560,7 +1560,7 @@ // if image failed to load, try another method if (url == null) { - Thread.currentThread().getContextClassLoader().getResource(s); + url = Thread.currentThread().getContextClassLoader().getResource(s); } Image image = super.getImage(url); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2011-02-03 22:12:47
|
Revision: 3485 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3485&view=rev Author: kappa1 Date: 2011-02-03 22:12:41 +0000 (Thu, 03 Feb 2011) Log Message: ----------- AppletLoader - another attempt to fix the logo. Thx again to arielsan for spotting issues. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-02-03 09:35:00 UTC (rev 3484) +++ trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-02-03 22:12:41 UTC (rev 3485) @@ -1555,14 +1555,38 @@ * @return the Image file */ protected Image getImage(String s) { + + Image image = null; + try { - URL url = url = new URL(getCodeBase(), s); - - // if image failed to load, try another method - if (url == null) { - url = Thread.currentThread().getContextClassLoader().getResource(s); - } + image = getImage(new URL(getCodeBase(), s)); + } catch (Exception e) { + /* */ + } + + // if image failed to load, try another method + if (image == null) { + image = getImage(Thread.currentThread().getContextClassLoader().getResource(s)); + } + + // if image loaded sucessfully return it + if (image != null) { + return image; + } + // show error as image could not be loaded + fatalErrorOccured("Unable to load logo and progressbar images", null); + return null; + } + + /** + * Get Image from path provided + * + * @param url location of the image + * @return the Image file + */ + public Image getImage(URL url) { + try { Image image = super.getImage(url); // wait for image to load @@ -1577,13 +1601,10 @@ } catch (Exception e) { /* */ } - - // show error as image could not be loaded - fatalErrorOccured("Unable to load logo and progressbar images", null); + return null; } - /** * Get jar name from URL. * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2011-02-17 19:10:05
|
Revision: 3491 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3491&view=rev Author: kappa1 Date: 2011-02-17 19:09:59 +0000 (Thu, 17 Feb 2011) Log Message: ----------- AppletLoader Fix: set correct context classloader for the applet loaded by the AppletLoader. Credit to arielsan for finding the issue and supplying a fix/patch. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-02-14 20:42:15 UTC (rev 3490) +++ trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-02-17 19:09:59 UTC (rev 3491) @@ -774,7 +774,7 @@ // set lwjgl properties setLWJGLProperties(); - // make applet switch on EDT as an AWT/Swing permission dialog could be called + // make applet switch on the EDT as an AWT/Swing permission dialog could be called EventQueue.invokeAndWait(new Runnable() { public void run() { try { @@ -1023,7 +1023,10 @@ percentage = 100; debug_sleep(2000); - + + // set correct context classloader for lwjgl applet + Thread.currentThread().setContextClassLoader(classLoader); + Class appletClass = classLoader.loadClass(getParameter("al_main")); lwjglApplet = (Applet) appletClass.newInstance(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2011-02-17 19:43:40
|
Revision: 3492 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3492&view=rev Author: kappa1 Date: 2011-02-17 19:43:33 +0000 (Thu, 17 Feb 2011) Log Message: ----------- AppletLoader: add missing javadoc for the "lwjgl_arguments" parameter. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-02-17 19:09:59 UTC (rev 3491) +++ trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-02-17 19:43:33 UTC (rev 3492) @@ -97,9 +97,11 @@ * The following applet parameters are required: * <ul> * <li>al_main - [String] Full package and class the applet to instantiate and display when loaded.</li> + * <li>al_jars - [String] Comma seperated list of jars to download.</li> + * <p> * <li>al_logo - [String Path of of the logo resource to paint while loading.</li> * <li>al_progressbar - [String] Path of the progressbar resource to paint on top of the logo, width clipped by percentage.</li> - * <li>al_jars - [String] Comma seperated list of jars to download.</li> + * <p> * <li>al_windows - [String] Jar containing native files for windows.</li> * <li>al_linux - [String] Jar containing native files for linux.</li> * <li>al_mac - [String] Jar containing native files for mac.</li> @@ -115,14 +117,16 @@ * <li>al_cache - [boolean] Whether to use cache system. <i>Default: true</i>.</li> * <li>al_debug - [boolean] Whether to enable debug mode. <i>Default: false</i>.</li> * <li>al_prepend_host - [boolean] Whether to limit caching to this domain, disable if your applet is hosted on multple domains and needs to share the cache. <i>Default: true</i>.</li> - * <ul> + * <p> * <li>al_windows64 - [String] If specified it will be used instead of al_windows on 64bit windows systems.</li> * <li>al_windows32 - [String] If specifed it will be used instead of al_windows on 32bit windows systems.</li> * <li>al_linux64 - [String] If specifed it will be used instead of al_linux on 64bit linux systems.</li> * <li>al_linux32 - [String] If specifed it will be used instead of al_linux on 32bit linux systems.</li> - * <ul> + * <p> * <li>boxbgcolor - [String] any String AWT color ("red", "blue", etc), RGB (0-255) or hex formated color (#RRGGBB) to use as background. <i>Default: #ffffff</i>.</li> * <li>boxfgcolor - [String] any String AWT color ("red", "blue", etc), RGB (0-255) or hex formated color (#RRGGBB) to use as foreground. <i>Default: #000000</i>.</li> + * <p> + * <li>lwjgl_arguments - </li> [String] used to pass the hidden LWJGL parameters to LWJGL e.g. ("-Dorg.lwjgl.input.Mouse.allowNegativeMouseCoords=true -Dorg.lwjgl.util.Debug=true").</li> * </ul> * </p> * @author kappaOne This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2011-03-07 22:22:15
|
Revision: 3495 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3495&view=rev Author: kappa1 Date: 2011-03-07 22:22:08 +0000 (Mon, 07 Mar 2011) Log Message: ----------- AppletLoader: Add better checks/protection to reading cache/version files in case of corruption. Close resources properly when writing cache/version files. Add preliminary list of contributors. Thx to Arielsan for finding issue and providing patch. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-03-06 01:34:06 UTC (rev 3494) +++ trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-03-07 22:22:08 UTC (rev 3495) @@ -129,10 +129,23 @@ * <li>lwjgl_arguments - </li> [String] used to pass the hidden LWJGL parameters to LWJGL e.g. ("-Dorg.lwjgl.input.Mouse.allowNegativeMouseCoords=true -Dorg.lwjgl.util.Debug=true").</li> * </ul> * </p> - * @author kappaOne + * @author kappaOne <one...@gm...> * @author Brian Matzon <br...@ma...> * @version $Revision$ * $Id$ + * + * Contributors: + * <ul> + * <li>Arielsan</li> + * <li>Bobjob</li> + * <li>Dashiva</li> + * <li>Kevglass</li> + * <li>MatthiasM</li> + * <li>Mickelukas</li> + * <li>NateS</li> + * <li>Ruben01</li> + * </ul> + * */ public class AppletLoader extends Applet implements Runnable, AppletStub { @@ -844,10 +857,22 @@ * @throws Exception if it fails to read value */ protected float readVersionFile(File file) throws Exception { - DataInputStream dis = new DataInputStream(new FileInputStream(file)); - float version = dis.readFloat(); - dis.close(); - return version; + FileInputStream fis = new FileInputStream(file); + try { + DataInputStream dis = new DataInputStream(fis); + float version = dis.readFloat(); + dis.close(); + return version; + } catch (Exception e) { + // failed to read version file + e.printStackTrace(); + } + finally { + fis.close(); + } + + // return 0 if failed to read file + return 0; } /** @@ -858,9 +883,11 @@ * @throws Exception if it fails to write file */ protected void writeVersionFile(File file, float version) throws Exception { - DataOutputStream dos = new DataOutputStream(new FileOutputStream(file)); + FileOutputStream fos = new FileOutputStream(file); + DataOutputStream dos = new DataOutputStream(fos); dos.writeFloat(version); dos.close(); + fos.close(); } /** @@ -872,10 +899,21 @@ */ @SuppressWarnings("unchecked") protected HashMap<String, Long> readCacheFile(File file) throws Exception { - ObjectInputStream dis = new ObjectInputStream(new FileInputStream(file)); - HashMap<String, Long> hashMap = (HashMap<String, Long>)dis.readObject(); - dis.close(); - return hashMap; + FileInputStream fis = new FileInputStream(file); + try { + ObjectInputStream dis = new ObjectInputStream(fis); + HashMap<String, Long> hashMap = (HashMap<String, Long>) dis.readObject(); + dis.close(); + return hashMap; + } catch (Exception e) { + // failed to read cache file + e.printStackTrace(); + } finally { + fis.close(); + } + + // return an empty map if failed to read file + return new HashMap<String, Long>(); } /** @@ -886,9 +924,11 @@ * @throws Exception if it fails to write file */ protected void writeCacheFile(File file, HashMap<String, Long> filesLastModified) throws Exception { - ObjectOutputStream dos = new ObjectOutputStream(new FileOutputStream(file)); + FileOutputStream fos = new FileOutputStream(file); + ObjectOutputStream dos = new ObjectOutputStream(fos); dos.writeObject(filesLastModified); dos.close(); + fos.close(); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2011-03-10 21:49:08
|
Revision: 3496 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3496&view=rev Author: kappa1 Date: 2011-03-10 21:49:01 +0000 (Thu, 10 Mar 2011) Log Message: ----------- AppletLoader: clean up and simplify code relating to reading and writing cache/version files. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-03-07 22:22:08 UTC (rev 3495) +++ trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-03-10 21:49:01 UTC (rev 3496) @@ -41,8 +41,6 @@ import java.awt.Image; import java.awt.MediaTracker; import java.awt.image.ImageObserver; -import java.io.DataInputStream; -import java.io.DataOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -745,7 +743,7 @@ // if version file exists if (versionFile.exists()) { // compare to new version - if (latestVersion != readVersionFile(versionFile)) { + if (latestVersion != readFloatFile(versionFile)) { versionAvailable = true; percentage = 90; @@ -774,11 +772,11 @@ // save version information once jars downloaded successfully if (version != null) { percentage = 90; - writeVersionFile(versionFile, latestVersion); + writeObjectFile(versionFile, latestVersion); } // save file names with last modified info once downloaded successfully - writeCacheFile(new File(dir, "cache"), filesLastModified); + writeObjectFile(new File(dir, "timestamps"), filesLastModified); } // add the downloaded jars and natives to classpath @@ -850,83 +848,81 @@ } /** - * read the current version file + * read float from File * - * @param file the file to read - * @return the version value of saved file - * @throws Exception if it fails to read value + * @param file to be read + * @return the float stored in the file or 0 if it fails */ - protected float readVersionFile(File file) throws Exception { - FileInputStream fis = new FileInputStream(file); + protected float readFloatFile(File file) { try { - DataInputStream dis = new DataInputStream(fis); - float version = dis.readFloat(); - dis.close(); - return version; + Float version = (Float)readObjectFile(file); + return version.floatValue(); } catch (Exception e) { // failed to read version file e.printStackTrace(); } - finally { - fis.close(); - } // return 0 if failed to read file return 0; } - + /** - * write out version file of applet + * read the HashMap from File * - * @param file the file to write out to - * @param version the version of the applet as a float - * @throws Exception if it fails to write file + * @param file the file to read + * @return the hashmap stored in the file or an empty hashmap if it fails */ - protected void writeVersionFile(File file, float version) throws Exception { - FileOutputStream fos = new FileOutputStream(file); - DataOutputStream dos = new DataOutputStream(fos); - dos.writeFloat(version); - dos.close(); - fos.close(); + @SuppressWarnings("unchecked") + protected HashMap<String, Long> readHashMapFile(File file) { + + try { + return (HashMap<String, Long>) readObjectFile(file); + } catch (Exception e) { + // failed to read hashmap from file + e.printStackTrace(); + } + + // return an empty map if failed to read file + return new HashMap<String, Long>(); } - + /** - * read the current cache file - * + * read the object from the File + * * @param file the file to read - * @return the hashmap containing the files names and lastModified times - * @throws Exception if it fails to read hashmap + * @return the object contained in the file or null if it fails + * @throws Exception if it fails to read object from file */ - @SuppressWarnings("unchecked") - protected HashMap<String, Long> readCacheFile(File file) throws Exception { + protected Object readObjectFile(File file) throws Exception { FileInputStream fis = new FileInputStream(file); + try { ObjectInputStream dis = new ObjectInputStream(fis); - HashMap<String, Long> hashMap = (HashMap<String, Long>) dis.readObject(); + Object object = dis.readObject(); dis.close(); - return hashMap; + return object; } catch (Exception e) { - // failed to read cache file + // failed to read file e.printStackTrace(); } finally { fis.close(); } - // return an empty map if failed to read file - return new HashMap<String, Long>(); + // return null if failed to read file + return null; } - + /** - * write out cache file of applet + * write object to specified File * * @param file the file to write out to - * @param filesLastModified the hashmap containing files names and lastModified times + * @param object the contents of the file * @throws Exception if it fails to write file */ - protected void writeCacheFile(File file, HashMap<String, Long> filesLastModified) throws Exception { + protected void writeObjectFile(File file, Object object) throws Exception { FileOutputStream fos = new FileOutputStream(file); ObjectOutputStream dos = new ObjectOutputStream(fos); - dos.writeObject(filesLastModified); + dos.writeObject(object); dos.close(); fos.close(); } @@ -1103,11 +1099,11 @@ URLConnection urlconnection; - File cacheFile = new File(dir, "cache"); + File timestampsFile = new File(dir, "timestamps"); - // if cache file exists, load it - if (cacheFile.exists()) { - filesLastModified = readCacheFile(cacheFile); + // if timestamps file exists, load it + if (timestampsFile.exists()) { + filesLastModified = readHashMapFile(timestampsFile); } // calculate total size of jars to download This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2011-03-12 21:16:29
|
Revision: 3497 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3497&view=rev Author: kappa1 Date: 2011-03-12 21:16:22 +0000 (Sat, 12 Mar 2011) Log Message: ----------- AppletLoader: implemented headless mode. Use the "al_headless" parameter to enable it. Use liveconnect to access the getStatus() and getMessages() methods to obtain the progress of the AppletLoader. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-03-10 21:49:01 UTC (rev 3496) +++ trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-03-12 21:16:22 UTC (rev 3497) @@ -257,7 +257,16 @@ /** whether pack200 is supported */ protected boolean pack200Supported; + + /** whether to run in headless mode */ + protected boolean headless = false; + + /** whether to switch applets in headless mode or wait longer */ + protected boolean headlessWaiting = true; + /** messages to be passed via liveconnect in headless mode */ + protected String[] headlessMessage; + /** generic error message to display on error */ protected String[] genericErrorMessage = { "An error occured while loading the applet.", "Please contact support to resolve this issue.", @@ -273,7 +282,7 @@ /** have natives been loaded by another instance of this applet */ protected static boolean natives_loaded; - + /* * @see java.applet.Applet#init() */ @@ -298,14 +307,19 @@ // whether to prepend host to cache path prependHost = getBooleanParameter("al_prepend_host", true); + // whether to run in headless mode + headless = getBooleanParameter("al_headless", false); + // get colors of applet bgColor = getColor("boxbgcolor", Color.white); setBackground(bgColor); fgColor = getColor("boxfgcolor", Color.black); - // load logos, if value is "" then an image is not loaded - logo = getImage(getStringParameter("al_logo", "appletlogo.gif")); - progressbar = getImage(getStringParameter("al_progressbar", "appletprogress.gif")); + if (!headless) { + // load logos + logo = getImage(getStringParameter("al_logo", "appletlogo.gif")); + progressbar = getImage(getStringParameter("al_progressbar", "appletprogress.gif")); + } // check for lzma support try { @@ -349,17 +363,19 @@ loaderThread.setName("AppletLoader.loaderThread"); loaderThread.start(); - animationThread = new Thread() { - public void run() { - while(loaderThread != null) { - repaint(); - AppletLoader.this.sleep(100); + if (!headless) { + animationThread = new Thread() { + public void run() { + while(loaderThread != null) { + repaint(); + AppletLoader.this.sleep(100); + } + animationThread = null; } - animationThread = null; - } - }; - animationThread.setName("AppletLoader.animationthread"); - animationThread.start(); + }; + animationThread.setName("AppletLoader.animationthread"); + animationThread.start(); + } } } } @@ -403,6 +419,48 @@ } /** + * Retrieves the current status of the AppletLoader and is + * used by liveconnect when running in headless mode. + * + * This method will return the current progress of the AppletLoader + * as a value from 0-100. In the case of a fatal error it will + * return -1. If the certificate is refused it will return -2. + * + * When method returns 100 the AppletLoader will sleep until the + * method is called again. When called again it will switch to the + * LWJGL Applet. This is a useful trigger to start the LWJGL applet + * when needed. + */ + public int getStatus() { + if (fatalError) { + if (certificateRefused) return -2; + headlessMessage = (certificateRefused) ? certificateRefusedMessage : genericErrorMessage; + return -1; + } + + if (percentage == 100 && headlessWaiting) { + headlessWaiting = false; + } + + if (percentage == 95) { + percentage = 100; // ready to switch applet + } + + String[] message = {getDescriptionForState(), subtaskMessage}; + headlessMessage = message; + + return percentage; + } + + /** + * Retrieves the current message for the current status. + * Used by liveconnect when running in headless mode. + */ + public String[] getMessages() { + return headlessMessage; + } + + /** * Transfers the call of AppletResize from the stub to the lwjglApplet. */ public void appletResize(int width, int height) { @@ -471,7 +529,7 @@ og.drawString(errorMessage[i], messageX, messageY + i*fm.getHeight()); } } - } else { + } else if (!headless) { og.setColor(fgColor); painting = true; @@ -785,6 +843,13 @@ // set lwjgl properties setLWJGLProperties(); + // if headless mode then sleep, until told to continue + if (headless) { + while(headlessWaiting) { + Thread.sleep(100); + } + } + // make applet switch on the EDT as an AWT/Swing permission dialog could be called EventQueue.invokeAndWait(new Runnable() { public void run() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2011-03-13 14:54:42
|
Revision: 3498 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3498&view=rev Author: kappa1 Date: 2011-03-13 14:54:36 +0000 (Sun, 13 Mar 2011) Log Message: ----------- AppletLoader: fix JVM bug where '!' is not escaped on the URL, thanks to NateS for spotting it and special thanks to MatthiasM for the fix. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-03-12 21:16:22 UTC (rev 3497) +++ trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-03-13 14:54:36 UTC (rev 3498) @@ -1009,7 +1009,10 @@ URL[] urls = new URL[urlList.length]; for (int i = 0; i < urlList.length; i++) { - urls[i] = new URL("file:" + path + getJarName(urlList[i])); + String file = new File(path, getJarName(urlList[i])).toURI().toString(); + // fix JVM bug where ! is not escaped + file = file.replaceAll("!", "%21"); + urls[i] = new URL(file); } // add downloaded jars to the classpath with required permissions This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2011-03-26 15:54:58
|
Revision: 3499 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3499&view=rev Author: kappa1 Date: 2011-03-26 15:54:52 +0000 (Sat, 26 Mar 2011) Log Message: ----------- AppletLoader: fix bug with al_version (should work correctly now). Thx to pjohnsen for spotting it. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-03-13 14:54:36 UTC (rev 3498) +++ trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-03-26 15:54:52 UTC (rev 3499) @@ -801,7 +801,7 @@ // if version file exists if (versionFile.exists()) { // compare to new version - if (latestVersion != readFloatFile(versionFile)) { + if (latestVersion == readFloatFile(versionFile)) { versionAvailable = true; percentage = 90; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2011-03-26 15:58:28
|
Revision: 3500 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3500&view=rev Author: kappa1 Date: 2011-03-26 15:58:21 +0000 (Sat, 26 Mar 2011) Log Message: ----------- AppletLoader: minor javadoc credits update. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-03-26 15:54:52 UTC (rev 3499) +++ trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-03-26 15:58:21 UTC (rev 3500) @@ -137,11 +137,13 @@ * <li>Arielsan</li> * <li>Bobjob</li> * <li>Dashiva</li> - * <li>Kevglass</li> - * <li>MatthiasM</li> + * <li>Kevin Glass</li> + * <li>Matthias Mann</li> * <li>Mickelukas</li> * <li>NateS</li> * <li>Ruben01</li> + * <li>Shannon Smith</li> + * <li>pjohnsen</li> * </ul> * */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2011-04-26 11:04:20
|
Revision: 3518 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3518&view=rev Author: kappa1 Date: 2011-04-26 11:04:12 +0000 (Tue, 26 Apr 2011) Log Message: ----------- AppletLoader: close fileoutputstream properly when extracting pack files. Minor clean up of extract lzma and gzip methods. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-04-16 21:13:27 UTC (rev 3517) +++ trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-04-26 11:04:12 UTC (rev 3518) @@ -1385,8 +1385,7 @@ Constructor constructor = clazz.getDeclaredConstructor(InputStream.class); InputStream inputHandle = (InputStream) constructor.newInstance(fileInputHandle); - OutputStream outputHandle; - outputHandle = new FileOutputStream(out); + OutputStream outputHandle = new FileOutputStream(out); byte [] buffer = new byte [1<<14]; @@ -1399,9 +1398,6 @@ inputHandle.close(); outputHandle.close(); - outputHandle = null; - inputHandle = null; - // delete LZMA file, as it is no longer needed f.delete(); } @@ -1419,8 +1415,7 @@ InputStream inputHandle = new GZIPInputStream(fileInputHandle); - OutputStream outputHandle; - outputHandle = new FileOutputStream(out); + OutputStream outputHandle = new FileOutputStream(out); byte [] buffer = new byte [1<<14]; @@ -1433,9 +1428,6 @@ inputHandle.close(); outputHandle.close(); - outputHandle = null; - inputHandle = null; - // delete GZip file, as it is no longer needed f.delete(); } @@ -1454,6 +1446,7 @@ Pack200.Unpacker unpacker = Pack200.newUnpacker(); unpacker.unpack(f, jostream); jostream.close(); + fostream.close(); // delete pack file as its no longer needed f.delete(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2011-04-30 23:54:31
|
Revision: 3520 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3520&view=rev Author: kappa1 Date: 2011-04-30 23:54:24 +0000 (Sat, 30 Apr 2011) Log Message: ----------- AppletLoader: added jar validation to detect corruption and ensures that the cache system doesn't mark corrupt files as successfully downloads. Thx to Riven and MatthiasM for assisting with the implementation. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-04-28 17:54:46 UTC (rev 3519) +++ trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-04-30 23:54:24 UTC (rev 3520) @@ -41,6 +41,7 @@ import java.awt.Image; import java.awt.MediaTracker; import java.awt.image.ImageObserver; +import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -77,7 +78,11 @@ import java.util.jar.JarFile; import java.util.jar.JarOutputStream; import java.util.jar.Pack200; +import java.util.zip.CRC32; +import java.util.zip.CheckedInputStream; import java.util.zip.GZIPInputStream; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; import sun.security.util.SecurityConstants; @@ -141,6 +146,7 @@ * <li>Matthias Mann</li> * <li>Mickelukas</li> * <li>NateS</li> + * <li>Riven</li> * <li>Ruben01</li> * <li>Shannon Smith</li> * <li>pjohnsen</li> @@ -163,21 +169,24 @@ /** extracting packages */ public static final int STATE_EXTRACTING_PACKAGES = 5; + + /** validating packages */ + public static final int STATE_VALIDATING_PACKAGES = 6; /** updating the classpath */ - public static final int STATE_UPDATING_CLASSPATH = 6; + public static final int STATE_UPDATING_CLASSPATH = 7; /** switching to real applet */ - public static final int STATE_SWITCHING_APPLET = 7; + public static final int STATE_SWITCHING_APPLET = 8; /** initializing real applet */ - public static final int STATE_INITIALIZE_REAL_APPLET = 8; + public static final int STATE_INITIALIZE_REAL_APPLET = 9; /** stating real applet */ - public static final int STATE_START_REAL_APPLET = 9; + public static final int STATE_START_REAL_APPLET = 10; /** done */ - public static final int STATE_DONE = 10; + public static final int STATE_DONE = 11; /** used to calculate length of progress bar */ protected int percentage; @@ -261,13 +270,13 @@ protected boolean pack200Supported; /** whether to run in headless mode */ - protected boolean headless = false; + protected boolean headless = false; /** whether to switch applets in headless mode or wait longer */ - protected boolean headlessWaiting = true; + protected boolean headlessWaiting = true; /** messages to be passed via liveconnect in headless mode */ - protected String[] headlessMessage; + protected String[] headlessMessage; /** generic error message to display on error */ protected String[] genericErrorMessage = { "An error occured while loading the applet.", @@ -632,6 +641,8 @@ return "Downloading packages"; case STATE_EXTRACTING_PACKAGES: return "Extracting downloaded packages"; + case STATE_VALIDATING_PACKAGES: + return "Validating packages"; case STATE_UPDATING_CLASSPATH: return "Updating classpath"; case STATE_SWITCHING_APPLET: @@ -827,7 +838,10 @@ extractJars(path); // 55-65% // Extracts Native Files - extractNatives(path); // 65-85% + extractNatives(path); // 65-80% + + // Validate Jars // 80-90% + validateJars(path); // save version information once jars downloaded successfully if (version != null) { @@ -1519,7 +1533,7 @@ setState(STATE_EXTRACTING_PACKAGES); - float percentageParts = 20f/nativeJarCount; // parts for each native jar from 20% + float percentageParts = 15f/nativeJarCount; // parts for each native jar from 15% // create native folder File nativeFolder = new File(path + "natives"); @@ -1649,6 +1663,87 @@ } } } + + /** + * Check and validate jar which will be loaded into the classloader to make + * sure that they are not corrupt. This will ensure that cached files are + * never marked as being successfully downloaded if they are corrupt. + * + * @param path - where the jars are stored + * @throws Exception if a corrupt jar is found + */ + protected void validateJars(String path) throws Exception { + + setState(STATE_VALIDATING_PACKAGES); + + percentage = 80; + + float percentageParts = 10f / urlList.length; // percentage for each file out of 10% + + for (int i = 0; i < urlList.length - nativeJarCount; i++) { + + debug_sleep(1000); + + // if file not downloaded, no need to validate again + if (fileSizes[i] == -2) continue; + + subtaskMessage = "Validating: " + getJarName(urlList[i]); + + File file = new File(path, getJarName(urlList[i])); + if (!isZipValid(file)) { + throw new Exception("The file " + getJarName(urlList[i]) + " is corrupt!"); + } + + percentage = 80 + (int)(percentageParts * i); + } + + subtaskMessage = ""; + } + + /** + * This method will check if a zip file is valid by running through it + * and checking for any corruption and CRC failures + * + * @param file - zip file to test + * @return boolean - runs false if the file is corrupt + */ + protected boolean isZipValid(File file) { + + try { + ZipFile zipFile = new ZipFile(file); + + try { + Enumeration e = zipFile.entries(); + + byte[] buffer = new byte[4096]; + + while(e.hasMoreElements()) { + ZipEntry zipEntry = (ZipEntry) e.nextElement(); + + CRC32 crc = new CRC32(); + + BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(zipEntry)); + CheckedInputStream cis = new CheckedInputStream(bis, crc); + + while(cis.read(buffer, 0, buffer.length) != -1) { + // scroll through zip entry + } + + if (crc.getValue() != zipEntry.getCrc()) { + System.out.println("CRC " + crc.getValue() + " " + zipEntry.getCrc()); + return false; // CRC match failed, corrupt zip + } + } + + return true; // valid zip file + } finally { + zipFile.close(); + } + } catch (IOException e) { + e.printStackTrace(); + return false; + } + } /** * Get Image from path provided This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2011-04-30 23:56:30
|
Revision: 3521 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3521&view=rev Author: kappa1 Date: 2011-04-30 23:56:24 +0000 (Sat, 30 Apr 2011) Log Message: ----------- AppletLoader: minor tweak on comments Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-04-30 23:54:24 UTC (rev 3520) +++ trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-04-30 23:56:24 UTC (rev 3521) @@ -1665,9 +1665,9 @@ } /** - * Check and validate jar which will be loaded into the classloader to make - * sure that they are not corrupt. This will ensure that cached files are - * never marked as being successfully downloaded if they are corrupt. + * Check and validate jars which will be loaded into the classloader to make + * sure that they are not corrupt. This ensures corrupt files are never marked + * as successfully downloadeds by the cache system. * * @param path - where the jars are stored * @throws Exception if a corrupt jar is found This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2011-05-01 00:03:32
|
Revision: 3522 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3522&view=rev Author: kappa1 Date: 2011-05-01 00:03:26 +0000 (Sun, 01 May 2011) Log Message: ----------- Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-04-30 23:56:24 UTC (rev 3521) +++ trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-05-01 00:03:26 UTC (rev 3522) @@ -1667,7 +1667,7 @@ /** * Check and validate jars which will be loaded into the classloader to make * sure that they are not corrupt. This ensures corrupt files are never marked - * as successfully downloadeds by the cache system. + * as successful downloadeds by the cache system. * * @param path - where the jars are stored * @throws Exception if a corrupt jar is found This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2011-05-01 00:09:49
|
Revision: 3523 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3523&view=rev Author: kappa1 Date: 2011-05-01 00:09:43 +0000 (Sun, 01 May 2011) Log Message: ----------- AppletLoader: remove unneeded debug code Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-05-01 00:03:26 UTC (rev 3522) +++ trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-05-01 00:09:43 UTC (rev 3523) @@ -1730,7 +1730,6 @@ } if (crc.getValue() != zipEntry.getCrc()) { - System.out.println("CRC " + crc.getValue() + " " + zipEntry.getCrc()); return false; // CRC match failed, corrupt zip } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2011-05-04 23:11:17
|
Revision: 3525 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3525&view=rev Author: kappa1 Date: 2011-05-04 23:11:11 +0000 (Wed, 04 May 2011) Log Message: ----------- AppletLoader: fix String replace bug on file names, full credits to Riven for spotting it and assisting with the fix. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-05-04 19:24:57 UTC (rev 3524) +++ trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-05-04 23:11:11 UTC (rev 3525) @@ -665,11 +665,11 @@ */ protected String trimExtensionByCapabilities(String file) { if (!pack200Supported) { - file = file.replaceAll(".pack", ""); + file = replaceLast(file, ".pack", ""); } if (!lzmaSupported) { - file = file.replaceAll(".lzma", ""); + file = replaceLast(file, ".lzma", ""); } return file; } @@ -1027,7 +1027,7 @@ for (int i = 0; i < urlList.length; i++) { String file = new File(path, getJarName(urlList[i])).toURI().toString(); // fix JVM bug where ! is not escaped - file = file.replaceAll("!", "%21"); + file = file.replace("!", "%21"); urls[i] = new URL(file); } @@ -1486,37 +1486,37 @@ String filename = getFileName(urlList[i]); if (filename.endsWith(".pack.lzma")) { - subtaskMessage = "Extracting: " + filename + " to " + filename.replaceAll(".lzma", ""); + subtaskMessage = "Extracting: " + filename + " to " + replaceLast(filename, ".lzma", ""); debug_sleep(1000); - extractLZMA(path + filename, path + filename.replaceAll(".lzma", "")); + extractLZMA(path + filename, path + replaceLast(filename, ".lzma", "")); - subtaskMessage = "Extracting: " + filename.replaceAll(".lzma", "") + " to " + filename.replaceAll(".pack.lzma", ""); + subtaskMessage = "Extracting: " + replaceLast(filename, ".lzma", "") + " to " + replaceLast(filename, ".pack.lzma", ""); debug_sleep(1000); - extractPack(path + filename.replaceAll(".lzma", ""), path + filename.replaceAll(".pack.lzma", "")); + extractPack(path + replaceLast(filename, ".lzma", ""), path + replaceLast(filename, ".pack.lzma", "")); } else if (filename.endsWith(".pack.gz")) { - subtaskMessage = "Extracting: " + filename + " to " + filename.replaceAll(".gz", ""); + subtaskMessage = "Extracting: " + filename + " to " + replaceLast(filename, ".gz", ""); debug_sleep(1000); - extractGZip(path + filename, path + filename.replaceAll(".gz", "")); + extractGZip(path + filename, path + replaceLast(filename, ".gz", "")); - subtaskMessage = "Extracting: " + filename.replaceAll(".gz", "") + " to " + filename.replaceAll(".pack.gz", ""); + subtaskMessage = "Extracting: " + replaceLast(filename, ".gz", "") + " to " + replaceLast(filename, ".pack.gz", ""); debug_sleep(1000); - extractPack(path + filename.replaceAll(".gz", ""), path + filename.replaceAll(".pack.gz", "")); + extractPack(path + replaceLast(filename, ".gz", ""), path + replaceLast(filename, ".pack.gz", "")); } else if (filename.endsWith(".pack")) { - subtaskMessage = "Extracting: " + filename + " to " + filename.replace(".pack", ""); + subtaskMessage = "Extracting: " + filename + " to " + replaceLast(filename, ".pack", ""); debug_sleep(1000); - extractPack(path + filename, path + filename.replace(".pack", "")); + extractPack(path + filename, path + replaceLast(filename, ".pack", "")); } else if (filename.endsWith(".lzma")) { - subtaskMessage = "Extracting: " + filename + " to " + filename.replace(".lzma", ""); + subtaskMessage = "Extracting: " + filename + " to " + replaceLast(filename, ".lzma", ""); debug_sleep(1000); - extractLZMA(path + filename, path + filename.replace(".lzma", "")); + extractLZMA(path + filename, path + replaceLast(filename, ".lzma", "")); } else if (filename.endsWith(".gz")) { - subtaskMessage = "Extracting: " + filename + " to " + filename.replace(".gz", ""); + subtaskMessage = "Extracting: " + filename + " to " + replaceLast(filename, ".gz", ""); debug_sleep(1000); - extractGZip(path + filename, path + filename.replace(".gz", "")); + extractGZip(path + filename, path + replaceLast(filename, ".gz", "")); } } } @@ -1814,15 +1814,15 @@ String fileName = url.getFile(); if (fileName.endsWith(".pack.lzma")) { - fileName = fileName.replaceAll(".pack.lzma", ""); + fileName = replaceLast(fileName, ".pack.lzma", ""); } else if (fileName.endsWith(".pack.gz")) { - fileName = fileName.replaceAll(".pack.gz", ""); + fileName = replaceLast(fileName, ".pack.gz", ""); } else if (fileName.endsWith(".pack")) { - fileName = fileName.replaceAll(".pack", ""); + fileName = replaceLast(fileName, ".pack", ""); } else if (fileName.endsWith(".lzma")) { - fileName = fileName.replaceAll(".lzma", ""); + fileName = replaceLast(fileName, ".lzma", ""); } else if (fileName.endsWith(".gz")) { - fileName = fileName.replaceAll(".gz", ""); + fileName = replaceLast(fileName, ".gz", ""); } return fileName.substring(fileName.lastIndexOf('/') + 1); @@ -1882,6 +1882,25 @@ } /** + * Replaces the last occurrence of the specified target substring with + * the specified replacement string in a string. + * + * @param original - String to search + * @param target - substring to find + * @param replacement - what to replace target substring with + * @return - return the modified string, if target substring not found return original string + */ + public String replaceLast(String original, String target, String replacement) { + int index = original.lastIndexOf(target); + + if(index == -1) { + return original; + } + + return original.substring(0, index) + replacement + original.substring(index + target.length()); + } + + /** * Retrieves the String value for the parameter * @param name Name of parameter * @param defaultValue default value to return if no such parameter This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2011-05-07 16:29:21
|
Revision: 3526 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3526&view=rev Author: kappa1 Date: 2011-05-07 16:29:13 +0000 (Sat, 07 May 2011) Log Message: ----------- AppletLoader: remove the last dependency on the sun.* package. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-05-04 23:11:11 UTC (rev 3525) +++ trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-05-07 16:29:13 UTC (rev 3526) @@ -84,8 +84,6 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipFile; -import sun.security.util.SecurityConstants; - /** * <p> * The AppletLoader enables deployment of LWJGL to applets in an easy @@ -1046,12 +1044,12 @@ if (host != null && (host.length() > 0)) { // add permission for downloaded jars to access host they were from - perms.add(new SocketPermission(host, SecurityConstants.SOCKET_CONNECT_ACCEPT_ACTION)); + perms.add(new SocketPermission(host, "connect,accept")); } else if ( "file".equals(codesource.getLocation().getProtocol()) ) { // if running locally add file permission String path = codesource.getLocation().getFile().replace('/', File.separatorChar); - perms.add(new FilePermission(path, SecurityConstants.FILE_READ_ACTION)); + perms.add(new FilePermission(path, "read")); } } catch (Exception e) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2011-05-13 16:24:17
|
Revision: 3531 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3531&view=rev Author: kappa1 Date: 2011-05-13 16:24:10 +0000 (Fri, 13 May 2011) Log Message: ----------- AppletLoader: add support for optional mac arch specific natives, al_mac32, al_mac64, al_macppc, if they are not specified AppletLoader will fall back to the usual al_mac parameter. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-05-11 14:21:59 UTC (rev 3530) +++ trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-05-13 16:24:10 UTC (rev 3531) @@ -713,7 +713,20 @@ } } else if (osName.startsWith("Mac") || osName.startsWith("Darwin")) { - nativeJarList = getParameter("al_mac"); + + // check if arch specific natives have been specified + if (System.getProperty("os.arch").endsWith("64")) { + nativeJarList = getParameter("al_mac64"); + } else if (System.getProperty("os.arch").endsWith("ppc")) { + nativeJarList = getParameter("al_macppc"); + } else { + nativeJarList = getParameter("al_mac32"); + } + + if (nativeJarList == null) { + nativeJarList = getParameter("al_mac"); + } + } else if (osName.startsWith("Solaris") || osName.startsWith("SunOS")) { nativeJarList = getParameter("al_solaris"); } else if (osName.startsWith("FreeBSD")) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2011-05-13 19:16:40
|
Revision: 3532 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3532&view=rev Author: kappa1 Date: 2011-05-13 19:16:34 +0000 (Fri, 13 May 2011) Log Message: ----------- AppletLoader: small fix to also include "ppc64" on macs. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-05-13 16:24:10 UTC (rev 3531) +++ trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2011-05-13 19:16:34 UTC (rev 3532) @@ -140,14 +140,15 @@ * <li>Arielsan</li> * <li>Bobjob</li> * <li>Dashiva</li> + * <li>Dr_evil</li> * <li>Kevin Glass</li> * <li>Matthias Mann</li> * <li>Mickelukas</li> * <li>NateS</li> + * <li>pjohnsen</li> * <li>Riven</li> * <li>Ruben01</li> * <li>Shannon Smith</li> - * <li>pjohnsen</li> * </ul> * */ @@ -717,7 +718,7 @@ // check if arch specific natives have been specified if (System.getProperty("os.arch").endsWith("64")) { nativeJarList = getParameter("al_mac64"); - } else if (System.getProperty("os.arch").endsWith("ppc")) { + } else if (System.getProperty("os.arch").contains("ppc")) { nativeJarList = getParameter("al_macppc"); } else { nativeJarList = getParameter("al_mac32"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |