start browser discovery code for Windows

Former-commit-id: 1060e6959d
Former-commit-id: 006294d2bc4e20cb278a2c8679d8263fe1f13338
This commit is contained in:
idk
2022-08-27 21:36:02 -04:00
parent 8494d297c7
commit 5acee82d76

View File

@ -46,14 +46,33 @@ public class I2PGenericUnsafeBrowser {
* the worst-case scenario but in case it isn't, we can use this function to figure it out.
* Adapted from:
* https://stackoverflow.com/questions/15852885/method-returning-default-browser-as-a-string
* and from:
* https://github.com/i2p/i2p.i2p/blob/master/apps/systray/java/src/net/i2p/apps/systray/UrlLauncher.java
*
* @return path to the default browser ready for execution. Empty string on Linux and OSX.
*/
public static String getDefaultWindowsBrowser() {
if (getOperatingSystem() == "Windows"){
String defaultBrowser = getDefaultOutOfRegistry("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\Shell\\Associations\\URLAssociations\\https\\UserChoice")
if (defaultBrowser != "")
return defaultBrowser;
defaultBrowser = getDefaultOutOfRegistry("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\Shell\\Associations\\URLAssociations\\http\\UserChoice")
if (defaultBrowser != "")
return defaultBrowser;
defaultBrowser = getDefaultOutOfRegistry("HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes\\microsoft-edge\\shell\\open\\command");
if (defaultBrowser != "")
return defaultBrowser;
defaultBrowser = getDefaultOutOfRegistry("HKEY_CLASSES_ROOT\\http\\shell\\open\\command");
if (defaultBrowser != "")
return defaultBrowser;
}
return "";
}
public static String getDefaultOutOfRegistry(String hkeyquery){
try {
// Get registry where we find the default browser
Process process = Runtime.getRuntime().exec("REG QUERY HKEY_CLASSES_ROOT\\http\\shell\\open\\command");
Process process = Runtime.getRuntime().exec("REG QUERY " + hkeyquery);
Scanner kb = new Scanner(process.getInputStream());
while (kb.hasNextLine()) {
String line = kb.nextLine();
@ -68,10 +87,10 @@ public class I2PGenericUnsafeBrowser {
} catch (Exception e) {
e.printStackTrace();
}
}
return "";
}
//"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\Shell\Associations\URLAssociations\(http|https)\UserChoice"
public static String findUnsafeBrowserAnywhere() {
return getDefaultWindowsBrowser();
}