From 73a1bf8482117d893b7ef100b9a65053530ad887 Mon Sep 17 00:00:00 2001 From: Andreas Kuhtz Date: Thu, 18 Nov 2021 09:30:41 +0100 Subject: [PATCH] #36: Support firefox profile for firefox 67 or newer. --- .../browser/firefox/FirefoxSettingParser.java | 30 +++++---- .../firefox/LinuxFirefoxProfileSource.java | 22 +++---- .../firefox/OsxFirefoxProfileSource.java | 25 ++++--- .../firefox/WinFirefoxProfileSource.java | 66 +++++++++---------- 4 files changed, 71 insertions(+), 72 deletions(-) diff --git a/src/main/java/com/github/markusbernhardt/proxy/search/browser/firefox/FirefoxSettingParser.java b/src/main/java/com/github/markusbernhardt/proxy/search/browser/firefox/FirefoxSettingParser.java index bd3c4842..144f2e1a 100644 --- a/src/main/java/com/github/markusbernhardt/proxy/search/browser/firefox/FirefoxSettingParser.java +++ b/src/main/java/com/github/markusbernhardt/proxy/search/browser/firefox/FirefoxSettingParser.java @@ -5,8 +5,10 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; +import java.util.List; import java.util.Map.Entry; import java.util.Properties; +import java.util.stream.Collectors; import org.ini4j.Ini; import org.ini4j.Profile.Section; @@ -98,20 +100,24 @@ protected File getSettingsFile(FirefoxProfileSource source) throws IOException { if (profilesIniFile.exists()) { Ini profilesIni = new Ini(profilesIniFile); - String keyFF67 = - profilesIni.keySet().stream().filter(s -> s.startsWith("Install")).findFirst().orElse(null); - if (keyFF67 != null) { - Logger - .log(getClass(), LogLevel.DEBUG, "Firefox settings for F67+ detected, section key is: {}", keyFF67); - Section section = profilesIni.get(keyFF67); + final List keysFF67 = + profilesIni.keySet().stream().filter(s -> s.startsWith("Install")).collect(Collectors.toList()); + if (!keysFF67.isEmpty()) { + Logger.log(getClass(), LogLevel.DEBUG, "Firefox settings for FF67+ detected."); - if ("1".equals(section.get("Locked"))) { - File profileFolder = - new File(profilesIniFile.getParentFile().getAbsolutePath(), section.get("Default")); - Logger.log(getClass(), LogLevel.DEBUG, "Firefox settings folder is {}", profileFolder); + for (String keyFF67 : keysFF67) { - File settingsFile = new File(profileFolder, "prefs.js"); - return settingsFile; + Logger.log(getClass(), LogLevel.DEBUG, "Current FF67+ section key is: {}", keysFF67); + Section section = profilesIni.get(keyFF67); + + if ("1".equals(section.get("Locked"))) { + File profileFolder = + new File(profilesIniFile.getParentFile().getAbsolutePath(), section.get("Default")); + Logger.log(getClass(), LogLevel.DEBUG, "Firefox settings folder is {}", profileFolder); + + File settingsFile = new File(profileFolder, "prefs.js"); + return settingsFile; + } } } else { diff --git a/src/main/java/com/github/markusbernhardt/proxy/search/browser/firefox/LinuxFirefoxProfileSource.java b/src/main/java/com/github/markusbernhardt/proxy/search/browser/firefox/LinuxFirefoxProfileSource.java index 0d9c4e73..ecfea134 100644 --- a/src/main/java/com/github/markusbernhardt/proxy/search/browser/firefox/LinuxFirefoxProfileSource.java +++ b/src/main/java/com/github/markusbernhardt/proxy/search/browser/firefox/LinuxFirefoxProfileSource.java @@ -5,25 +5,23 @@ import com.github.markusbernhardt.proxy.util.PlatformUtil; /***************************************************************************** - * Searches for Firefox profile on an Linux / Unix base system. This will scan - * the .mozilla folder in the users home directory to find the profiles. + * Searches for Firefox profile on an Linux / Unix base system. This will scan the .mozilla folder in the users + * home directory to find the profiles. * * @author Markus Bernhardt, Copyright 2016 * @author Bernd Rosstauscher, Copyright 2009 ****************************************************************************/ -// TODO 02.06.2015 bros Format has changed in newer versions of firefox. - class LinuxFirefoxProfileSource implements FirefoxProfileSource { - /************************************************************************* - * Get profiles.ini for the Linux Firefox profile - ************************************************************************/ + /************************************************************************* + * Get profiles.ini for the Linux Firefox profile + ************************************************************************/ - @Override - public File getProfilesIni() { - File userDir = new File(PlatformUtil.getUserHomeDir()); - return new File(userDir, ".mozilla" + File.separator + "firefox" + File.separator + "profiles.ini"); - } + @Override + public File getProfilesIni() { + File userDir = new File(PlatformUtil.getUserHomeDir()); + return new File(userDir, ".mozilla" + File.separator + "firefox" + File.separator + "profiles.ini"); + } } diff --git a/src/main/java/com/github/markusbernhardt/proxy/search/browser/firefox/OsxFirefoxProfileSource.java b/src/main/java/com/github/markusbernhardt/proxy/search/browser/firefox/OsxFirefoxProfileSource.java index 39339da5..cf126969 100644 --- a/src/main/java/com/github/markusbernhardt/proxy/search/browser/firefox/OsxFirefoxProfileSource.java +++ b/src/main/java/com/github/markusbernhardt/proxy/search/browser/firefox/OsxFirefoxProfileSource.java @@ -5,27 +5,24 @@ import com.github.markusbernhardt.proxy.util.PlatformUtil; /***************************************************************************** - * Searches for Firefox profile on an OSX system. This will scan the - * Library/Application Support/Firefox folder in the users home directory - * to find the profiles. + * Searches for Firefox profile on an OSX system. This will scan the Library/Application Support/Firefox folder + * in the users home directory to find the profiles. * * @author Markus Bernhardt, Copyright 2016 * @author Bernd Rosstauscher, Copyright 2009 ****************************************************************************/ -// TODO 02.06.2015 bros Format has changed in newer versions of firefox. - class OsxFirefoxProfileSource implements FirefoxProfileSource { - /************************************************************************* - * Get profiles.ini for the Linux Firefox profile - ************************************************************************/ + /************************************************************************* + * Get profiles.ini for the Linux Firefox profile + ************************************************************************/ - @Override - public File getProfilesIni() { - File userDir = new File(PlatformUtil.getUserHomeDir()); - return new File(userDir, "Library" + File.separator + "Application Support" + File.separator + "Firefox" - + File.separator + "profiles.ini"); - } + @Override + public File getProfilesIni() { + File userDir = new File(PlatformUtil.getUserHomeDir()); + return new File(userDir, "Library" + File.separator + "Application Support" + File.separator + "Firefox" + + File.separator + "profiles.ini"); + } } diff --git a/src/main/java/com/github/markusbernhardt/proxy/search/browser/firefox/WinFirefoxProfileSource.java b/src/main/java/com/github/markusbernhardt/proxy/search/browser/firefox/WinFirefoxProfileSource.java index c1de7b15..6c2de0a1 100644 --- a/src/main/java/com/github/markusbernhardt/proxy/search/browser/firefox/WinFirefoxProfileSource.java +++ b/src/main/java/com/github/markusbernhardt/proxy/search/browser/firefox/WinFirefoxProfileSource.java @@ -7,8 +7,8 @@ import com.sun.jna.platform.win32.ShlObj; /***************************************************************************** - * Finds the Firefox profile on Windows platforms. On Windows the profiles are - * located in the users appdata directory under: + * Finds the Firefox profile on Windows platforms. On Windows the profiles are located in the users appdata directory + * under: *

* Mozilla\Firefox\Profiles\ *

@@ -18,39 +18,37 @@ * @author Bernd Rosstauscher, Copyright 2009 ****************************************************************************/ -// TODO 02.06.2015 bros Format has changed in newer versions of firefox. - class WinFirefoxProfileSource implements FirefoxProfileSource { - /************************************************************************* - * Constructor - ************************************************************************/ - - public WinFirefoxProfileSource() { - super(); - } - - /************************************************************************* - * Reads the current location of the app data folder from the registry. - * - * @return a path to the folder. - ************************************************************************/ - - private String getAppFolder() { - return Shell32Util.getFolderPath(ShlObj.CSIDL_APPDATA); - } - - /************************************************************************* - * Get profiles.ini for the Windows Firefox profile - * - * @throws IOException - * on error. - ************************************************************************/ - - @Override - public File getProfilesIni() throws IOException { - File appDataDir = new File(getAppFolder()); - return new File(appDataDir, "Mozilla" + File.separator + "Firefox" + File.separator + "profiles.ini"); - } + /************************************************************************* + * Constructor + ************************************************************************/ + + public WinFirefoxProfileSource() { + super(); + } + + /************************************************************************* + * Reads the current location of the app data folder from the registry. + * + * @return a path to the folder. + ************************************************************************/ + + private String getAppFolder() { + return Shell32Util.getFolderPath(ShlObj.CSIDL_APPDATA); + } + + /************************************************************************* + * Get profiles.ini for the Windows Firefox profile + * + * @throws IOException + * on error. + ************************************************************************/ + + @Override + public File getProfilesIni() throws IOException { + File appDataDir = new File(getAppFolder()); + return new File(appDataDir, "Mozilla" + File.separator + "Firefox" + File.separator + "profiles.ini"); + } }