Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is the full code, console application. Summary: preferences file is located in application roaming folder, something like this on windows 7:</p> <p>C:\Users\MYNAME\AppData\Roaming\Mozilla\Firefox\Profiles\d9i9jniz.default\prefs.js</p> <p>We alter this file so that it includes "user_pref("browser.download.useDownloadDir", false);"</p> <p>Restart firefox, and done. Only run this application when firefox is not running.</p> <pre><code> static void Main(string[] args) { if (isFireFoxOpen()) { Console.WriteLine("Firefox is open, close it"); } else { string pathOfPrefsFile = GetPathOfPrefsFile(); updateSettingsFile(pathOfPrefsFile); Console.WriteLine("Done"); } Console.ReadLine(); } private static void updateSettingsFile(string pathOfPrefsFile) { string[] contentsOfFile = File.ReadAllLines(pathOfPrefsFile); // We are looking for "user_pref("browser.download.useDownloadDir", true);" // This needs to be set to: // "user_pref("browser.download.useDownloadDir", false);" List&lt;String&gt; outputLines = new List&lt;string&gt;(); foreach (string line in contentsOfFile) { if (line.StartsWith("user_pref(\"browser.download.useDownloadDir\"")) { Console.WriteLine("Found it already in file, replacing"); } else { outputLines.Add(line); } } // Finally add the value we want to the end outputLines.Add("user_pref(\"browser.download.useDownloadDir\", false);"); // Rename the old file preferences for safety... File.Move(pathOfPrefsFile, Path.GetDirectoryName(pathOfPrefsFile) + @"\" + Path.GetFileName(pathOfPrefsFile) + ".OLD." + Guid.NewGuid().ToString()); // Write the new file. File.WriteAllLines(pathOfPrefsFile, outputLines.ToArray()); } private static string GetPathOfPrefsFile() { // Get roaming folder, and get the profiles.ini string iniFilePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Mozilla\Firefox\profiles.ini"; // Profiles.ini tells us what folder the preferences file is in. string contentsOfIni = File.ReadAllText(iniFilePath); int locOfPath = contentsOfIni.IndexOf("Path=Profiles"); int endOfPath = contentsOfIni.IndexOf(".default", locOfPath); int startOfPath = locOfPath + "Path=Profiles".Length + 1; int countofCopy = ((endOfPath + ".default".Length) - startOfPath); string path = contentsOfIni.Substring(startOfPath, countofCopy); string toReturn = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Mozilla\Firefox\Profiles\" + path + @"\prefs.js"; return toReturn; } public static bool isFireFoxOpen() { foreach (Process proc in Process.GetProcesses()) { if (proc.ProcessName == "firefox") { return true; } } return false; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload