From: <eli...@us...> - 2006-07-03 11:30:49
|
Revision: 2420 Author: elias_naur Date: 2006-07-03 04:30:30 -0700 (Mon, 03 Jul 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2420&view=rev Log Message: ----------- Removed org.lwjgl.util.model Modified Paths: -------------- trunk/LWJGL/build.xml Added Paths: ----------- trunk/LWJGL/src/java/org/lwjgl/util/applet/ trunk/LWJGL/src/java/org/lwjgl/util/applet/LWJGLInstaller.java Removed Paths: ------------- trunk/LWJGL/res/model/ trunk/LWJGL/src/java/org/lwjgl/util/applet/LWJGLInstaller.java trunk/LWJGL/src/java/org/lwjgl/util/model/ Modified: trunk/LWJGL/build.xml =================================================================== --- trunk/LWJGL/build.xml 2006-07-03 10:28:32 UTC (rev 2419) +++ trunk/LWJGL/build.xml 2006-07-03 11:30:30 UTC (rev 2420) @@ -31,6 +31,17 @@ <exclude name="org/lwjgl/examples/**" /> </fileset> + <fileset id="lwjgl_util_applet.fileset" dir="${lwjgl.bin}"> + <exclude name="**.*"/> + <include name="org/lwjgl/util/applet/**"/> + </fileset> + + <fileset id="lwjgl_util_applet_natives.fileset" dir="${lwjgl.lib}"> + <include name="win32/**"/> + <include name="linux/**"/> + <include name="macosx/**"/> + </fileset> + <!-- Files to include in the lwjgl_test.jar file --> <fileset id="lwjgl_test.fileset" dir="${lwjgl.bin}"> <exclude name="**.*" /> @@ -53,16 +64,10 @@ <fileset id="lwjgl_util.fileset" dir="${lwjgl.bin}"> <exclude name="**.*" /> <exclude name="org/lwjgl/util/generator/**" /> - <exclude name="org/lwjgl/util/model/**" /> + <exclude name="org/lwjgl/util/applet/**" /> <include name="org/lwjgl/util/**" /> </fileset> - <!-- Files to include in the lwjgl_model.jar file --> - <fileset id="lwjgl_model.fileset" dir="${lwjgl.bin}"> - <exclude name="**.*" /> - <include name="org/lwjgl/util/model/**" /> - </fileset> - <!-- Files to include in the lwjgl_fmod3.jar file --> <fileset id="lwjgl_fmod3.fileset" dir="${lwjgl.bin}"> <exclude name="**.*" /> @@ -162,7 +167,6 @@ <include name="**" /> <exclude name="jar/lwjgl_fmod3.jar" /> <exclude name="jar/lwjgl_devil.jar" /> - <exclude name="jar/lwjgl_model.jar" /> <exclude name="native/win32/lwjgl-*.dll" /> <exclude name="native/win32/DevIL.dll" /> <exclude name="native/win32/ILU.dll" /> @@ -171,7 +175,6 @@ <exclude name="native/linux/liblwjgl-*.so" /> <exclude name="native/macosx/libIL*.dylib" /> <exclude name="native/macosx/liblwjgl-*.jnilib" /> - <exclude name="res/model/**" /> <exclude name="res/ILtest.*" /> <exclude name="res/Missing_you.mod" /> <exclude name="res/phero*.*" /> @@ -182,7 +185,6 @@ <patternset id="lwjgl_optional"> <include name="jar/lwjgl_fmod3.jar" /> <include name="jar/lwjgl_devil.jar" /> - <include name="jar/lwjgl_model.jar" /> <include name="native/win32/lwjgl-*.dll" /> <include name="native/win32/DevIL.dll" /> <include name="native/win32/ILU.dll" /> @@ -314,6 +316,12 @@ <jar destfile="${lwjgl.temp}/jar/lwjgl.jar" taskname="lwjgl.jar"> <fileset refid="lwjgl.fileset" /> </jar> + + <!-- Create lwjgl_util_applet.jar --> + <jar destfile="${lwjgl.temp}/jar/lwjgl_util_applet.jar" taskname="lwjgl_util_applet.jar"> + <fileset refid="lwjgl_util_applet.fileset" /> + <fileset refid="lwjgl_util_applet_natives.fileset"/> + </jar> <!-- Create lwjgl_test.jar --> <jar destfile="${lwjgl.temp}/jar/lwjgl_test.jar" taskname="lwjgl_test.jar"> @@ -326,11 +334,6 @@ <fileset refid="lwjgl_util.fileset" /> </jar> - <!-- Create lwjgl_model.jar --> - <jar destfile="${lwjgl.temp}/jar/lwjgl_model.jar" taskname="lwjgl_model.jar"> - <fileset refid="lwjgl_model.fileset" /> - </jar> - <!-- Create lwjgl_fmod.jar --> <jar destfile="${lwjgl.temp}/jar/lwjgl_fmod3.jar" taskname="lwjgl_fmod3.jar"> <fileset refid="lwjgl_fmod3.fileset" /> @@ -348,18 +351,15 @@ <fileset refid="lwjgl_applet.fileset" /> </jar> <copy file="${lwjgl.lib}/lwjgl.jar" todir="applet"/> + <copy file="${lwjgl.lib}/lwjgl_util_applet.jar" todir="applet"/> <copy file="${lwjgl.lib}/lwjgl_util.jar" todir="applet"/> <copy file="${lwjgl.lib}/lwjgl_fmod3.jar" todir="applet"/> <copy file="${lwjgl.lib}/lwjgl_devil.jar" todir="applet"/> <zip destfile="applet/res.jar"> <zipfileset dir="${lwjgl.res}" includes="Footsteps.wav, ILtest.tga, Missing_you.mod"/> </zip> - <zip destfile="applet/lwjgl.jar" update="true"> - <zipfileset dir="${lwjgl.lib}" prefix="native" includes="win32/**"/> - <zipfileset dir="${lwjgl.lib}" prefix="native" includes="linux/**"/> - <zipfileset dir="${lwjgl.lib}" prefix="native" includes="macosx/**"/> - </zip> <signjar jar="applet/lwjgl.jar" alias="lwjgl" keystore="applet/lwjglkeystore" storepass="123456"/> + <signjar jar="applet/lwjgl_util_applet.jar" alias="lwjgl" keystore="applet/lwjglkeystore" storepass="123456"/> <signjar jar="applet/lwjgl_fmod3.jar" alias="lwjgl" keystore="applet/lwjglkeystore" storepass="123456"/> <signjar jar="applet/lwjgl_devil.jar" alias="lwjgl" keystore="applet/lwjglkeystore" storepass="123456"/> </target> @@ -438,6 +438,7 @@ <target name="headers" description="invokes javah on java classes" depends="compile"> <!-- platform specific classes --> <javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.native}/linux" force="yes"> + <class name="org.lwjgl.opengl.LinuxKeyboard" /> <class name="org.lwjgl.opengl.LinuxDisplay" /> <class name="org.lwjgl.opengl.LinuxPeerInfo" /> <class name="org.lwjgl.opengl.LinuxPbufferPeerInfo" /> Copied: trunk/LWJGL/src/java/org/lwjgl/util/applet (from rev 2415, trunk/LWJGL/src/java/org/lwjgl/applet) Deleted: trunk/LWJGL/src/java/org/lwjgl/util/applet/LWJGLInstaller.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/applet/LWJGLInstaller.java 2006-07-02 22:01:27 UTC (rev 2415) +++ trunk/LWJGL/src/java/org/lwjgl/util/applet/LWJGLInstaller.java 2006-07-03 11:30:30 UTC (rev 2420) @@ -1,318 +0,0 @@ -/* - * Copyright (c) 2006 LWJGL Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.lwjgl.applet; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileFilter; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.security.AccessController; -import java.security.PrivilegedAction; - -import org.lwjgl.LWJGLException; -import org.lwjgl.LWJGLUtil; - -/** - * <p> - * - * </p> - * @author Brian Matzon <br...@ma...> - * @version $Revision$ - * $Id$ - */ -public class LWJGLInstaller { - - /** - * Files to install for each supported platform - * @see org.lwjgl.LWJGLUtil#getPlatform() - */ - public static final String[][] PLATFORM_FILES = { - { "lwjgl", "lwjgl-fmod3", "lwjgl-devil", "openal", "fmod", "IL", "ILU", "ILUT", "jinput-osx"}, - { "lwjgl", "lwjgl-fmod3", "lwjgl-devil", "openal", "fmod", "IL", "ILU", "ILUT", "jinput-linux"}, - { "lwjgl", "lwjgl-fmod3", "lwjgl-devil", "OpenAL32", "fmod", "DevIL", "ILU", "ILUT", "jinput-dx8", "jinput-raw"} - }; - - /** Whether the installer has been called */ - public static boolean installed; - - /** Whether to hook uninstall rutine. Must be called prior to installation */ - public static boolean disableUninstall = false; - - /** Directory that was installed into */ - public static String installDirectory; - - /** Buffer used when copying files */ - private static final byte[] COPY_BUFFER = new byte[4096]; - - private LWJGLInstaller() { - /* Unused */ - } - - /** - * Create a temporary installation of LWJGL. - * This will extract the relevant native files (for the platform) into - * the users temp directory, and instruct the LWJGL subsystem to load its - * native files from there. - * The files required by the installer, are gotten from the classloader via its - * getResource command, and are assumed to in the path: /native/<win32|linux|macosx>/ - * Any call to this method will also add a shutdown hook to the uninstall of the libraries - * Note: Due to the nature of native libraries, we cannot actually uninstall the currently - * loaded files, but rather the "last" installed. This means that the most recent install of LWJGL - * will always be present in the users temp dir. - * - * @see java.lang.ClassLoader#getResource(String) - * @return true if the installation was successfull - */ - public static boolean tempInstall() throws LWJGLException { - // only need to install once - if (installed) { - return true; - } - - // libraries to validate and install - String[] libraries = PLATFORM_FILES[LWJGLUtil.getPlatform() - 1]; - - // Validate the certificates of the native files - validateCertificates(); - - // install shutdown installer hook - if(!disableUninstall) { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - Runtime.getRuntime().addShutdownHook(new Thread() { - public void run() { - LWJGLInstaller.uninstall(); - } - }); - return null; - } - }); - } - - // create a temporary dir for the native files - String user_temp_dir = getPriveledgedString("java.io.tmpdir"); - String path = createTemporaryDir(user_temp_dir); - if(path == null) { - throw new LWJGLException("Failed creation of temporary directory in " + user_temp_dir); - } - - // extract natives - for (int i = 0; i < libraries.length; i++) { - String library = System.mapLibraryName(libraries[i]); - if(!extract(library, path)) { - LWJGLUtil.log("Failed extract of " + library + " to " + path); - uninstall(); - return false; - } - } - - installDirectory = path; - return installed = true; - } - - /** - * Validates the certificates of the native libraries. - * When installing native libraries, it is imperative that we also check the certficates. - * The reson for this, is that a user may inject a malicious jar to the classpath - * before the "real" LWJGL jar, containing native libraries with unwanted code. - * By forcing all the native libraries to have the same certificate as the signed - * installer, we can also be sure that the native libraries indeed are correct. - * @throws LWJGLException If we encounter a certificate mismatch - */ - private static void validateCertificates() throws LWJGLException { - /* TODO */ - } - - /** - * Extracts a file in the classpath to a specified dir - * - * @param file File to extract - * @param path Path to extract to - * @return true if the file was extracted successdully - */ - private static boolean extract(final String file, final String path) throws LWJGLException { - return (Boolean) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - // check for existing file, and get out - File out = new File(path + File.separator + file); - if (out.exists()) { - return false; - } - - // create the new file and copy it to its destination - try { - out.createNewFile(); - String in = "/native/" + LWJGLUtil.getPlatformName() + "/" + file; - OutputStream os = new BufferedOutputStream(new FileOutputStream(out)); - InputStream is = new BufferedInputStream(getClass().getResourceAsStream(in)); - - // Sanity check - // =========================================== - if (os == null) { - LWJGLUtil.log("Unable to write to outputstream at " + out.getAbsolutePath()); - return false; - } - - if (is == null) { - LWJGLUtil.log("Unable to read classpath inputstream from " + in); - return false; - } - // ------------------------------------------- - - // copy the actual file - copyFile(is, os); - } catch (IOException ioe) { - LWJGLUtil.log("Exception while extracting " + file + ": " + ioe.getMessage()); - return false; - } - return true; - } - }); - } - - /** - * Copies an inputstream to an outputstream - * @param is InputStream to read from - * @param os OutputStream to write to - * @throws IOException if the copy process fail in any way - */ - static void copyFile(InputStream is, OutputStream os) throws IOException { - int len; - while ((len = is.read(COPY_BUFFER)) > 0) { - os.write(COPY_BUFFER, 0, len); - } - is.close(); - os.close(); - } - - /** - * Creates the temporary dir to store lwjgl files in. - * The temporary dir will be created in the users temp dir and - * called 'lwjgl-' and appended System.currentTimeMillis(). A watermark file - * called '.lwjglinstaller' will also be created in the directory. - * @return Name of temp directory or null if directory creation failed - */ - static String createTemporaryDir(final String user_temp_dir) { - return (String) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - // create the temp directory - File tempDir = new File(user_temp_dir + File.separator + "lwjgl-" + System.currentTimeMillis()); - if(!tempDir.mkdir()) { - return null; - } - - // add the watermark file - // TODO: Write some info to the file ? - try { - File watermark = new File(tempDir.getAbsolutePath() + File.separator + ".lwjglinstaller"); - watermark.createNewFile(); - } catch (IOException ioe) { - return null; - } - return tempDir.getAbsolutePath(); - } - }); - } - - - /** - * Gets a property as a privileged action. - */ - private static String getPriveledgedString(final String property) { - return (String) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return System.getProperty(property); - } - }); - } - - /** - * Uninstalls any PREVIOUS installations - * We cannot uninstall the current installation, since the files are locked - * by the VM. - */ - private static void uninstall() { - LWJGLUtil.log("running LWJGL uninstaller"); - - // locate all installer dirs and uninstall them - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - String temp = System.getProperty("java.io.tmpdir"); - File tempDir = new File(temp); - File[] files = tempDir.listFiles(new FileFilter() { - - /* - * @see java.io.FileFilter#accept(java.io.File) - */ - public boolean accept(File pathname) { - return pathname.getAbsolutePath().indexOf("lwjgl") != -1 && isInstallDirectory(pathname); - } - - /** - * Checks whether the specified directory is an install directory. - * This is done by checking for the watermark file - * @param directory Directory to check - * @return true if the directory is an install directory - */ - private boolean isInstallDirectory(File directory) { - File installFile = new File(directory.getAbsolutePath() + File.separator + ".lwjglinstaller"); - return installFile.exists(); - } - - }); - - // uninstall each of the dirs - for (int i = 0; i < files.length; i++) { - uninstall(files[i]); - } - return null; - } - }); - } - - /** - * Uninstall LWJGL from a directory. This deletes all the files in the directory - * and deletes the directory too. - * @param file directory to uninstall LWJGL from - */ - private static void uninstall(File file) { - File[] files = file.listFiles(); - for (int i = 0; i < files.length; i++) { - files[i].delete(); - } - file.delete(); - } -} \ No newline at end of file Copied: trunk/LWJGL/src/java/org/lwjgl/util/applet/LWJGLInstaller.java (from rev 2419, trunk/LWJGL/src/java/org/lwjgl/applet/LWJGLInstaller.java) =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/applet/LWJGLInstaller.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/util/applet/LWJGLInstaller.java 2006-07-03 11:30:30 UTC (rev 2420) @@ -0,0 +1,312 @@ +/* + * Copyright (c) 2006 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.util.applet; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileFilter; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.security.PrivilegedExceptionAction; + +import org.lwjgl.LWJGLUtil; + +/** + * <p> + * + * </p> + * @author Brian Matzon <br...@ma...> + * @version $Revision$ + * $Id$ + */ +public class LWJGLInstaller { + + /** + * Files to install for each supported platform + * @see org.lwjgl.LWJGLUtil#getPlatform() + */ + public static final String[][] PLATFORM_FILES = { + { "lwjgl", "lwjgl-fmod3", "lwjgl-devil", "openal", "fmod", "IL", "ILU", "ILUT", "jinput-osx"}, + { "lwjgl", "lwjgl-fmod3", "lwjgl-devil", "openal", "fmod", "IL", "ILU", "ILUT", "jinput-linux"}, + { "lwjgl", "lwjgl-fmod3", "lwjgl-devil", "OpenAL32", "fmod", "DevIL", "ILU", "ILUT", "jinput-dx8", "jinput-raw"} + }; + + /** Whether the installer has been called */ + public static boolean installed; + + /** Whether to hook uninstall rutine. Must be called prior to installation */ + public static boolean disableUninstall = false; + + /** Buffer used when copying files */ + private static final byte[] COPY_BUFFER = new byte[4096]; + + private LWJGLInstaller() { + /* Unused */ + } + + /** + * Create a temporary installation of LWJGL. + * This will extract the relevant native files (for the platform) into + * the users temp directory, and instruct the LWJGL subsystem to load its + * native files from there. + * The files required by the installer, are gotten from the classloader via its + * getResource command, and are assumed to in the path: /native/<win32|linux|macosx>/ + * Any call to this method will also add a shutdown hook to the uninstall of the libraries + * Note: Due to the nature of native libraries, we cannot actually uninstall the currently + * loaded files, but rather the "last" installed. This means that the most recent install of LWJGL + * will always be present in the users temp dir. + * + * @see java.lang.ClassLoader#getResource(String) + */ + public static void tempInstall() throws Exception { + // only need to install once + if (installed) { + return; + } + + try { + // libraries to validate and install + String[] libraries = PLATFORM_FILES[LWJGLUtil.getPlatform() - 1]; + + // Validate the certificates of the native files + validateCertificates(); + + // install shutdown installer hook + if(!disableUninstall) { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + Runtime.getRuntime().addShutdownHook(new Thread() { + public void run() { + uninstall(); + } + }); + return null; + } + }); + } + + // create a temporary dir for the native files + String user_temp_dir = getPriviledgedString("java.io.tmpdir"); + final String path = createTemporaryDir(user_temp_dir); + + // extract natives + for (int i = 0; i < libraries.length; i++) { + String library = System.mapLibraryName(libraries[i]); + extract(library, path); + } + + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + System.setProperty("org.lwjgl.librarypath", path); + return null; + } + }); + } catch (Exception e) { + LWJGLUtil.log("Failed extraction e = " + e.getMessage()); + uninstall(); + throw e; + } + } + + /** + * Validates the certificates of the native libraries. + * When installing native libraries, it is imperative that we also check the certficates. + * The reson for this, is that a user may inject a malicious jar to the classpath + * before the "real" LWJGL jar, containing native libraries with unwanted code. + * By forcing all the native libraries to have the same certificate as the signed + * installer, we can also be sure that the native libraries indeed are correct. + * @throws Exception If we encounter a certificate mismatch + */ + private static void validateCertificates() throws Exception { + /* TODO */ + } + + /** + * Extracts a file in the classpath to a specified dir + * + * @param file File to extract + * @param path Path to extract to + */ + private static void extract(final String file, final String path) { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + // check for existing file, and get out + File out = new File(path + File.separator + file); + if (out.exists()) { + return null; + } + + // create the new file and copy it to its destination + try { + out.createNewFile(); + String in = "/native/" + LWJGLUtil.getPlatformName() + "/" + file; + OutputStream os = new BufferedOutputStream(new FileOutputStream(out)); + InputStream is = new BufferedInputStream(getClass().getResourceAsStream(in)); + + // Sanity check + // =========================================== + if (os == null) { + LWJGLUtil.log("Unable to write to outputstream at " + out.getAbsolutePath()); + return null; + } + + if (is == null) { + LWJGLUtil.log("Unable to read classpath inputstream from " + in); + return null; + } + // ------------------------------------------- + + // copy the actual file + copyFile(is, os); + } catch (IOException ioe) { + LWJGLUtil.log("Exception while extracting " + file + ": " + ioe.getMessage()); + return null; + } + return null; + } + }); + } + + /** + * Copies an inputstream to an outputstream + * @param is InputStream to read from + * @param os OutputStream to write to + * @throws IOException if the copy process fail in any way + */ + static void copyFile(InputStream is, OutputStream os) throws IOException { + int len; + while ((len = is.read(COPY_BUFFER)) > 0) { + os.write(COPY_BUFFER, 0, len); + } + is.close(); + os.close(); + } + + /** + * Creates the temporary dir to store lwjgl files in. + * The temporary dir will be created in the users temp dir and + * called 'lwjgl-' and appended System.currentTimeMillis(). A watermark file + * called '.lwjglinstaller' will also be created in the directory. + * @return Name of temp directory or null if directory creation failed + */ + static String createTemporaryDir(final String user_temp_dir) throws Exception { + return (String) AccessController.doPrivileged(new PrivilegedExceptionAction() { + public Object run() throws Exception { + // create the temp directory + File tempDir = new File(user_temp_dir + File.separator + "lwjgl-" + System.currentTimeMillis()); + if(!tempDir.mkdir()) { + throw new IOException("Failed to create directory: " + tempDir); + } + + // add the watermark file + // TODO: Write some info to the file ? + File watermark = new File(tempDir.getAbsolutePath() + File.separator + ".lwjglinstaller"); + watermark.createNewFile(); + return tempDir.getAbsolutePath(); + } + }); + } + + + /** + * Gets a property as a privileged action. + */ + private static String getPriviledgedString(final String property) { + return (String) AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + return System.getProperty(property); + } + }); + } + + /** + * Uninstalls any PREVIOUS installations + * We cannot uninstall the current installation, since the files are locked + * by the VM. + */ + private static void uninstall() { + LWJGLUtil.log("running LWJGL uninstaller"); + + // locate all installer dirs and uninstall them + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + String temp = System.getProperty("java.io.tmpdir"); + File tempDir = new File(temp); + File[] files = tempDir.listFiles(new FileFilter() { + + /* + * @see java.io.FileFilter#accept(java.io.File) + */ + public boolean accept(File pathname) { + return pathname.getAbsolutePath().indexOf("lwjgl") != -1 && isInstallDirectory(pathname); + } + + /** + * Checks whether the specified directory is an install directory. + * This is done by checking for the watermark file + * @param directory Directory to check + * @return true if the directory is an install directory + */ + private boolean isInstallDirectory(File directory) { + File installFile = new File(directory.getAbsolutePath() + File.separator + ".lwjglinstaller"); + return installFile.exists(); + } + + }); + + // uninstall each of the dirs + for (int i = 0; i < files.length; i++) { + uninstall(files[i]); + } + return null; + } + }); + } + + /** + * Uninstall LWJGL from a directory. This deletes all the files in the directory + * and deletes the directory too. + * @param file directory to uninstall LWJGL from + */ + private static void uninstall(File file) { + File[] files = file.listFiles(); + for (int i = 0; i < files.length; i++) { + files[i].delete(); + } + file.delete(); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |