forked from I2P_Developers/i2p.i2p
Compare commits
3 Commits
i2p-2.7.0
...
advanced-u
Author | SHA1 | Date | |
---|---|---|---|
8922dfeb63 | |||
0904616a59 | |||
a701af21c6 |
@ -44,8 +44,6 @@ import net.i2p.util.SystemVersion;
|
||||
* @author hypercubus
|
||||
*/
|
||||
public class UrlLauncher implements ClientApp {
|
||||
|
||||
private final ShellCommand _shellCommand;
|
||||
private volatile ClientAppState _state;
|
||||
private final I2PAppContext _context;
|
||||
private final ClientAppManager _mgr;
|
||||
@ -101,7 +99,7 @@ public class UrlLauncher implements ClientApp {
|
||||
if (args == null || args.length <= 0)
|
||||
args = new String[] { context.portMapper().getConsoleURL() };
|
||||
_args = args;
|
||||
_shellCommand = new ShellCommand();
|
||||
//_shellCommand = new ShellCommand();
|
||||
_state = INITIALIZED;
|
||||
}
|
||||
|
||||
@ -116,7 +114,7 @@ public class UrlLauncher implements ClientApp {
|
||||
_log = _context.logManager().getLog(UrlLauncher.class);
|
||||
_mgr = null;
|
||||
_args = null;
|
||||
_shellCommand = new ShellCommand();
|
||||
//_shellCommand = new ShellCommand();
|
||||
_state = INITIALIZED;
|
||||
}
|
||||
|
||||
@ -200,76 +198,9 @@ public class UrlLauncher implements ClientApp {
|
||||
if (cbrowser != null) {
|
||||
return openUrl(url, cbrowser);
|
||||
}
|
||||
if (SystemVersion.isMac()) {
|
||||
String osName = System.getProperty("os.name");
|
||||
if (osName.toLowerCase(Locale.US).startsWith("mac os x")) {
|
||||
String[] args = new String[] { "open", url };
|
||||
if (_log.shouldDebug()) _log.debug("Execute: " + Arrays.toString(args));
|
||||
if (_shellCommand.executeSilentAndWaitTimed(args , 5))
|
||||
//I2PBrowser i2pBrowser = new I2PBrowser();
|
||||
//i2pBrowser.launchAndDetach(false, String[]{url});
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
String[] args = new String[] { "iexplore", url };
|
||||
if (_log.shouldDebug()) _log.debug("Execute: " + Arrays.toString(args));
|
||||
if (_shellCommand.executeSilentAndWaitTimed(args , 5))
|
||||
return true;
|
||||
} else if (SystemVersion.isWindows()) {
|
||||
String[] browserString = new String[] { "C:\\Program Files\\Internet Explorer\\iexplore.exe", "-nohome", url };
|
||||
File foo = new File(_context.getTempDir(), "browser" + _context.random().nextLong() + ".reg");
|
||||
String[] args = new String[] { "regedit", "/E", foo.getAbsolutePath(), "HKEY_CLASSES_ROOT\\http\\shell\\open\\command" };
|
||||
if (_log.shouldDebug()) _log.debug("Execute: " + Arrays.toString(args));
|
||||
boolean ok = _shellCommand.executeSilentAndWait(args);
|
||||
if (ok) {
|
||||
BufferedReader bufferedReader = null;
|
||||
try {
|
||||
bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(foo), "UTF-16"));
|
||||
for (String line; (line = bufferedReader.readLine()) != null; ) {
|
||||
// @="\"C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe\" -osint -url \"%1\""
|
||||
if (line.startsWith("@=")) {
|
||||
if (_log.shouldDebug()) _log.debug("From RegEdit: " + line);
|
||||
line = line.substring(2).trim();
|
||||
if (line.startsWith("\"") && line.endsWith("\""))
|
||||
line = line.substring(1, line.length() - 1);
|
||||
line = line.replace("\\\\", "\\");
|
||||
line = line.replace("\\\"", "\"");
|
||||
if (_log.shouldDebug()) _log.debug("Mod RegEdit: " + line);
|
||||
// "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -osint -url "%1"
|
||||
// use the whole line
|
||||
String[] aarg = parseArgs(line, url);
|
||||
if (aarg.length > 0) {
|
||||
browserString = aarg;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
if (_log.shouldWarn())
|
||||
_log.warn("Reading regedit output", e);
|
||||
} finally {
|
||||
if (bufferedReader != null)
|
||||
try { bufferedReader.close(); } catch (IOException ioe) {}
|
||||
foo.delete();
|
||||
}
|
||||
} else if (_log.shouldWarn()) {
|
||||
_log.warn("Regedit Failed: " + Arrays.toString(args));
|
||||
}
|
||||
if (_log.shouldDebug()) _log.debug("Execute: " + Arrays.toString(browserString));
|
||||
if (_shellCommand.executeSilentAndWaitTimed(browserString, 5))
|
||||
return true;
|
||||
if (_log.shouldInfo()) _log.info("Failed: " + Arrays.toString(browserString));
|
||||
} else {
|
||||
// fall through
|
||||
}
|
||||
String[] args = new String[2];
|
||||
args[1] = url;
|
||||
for (int i = 0; i < BROWSERS.length; i++) {
|
||||
args[0] = BROWSERS[i];
|
||||
if (_log.shouldDebug()) _log.debug("Execute: " + Arrays.toString(args));
|
||||
if (_shellCommand.executeSilentAndWaitTimed(args, 5))
|
||||
return true;
|
||||
if (_log.shouldInfo()) _log.info("Failed: " + Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -301,8 +232,15 @@ public class UrlLauncher implements ClientApp {
|
||||
if (validateUrlFormat(url)) {
|
||||
String[] args = parseArgs(browser, url);
|
||||
if (args.length > 0) {
|
||||
if (_log.shouldDebug()) _log.debug("Execute: " + Arrays.toString(args));
|
||||
if (_shellCommand.executeSilentAndWaitTimed(args, 5))
|
||||
//I2PBrowser i2pBrowser = new I2PBrowser();
|
||||
//ArrayList<String> visitURL = new ArrayList<String>();
|
||||
//for (String arg : args){
|
||||
// if (arg != args[0])
|
||||
// visitURL.append(arg);
|
||||
//}
|
||||
//I2PBrowser.generic = true;
|
||||
//I2PBrowser.setBrowser(args[0]);
|
||||
//i2pBrowser.launchAndDetatch(false, visitURL.toArray(new String[visitURL.size()]));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user