org.lwjgl.util.applet
Class AppletLoader

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by java.applet.Applet
                  extended by org.lwjgl.util.applet.AppletLoader
All Implemented Interfaces:
java.applet.AppletStub, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.lang.Runnable, javax.accessibility.Accessible

public class AppletLoader
extends java.applet.Applet
implements java.lang.Runnable, java.applet.AppletStub

The AppletLoader enables deployment of LWJGL to applets in an easy and polished way. The loader will display a configurable logo and progressbar while the relevant jars (generic and native) are downloaded from a specified source.

The downloaded jars are extracted to the users temporary directory - and if enabled, cached for faster loading in future uses.

The following applet parameters are required:

Additionally the following parameters can be supplied to tweak the behaviour of the AppletLoader.

Version:
$Revision$ $Id$ Contributors:
Author:
kappaOne , Brian Matzon
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.applet.Applet
java.applet.Applet.AccessibleApplet
 
Nested classes/interfaces inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  java.lang.Thread animationThread
          animation thread that renders our load screen while loading
protected  java.awt.Color bgColor
          background color of applet
protected  boolean cacheEnabled
          whether to use caching system, only download files that have changed
protected  boolean certificateRefused
          whether a certificate refused error occurred
protected  java.lang.String[] certificateRefusedMessage
          error message to display if user refuses to accept certificate
protected  java.lang.ClassLoader classLoader
          classLoader used to add downloaded jars to the classpath
protected  int concurrentLookupThreads
          threads to use when fetching information of files to be downloaded
protected  int currentSizeDownload
          current size of download in bytes
protected  int currentSizeExtract
          current size of extracted in bytes
protected  boolean debugMode
          whether we're running in debug mode
protected  java.lang.String[] errorMessage
          fatal error message to display
protected  boolean fatalError
          whether a fatal error occurred
protected  java.awt.Color fgColor
          color to write foreground in
protected  int[] fileSizes
          Sizes of files to download
protected  java.util.HashMap<java.lang.String,java.lang.Long> filesLastModified
          Used to store file names with lastModified time
protected  java.lang.String[] genericErrorMessage
          generic error message to display on error
protected  boolean headless
          whether to run in headless mode
protected  java.lang.String[] headlessMessage
          messages to be passed via liveconnect in headless mode
protected  boolean headlessWaiting
          whether to switch applets in headless mode or wait longer
protected  java.lang.Thread loaderThread
          actual thread that does the loading
protected  java.awt.Image logo
          logo to be shown while loading
protected  java.awt.Image logoBuffer
          logo to be shown while loading
protected  java.applet.Applet lwjglApplet
          applet to load after all downloads are complete
protected  boolean lzmaSupported
          whether lzma is supported
protected  java.lang.String[] minimumJREMessage
          error message to display if minimum JRE version is not met
protected  boolean minimumJreNotFound
          whether the minimum required JRE version is not found
protected  int nativeJarCount
          Number of native jars
protected static boolean natives_loaded
          have natives been loaded by another instance of this applet
protected  java.awt.Image offscreen
          offscreen image used
protected  boolean pack200Supported
          whether pack200 is supported
protected  boolean painting
          set to true while painting is done
protected  int percentage
          used to calculate length of progress bar
protected  boolean prependHost
          whether to prepend host to cache path
protected  java.awt.Image progressbar
          progressbar to render while loading
protected  java.awt.Image progressbarBuffer
          progressbar to render while loading
protected  int state
          state of applet loader
static int STATE_CHECK_JRE_VERSION
          checking version of jre
static int STATE_CHECKING_CACHE
          checking for already downloaded files
static int STATE_CHECKING_FOR_UPDATES
          checking if any updates are available for cache files
static int STATE_DETERMINING_PACKAGES
          determining which packages that are required
static int STATE_DONE
          done
static int STATE_DOWNLOADING
          downloading packages
static int STATE_EXTRACTING_PACKAGES
          extracting packages
static int STATE_INIT
          initializing
static int STATE_INITIALIZE_REAL_APPLET
          initializing real applet
static int STATE_START_REAL_APPLET
          stating real applet
static int STATE_SWITCHING_APPLET
          switching to real applet
static int STATE_UPDATING_CLASSPATH
          updating the classpath
static int STATE_VALIDATING_PACKAGES
          validating packages
protected  java.lang.String subtaskMessage
          String to display as a subtask
protected  int totalSizeDownload
          total size of download in bytes
protected  int totalSizeExtract
          total size of extracted in bytes
protected  java.net.URL[] urlList
          urls of the jars to download
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
AppletLoader()
           
 
Method Summary
 void appletResize(int width, int height)
          Transfers the call of AppletResize from the stub to the lwjglApplet.
protected static boolean certificatesMatch(java.security.cert.Certificate[] certs1, java.security.cert.Certificate[] certs2)
          Compare two certificate chains to see if they match
protected  void cleanUp()
          Clean up resources
protected  boolean compareVersion(java.io.File versionFile, java.lang.String version)
          This method will return true if the version stored in the file matches the supplied String version.
protected  void debug_sleep(long ms)
          Utility method for sleeping Will only really sleep if debug has been enabled
 void destroy()
           
protected  void downloadJars(java.lang.String path)
          Will download the jars from the server using the list of urls in urlList, while at the same time updating progress bar
protected  void extractGZip(java.lang.String in, java.lang.String out)
          Extract GZip File
protected  void extractJars(java.lang.String path)
          Extract all jars from any lzma/gz/pack files
protected  void extractLZMA(java.lang.String in, java.lang.String out)
          Extract LZMA File
protected  void extractNatives(java.lang.String path)
          This method will extract all file from the native jar and extract them to the subdirectory called "natives" in the local path, will also check to see if the native jar files is signed properly
protected  void extractPack(java.lang.String in, java.lang.String out)
          Extract Pack File
protected  void fatalErrorOccured(java.lang.String error, java.lang.Exception e)
          Sets the error message and print debug information
 java.applet.Applet getApplet()
          Retrieves the applet that has been loaded.
protected  boolean getBooleanParameter(java.lang.String name, boolean defaultValue)
          Retrieves the boolean value for the parameter
protected  java.lang.String getCacheDirectory()
          This method will return the location of the cache directory.
protected  java.awt.Color getColor(java.lang.String param, java.awt.Color defaultColor)
          Retrieves the color
protected static java.security.cert.Certificate[] getCurrentCertificates()
          Returns the current certificate chain of the AppletLoader
protected  java.lang.String getDescriptionForState()
           
protected  java.lang.String getFileName(java.net.URL url)
          Get file name portion of URL.
protected  java.awt.Image getImage(java.lang.String s)
          Get Image from path provided
 java.awt.Image getImage(java.net.URL url)
          Get Image from path provided
protected  int getIntParameter(java.lang.String name, int defaultValue)
          Retrieves the int value for the applet
protected  void getJarInfo(java.io.File dir)
          This method will get the files sizes of the files to download.
protected  java.io.InputStream getJarInputStream(java.lang.String currentFile, java.net.URLConnection urlconnection)
          Retrieves a jar files input stream.
protected  java.lang.String getJarName(java.net.URL url)
          Get jar name from URL.
protected  java.lang.String getLWJGLCacheDir()
          Get path to the lwjgl cache directory.
 java.lang.String[] getMessages()
          Retrieves the current message for the current status.
 int getStatus()
          Retrieves the current status of the AppletLoader and is used by liveconnect when running in headless mode.
protected  java.lang.String getStringParameter(java.lang.String name, java.lang.String defaultValue)
          Retrieves the String value for the parameter
 boolean imageUpdate(java.awt.Image img, int flag, int x, int y, int width, int height)
          When an animated gif frame is ready to be drawn the ImageObserver will call this method.
 void init()
           
 boolean isMinJREVersionAvailable()
          When this method is supplied with a JRE version it will compare it to the current JRE version.
protected  boolean isZipValid(java.io.File file)
          This method will check if a zip file is valid by running through it and checking for any corruption and CRC failures
protected  void loadJarURLs()
          Reads list of jars to download and adds the urls to urlList also finds out which OS you are on and adds appropriate native jar to the urlList
 void paint(java.awt.Graphics g)
           
protected  java.util.HashMap<java.lang.String,java.lang.Long> readHashMapFile(java.io.File file)
          read the HashMap from File
protected  java.lang.Object readObjectFile(java.io.File file)
          read the object from the File
protected  java.lang.String readStringFile(java.io.File file)
          read String object from File
 java.lang.String replaceLast(java.lang.String original, java.lang.String target, java.lang.String replacement)
          Replaces the last occurrence of the specified target substring with the specified replacement string in a string.
 void run()
          9 steps 1) check jre version meets minimum requirements 2) check applet cache and decide which jars to download 3) download the jars 4) extract native files 5) validate jars for any corruption 6) save applet cache information 7) add jars to class path 8) set any lwjgl properties 9) switch to loaded applet
protected  void setLWJGLProperties()
          Parses the java_arguments list and sets lwjgl specific properties accordingly, before the launch.
protected  void setState(int state)
          set the state of applet loader
protected  void sleep(long ms)
          Utility method for sleeping
 void start()
           
 void stop()
           
protected  void switchApplet()
          replace the current applet with the lwjgl applet using AppletStub and initialise and start it
protected  java.lang.String trimExtensionByCapabilities(java.lang.String file)
          Trims the passed file string based on the available capabilities
 void update(java.awt.Graphics g)
           
protected  void updateClassPath(java.lang.String path)
          Edits the ClassPath at runtime to include the jars that have just been downloaded and then adds the lwjgl natives folder property.
protected  void validateJars(java.lang.String path)
          Check and validate jars which will be loaded into the classloader to make sure that they are not corrupt.
protected  void writeObjectFile(java.io.File file, java.lang.Object object)
          write object to specified File
 
Methods inherited from class java.applet.Applet
getAccessibleContext, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getLocale, getParameter, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.applet.AppletStub
getAppletContext, getCodeBase, getDocumentBase, getParameter, isActive
 

Field Detail

STATE_INIT

public static final int STATE_INIT
initializing

See Also:
Constant Field Values

STATE_CHECK_JRE_VERSION

public static final int STATE_CHECK_JRE_VERSION
checking version of jre

See Also:
Constant Field Values

STATE_DETERMINING_PACKAGES

public static final int STATE_DETERMINING_PACKAGES
determining which packages that are required

See Also:
Constant Field Values

STATE_CHECKING_CACHE

public static final int STATE_CHECKING_CACHE
checking for already downloaded files

See Also:
Constant Field Values

STATE_CHECKING_FOR_UPDATES

public static final int STATE_CHECKING_FOR_UPDATES
checking if any updates are available for cache files

See Also:
Constant Field Values

STATE_DOWNLOADING

public static final int STATE_DOWNLOADING
downloading packages

See Also:
Constant Field Values

STATE_EXTRACTING_PACKAGES

public static final int STATE_EXTRACTING_PACKAGES
extracting packages

See Also:
Constant Field Values

STATE_VALIDATING_PACKAGES

public static final int STATE_VALIDATING_PACKAGES
validating packages

See Also:
Constant Field Values

STATE_UPDATING_CLASSPATH

public static final int STATE_UPDATING_CLASSPATH
updating the classpath

See Also:
Constant Field Values

STATE_SWITCHING_APPLET

public static final int STATE_SWITCHING_APPLET
switching to real applet

See Also:
Constant Field Values

STATE_INITIALIZE_REAL_APPLET

public static final int STATE_INITIALIZE_REAL_APPLET
initializing real applet

See Also:
Constant Field Values

STATE_START_REAL_APPLET

public static final int STATE_START_REAL_APPLET
stating real applet

See Also:
Constant Field Values

STATE_DONE

public static final int STATE_DONE
done

See Also:
Constant Field Values

percentage

protected volatile int percentage
used to calculate length of progress bar


currentSizeDownload

protected int currentSizeDownload
current size of download in bytes


totalSizeDownload

protected int totalSizeDownload
total size of download in bytes


currentSizeExtract

protected int currentSizeExtract
current size of extracted in bytes


totalSizeExtract

protected int totalSizeExtract
total size of extracted in bytes


logo

protected java.awt.Image logo
logo to be shown while loading


logoBuffer

protected java.awt.Image logoBuffer
logo to be shown while loading


progressbar

protected java.awt.Image progressbar
progressbar to render while loading


progressbarBuffer

protected java.awt.Image progressbarBuffer
progressbar to render while loading


offscreen

protected java.awt.Image offscreen
offscreen image used


painting

protected boolean painting
set to true while painting is done


bgColor

protected java.awt.Color bgColor
background color of applet


fgColor

protected java.awt.Color fgColor
color to write foreground in


urlList

protected java.net.URL[] urlList
urls of the jars to download


classLoader

protected java.lang.ClassLoader classLoader
classLoader used to add downloaded jars to the classpath


loaderThread

protected java.lang.Thread loaderThread
actual thread that does the loading


animationThread

protected java.lang.Thread animationThread
animation thread that renders our load screen while loading


lwjglApplet

protected java.applet.Applet lwjglApplet
applet to load after all downloads are complete


debugMode

protected boolean debugMode
whether we're running in debug mode


prependHost

protected boolean prependHost
whether to prepend host to cache path


filesLastModified

protected java.util.HashMap<java.lang.String,java.lang.Long> filesLastModified
Used to store file names with lastModified time


fileSizes

protected int[] fileSizes
Sizes of files to download


nativeJarCount

protected int nativeJarCount
Number of native jars


cacheEnabled

protected boolean cacheEnabled
whether to use caching system, only download files that have changed


subtaskMessage

protected java.lang.String subtaskMessage
String to display as a subtask


state

protected volatile int state
state of applet loader


lzmaSupported

protected boolean lzmaSupported
whether lzma is supported


pack200Supported

protected boolean pack200Supported
whether pack200 is supported


headless

protected boolean headless
whether to run in headless mode


headlessWaiting

protected boolean headlessWaiting
whether to switch applets in headless mode or wait longer


headlessMessage

protected java.lang.String[] headlessMessage
messages to be passed via liveconnect in headless mode


concurrentLookupThreads

protected int concurrentLookupThreads
threads to use when fetching information of files to be downloaded


fatalError

protected boolean fatalError
whether a fatal error occurred


certificateRefused

protected boolean certificateRefused
whether a certificate refused error occurred


minimumJreNotFound

protected boolean minimumJreNotFound
whether the minimum required JRE version is not found


genericErrorMessage

protected java.lang.String[] genericErrorMessage
generic error message to display on error


certificateRefusedMessage

protected java.lang.String[] certificateRefusedMessage
error message to display if user refuses to accept certificate


minimumJREMessage

protected java.lang.String[] minimumJREMessage
error message to display if minimum JRE version is not met


errorMessage

protected java.lang.String[] errorMessage
fatal error message to display


natives_loaded

protected static boolean natives_loaded
have natives been loaded by another instance of this applet

Constructor Detail

AppletLoader

public AppletLoader()
Method Detail

init

public void init()
Overrides:
init in class java.applet.Applet

start

public void start()
Overrides:
start in class java.applet.Applet

stop

public void stop()
Overrides:
stop in class java.applet.Applet

destroy

public void destroy()
Overrides:
destroy in class java.applet.Applet

cleanUp

protected void cleanUp()
Clean up resources


getApplet

public java.applet.Applet getApplet()
Retrieves the applet that has been loaded. Useful for liveconnect.


getStatus

public int getStatus()
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. If the minimum jre requirement is not met will return -3. 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.


getMessages

public java.lang.String[] getMessages()
Retrieves the current message for the current status. Used by liveconnect when running in headless mode.


appletResize

public void appletResize(int width,
                         int height)
Transfers the call of AppletResize from the stub to the lwjglApplet.

Specified by:
appletResize in interface java.applet.AppletStub

update

public final void update(java.awt.Graphics g)
Overrides:
update in class java.awt.Container

paint

public void paint(java.awt.Graphics g)
Overrides:
paint in class java.awt.Container

imageUpdate

public boolean imageUpdate(java.awt.Image img,
                           int flag,
                           int x,
                           int y,
                           int width,
                           int height)
When an animated gif frame is ready to be drawn the ImageObserver will call this method. The Image frame is copied into a buffer, which is then drawn. This is done to prevent image tearing on gif animations.

Specified by:
imageUpdate in interface java.awt.image.ImageObserver
Overrides:
imageUpdate in class java.awt.Component

getDescriptionForState

protected java.lang.String getDescriptionForState()
Returns:
string describing the state of the loader

trimExtensionByCapabilities

protected java.lang.String trimExtensionByCapabilities(java.lang.String file)
Trims the passed file string based on the available capabilities

Parameters:
file - string of files to be trimmed
Returns:
trimmed string based on capabilities of client

loadJarURLs

protected void loadJarURLs()
                    throws java.lang.Exception
Reads list of jars to download and adds the urls to urlList also finds out which OS you are on and adds appropriate native jar to the urlList

Throws:
java.lang.Exception

run

public void run()
9 steps 1) check jre version meets minimum requirements 2) check applet cache and decide which jars to download 3) download the jars 4) extract native files 5) validate jars for any corruption 6) save applet cache information 7) add jars to class path 8) set any lwjgl properties 9) switch to loaded applet

Specified by:
run in interface java.lang.Runnable

isMinJREVersionAvailable

public boolean isMinJREVersionAvailable()
                                 throws java.lang.Exception
When this method is supplied with a JRE version it will compare it to the current JRE version. minimum requried JRE version is set using al_min_jre parameter, if not this is not set then the value will default to version 1.5 The minimumVersion should follow a structure such as x.x.x_x Example values would include 1.6.0_10 or a subset like 1.6.0 or 1.6

Returns:
returns true if the available version is greater or equal to the minimum version required
Throws:
java.lang.Exception - a NumberFormatException is thrown if the string is not valid

compareVersion

protected boolean compareVersion(java.io.File versionFile,
                                 java.lang.String version)
This method will return true if the version stored in the file matches the supplied String version.

Parameters:
versionFile - - location to file containing version information
version - - String version that needs to be compared
Returns:
returns true if the version in file matches specified version

setLWJGLProperties

protected void setLWJGLProperties()
Parses the java_arguments list and sets lwjgl specific properties accordingly, before the launch.


getCacheDirectory

protected java.lang.String getCacheDirectory()
                                      throws java.lang.Exception
This method will return the location of the cache directory. All the applet files will be downloaded and stored here. A folder will be created inside the LWJGL cache directory from the al_title parameter. This folder will also be prepended by the host name of the codebase to avoid conflict with same named applets on other hosts.

Returns:
path to applets cache directory
Throws:
java.lang.Exception - if access is denied

getLWJGLCacheDir

protected java.lang.String getLWJGLCacheDir()
Get path to the lwjgl cache directory. This location will be where the OS keeps temporary files.

Returns:
path to the lwjgl cache directory

readStringFile

protected java.lang.String readStringFile(java.io.File file)
read String object from File

Parameters:
file - to be read
Returns:
the String stored in the file or null if it fails

readHashMapFile

protected java.util.HashMap<java.lang.String,java.lang.Long> readHashMapFile(java.io.File file)
read the HashMap from File

Parameters:
file - the file to read
Returns:
the hashmap stored in the file or an empty hashmap if it fails

readObjectFile

protected java.lang.Object readObjectFile(java.io.File file)
                                   throws java.lang.Exception
read the object from the File

Parameters:
file - the file to read
Returns:
the object contained in the file or null if it fails
Throws:
java.lang.Exception - if it fails to read object from file

writeObjectFile

protected void writeObjectFile(java.io.File file,
                               java.lang.Object object)
                        throws java.lang.Exception
write object to specified File

Parameters:
file - the file to write out to
object - the contents of the file
Throws:
java.lang.Exception - if it fails to write file

updateClassPath

protected void updateClassPath(java.lang.String path)
                        throws java.lang.Exception
Edits the ClassPath at runtime to include the jars that have just been downloaded and then adds the lwjgl natives folder property.

Parameters:
path - location where applet is stored
Throws:
java.lang.Exception - if it fails to add classpath

switchApplet

protected void switchApplet()
                     throws java.lang.Exception
replace the current applet with the lwjgl applet using AppletStub and initialise and start it

Throws:
java.lang.Exception

getJarInfo

protected void getJarInfo(java.io.File dir)
                   throws java.lang.Exception
This method will get the files sizes of the files to download. It wil further get the lastModified time of files and save it in a hashmap, if cache is enabled it will mark those files that have not changed since last download to not redownloaded.

Parameters:
dir - - location to read cache file from
Throws:
java.lang.Exception - - if fails to get infomation

downloadJars

protected void downloadJars(java.lang.String path)
                     throws java.lang.Exception
Will download the jars from the server using the list of urls in urlList, while at the same time updating progress bar

Parameters:
path - location of the directory to save to
Throws:
java.lang.Exception - if download fails

getJarInputStream

protected java.io.InputStream getJarInputStream(java.lang.String currentFile,
                                                java.net.URLConnection urlconnection)
                                         throws java.lang.Exception
Retrieves a jar files input stream. This method exists primarily to fix an Opera hang in getInputStream

Parameters:
urlconnection - connection to get input stream from
Returns:
InputStream or null if not possible
Throws:
java.lang.Exception

extractLZMA

protected void extractLZMA(java.lang.String in,
                           java.lang.String out)
                    throws java.lang.Exception
Extract LZMA File

Parameters:
in - Input path to pack file
out - output path to resulting file
Throws:
java.lang.Exception - if any errors occur

extractGZip

protected void extractGZip(java.lang.String in,
                           java.lang.String out)
                    throws java.lang.Exception
Extract GZip File

Parameters:
in - Input path to pack file
out - output path to resulting file
Throws:
java.lang.Exception - if any errors occur

extractPack

protected void extractPack(java.lang.String in,
                           java.lang.String out)
                    throws java.lang.Exception
Extract Pack File

Parameters:
in - Input path to pack file
out - output path to resulting file
Throws:
java.lang.Exception - if any errors occur

extractJars

protected void extractJars(java.lang.String path)
                    throws java.lang.Exception
Extract all jars from any lzma/gz/pack files

Parameters:
path - output path
Throws:
java.lang.Exception - if any errors occur

extractNatives

protected void extractNatives(java.lang.String path)
                       throws java.lang.Exception
This method will extract all file from the native jar and extract them to the subdirectory called "natives" in the local path, will also check to see if the native jar files is signed properly

Parameters:
path - base folder containing all downloaded jars
Throws:
java.lang.Exception - if it fails to extract files

certificatesMatch

protected static boolean certificatesMatch(java.security.cert.Certificate[] certs1,
                                           java.security.cert.Certificate[] certs2)
                                    throws java.lang.Exception
Compare two certificate chains to see if they match

Parameters:
cert1 - first chain of certificates
cert2 - second chain of certificates
Returns:
true if the certificate chains are the same
Throws:
java.lang.Exception

getCurrentCertificates

protected static java.security.cert.Certificate[] getCurrentCertificates()
                                                                  throws java.lang.Exception
Returns the current certificate chain of the AppletLoader

Returns:
- certificate chain of AppletLoader
Throws:
java.lang.Exception

validateJars

protected void validateJars(java.lang.String path)
                     throws java.lang.Exception
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 successful downloadeds by the cache system.

Parameters:
path - - where the jars are stored
Throws:
java.lang.Exception - if a corrupt jar is found

isZipValid

protected boolean isZipValid(java.io.File file)
This method will check if a zip file is valid by running through it and checking for any corruption and CRC failures

Parameters:
file - - zip file to test
Returns:
boolean - runs false if the file is corrupt

getImage

protected java.awt.Image getImage(java.lang.String s)
Get Image from path provided

Parameters:
s - location of the image
Returns:
the Image file

getImage

public java.awt.Image getImage(java.net.URL url)
Get Image from path provided

Overrides:
getImage in class java.applet.Applet
Parameters:
url - location of the image
Returns:
the Image file

getJarName

protected java.lang.String getJarName(java.net.URL url)
Get jar name from URL.

Parameters:
url - Get jar file name from this url
Returns:
file name as string

getFileName

protected java.lang.String getFileName(java.net.URL url)
Get file name portion of URL.

Parameters:
url - Get file name from this url
Returns:
file name as string

getColor

protected java.awt.Color getColor(java.lang.String param,
                                  java.awt.Color defaultColor)
Retrieves the color

Parameters:
param - Color to load
defaultColor - Default color to use if no color to load
Returns:
Color to use

replaceLast

public java.lang.String replaceLast(java.lang.String original,
                                    java.lang.String target,
                                    java.lang.String replacement)
Replaces the last occurrence of the specified target substring with the specified replacement string in a string.

Parameters:
original - - String to search
target - - substring to find
replacement - - what to replace target substring with
Returns:
- return the modified string, if target substring not found return original string

getStringParameter

protected java.lang.String getStringParameter(java.lang.String name,
                                              java.lang.String defaultValue)
Retrieves the String value for the parameter

Parameters:
name - Name of parameter
defaultValue - default value to return if no such parameter
Returns:
value of parameter or defaultValue

getBooleanParameter

protected boolean getBooleanParameter(java.lang.String name,
                                      boolean defaultValue)
Retrieves the boolean value for the parameter

Parameters:
name - Name of parameter
defaultValue - default value to return if no such parameter
Returns:
value of parameter or defaultValue

getIntParameter

protected int getIntParameter(java.lang.String name,
                              int defaultValue)
Retrieves the int value for the applet

Parameters:
name - Name of parameter
defaultValue - default value to return if no such parameter
Returns:
value of parameter or defaultValue

fatalErrorOccured

protected void fatalErrorOccured(java.lang.String error,
                                 java.lang.Exception e)
Sets the error message and print debug information

Parameters:
error - Error message to print

setState

protected void setState(int state)
set the state of applet loader

Parameters:
new - state of applet loader

debug_sleep

protected void debug_sleep(long ms)
Utility method for sleeping Will only really sleep if debug has been enabled

Parameters:
ms - milliseconds to sleep

sleep

protected void sleep(long ms)
Utility method for sleeping

Parameters:
ms - milliseconds to sleep


Copyright © 2002-2009 lwjgl.org. All Rights Reserved.