org.jrabbit.base.directory
Class EngineDirectory

java.lang.Object
  extended by org.jrabbit.base.directory.EngineDirectory

public class EngineDirectory
extends java.lang.Object

Provides some convenience methods for managing files and folders to store data. All methods are based out of a single main directory. The Java Rabbit Engine automatically creates this folder on the user's computer where it stores any data it needs on the computer. This ranges from the native libraries required to run OpenGL, or to saved games that need to persist between plays. This automatic folder creation is required for the engine to run from a desktop. The directory has a default name (jRabbit Data) and location (which varies by OS). Both of these things can be changed at game startup, but once jRabbit is fully initialized certain things are in place and changing these settings is disabled.

Author:
Chris Molini

Field Summary
private static java.io.File directory
          When EngineDirectory is initialized, the settings for directory name are locked and this File is created from them.
private static java.lang.String directoryName
          The name of the folder that all jRabbit data will be contained in.
private static boolean hidden
          Whether or not the folder should be made as hidden.
private static java.lang.String rootDirectory
          The path to the parent directory our main directory.
 
Constructor Summary
EngineDirectory()
           
 
Method Summary
private static java.lang.String defaultDirectory()
          Calculates the default directory location.
static java.io.File directory()
          Returns a File that references the main directory.
static java.lang.String directoryName()
          Accesses the name of the directory.
static java.lang.String directoryPath()
          Retrieves the complete path to the directory.
static boolean hidden()
          Learns whether or not the directory is set to be hidden.
static void init()
          Initializes the directory; after this the developer is not allowed to change the references to location or folder name.
static boolean makeSubDirectory(java.lang.String subPath)
          Convenience method to create a folder or folders inside the main directory.
static boolean setDirectoryLocation(java.lang.String path)
          Attempts to change the location of the root directory.
static boolean setDirectoryName(java.lang.String name)
          Attempts to change the name of the folder where data is stored.
static boolean setHideDirectory(boolean hide)
          Attempts to set whether or not the directory should be null.
static java.io.File subDirectory(java.lang.String subPath)
          Gets a reference to a folder within the main directory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hidden

private static boolean hidden
Whether or not the folder should be made as hidden. NOTE: For Linux computers, this is set to true by default.


rootDirectory

private static java.lang.String rootDirectory
The path to the parent directory our main directory. The default value is based on OS.


directoryName

private static java.lang.String directoryName
The name of the folder that all jRabbit data will be contained in.


directory

private static java.io.File directory
When EngineDirectory is initialized, the settings for directory name are locked and this File is created from them.

Constructor Detail

EngineDirectory

public EngineDirectory()
Method Detail

defaultDirectory

private static java.lang.String defaultDirectory()
Calculates the default directory location. The computer is recognized as a Windows, Linux, or Macintosh machine, then the root directory is placed in the "application data" directory for each: ../AppData/, ../local/, and ../Application Support/, respectively. If the machine is not registered as any of these, the directory defaults to the same one the game is run from.

Returns:
The default directory location, based upon the OS running the game.

setDirectoryLocation

public static boolean setDirectoryLocation(java.lang.String path)
Attempts to change the location of the root directory. If the directory has already been initialized, the operation does not work.

Parameters:
path - The new location of the main engine directory.
Returns:
True if the operation succeeded (which means the directory has not been initialized yet), false if not.

setDirectoryName

public static boolean setDirectoryName(java.lang.String name)
Attempts to change the name of the folder where data is stored. Does not work if the directory has been initialized.

Parameters:
name - The new name for the directory.
Returns:
True if the operation was a success, false if the directory has already been initialized.

directoryName

public static java.lang.String directoryName()
Accesses the name of the directory.

Returns:
The name of the folder where jRabbit data is stored.

directoryPath

public static java.lang.String directoryPath()
Retrieves the complete path to the directory.

Returns:
The path to the directory; this is a simple combination of the directory location and the name of the directory.

hidden

public static boolean hidden()
Learns whether or not the directory is set to be hidden.

Returns:
True if the folder is hidden, false if not.

setHideDirectory

public static boolean setHideDirectory(boolean hide)
Attempts to set whether or not the directory should be null.

Parameters:
hide - True if the directory should be hidden, false if not.
Returns:
True if the operation succeeded (if the directory was not initialized), false if not.

directory

public static java.io.File directory()
Returns a File that references the main directory. If null, then the directory has not been initialized and the developer may still make changes to its location or name.

Returns:
The File object that corresponds to the main directory.

init

public static void init()
Initializes the directory; after this the developer is not allowed to change the references to location or folder name.


makeSubDirectory

public static boolean makeSubDirectory(java.lang.String subPath)
Convenience method to create a folder or folders inside the main directory.

Parameters:
subPath - The path to the subfolder.
Returns:
Whether or not the attempt to create the subdirectory succeeded.

subDirectory

public static java.io.File subDirectory(java.lang.String subPath)
Gets a reference to a folder within the main directory.

Parameters:
subPath - The path to the subfolder.
Returns:
A reference to a file object pointing to a folder within the directory.