On Aug 22, 2:52 pm, "pedrito" <pixbypedrito at yahoo.comwrote:
I have a small library on SourceForge for reading cookie files from IE and
Firefox:http://ncookiereader.sourceforge.net/
throw new NotImplementedException("No support for finding the cookie path yet.");
For what it's worth, here's what I did once to find the Firefox cookie
path (using the default profile of the current user):
private const string PATH_PROFILES_INI = @"%APPDATA%\Mozilla\Firefox
\profiles.ini";
private const string PATH_COOKIES_TXT = @"%APPDATA%\Mozilla\Firefox\
%PROFILE%\cookies.txt";
....
string pathAppData =
Environment.GetEnvironmentVariable("APPDATA");
string profilesIniPath = PATH_PROFILES_INI.Replace("%APPDATA%",
pathAppData);
string profileDir = null;
// Find default profile in profiles.ini
Dictionary<string, string>[] firefoxProfilesIni =
ParseIniFile(profilesIniPath);
foreach (Dictionary<string, stringiniGroup in
firefoxProfilesIni) {
if (iniGroup.ContainsKey("Default") && iniGroup["Default"] ==
"1")
profileDir = iniGroup["Path"];
}
_cookiePath = PATH_COOKIES_TXT.Replace("%PROFILE%",
profileDir).Replace("%APPDATA%", pathAppData);
....
const string INI_PATTERN = @"\s*\[([^\]]*)\]\r?\n([^\[]*)";
public static Dictionary<string, string>[] ParseIniFile(string
IniFilePath) {
List<Dictionary<string, string>dictList = new
List<Dictionary<string, string>>();
string iniContents = File.ReadAllText(IniFilePath);
MatchCollection mc = Regex.Matches(iniContents, INI_PATTERN,
RegexOptions.Singleline);
foreach (Match m in mc) {
Dictionary<string, stringdict = new Dictionary<string,
string>();
string iniGroupName = m.Groups[1].Value.Trim();
dict.Add("_name", iniGroupName);
string[] newlines = { "\n", "\r", "\r\n" };
foreach (string keyvalue in m.Groups[2].Value.Split(newlines,
StringSplitOptions.RemoveEmptyEntries)) {
if (keyvalue.Contains("=")) {
dict.Add(keyvalue.Split('=')[0].Trim(),
keyvalue.Split('=')[1].Trim());
}
}
dictList.Add(dict);
}
return dictList.ToArray();
}