Package com.biglybt.platform.macosx
Class PlatformManagerImpl
- java.lang.Object
-
- com.biglybt.platform.macosx.PlatformManagerImpl
-
- All Implemented Interfaces:
AEDiagnosticsEvidenceGenerator
,PlatformManager
,PlatformManager
public class PlatformManagerImpl extends java.lang.Object implements PlatformManager, AEDiagnosticsEvidenceGenerator
Performs platform-specific operations with Mac OS X- Version:
- 1.0 Initial Version
- See Also:
PlatformManager
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
BUNDLE_ID
private java.util.HashSet
capabilitySet
private java.lang.Class<?>
claFileManager
protected static AEMonitor
class_mon
private java.lang.String
computer_name
private boolean
computer_name_tried
private Core
core
private static java.lang.String[]
EXTENSIONS
private static java.lang.String
fileBrowserName
private static LogIDs
LOGID
private static java.lang.String[]
MIMETYPES
private java.lang.Process
prevent_computer_proc
private boolean
prevent_computer_sleep
private boolean
prevent_computer_sleep_pending
private static java.lang.String[]
SCHEMES
protected static PlatformManagerImpl
singleton
-
Fields inherited from interface com.biglybt.pif.platform.PlatformManager
LOC_DOCUMENTS, LOC_DOWNLOADS, LOC_MUSIC, LOC_USER_DATA, LOC_VIDEO
-
Fields inherited from interface com.biglybt.platform.PlatformManager
ERR_UNSUPPORTED, PT_MACOSX, PT_OTHER, PT_UNIX, PT_WINDOWS, SD_ALL, SD_HIBERNATE, SD_SHUTDOWN, SD_SLEEP, USER_REQUEST_INFO, USER_REQUEST_QUESTION, USER_REQUEST_WARNING
-
-
Constructor Summary
Constructors Constructor Description PlatformManagerImpl()
Creates a new PlatformManager and initializes its capabilities
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListener(PlatformManagerListener listener)
private java.io.File
checkAndGetLocalVMOptionFile()
private void
checkCapability(PlatformManagerCapabilities capability)
protected static boolean
compileOSAScript(java.lang.CharSequence[] cmds, java.io.File destination)
Compiles a new AppleScript instance to the specified locationprotected static boolean
compileOSAScript(java.lang.CharSequence cmd, java.io.File destination)
Compiles a new AppleScript instance to the specified locationprivate boolean
containsTag(java.lang.String line, java.lang.String tag)
private void
convertToXML(java.io.File file)
void
copyFilePermissions(java.lang.String from_file_name, java.lang.String to_file_name)
void
createProcess(java.lang.String cmd, boolean inheritsHandles)
void
dispose()
Disposes system resources.private java.lang.String
findCommand(java.lang.String name)
void
generate(IndentWriter writer)
private java.io.File
getAbsoluteBundleFile()
Bundle Path is the .app file that launched vuze, usually /Applications/Vuze.appjava.lang.String
getApplicationCommandLine()
command to launch Vuzejava.lang.String
getAzComputerID()
private java.lang.String
getBundlePath()
Bundle Path is the .app file that launched vuze, usually /Applications/Vuze.appjava.lang.String
getComputerName()
java.lang.String[]
getExplicitVMOptions()
private static java.lang.String
getFileBrowserName()
Gets the preferred file browser nameprivate java.lang.Class<?>
getFileManagerClass()
private java.io.File[]
getJVMOptionFiles()
private java.lang.String
getJVMOptionRedirect()
java.io.File
getLocation(long location_id)
Get a well-known location, if defined for the platformprivate java.io.File
getLoginPList()
int
getMaxOpenFiles()
This max-open-files concept here is from linux/osx where network connections are treated as 'files'int
getPlatformType()
boolean
getPreventComputerSleep()
boolean
getRunAtLogin()
int
getShutdownTypes()
static PlatformManagerImpl
getSingleton()
Gets the platform manager singleton, which was already initializedjava.lang.String
getUserDataDirectory()
java.lang.String
getVersion()
java.io.File
getVMOptionFile()
boolean
hasCapability(PlatformManagerCapabilities capability)
Gets whether the platform manager supports a capabilityprivate boolean
hasVMOptions()
private static void
initializeSingleton()
Instantiates the singletonboolean
isAdditionalFileTypeRegistered(java.lang.String name, java.lang.String type)
Checks to see if the supplied file type is registered with this applicationboolean
isApplicationRegistered()
private boolean
isOurExt(java.lang.String ext)
private boolean
isOurMimeType(java.lang.String mimetype)
private boolean
isOurScheme(java.lang.String scheme)
java.lang.Class<?>
loadClass(java.lang.ClassLoader loader, java.lang.String class_name)
Gives a particular platform the ability to alter the class-loading methodstatic void
main(java.lang.String[] args)
protected static java.lang.String
performOSAScript(java.io.File script)
Compiles a new AppleScript instance and runs itprotected static java.lang.String
performOSAScript(java.lang.CharSequence cmd)
Compiles a new AppleScript instance and runs itprotected static java.lang.String
performOSAScript(java.lang.CharSequence[] cmds)
Compiles a new AppleScript instance and runs itvoid
performRecoverableFileDelete(java.lang.String path)
protected static java.lang.Process
performRuntimeExec(java.lang.String[] cmdargs)
void
ping(java.net.InetAddress interface_address, java.net.InetAddress target, PlatformManagerPingCallback callback)
void
playSystemAlert()
Plays the system alert (the jingle is specified by the user in System Preferences)void
registerAdditionalFileType(java.lang.String name, java.lang.String description, java.lang.String type, java.lang.String content_type)
Registers a file type with this applicationvoid
registerApplication()
void
removeListener(PlatformManagerListener listener)
void
requestUserAttention(int type, java.lang.Object data)
If the application is not active causes the application icon at the bottom to bounce until the application becomes active If the application is already active then this method does nothing.void
setExplicitVMOptions(java.lang.String[] options)
void
setPreventComputerSleep(boolean prevent_it)
void
setRunAtLogin(boolean run)
void
setTCPTOSEnabled(boolean enabled)
enable or disable the platforms support for TCP TOSboolean
setUseSystemTheme(boolean use_it)
void
showFile(java.lang.String path)
Reveals the file or directory with the platform's default browservoid
showInFinder(java.io.File path)
Shows the given file or directory in Findervoid
showInTerminal(java.io.File path)
Shows the given file or directory in Terminal by executing cd /absolute/path/tovoid
showInTerminal(java.lang.String path)
Shows the given file or directory in Terminal by executing cd /absolute/path/tovoid
shutdown(int type)
void
startup(Core _core)
boolean
testNativeAvailability(java.lang.String name)
void
traceRoute(java.net.InetAddress interface_address, java.net.InetAddress target, PlatformManagerPingCallback callback)
void
unregisterAdditionalFileType(java.lang.String name, java.lang.String type)
Removes a file-type registration
-
-
-
Field Detail
-
LOGID
private static final LogIDs LOGID
-
BUNDLE_ID
private static final java.lang.String BUNDLE_ID
- See Also:
- Constant Field Values
-
SCHEMES
private static final java.lang.String[] SCHEMES
-
MIMETYPES
private static final java.lang.String[] MIMETYPES
-
EXTENSIONS
private static final java.lang.String[] EXTENSIONS
-
singleton
protected static PlatformManagerImpl singleton
-
class_mon
protected static AEMonitor class_mon
-
fileBrowserName
private static java.lang.String fileBrowserName
-
capabilitySet
private final java.util.HashSet capabilitySet
-
computer_name
private volatile java.lang.String computer_name
-
computer_name_tried
private volatile boolean computer_name_tried
-
claFileManager
private java.lang.Class<?> claFileManager
-
core
private Core core
-
prevent_computer_sleep_pending
private boolean prevent_computer_sleep_pending
-
prevent_computer_sleep
private boolean prevent_computer_sleep
-
prevent_computer_proc
private java.lang.Process prevent_computer_proc
-
-
Method Detail
-
getSingleton
public static PlatformManagerImpl getSingleton()
Gets the platform manager singleton, which was already initialized
-
initializeSingleton
private static void initializeSingleton()
Instantiates the singleton
-
getPlatformType
public int getPlatformType()
- Specified by:
getPlatformType
in interfacePlatformManager
-
getVersion
public java.lang.String getVersion() throws PlatformManagerException
- Specified by:
getVersion
in interfacePlatformManager
- Throws:
PlatformManagerException
-
setUseSystemTheme
public boolean setUseSystemTheme(boolean use_it) throws PlatformManagerException
- Specified by:
setUseSystemTheme
in interfacePlatformManager
- Returns:
- if changes were made then true is returned, otherwise false
- Throws:
PlatformManagerException
-
getVMOptionFile
public java.io.File getVMOptionFile() throws PlatformManagerException
- Specified by:
getVMOptionFile
in interfacePlatformManager
- Throws:
PlatformManagerException
-
checkCapability
private void checkCapability(PlatformManagerCapabilities capability) throws PlatformManagerException
- Throws:
PlatformManagerException
-
getExplicitVMOptions
public java.lang.String[] getExplicitVMOptions() throws PlatformManagerException
- Specified by:
getExplicitVMOptions
in interfacePlatformManager
- Throws:
PlatformManagerException
-
setExplicitVMOptions
public void setExplicitVMOptions(java.lang.String[] options) throws PlatformManagerException
- Specified by:
setExplicitVMOptions
in interfacePlatformManager
- Throws:
PlatformManagerException
-
checkAndGetLocalVMOptionFile
private java.io.File checkAndGetLocalVMOptionFile() throws PlatformManagerException
- Throws:
PlatformManagerException
-
getJVMOptionRedirect
private java.lang.String getJVMOptionRedirect()
-
hasVMOptions
private boolean hasVMOptions()
-
getJVMOptionFiles
private java.io.File[] getJVMOptionFiles()
-
startup
public void startup(Core _core) throws PlatformManagerException
- Specified by:
startup
in interfacePlatformManager
- Throws:
PlatformManagerException
-
getShutdownTypes
public int getShutdownTypes()
- Specified by:
getShutdownTypes
in interfacePlatformManager
-
shutdown
public void shutdown(int type) throws PlatformManagerException
- Specified by:
shutdown
in interfacePlatformManager
- Throws:
PlatformManagerException
-
setPreventComputerSleep
public void setPreventComputerSleep(boolean prevent_it) throws PlatformManagerException
- Specified by:
setPreventComputerSleep
in interfacePlatformManager
- Throws:
PlatformManagerException
-
getPreventComputerSleep
public boolean getPreventComputerSleep()
- Specified by:
getPreventComputerSleep
in interfacePlatformManager
-
getRunAtLogin
public boolean getRunAtLogin() throws PlatformManagerException
- Specified by:
getRunAtLogin
in interfacePlatformManager
- Throws:
PlatformManagerException
-
setRunAtLogin
public void setRunAtLogin(boolean run) throws PlatformManagerException
- Specified by:
setRunAtLogin
in interfacePlatformManager
- Throws:
PlatformManagerException
-
convertToXML
private void convertToXML(java.io.File file) throws PlatformManagerException
- Throws:
PlatformManagerException
-
findCommand
private java.lang.String findCommand(java.lang.String name)
-
containsTag
private boolean containsTag(java.lang.String line, java.lang.String tag)
-
getLoginPList
private java.io.File getLoginPList() throws PlatformManagerException
- Throws:
PlatformManagerException
-
getUserDataDirectory
public java.lang.String getUserDataDirectory() throws PlatformManagerException
- Specified by:
getUserDataDirectory
in interfacePlatformManager
- Throws:
PlatformManagerException
- See Also:
SystemProperties.getUserPath()
-
getComputerName
public java.lang.String getComputerName()
- Specified by:
getComputerName
in interfacePlatformManager
- Returns:
- null if can't be found
-
getLocation
public java.io.File getLocation(long location_id) throws PlatformManagerException
Description copied from interface:PlatformManager
Get a well-known location, if defined for the platform- Specified by:
getLocation
in interfacePlatformManager
- Parameters:
location_id
- from above LOC_constants- Returns:
- Throws:
PlatformManagerException
-
isApplicationRegistered
public boolean isApplicationRegistered() throws PlatformManagerException
- Specified by:
isApplicationRegistered
in interfacePlatformManager
- Throws:
PlatformManagerException
-
isOurExt
private boolean isOurExt(java.lang.String ext)
-
isOurScheme
private boolean isOurScheme(java.lang.String scheme)
-
isOurMimeType
private boolean isOurMimeType(java.lang.String mimetype)
-
getBundlePath
private java.lang.String getBundlePath()
Bundle Path is the .app file that launched vuze, usually /Applications/Vuze.app
-
getAbsoluteBundleFile
private java.io.File getAbsoluteBundleFile()
Bundle Path is the .app file that launched vuze, usually /Applications/Vuze.app
-
getApplicationCommandLine
public java.lang.String getApplicationCommandLine() throws PlatformManagerException
command to launch Vuze- Specified by:
getApplicationCommandLine
in interfacePlatformManager
- Throws:
PlatformManagerException
-
isAdditionalFileTypeRegistered
public boolean isAdditionalFileTypeRegistered(java.lang.String name, java.lang.String type) throws PlatformManagerException
Description copied from interface:PlatformManager
Checks to see if the supplied file type is registered with this application- Specified by:
isAdditionalFileTypeRegistered
in interfacePlatformManager
- Returns:
- Throws:
PlatformManagerException
-
unregisterAdditionalFileType
public void unregisterAdditionalFileType(java.lang.String name, java.lang.String type) throws PlatformManagerException
Description copied from interface:PlatformManager
Removes a file-type registration- Specified by:
unregisterAdditionalFileType
in interfacePlatformManager
- Throws:
PlatformManagerException
-
registerAdditionalFileType
public void registerAdditionalFileType(java.lang.String name, java.lang.String description, java.lang.String type, java.lang.String content_type) throws PlatformManagerException
Description copied from interface:PlatformManager
Registers a file type with this application- Specified by:
registerAdditionalFileType
in interfacePlatformManager
- Throws:
PlatformManagerException
-
registerApplication
public void registerApplication() throws PlatformManagerException
- Specified by:
registerApplication
in interfacePlatformManager
- Throws:
PlatformManagerException
-
createProcess
public void createProcess(java.lang.String cmd, boolean inheritsHandles) throws PlatformManagerException
- Specified by:
createProcess
in interfacePlatformManager
- Throws:
PlatformManagerException
-
getFileManagerClass
private java.lang.Class<?> getFileManagerClass()
-
performRecoverableFileDelete
public void performRecoverableFileDelete(java.lang.String path) throws PlatformManagerException
- Specified by:
performRecoverableFileDelete
in interfacePlatformManager
- Throws:
PlatformManagerException
-
hasCapability
public boolean hasCapability(PlatformManagerCapabilities capability)
Gets whether the platform manager supports a capability
Users of PlatformManager should check for supported capabilities before calling the corresponding methods
Note that support for a particular capability may change arbitrarily in the duration of the application session, but the manager will cache where necessary.
- Specified by:
hasCapability
in interfacePlatformManager
- Parameters:
capability
- A platform manager capability- Returns:
- True if the manager supports the capability
-
dispose
public void dispose()
Disposes system resources. This method is optional.- Specified by:
dispose
in interfacePlatformManager
-
setTCPTOSEnabled
public void setTCPTOSEnabled(boolean enabled) throws PlatformManagerException
enable or disable the platforms support for TCP TOS- Specified by:
setTCPTOSEnabled
in interfacePlatformManager
- Throws:
PlatformManagerException
-
copyFilePermissions
public void copyFilePermissions(java.lang.String from_file_name, java.lang.String to_file_name) throws PlatformManagerException
- Specified by:
copyFilePermissions
in interfacePlatformManager
- Throws:
PlatformManagerException
-
showFile
public void showFile(java.lang.String path) throws PlatformManagerException
Reveals the file or directory with the platform's default browser- Specified by:
showFile
in interfacePlatformManager
- Parameters:
path
- The full path to a file or directory- Throws:
PlatformManagerException
- If this operation fails
-
playSystemAlert
public void playSystemAlert()
Plays the system alert (the jingle is specified by the user in System Preferences)
-
showInFinder
public void showInFinder(java.io.File path)
Shows the given file or directory in Finder
- Parameters:
path
- Absolute path to the file or directory
-
showInTerminal
public void showInTerminal(java.lang.String path)
Shows the given file or directory in Terminal by executing cd /absolute/path/to
- Parameters:
path
- Absolute path to the file or directory
-
showInTerminal
public void showInTerminal(java.io.File path)
Shows the given file or directory in Terminal by executing cd /absolute/path/to
- Parameters:
path
- Absolute path to the file or directory
-
performOSAScript
protected static java.lang.String performOSAScript(java.lang.CharSequence cmd) throws java.io.IOException
Compiles a new AppleScript instance and runs it- Parameters:
cmd
- AppleScript command to execute; do not surround command with extra quotation marks- Returns:
- Output of the script
- Throws:
java.io.IOException
- If the script failed to execute
-
performOSAScript
protected static java.lang.String performOSAScript(java.lang.CharSequence[] cmds) throws java.io.IOException
Compiles a new AppleScript instance and runs it- Parameters:
cmds
- AppleScript Sequence of commands to execute; do not surround command with extra quotation marks- Returns:
- Output of the script
- Throws:
java.io.IOException
- If the script failed to execute
-
performOSAScript
protected static java.lang.String performOSAScript(java.io.File script) throws java.io.IOException
Compiles a new AppleScript instance and runs it- Parameters:
script
- AppleScript file (.scpt) to execute- Returns:
- Output of the script
- Throws:
java.io.IOException
- If the script failed to execute
-
compileOSAScript
protected static boolean compileOSAScript(java.lang.CharSequence cmd, java.io.File destination)
Compiles a new AppleScript instance to the specified location- Parameters:
cmd
- Command to compile; do not surround command with extra quotation marksdestination
- Destination location of the AppleScript file- Returns:
- True if compiled successfully
-
compileOSAScript
protected static boolean compileOSAScript(java.lang.CharSequence[] cmds, java.io.File destination)
Compiles a new AppleScript instance to the specified location- Parameters:
cmds
- Sequence of commands to compile; do not surround command with extra quotation marksdestination
- Destination location of the AppleScript file- Returns:
- True if compiled successfully
-
performRuntimeExec
protected static java.lang.Process performRuntimeExec(java.lang.String[] cmdargs) throws java.io.IOException
- Throws:
java.io.IOException
- See Also:
Runtime.exec(String[])
-
getFileBrowserName
private static java.lang.String getFileBrowserName()
Gets the preferred file browser name
Currently supported browsers are Path Finder and Finder. If Path Finder is currently running (not just installed), then "Path Finder is returned; else, "Finder" is returned.
- Returns:
- "Path Finder" if it is currently running; else "Finder"
-
testNativeAvailability
public boolean testNativeAvailability(java.lang.String name) throws PlatformManagerException
- Specified by:
testNativeAvailability
in interfacePlatformManager
- Throws:
PlatformManagerException
-
traceRoute
public void traceRoute(java.net.InetAddress interface_address, java.net.InetAddress target, PlatformManagerPingCallback callback) throws PlatformManagerException
- Specified by:
traceRoute
in interfacePlatformManager
- Throws:
PlatformManagerException
-
ping
public void ping(java.net.InetAddress interface_address, java.net.InetAddress target, PlatformManagerPingCallback callback) throws PlatformManagerException
- Specified by:
ping
in interfacePlatformManager
- Throws:
PlatformManagerException
-
getMaxOpenFiles
public int getMaxOpenFiles() throws PlatformManagerException
Description copied from interface:PlatformManager
This max-open-files concept here is from linux/osx where network connections are treated as 'files'- Specified by:
getMaxOpenFiles
in interfacePlatformManager
- Returns:
- Throws:
PlatformManagerException
-
addListener
public void addListener(PlatformManagerListener listener)
- Specified by:
addListener
in interfacePlatformManager
-
removeListener
public void removeListener(PlatformManagerListener listener)
- Specified by:
removeListener
in interfacePlatformManager
-
generate
public void generate(IndentWriter writer)
- Specified by:
generate
in interfaceAEDiagnosticsEvidenceGenerator
-
getAzComputerID
public java.lang.String getAzComputerID() throws PlatformManagerException
- Throws:
PlatformManagerException
-
requestUserAttention
public void requestUserAttention(int type, java.lang.Object data) throws PlatformManagerException
If the application is not active causes the application icon at the bottom to bounce until the application becomes active If the application is already active then this method does nothing. Note: This is an undocumented feature from Apple so it's behavior may change without warning- Specified by:
requestUserAttention
in interfacePlatformManager
- Parameters:
type
- one of USER_REQUEST_INFO, USER_REQUEST_WARNING- Throws:
PlatformManagerException
-
loadClass
public java.lang.Class<?> loadClass(java.lang.ClassLoader loader, java.lang.String class_name) throws PlatformManagerException
Description copied from interface:PlatformManager
Gives a particular platform the ability to alter the class-loading method- Specified by:
loadClass
in interfacePlatformManager
- Returns:
- Throws:
PlatformManagerException
-
main
public static void main(java.lang.String[] args)
-
-