📄 platformmanagerimpl.java
字号:
getAdditionalFileTypeRegistrationDetails(
String name,
String type )
throws PlatformManagerException
{
String az_exe_str;
try{
az_exe_str = getApplicationEXELocation().toString();
}catch( Throwable e ){
return( RT_NONE );
}
try{
String test1 =
access.readStringValue(
AEWin32Access.HKEY_CLASSES_ROOT,
name + "\\shell\\open\\command",
"" );
if ( !test1.equals( "\"" + az_exe_str + "\" \"%1\"" )){
return( test1.length() ==0?RT_NONE:RT_OTHER );
}
// MRU list is just that, to remove the "always open with" we need to kill
// the "application" entry, if it exists
try{
String always_open_with =
access.readStringValue(
AEWin32Access.HKEY_CURRENT_USER,
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\" + type,
"Application" );
//System.out.println( "mru_list = " + mru_list );
if ( always_open_with.length() > 0 ){
// AZ is default so if this entry exists it denotes another (non-AZ) app
return( RT_OTHER );
}
}catch( Throwable e ){
// e.printStackTrace();
// failure means things are OK
}
/*
try{
String mru_list =
access.readStringValue(
AEWin32Access.HKEY_CURRENT_USER,
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\.torrent\\OpenWithList",
"MRUList" );
//System.out.println( "mru_list = " + mru_list );
if ( mru_list.length() > 0 ){
String mru =
access.readStringValue(
AEWin32Access.HKEY_CURRENT_USER,
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\.torrent\\OpenWithList",
"" + mru_list.charAt(0) );
//System.out.println( "mru = " + mru );
return( mru.equalsIgnoreCase(app_exe_name));
}
}catch( Throwable e ){
// e.printStackTrace();
// failure means things are OK
}
*/
return( RT_AZ );
}catch( Throwable e ){
if ( e.getMessage() == null ||
e.getMessage().indexOf("RegOpenKey failed") == -1 ){
Debug.printStackTrace( e );
}
return( RT_NONE );
}
}
public void
registerApplication()
throws PlatformManagerException
{
registerMagnet();
registerAdditionalFileType( NEW_MAIN_ASSOC, "Azureus Download", ".torrent", "application/x-bittorrent" );
}
protected void
registerMagnet()
{
try{
registerAdditionalFileType(
"Magnet",
"Magnet URI",
".magnet",
"application/x-magnet",
true );
}catch( Throwable e ){
Debug.printStackTrace(e);
}
}
public void
registerAdditionalFileType(
String name, // e.g. "Azureus"
String description, // e.g. "BitTorrent File"
String type, // e.g. ".torrent"
String content_type ) // e.g. "application/x-bittorrent"
throws PlatformManagerException
{
registerAdditionalFileType( name, description, type, content_type, false );
}
public void
registerAdditionalFileType(
String name,
String description,
String type,
String content_type,
boolean url_protocol)
throws PlatformManagerException
{
// WriteRegStr HKCR ".torrent" "" "Azureus"
// WriteRegStr HKCR "Azureus" "" "Azureus Torrent"
// WriteRegStr HKCR "Azureus\shell" "" "open"
// WriteRegStr HKCR "Azureus\DefaultIcon" "" $INSTDIR\Azureus.exe,1
// WriteRegStr HKCR "Azureus\shell\open\command" "" '"$INSTDIR\Azureus.exe" "%1"'
// WriteRegStr HKCR "Azureus\Content Type" "" "application/x-bittorrent"
try{
String az_exe_string = getApplicationEXELocation().toString();
unregisterAdditionalFileType( name, type );
access.writeStringValue(
AEWin32Access.HKEY_CLASSES_ROOT,
type,
"",
name );
access.writeStringValue(
AEWin32Access.HKEY_CLASSES_ROOT,
name,
"",
description );
access.writeStringValue(
AEWin32Access.HKEY_CLASSES_ROOT,
name + "\\shell",
"",
"open" );
access.writeStringValue(
AEWin32Access.HKEY_CLASSES_ROOT,
name + "\\DefaultIcon",
"",
az_exe_string + "," + getIconIndex());
access.writeStringValue(
AEWin32Access.HKEY_CLASSES_ROOT,
name + "\\shell\\open\\command",
"",
"\"" + az_exe_string + "\" \"%1\"" );
access.writeStringValue(
AEWin32Access.HKEY_CLASSES_ROOT,
name + "\\Content Type" ,
"",
content_type );
if ( url_protocol ){
access.writeStringValue(
AEWin32Access.HKEY_CLASSES_ROOT,
name,
"URL Protocol",
"" );
}
}catch( PlatformManagerException e ){
throw(e );
}catch( Throwable e ){
throw( new PlatformManagerException( "Failed to write registry details", e ));
}
}
public void
unregisterAdditionalFileType(
String name, // e.g. "Azureus"
String type ) // e.g. ".torrent"
throws PlatformManagerException
{
try{
try{
access.deleteValue(
AEWin32Access.HKEY_CURRENT_USER,
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\" + type,
"Application" );
}catch( Throwable e ){
// e.printStackTrace();
}
try{
access.deleteKey(
AEWin32Access.HKEY_CLASSES_ROOT,
type );
}catch( Throwable e ){
// Debug.printStackTrace( e );
}
try{
access.deleteKey(
AEWin32Access.HKEY_CLASSES_ROOT,
name,
true );
}catch( Throwable e ){
// Debug.printStackTrace( e );
}
}catch( Throwable e ){
throw( new PlatformManagerException( "Failed to delete registry details", e ));
}
}
public void
createProcess(
String command_line,
boolean inherit_handles )
throws PlatformManagerException
{
try{
access.createProcess( command_line, inherit_handles );
}catch( Throwable e ){
throw( new PlatformManagerException( "Failed to create process", e ));
}
}
public void
performRecoverableFileDelete(
String file_name )
throws PlatformManagerException
{
try{
access.moveToRecycleBin( file_name );
}catch( Throwable e ){
throw( new PlatformManagerException( "Failed to move file", e ));
}
}
public void
setTCPTOSEnabled(
boolean enabled )
throws PlatformManagerException
{
try{
access.writeWordValue(
AEWin32Access.HKEY_LOCAL_MACHINE,
"System\\CurrentControlSet\\Services\\Tcpip\\Parameters",
"DisableUserTOSSetting",
enabled?0:1);
}catch( Throwable e ){
throw( new PlatformManagerException( "Failed to write registry details", e ));
}
}
public void
copyFilePermissions(
String from_file_name,
String to_file_name )
throws PlatformManagerException
{
try{
access.copyFilePermissions( from_file_name, to_file_name );
}catch( Throwable e ){
throw( new PlatformManagerException( "Failed to copy file permissions", e ));
}
}
/**
* {@inheritDoc}
*/
public void showFile(String file_name)
throws PlatformManagerException
{
try
{
File file = new File(file_name);
Runtime.getRuntime().exec(
new String[] { "explorer.exe",
file.isDirectory() ? "/e," : "/e,/select,",
"\"" + file_name + "\"" });
}
catch (IOException e)
{
throw new PlatformManagerException("Failed to show file " + file_name, e);
}
}
public boolean
testNativeAvailability(
String name )
throws PlatformManagerException
{
if ( !hasCapability( PlatformManagerCapabilities.TestNativeAvailability )){
throw new PlatformManagerException("Unsupported capability called on platform manager");
}
try{
return( access.testNativeAvailability( name ));
}catch( Throwable e ){
throw( new PlatformManagerException( "Failed to test availability", e ));
}
}
public void
traceRoute(
InetAddress interface_address,
InetAddress target,
PlatformManagerPingCallback callback )
throws PlatformManagerException
{
if ( !hasCapability( PlatformManagerCapabilities.TraceRouteAvailability )){
throw new PlatformManagerException("Unsupported capability called on platform manager");
}
try{
access.traceRoute( interface_address, target, callback );
}catch( Throwable e ){
throw( new PlatformManagerException( "Failed to trace route", e ));
}
}
public void
ping(
InetAddress interface_address,
InetAddress target,
PlatformManagerPingCallback callback )
throws PlatformManagerException
{
if ( !hasCapability( PlatformManagerCapabilities.PingAvailability )){
throw new PlatformManagerException("Unsupported capability called on platform manager");
}
try{
access.ping( interface_address, target, callback );
}catch( Throwable e ){
throw( new PlatformManagerException( "Failed to trace route", e ));
}
}
/**
* {@inheritDoc}
*/
public boolean
hasCapability(
PlatformManagerCapabilities capability)
{
return capabilitySet.contains(capability);
}
/**
* Does nothing
*/
public void dispose()
{
}
public void
eventOccurred(
int type )
{
int t_type;
if ( type == AEWin32AccessListener.ET_SHUTDOWN ){
t_type = PlatformManagerListener.ET_SHUTDOWN;
}else{
return;
}
if ( t_type != -1 ){
for (int i=0;i<listeners.size();i++){
try{
((PlatformManagerListener)listeners.get(i)).eventOccurred( t_type );
}catch( Throwable e ){
Debug.printStackTrace(e);
}
}
}
}
public void
addListener(
PlatformManagerListener listener )
{
listeners.add( listener );
}
public void
removeListener(
PlatformManagerListener listener )
{
listeners.remove( listener );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -