📄 platformmanagerimpl.java
字号:
try
{
String existing = access.readStringValue(1, "magnet\\shell\\open\\command", "");
magnet_exe_managing = existing.toLowerCase().indexOf("\\magnet.exe") != -1;
}
catch (Throwable e) { }
if (!magnet_exe_managing && (force || getAdditionalFileTypeRegistrationDetails("Magnet", ".magnet") == 0))
try
{
registerAdditionalFileType("Magnet", "Magnet URI", ".magnet", "application/x-magnet", true);
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
createKey(3, "Software\\magnet");
createKey(3, "Software\\magnet\\Handlers");
createKey(3, "Software\\magnet\\Handlers\\Azureus");
access.writeStringValue(3, "Software\\magnet\\Handlers\\Azureus", "DefaultIcon", (new StringBuilder()).append("\"").append(az_exe_string).append(",").append(getIconIndex()).append("\"").toString());
access.writeStringValue(3, "Software\\magnet\\Handlers\\Azureus", "Description", "Download with Vuze (formerly Azureus)");
access.writeStringValue(3, "Software\\magnet\\Handlers\\Azureus", "ShellExecute", (new StringBuilder()).append("\"").append(az_exe_string).append("\" %URL").toString());
access.writeWordValue(3, "Software\\magnet\\Handlers\\Azureus\\Type", "urn:btih", 0);
}
catch (Throwable e) { }
}
protected boolean createKey(int type, String key)
{
access.readStringValue(type, key, "");
return true;
Throwable e;
e;
access.writeStringValue(type, key, "", "");
return true;
Throwable f;
f;
return false;
}
protected void registerDHT()
{
try
{
registerAdditionalFileType("DHT", "DHT URI", ".dht", "application/x-dht", true);
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
}
public void registerAdditionalFileType(String name, String description, String type, String content_type)
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
{
try
{
String az_exe_string = getApplicationEXELocation().toString();
unregisterAdditionalFileType(name, type);
writeStringToHKCRandHKCU(type, "", name);
writeStringToHKCRandHKCU(type, "Content Type", content_type);
writeStringToHKCRandHKCU((new StringBuilder()).append("MIME\\Database\\Content Type\\").append(content_type).toString(), "Extension", type);
writeStringToHKCRandHKCU(name, "", description);
writeStringToHKCRandHKCU((new StringBuilder()).append(name).append("\\shell").toString(), "", "open");
writeStringToHKCRandHKCU((new StringBuilder()).append(name).append("\\DefaultIcon").toString(), "", (new StringBuilder()).append(az_exe_string).append(",").append(getIconIndex()).toString());
writeStringToHKCRandHKCU((new StringBuilder()).append(name).append("\\shell\\open\\command").toString(), "", (new StringBuilder()).append("\"").append(az_exe_string).append("\" \"%1\"").toString());
writeStringToHKCRandHKCU(name, "Content Type", content_type);
if (url_protocol)
writeStringToHKCRandHKCU(name, "URL Protocol", "");
}
catch (PlatformManagerException e)
{
throw e;
}
catch (Throwable e)
{
throw new PlatformManagerException("Failed to write registry details", e);
}
}
private void writeStringToHKCRandHKCU(String subkey, String name, String value)
{
try
{
access.writeStringValue(1, subkey, name, value);
}
catch (Throwable e)
{
if (!Constants.isWindowsVista)
Debug.out(e);
}
try
{
access.writeStringValue(4, (new StringBuilder()).append("Software\\Classes\\").append(subkey).toString(), name, value);
}
catch (Throwable e)
{
Debug.out(e);
}
}
public void unregisterAdditionalFileType(String name, String type)
throws PlatformManagerException
{
try
{
try
{
access.deleteValue(4, (new StringBuilder()).append("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\").append(type).toString(), "Application");
}
catch (Throwable e) { }
try
{
access.deleteKey(1, type);
}
catch (Throwable e) { }
try
{
access.deleteKey(1, name, true);
}
catch (Throwable e) { }
try
{
access.deleteKey(4, (new StringBuilder()).append("Software\\Classes\\").append(type).toString());
}
catch (Throwable e) { }
try
{
access.deleteKey(4, (new StringBuilder()).append("Software\\Classes\\").append(name).toString(), true);
}
catch (Throwable 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(3, "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);
}
}
public void showFile(String file_name)
throws PlatformManagerException
{
try
{
File file = new File(file_name);
access.createProcess((new StringBuilder()).append("explorer.exe ").append(file.isDirectory() ? "/e," : "/e,/select,").append("\"").append(file_name).append("\"").toString(), false);
}
catch (Throwable e)
{
throw new PlatformManagerException((new StringBuilder()).append("Failed to show file ").append(file_name).toString(), e);
}
}
public boolean testNativeAvailability(String name)
throws PlatformManagerException
{
if (!hasCapability(PlatformManagerCapabilities.TestNativeAvailability))
throw new PlatformManagerException("Unsupported capability called on platform manager");
return access.testNativeAvailability(name);
Throwable e;
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);
}
}
public int shellExecute(String operation, String file, String parameters, String directory, int SW_const)
throws PlatformManagerException
{
return access.shellExecute(operation, file, parameters, directory, SW_const);
Throwable e;
e;
throw new PlatformManagerException("Failed to shellExecute", e);
}
public boolean hasCapability(PlatformManagerCapabilities capability)
{
return capabilitySet.contains(capability);
}
public void dispose()
{
}
public void eventOccurred(int type)
{
int t_type;
if (type == 1)
t_type = 1;
else
if (type == 2)
t_type = 2;
else
if (type == 3)
t_type = 3;
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);
}
public String getAzComputerID()
{
boolean needWrite = false;
String cid = null;
try
{
cid = access.readStringValue(3, (new StringBuilder()).append("SOFTWARE\\").append(app_name).toString(), "CID");
}
catch (Exception e) { }
if (cid == null || cid.length() == 0)
{
needWrite = true;
try
{
File commonPath = new File(access.getCommonAppData(), app_name);
if (commonPath.isDirectory())
{
File fCID = new File(commonPath, "azCID.txt");
if (fCID.exists())
cid = FileUtil.readFileAsString(fCID, 255, "utf8");
}
}
catch (Exception e) { }
}
if (cid == null || cid.length() == 0)
{
needWrite = true;
cid = COConfigurationManager.getStringParameter("ID");
}
if (cid == null || cid.length() == 0)
{
needWrite = true;
cid = RandomUtils.generateRandomAlphanumerics(20);
}
if (needWrite)
setAzComputerID(cid);
return cid;
}
private void setAzComputerID(String cid)
{
try
{
access.writeStringValue(3, (new StringBuilder()).append("SOFTWARE\\").append(app_name).toString(), "CID", cid);
}
catch (Exception e)
{
Debug.out((new StringBuilder()).append("Could not write CID: ").append(e.getMessage()).toString());
}
try
{
String sCommonAppData = access.getCommonAppData();
if (sCommonAppData != null && sCommonAppData.length() > 0)
{
File commonPath = new File(sCommonAppData);
if (commonPath.isDirectory())
{
commonPath = new File(commonPath, app_name);
FileUtil.mkdirs(commonPath);
File fCID = new File(commonPath, "azCID.txt");
FileUtil.writeBytesAsFile(fCID.getAbsolutePath(), cid.getBytes("utf8"));
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void main(String args[])
{
try
{
PlatformManagerImpl impl = new PlatformManagerImpl();
System.out.println(impl.getAzComputerID());
}
catch (PlatformManagerException e)
{
e.printStackTrace();
}
}
public void requestUserAttention(int type, Object data)
throws PlatformManagerException
{
throw new PlatformManagerException("Unsupported capability called on platform manager");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -