Package org.lwjgl.util.applet
Class AppletLoader
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- java.awt.Panel
-
- java.applet.Applet
-
- org.lwjgl.util.applet.AppletLoader
-
- All Implemented Interfaces:
AppletStub
,ImageObserver
,MenuContainer
,Serializable
,Runnable
,Accessible
public class AppletLoader extends Applet implements Runnable, 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:
- al_main - [String] Full package and class the applet to instantiate and display when loaded.
- al_jars - [String] Comma separated list of jars to download.
- al_windows - [String] Jar containing native files for windows.
- al_linux - [String] Jar containing native files for linux.
- al_mac - [String] Jar containing native files for mac.
- al_solaris - [String] Jar containing native files for solaris.
- al_freebsd - [String] Jar containing native files for freebsd.
- al_openbsd - [String] Jar containing native files for openbsd.
Additionally the following parameters can be supplied to tweak the behaviour of the AppletLoader.
- al_cache - [boolean] Whether to use cache system. Default: true.
- al_version - [int or float] Version of deployment. If this is specified, the jars will be cached and reused if the version matches. If version doesn't match all of the files are reloaded.
- al_debug - [boolean] Whether to enable debug mode. Default: false.
- al_min_jre - [String] Specify the minimum jre version that the applet requires, should be in format like 1.6.0_24 or a subset like 1.6 Default: 1.5.
- al_prepend_host - [boolean] Whether to limit caching to this domain, disable if your applet is hosted on multiple domains and needs to share the cache. Default: true.
- al_lookup_threads - [int] Specify the number of concurrent threads to use to get file information before downloading. Default: 1.
- al_windows64 - [String] If specified it will be used instead of al_windows on 64bit windows systems.
- al_windows32 - [String] If specified it will be used instead of al_windows on 32bit windows systems.
- al_linux64 - [String] If specified it will be used instead of al_linux on 64bit linux systems.
- al_linux32 - [String] If specified it will be used instead of al_linux on 32bit linux systems.
- al_mac32 - [String] If specified it will be used instead of al_mac on 64bit mac systems.
- al_mac64 - [String] If specified it will be used instead of al_mac on 32bit mac systems.
- al_macppc - [String] If specified it will be used instead of al_mac on PPC mac systems.
- boxbgcolor - [String] any String AWT color ("red", "blue", etc), RGB (0-255) or hex formated color (#RRGGBB) to use as background. Default: #ffffff.
- boxfgcolor - [String] any String AWT color ("red", "blue", etc), RGB (0-255) or hex formated color (#RRGGBB) to use as foreground. Default: #000000.
- al_logo - [String Path of of the logo resource to paint while loading.Default: "appletlogo.gif".
- al_progressbar - [String] Path of the progressbar resource to paint on top of the logo, width clipped by percentage.Default: "appletprogress.gif".
- lwjgl_arguments - [String] used to pass LWJGL parameters to LWJGL e.g. ("-Dorg.lwjgl.input.Mouse.allowNegativeMouseCoords=true -Dorg.lwjgl.util.Debug=true").
- Version:
- $Revision$
$Id$
Contributors:
- Arielsan
- Bobjob
- Dashiva
- Dr_evil
- Elias Naur
- Kevin Glass
- Matthias Mann
- Mickelukas
- NateS
- Pelle Johnsen
- Riven
- Ruben01
- Shannon Smith
- Author:
- kappaOne
, Brian Matzon - See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.applet.Applet
Applet.AccessibleApplet
-
Nested classes/interfaces inherited from class java.awt.Panel
Panel.AccessibleAWTPanel
-
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
-
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
-
Field Summary
Fields Modifier and Type Field Description protected Thread
animationThread
animation thread that renders our load screen while loadingprotected Color
bgColor
background color of appletprotected boolean
cacheEnabled
whether to use caching system, only download files that have changedprotected boolean
certificateRefused
whether a certificate refused error occurredprotected String[]
certificateRefusedMessage
error message to display if user refuses to accept certificateprotected ClassLoader
classLoader
classLoader used to add downloaded jars to the classpathprotected int
concurrentLookupThreads
threads to use when fetching information of files to be downloadedprotected int
currentSizeExtract
current size of extracted in bytesprotected boolean
debugMode
whether we're running in debug modeprotected String[]
errorMessage
fatal error message to displayprotected boolean
fatalError
whether a fatal error occurredprotected Color
fgColor
color to write foreground inprotected int[]
fileSizes
Sizes of files to downloadprotected HashMap<String,Long>
filesLastModified
Used to store file names with lastModified timeprotected String[]
genericErrorMessage
generic error message to display on errorprotected boolean
headless
whether to run in headless modeprotected String[]
headlessMessage
messages to be passed via liveconnect in headless modeprotected boolean
headlessWaiting
whether to switch applets in headless mode or wait longerprotected Thread
loaderThread
actual thread that does the loadingprotected Image
logo
logo to be shown while loadingprotected Image
logoBuffer
logo to be shown while loadingprotected Applet
lwjglApplet
applet to load after all downloads are completeprotected boolean
lzmaSupported
whether lzma is supportedprotected String[]
minimumJREMessage
error message to display if minimum JRE version is not metprotected boolean
minimumJreNotFound
whether the minimum required JRE version is not foundprotected int
nativeJarCount
Number of native jarsprotected static boolean
natives_loaded
have natives been loaded by another instance of this appletprotected Image
offscreen
offscreen image usedprotected boolean
pack200Supported
whether pack200 is supportedprotected boolean
painting
set to true while painting is doneprotected int
percentage
used to calculate length of progress barprotected boolean
prependHost
whether to prepend host to cache pathprotected Image
progressbar
progressbar to render while loadingprotected Image
progressbarBuffer
progressbar to render while loadingprotected int
state
state of applet loaderstatic int
STATE_CHECK_JRE_VERSION
checking version of jrestatic int
STATE_CHECKING_CACHE
checking for already downloaded filesstatic int
STATE_CHECKING_FOR_UPDATES
checking if any updates are available for cache filesstatic int
STATE_DETERMINING_PACKAGES
determining which packages that are requiredstatic int
STATE_DONE
donestatic int
STATE_DOWNLOADING
downloading packagesstatic int
STATE_EXTRACTING_PACKAGES
extracting packagesstatic int
STATE_INIT
initializingstatic int
STATE_INITIALIZE_REAL_APPLET
initializing real appletstatic int
STATE_START_REAL_APPLET
stating real appletstatic int
STATE_SWITCHING_APPLET
switching to real appletstatic int
STATE_UPDATING_CLASSPATH
updating the classpathstatic int
STATE_VALIDATING_PACKAGES
validating packagesprotected String
subtaskMessage
String to display as a subtaskprotected int
totalDownloadSize
total size of download in bytesprotected int
totalSizeExtract
total size of extracted in bytesprotected 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
Constructors Constructor Description AppletLoader()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
appletResize(int width, int height)
Transfers the call of AppletResize from the stub to the lwjglApplet.protected static boolean
certificatesMatch(Certificate[] certs1, Certificate[] certs2)
Compare two certificate chains to see if they matchprotected void
cleanUp()
Clean up resourcesprotected boolean
compareVersion(File versionFile, 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 enabledvoid
destroy()
protected void
downloadJars(String path)
Will download the jars from the server using the list of urls in urlList, while at the same time updating progress barprotected void
extractGZip(String in, String out)
Extract GZip Fileprotected void
extractJars(String path)
Extract all jars from any lzma/gz/pack filesprotected void
extractLZMA(String in, String out)
Extract LZMA Fileprotected void
extractNatives(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 properlyprotected void
fatalErrorOccured(String error, Exception e)
Sets the error message and print debug informationApplet
getApplet()
Retrieves the applet that has been loaded.protected boolean
getBooleanParameter(String name, boolean defaultValue)
Retrieves the boolean value for the parameterprotected String
getCacheDirectory()
This method will return the location of the cache directory.protected Color
getColor(String param, Color defaultColor)
Retrieves the colorprotected static Certificate[]
getCurrentCertificates()
Returns the current certificate chain of the AppletLoaderprotected String
getDescriptionForState()
protected String
getFileName(URL url)
Get file name portion of URL.protected Image
getImage(String s)
Get Image from path providedImage
getImage(URL url)
Get Image from path providedprotected int
getIntParameter(String name, int defaultValue)
Retrieves the int value for the appletprotected void
getJarInfo(File dir)
This method will get the files sizes of the files to download.protected InputStream
getJarInputStream(String currentFile, URLConnection urlconnection)
Retrieves a jar files input stream.protected String
getJarName(URL url)
Get jar name from URL.protected String
getLWJGLCacheDir()
Get path to the lwjgl cache directory.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 String
getStringParameter(String name, String defaultValue)
Retrieves the String value for the parameterboolean
imageUpdate(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(File file)
This method will check if a zip file is valid by running through it and checking for any corruption and CRC failuresprotected 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 urlListvoid
paint(Graphics g)
protected HashMap<String,Long>
readHashMapFile(File file)
read the HashMap from Fileprotected Object
readObjectFile(File file)
read the object from the Fileprotected String
readStringFile(File file)
read String object from FileString
replaceLast(String original, String target, 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 appletprotected 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 loaderprotected void
sleep(long ms)
Utility method for sleepingvoid
start()
void
stop()
protected void
switchApplet()
replace the current applet with the lwjgl applet using AppletStub and initialise and start itprotected String
trimExtensionByCapabilities(String file)
Trims the passed file string based on the available capabilitiesvoid
update(Graphics g)
protected void
updateClassPath(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(String path)
Check and validate jars which will be loaded into the classloader to make sure that they are not corrupt.protected void
writeObjectFile(File file, 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, isValidateRoot, newAudioClip, play, play, resize, resize, setStub, showStatus
-
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, 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, 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, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, reshape, revalidate, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setMixingCutoutShape, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, 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
-
totalDownloadSize
protected int totalDownloadSize
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 Image logo
logo to be shown while loading
-
logoBuffer
protected Image logoBuffer
logo to be shown while loading
-
progressbar
protected Image progressbar
progressbar to render while loading
-
progressbarBuffer
protected Image progressbarBuffer
progressbar to render while loading
-
offscreen
protected Image offscreen
offscreen image used
-
painting
protected boolean painting
set to true while painting is done
-
bgColor
protected Color bgColor
background color of applet
-
fgColor
protected Color fgColor
color to write foreground in
-
urlList
protected URL[] urlList
urls of the jars to download
-
classLoader
protected ClassLoader classLoader
classLoader used to add downloaded jars to the classpath
-
loaderThread
protected Thread loaderThread
actual thread that does the loading
-
animationThread
protected Thread animationThread
animation thread that renders our load screen while loading
-
lwjglApplet
protected 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 HashMap<String,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 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 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 String[] genericErrorMessage
generic error message to display on error
-
certificateRefusedMessage
protected String[] certificateRefusedMessage
error message to display if user refuses to accept certificate
-
minimumJREMessage
protected String[] minimumJREMessage
error message to display if minimum JRE version is not met
-
errorMessage
protected String[] errorMessage
fatal error message to display
-
natives_loaded
protected static boolean natives_loaded
have natives been loaded by another instance of this applet
-
-
Method Detail
-
cleanUp
protected void cleanUp()
Clean up resources
-
getApplet
public 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 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 interfaceAppletStub
-
imageUpdate
public boolean imageUpdate(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 interfaceImageObserver
- Overrides:
imageUpdate
in classComponent
-
getDescriptionForState
protected String getDescriptionForState()
- Returns:
- string describing the state of the loader
-
trimExtensionByCapabilities
protected String trimExtensionByCapabilities(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 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:
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
-
isMinJREVersionAvailable
public boolean isMinJREVersionAvailable() throws 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:
Exception
- a NumberFormatException is thrown if the string is not valid
-
compareVersion
protected boolean compareVersion(File versionFile, 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 informationversion
- - 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 String getCacheDirectory() throws 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:
Exception
- if access is denied
-
getLWJGLCacheDir
protected 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 String readStringFile(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 HashMap<String,Long> readHashMapFile(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 Object readObjectFile(File file) throws 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:
Exception
- if it fails to read object from file
-
writeObjectFile
protected void writeObjectFile(File file, Object object) throws Exception
write object to specified File- Parameters:
file
- the file to write out toobject
- the contents of the file- Throws:
Exception
- if it fails to write file
-
updateClassPath
protected void updateClassPath(String path) throws 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:
Exception
- if it fails to add classpath
-
switchApplet
protected void switchApplet() throws Exception
replace the current applet with the lwjgl applet using AppletStub and initialise and start it- Throws:
Exception
-
getJarInfo
protected void getJarInfo(File dir) throws 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:
Exception
- - if fails to get infomation
-
downloadJars
protected void downloadJars(String path) throws 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:
Exception
- if download fails
-
getJarInputStream
protected InputStream getJarInputStream(String currentFile, URLConnection urlconnection) throws 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:
Exception
-
extractLZMA
protected void extractLZMA(String in, String out) throws Exception
Extract LZMA File- Parameters:
in
- Input path to pack fileout
- output path to resulting file- Throws:
Exception
- if any errors occur
-
extractGZip
protected void extractGZip(String in, String out) throws Exception
Extract GZip File- Parameters:
in
- Input path to pack fileout
- output path to resulting file- Throws:
Exception
- if any errors occur
-
extractJars
protected void extractJars(String path) throws Exception
Extract all jars from any lzma/gz/pack files- Parameters:
path
- output path- Throws:
Exception
- if any errors occur
-
extractNatives
protected void extractNatives(String path) throws 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:
Exception
- if it fails to extract files
-
certificatesMatch
protected static boolean certificatesMatch(Certificate[] certs1, Certificate[] certs2) throws Exception
Compare two certificate chains to see if they match- Parameters:
certs1
- first chain of certificatescerts2
- second chain of certificates- Returns:
- true if the certificate chains are the same
- Throws:
Exception
-
getCurrentCertificates
protected static Certificate[] getCurrentCertificates() throws Exception
Returns the current certificate chain of the AppletLoader- Returns:
- - certificate chain of AppletLoader
- Throws:
Exception
-
validateJars
protected void validateJars(String path) throws 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:
Exception
- if a corrupt jar is found
-
isZipValid
protected boolean isZipValid(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 Image getImage(String s)
Get Image from path provided- Parameters:
s
- location of the image- Returns:
- the Image file
-
getJarName
protected String getJarName(URL url)
Get jar name from URL.- Parameters:
url
- Get jar file name from this url- Returns:
- file name as string
-
getFileName
protected String getFileName(URL url)
Get file name portion of URL.- Parameters:
url
- Get file name from this url- Returns:
- file name as string
-
getColor
protected Color getColor(String param, Color defaultColor)
Retrieves the color- Parameters:
param
- Color to loaddefaultColor
- Default color to use if no color to load- Returns:
- Color to use
-
replaceLast
public String replaceLast(String original, String target, String replacement)
Replaces the last occurrence of the specified target substring with the specified replacement string in a string.- Parameters:
original
- - String to searchtarget
- - substring to findreplacement
- - what to replace target substring with- Returns:
- - return the modified string, if target substring not found return original string
-
getStringParameter
protected String getStringParameter(String name, String defaultValue)
Retrieves the String value for the parameter- Parameters:
name
- Name of parameterdefaultValue
- default value to return if no such parameter- Returns:
- value of parameter or defaultValue
-
getBooleanParameter
protected boolean getBooleanParameter(String name, boolean defaultValue)
Retrieves the boolean value for the parameter- Parameters:
name
- Name of parameterdefaultValue
- default value to return if no such parameter- Returns:
- value of parameter or defaultValue
-
getIntParameter
protected int getIntParameter(String name, int defaultValue)
Retrieves the int value for the applet- Parameters:
name
- Name of parameterdefaultValue
- default value to return if no such parameter- Returns:
- value of parameter or defaultValue
-
fatalErrorOccured
protected void fatalErrorOccured(String error, 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:
state
- 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
-
-