Skip to content

Commit

Permalink
#36: Support firefox profile for firefox 67 or newer.
Browse files Browse the repository at this point in the history
  • Loading branch information
akuhtz committed Nov 18, 2021
1 parent 3df45c8 commit 73a1bf8
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <i>.mozilla</i> folder in the users home directory to find the profiles.
* Searches for Firefox profile on an Linux / Unix base system. This will scan the <i>.mozilla</i> 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");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,24 @@
import com.github.markusbernhardt.proxy.util.PlatformUtil;

/*****************************************************************************
* Searches for Firefox profile on an OSX system. This will scan the
* <i>Library/Application Support/Firefox</i> folder in the users home directory
* to find the profiles.
* Searches for Firefox profile on an OSX system. This will scan the <i>Library/Application Support/Firefox</i> 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");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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:
* <p>
* <i>Mozilla\Firefox\Profiles\</i>
* </p>
Expand All @@ -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");
}

}

0 comments on commit 73a1bf8

Please sign in to comment.