📄 platformmanagerimpl.java
字号:
throw new PlatformManagerException("File not found");
} else
{
showInFinder(file);
return;
}
}
public void playSystemAlert()
{
try
{
performRuntimeExec(new String[] {
"beep"
});
}
catch (IOException e)
{
if (Logger.isEnabled())
Logger.log(new LogEvent(LOGID, 1, "Cannot play system alert"));
Logger.log(new LogEvent(LOGID, "", e));
}
}
public void showInFinder(File path)
{
boolean useOSA = !NativeInvocationBridge.sharedInstance().isEnabled() || !NativeInvocationBridge.sharedInstance().showInFinder(path, fileBrowserName);
if (useOSA)
{
StringBuffer sb = new StringBuffer();
sb.append("tell application \"");
sb.append(getFileBrowserName());
sb.append("\" to reveal (posix file \"");
sb.append(path);
sb.append("\" as alias)");
try
{
performOSAScript(sb);
}
catch (IOException e)
{
Logger.log(new LogAlert(false, 3, e.getMessage()));
}
}
}
public void showInTerminal(String path)
{
showInTerminal(new File(path));
}
public void showInTerminal(File path)
{
if (path.isFile())
path = path.getParentFile();
if (path != null && path.isDirectory())
{
StringBuffer sb = new StringBuffer();
sb.append("tell application \"");
sb.append("Terminal");
sb.append("\" to do script \"cd ");
sb.append(path.getAbsolutePath().replaceAll(" ", "\\ "));
sb.append("\"");
try
{
performOSAScript(sb);
}
catch (IOException e)
{
Logger.log(new LogAlert(false, 3, e.getMessage()));
}
} else
if (Logger.isEnabled())
Logger.log(new LogEvent(LOGID, 1, (new StringBuilder()).append("Cannot find ").append(path.getName()).toString()));
}
protected static String performOSAScript(CharSequence cmd)
throws IOException
{
return performOSAScript(new CharSequence[] {
cmd
});
}
protected static String performOSAScript(CharSequence cmds[])
throws IOException
{
long start = System.currentTimeMillis();
Debug.outNoStack("Executing OSAScript: ");
for (int i = 0; i < cmds.length; i++)
Debug.outNoStack((new StringBuilder()).append("\t").append(cmds[i]).toString());
String cmdargs[] = new String[2 * cmds.length + 1];
cmdargs[0] = "osascript";
for (int i = 0; i < cmds.length; i++)
{
cmdargs[i * 2 + 1] = "-e";
cmdargs[i * 2 + 2] = String.valueOf(cmds[i]);
}
Process osaProcess = performRuntimeExec(cmdargs);
BufferedReader reader = new BufferedReader(new InputStreamReader(osaProcess.getInputStream()));
String line = reader.readLine();
reader.close();
Debug.outNoStack((new StringBuilder()).append("OSAScript Output: ").append(line).toString());
reader = new BufferedReader(new InputStreamReader(osaProcess.getErrorStream()));
String errorMsg = reader.readLine();
reader.close();
Debug.outNoStack((new StringBuilder()).append("OSAScript Error (if any): ").append(errorMsg).toString());
Debug.outNoStack(MessageFormat.format("OSAScript execution ended ({0}ms)", new Object[] {
String.valueOf(System.currentTimeMillis() - start)
}));
try
{
osaProcess.destroy();
}
catch (Throwable t) { }
if (errorMsg != null)
throw new IOException(errorMsg);
else
return line;
}
protected static String performOSAScript(File script)
throws IOException
{
long start = System.currentTimeMillis();
Debug.outNoStack((new StringBuilder()).append("Executing OSAScript from file: ").append(script.getPath()).toString());
Process osaProcess = performRuntimeExec(new String[] {
"osascript", script.getPath()
});
BufferedReader reader = new BufferedReader(new InputStreamReader(osaProcess.getInputStream()));
String line = reader.readLine();
reader.close();
Debug.outNoStack((new StringBuilder()).append("OSAScript Output: ").append(line).toString());
reader = new BufferedReader(new InputStreamReader(osaProcess.getErrorStream()));
String errorMsg = reader.readLine();
reader.close();
Debug.outNoStack((new StringBuilder()).append("OSAScript Error (if any): ").append(errorMsg).toString());
Debug.outNoStack(MessageFormat.format("OSAScript execution ended ({0}ms)", new Object[] {
String.valueOf(System.currentTimeMillis() - start)
}));
try
{
osaProcess.destroy();
}
catch (Throwable t) { }
if (errorMsg != null)
throw new IOException(errorMsg);
else
return line;
}
protected static boolean compileOSAScript(CharSequence cmd, File destination)
{
return compileOSAScript(new CharSequence[] {
cmd
}, destination);
}
protected static boolean compileOSAScript(CharSequence cmds[], File destination)
{
long start = System.currentTimeMillis();
Debug.outNoStack((new StringBuilder()).append("Compiling OSAScript: ").append(destination.getPath()).toString());
for (int i = 0; i < cmds.length; i++)
Debug.outNoStack((new StringBuilder()).append("\t").append(cmds[i]).toString());
String cmdargs[] = new String[2 * cmds.length + 3];
cmdargs[0] = "osacompile";
for (int i = 0; i < cmds.length; i++)
{
cmdargs[i * 2 + 1] = "-e";
cmdargs[i * 2 + 2] = String.valueOf(cmds[i]);
}
cmdargs[cmdargs.length - 2] = "-o";
cmdargs[cmdargs.length - 1] = destination.getPath();
String errorMsg;
try
{
Process osaProcess = performRuntimeExec(cmdargs);
BufferedReader reader = new BufferedReader(new InputStreamReader(osaProcess.getErrorStream()));
errorMsg = reader.readLine();
reader.close();
}
catch (IOException e)
{
Debug.outNoStack((new StringBuilder()).append("OSACompile Execution Failed: ").append(e.getMessage()).toString());
Debug.printStackTrace(e);
return false;
}
Debug.outNoStack((new StringBuilder()).append("OSACompile Error (if any): ").append(errorMsg).toString());
Debug.outNoStack(MessageFormat.format("OSACompile execution ended ({0}ms)", new Object[] {
String.valueOf(System.currentTimeMillis() - start)
}));
return errorMsg == null;
}
protected static Process performRuntimeExec(String cmdargs[])
throws IOException
{
return Runtime.getRuntime().exec(cmdargs);
IOException e;
e;
Logger.log(new LogAlert(false, e.getMessage(), e));
throw e;
}
private static String getFileBrowserName()
{
return fileBrowserName;
}
public boolean testNativeAvailability(String name)
throws PlatformManagerException
{
throw new PlatformManagerException("Unsupported capability called on platform manager");
}
public void traceRoute(InetAddress interface_address, InetAddress target, PlatformManagerPingCallback callback)
throws PlatformManagerException
{
throw new PlatformManagerException("Unsupported capability called on platform manager");
}
public void ping(InetAddress interface_address, InetAddress target, PlatformManagerPingCallback callback)
throws PlatformManagerException
{
throw new PlatformManagerException("Unsupported capability called on platform manager");
}
public void addListener(PlatformManagerListener platformmanagerlistener)
{
}
public void removeListener(PlatformManagerListener platformmanagerlistener)
{
}
public void generate(IndentWriter writer)
{
writer.println("PlatformManager: MacOSX");
writer.indent();
if (OSXAccess.isLoaded())
try
{
writer.println((new StringBuilder()).append("Version ").append(getVersion()).toString());
writer.println((new StringBuilder()).append("User Data Dir: ").append(getLocation(1L)).toString());
writer.println((new StringBuilder()).append("User Doc Dir: ").append(getLocation(3L)).toString());
}
catch (PlatformManagerException e) { }
else
writer.println("Not loaded");
writer.exdent();
break MISSING_BLOCK_LABEL_125;
Exception exception;
exception;
writer.exdent();
throw exception;
}
public String getAzComputerID()
throws PlatformManagerException
{
throw new PlatformManagerException("Unsupported capability called on platform manager");
}
public void requestUserAttention(int type, Object data)
throws PlatformManagerException
{
try
{
NSApplication app = NSApplication.sharedApplication();
if (type == 1)
app.requestUserAttention(10);
else
if (type == 2)
app.requestUserAttention(0);
else
if (type != 3);
}
catch (Exception e)
{
throw new PlatformManagerException("Failed to request user attention", e);
}
}
static
{
LOGID = LogIDs.CORE;
initializeSingleton();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -