📄 platformmanagerimpl.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: PlatformManagerImpl.java
package org.gudy.azureus2.platform.win32;
import java.io.File;
import java.io.PrintStream;
import java.net.InetAddress;
import java.util.*;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.logging.LogAlert;
import org.gudy.azureus2.core3.logging.Logger;
import org.gudy.azureus2.core3.util.*;
import org.gudy.azureus2.platform.*;
import org.gudy.azureus2.platform.win32.access.AEWin32Access;
import org.gudy.azureus2.platform.win32.access.AEWin32AccessListener;
import org.gudy.azureus2.platform.win32.access.AEWin32Manager;
import org.gudy.azureus2.plugins.platform.PlatformManagerException;
public class PlatformManagerImpl
implements PlatformManager, AEWin32AccessListener
{
public static final int RT_NONE = 0;
public static final int RT_AZ = 1;
public static final int RT_OTHER = 2;
public static final String DLL_NAME = "aereg";
public static final String VUZE_ASSOC = "Vuze";
public static final String NEW_MAIN_ASSOC = "Azureus";
public static final String OLD_MAIN_ASS0C = "BitTorrent";
private static boolean initialising;
private static boolean init_tried;
private static PlatformManagerImpl singleton;
private static AEMonitor class_mon = new AEMonitor("PlatformManager");
private final Set capabilitySet = new HashSet();
private List listeners;
private final AEWin32Access access = AEWin32Manager.getAccessor(true);
private final String app_name = SystemProperties.getApplicationName();
private final String app_exe_name;
private File az_exe;
private boolean az_exe_checked;
public static PlatformManagerImpl getSingleton()
throws PlatformManagerException
{
PlatformManagerImpl platformmanagerimpl;
class_mon.enter();
if (singleton == null)
break MISSING_BLOCK_LABEL_24;
platformmanagerimpl = singleton;
class_mon.exit();
return platformmanagerimpl;
if (initialising)
System.err.println("PlatformManager: recursive entry during initialisation");
initialising = true;
if (!init_tried)
{
init_tried = true;
try
{
singleton = new PlatformManagerImpl();
singleton.applyPatches();
}
catch (PlatformManagerException e)
{
throw e;
}
catch (Throwable e)
{
if (e instanceof PlatformManagerException)
throw (PlatformManagerException)e;
else
throw new PlatformManagerException("Win32Platform: failed to initialise", e);
}
}
initialising = false;
break MISSING_BLOCK_LABEL_112;
Exception exception;
exception;
initialising = false;
throw exception;
e = singleton;
class_mon.exit();
return e;
Exception exception1;
exception1;
class_mon.exit();
throw exception1;
}
protected PlatformManagerImpl()
throws PlatformManagerException
{
listeners = new ArrayList();
access.addListener(this);
app_exe_name = (new StringBuilder()).append(app_name).append(".exe").toString();
initializeCapabilities();
}
private void initializeCapabilities()
{
if (access.isEnabled())
{
capabilitySet.add(PlatformManagerCapabilities.CreateCommandLineProcess);
capabilitySet.add(PlatformManagerCapabilities.GetUserDataDirectory);
capabilitySet.add(PlatformManagerCapabilities.RecoverableFileDelete);
capabilitySet.add(PlatformManagerCapabilities.RegisterFileAssociations);
capabilitySet.add(PlatformManagerCapabilities.ShowFileInBrowser);
capabilitySet.add(PlatformManagerCapabilities.GetVersion);
capabilitySet.add(PlatformManagerCapabilities.SetTCPTOSEnabled);
capabilitySet.add(PlatformManagerCapabilities.ComputerIDAvailability);
if (Constants.compareVersions(access.getVersion(), "1.11") >= 0 && !Constants.isWindows9598ME)
capabilitySet.add(PlatformManagerCapabilities.CopyFilePermissions);
if (Constants.compareVersions(access.getVersion(), "1.12") >= 0)
capabilitySet.add(PlatformManagerCapabilities.TestNativeAvailability);
if (Constants.compareVersions(access.getVersion(), "1.14") >= 0)
capabilitySet.add(PlatformManagerCapabilities.TraceRouteAvailability);
if (Constants.compareVersions(access.getVersion(), "1.15") >= 0)
capabilitySet.add(PlatformManagerCapabilities.PingAvailability);
} else
{
capabilitySet.add(PlatformManagerCapabilities.GetVersion);
}
}
protected void applyPatches()
{
label0:
{
try
{
File exe_loc = getApplicationEXELocation();
String az_exe_string = exe_loc.toString();
String current = access.readStringValue(1, "Azureus\\DefaultIcon", "");
String target = (new StringBuilder()).append(az_exe_string).append(",").append(getIconIndex()).toString();
if (current.indexOf(app_exe_name) != -1 && !current.equals(target))
writeStringToHKCRandHKCU("Azureus\\DefaultIcon", "", target);
}
catch (Throwable e) { }
if (!hasCapability(PlatformManagerCapabilities.CopyFilePermissions) || COConfigurationManager.getBooleanParameter("platform.win32.permfixdone2", false))
break label0;
try
{
String str = SystemProperties.getApplicationPath();
if (str.endsWith(File.separator))
str = str.substring(0, str.length() - 1);
fixPermissions(new File(str), new File(str));
}
catch (Throwable e)
{
COConfigurationManager.setParameter("platform.win32.permfixdone2", true);
break label0;
}
finally
{
COConfigurationManager.setParameter("platform.win32.permfixdone2", true);
throw exception;
}
COConfigurationManager.setParameter("platform.win32.permfixdone2", true);
break label0;
}
}
protected void fixPermissions(File parent, File dir)
throws PlatformManagerException
{
File files[] = dir.listFiles();
if (files == null)
return;
for (int i = 0; i < files.length; i++)
{
File file = files[i];
if (file.isFile())
copyFilePermissions(parent.getAbsolutePath(), file.getAbsolutePath());
}
}
protected int getIconIndex()
throws PlatformManagerException
{
return 0;
}
public String getVersion()
{
return access.getVersion();
}
protected File getApplicationEXELocation()
throws PlatformManagerException
{
if (az_exe != null)
break MISSING_BLOCK_LABEL_269;
String az_home = SystemProperties.getApplicationPath();
az_exe = (new File((new StringBuilder()).append(az_home).append(File.separator).append(app_exe_name).toString())).getAbsoluteFile();
if (!az_exe.exists())
try
{
az_home = access.getApplicationInstallDir(app_name);
az_exe = (new File((new StringBuilder()).append(az_home).append(File.separator).append(app_exe_name).toString())).getAbsoluteFile();
if (!az_exe.exists())
throw new PlatformManagerException((new StringBuilder()).append(app_exe_name).append(" not found in ").append(az_home).append(", please re-install").toString());
}
catch (Throwable e) { }
if (!az_exe.exists())
{
String msg = (new StringBuilder()).append(app_exe_name).append(" not found in ").append(az_home).append(" - can't check file associations. Please re-install ").append(app_name).toString();
az_exe = null;
if (!az_exe_checked)
Logger.log(new LogAlert(false, 1, msg));
throw new PlatformManagerException(msg);
}
az_exe_checked = true;
break MISSING_BLOCK_LABEL_269;
Exception exception;
exception;
az_exe_checked = true;
throw exception;
return az_exe;
}
public int getPlatformType()
{
return 1;
}
public String getUserDataDirectory()
throws PlatformManagerException
{
return (new StringBuilder()).append(access.getUserAppData()).append(SystemProperties.SEP).append(app_name).append(SystemProperties.SEP).toString();
Throwable e;
e;
throw new PlatformManagerException("Failed to read registry details", e);
}
public String getComputerName()
{
String host = System.getenv("COMPUTERNAME");
if (host != null && host.length() > 0)
return host;
else
return null;
}
public File getLocation(long location_id)
throws PlatformManagerException
{
if (location_id == 1L)
return new File(getUserDataDirectory());
if (location_id != 2L)
break MISSING_BLOCK_LABEL_55;
return new File(access.getUserMusicDir());
Throwable e;
e;
throw new PlatformManagerException("Failed to read registry details", e);
if (location_id != 3L)
break MISSING_BLOCK_LABEL_92;
return new File(access.getUserDocumentsDir());
e;
throw new PlatformManagerException("Failed to read registry details", e);
if (location_id != 4L)
break MISSING_BLOCK_LABEL_129;
return new File(access.getUserVideoDir());
e;
throw new PlatformManagerException("Failed to read registry details", e);
return null;
}
public String getApplicationCommandLine()
{
return getApplicationEXELocation().toString();
Throwable e;
e;
return null;
}
public boolean isApplicationRegistered()
throws PlatformManagerException
{
File exe_loc = getApplicationEXELocation();
if (exe_loc.exists())
checkExeKey(exe_loc);
try
{
registerMagnet(false);
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
try
{
if (getAdditionalFileTypeRegistrationDetails("DHT", ".dht") == 0)
registerDHT();
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
if (isAdditionalFileTypeRegistered("BitTorrent", ".torrent"))
{
unregisterAdditionalFileType("BitTorrent", ".torrent");
registerAdditionalFileType("Azureus", (new StringBuilder()).append(Constants.APP_NAME).append(" Download").toString(), ".torrent", "application/x-bittorrent");
}
boolean reg = isAdditionalFileTypeRegistered("Azureus", ".torrent");
if (!reg && !COConfigurationManager.getBooleanParameter("platform.win32.autoregdone", false))
{
registerAdditionalFileType("Azureus", (new StringBuilder()).append(Constants.APP_NAME).append(" Download").toString(), ".torrent", "application/x-bittorrent");
COConfigurationManager.setParameter("platform.win32.autoregdone", true);
reg = true;
}
boolean vuze_reg = isAdditionalFileTypeRegistered("Vuze", ".vuze");
if (!vuze_reg)
registerAdditionalFileType("Vuze", "Vuze File", ".vuze", "application/x-vuze");
return reg;
}
protected void checkExeKey(File exe)
{
checkExeKey(4, exe);
checkExeKey(3, exe);
}
protected void checkExeKey(int hkey, File exe)
{
String exe_str = exe.getAbsolutePath();
String str = null;
try
{
str = access.readStringValue(hkey, (new StringBuilder()).append("software\\").append(app_name).toString(), "exec");
}
catch (Throwable e) { }
try
{
if (str == null || !str.equals(exe_str))
access.writeStringValue(hkey, (new StringBuilder()).append("software\\").append(app_name).toString(), "exec", exe_str);
}
catch (Throwable e) { }
}
public boolean isAdditionalFileTypeRegistered(String name, String type)
throws PlatformManagerException
{
return getAdditionalFileTypeRegistrationDetails(name, type) == 1;
}
public int getAdditionalFileTypeRegistrationDetails(String name, String type)
throws PlatformManagerException
{
String az_exe_str;
Throwable e;
try
{
az_exe_str = getApplicationEXELocation().toString();
}
// Misplaced declaration of an exception variable
catch (Throwable e)
{
return 0;
}
String test1 = access.readStringValue(1, (new StringBuilder()).append(name).append("\\shell\\open\\command").toString(), "");
if (!test1.equals((new StringBuilder()).append("\"").append(az_exe_str).append("\" \"%1\"").toString()))
return test1.length() != 0 ? 2 : 0;
String test2 = access.readStringValue(1, type, "");
if (!test2.equals("Azureus"))
return test2.length() != 0 ? 2 : 0;
String always_open_with = access.readStringValue(4, (new StringBuilder()).append("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\").append(type).toString(), "Application");
if (always_open_with.length() > 0)
return 2;
break MISSING_BLOCK_LABEL_181;
Throwable e;
e;
return 1;
test1;
if (test1.getMessage() == null || test1.getMessage().indexOf("RegOpenKey failed") == -1)
Debug.printStackTrace(test1);
return 0;
}
public void registerApplication()
throws PlatformManagerException
{
registerMagnet(true);
registerDHT();
registerAdditionalFileType("Azureus", (new StringBuilder()).append(Constants.APP_NAME).append(" Download").toString(), ".torrent", "application/x-bittorrent");
registerAdditionalFileType("Vuze", "Vuze File", ".vuze", "application/x-vuze");
}
protected void registerMagnet(boolean force)
{
try
{
String az_exe_string = getApplicationEXELocation().toString();
boolean magnet_exe_managing = false;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -