【发布时间】:2013-08-24 22:36:58
【问题描述】:
firefox 历史文件的路径包含一个配置文件编号我如何在 C# 中动态获取此编号
C:\Users\\AppData\Roaming\Mozilla\Firefox\Profiles\.default\formhistory.sqlite
【问题讨论】:
firefox 历史文件的路径包含一个配置文件编号我如何在 C# 中动态获取此编号
C:\Users\\AppData\Roaming\Mozilla\Firefox\Profiles\.default\formhistory.sqlite
【问题讨论】:
您可以读出以下包含每个 firefoxprofile 的配置文件名称的 ini 文件:
"C:\Users\Username\AppData\Roaming\Mozilla\Firefox\profiles.ini"
【讨论】:
单击 Windows 开始按钮并在“开始”菜单底部的“搜索”框中键入 %APPDATA%\Mozilla\Firefox\Profiles\,而不按 Enter。配置文件列表将显示在“开始”菜单的顶部。
单击名称中带有“默认”的配置文件以在窗口中打开它。
【讨论】:
您需要阅读profiles.ini 文件并捕获默认配置文件
using System;
using System.Linq;
using System.IO;
namespace Firefox
{
class Reader
{
public static string ReadFirefoxProfile()
{
string apppath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string mozilla = System.IO.Path.Combine(apppath, "Mozilla");
bool exist = System.IO.Directory.Exists(mozilla);
if (exist)
{
string firefox = System.IO.Path.Combine(mozilla, "firefox");
if (System.IO.Directory.Exists(firefox))
{
string prof_file = System.IO.Path.Combine(firefox, "profiles.ini");
bool file_exist = System.IO.File.Exists(prof_file);
if (file_exist)
{
StreamReader rdr = new StreamReader(prof_file);
string resp = rdr.ReadToEnd();
string[] lines = resp.Split(new string[] { "\r\n" }, StringSplitOptions.None);
string location = lines.First(x => x.Contains("Path=")).Split(new string[] { "=" }, StringSplitOptions.None)[1];
string prof_dir = System.IO.Path.Combine(firefox, location);
return prof_dir;
}
}
}
return "";
}
}
}
【讨论】:
profiles.ini文件中的第一个Path键,在我的系统上似乎有一个[Install<HASH>]部分,其<HASH>值对应于[的部分名称仅] installs.ini 文件中的部分(对我来说,所有这些文件都在 ~/.mozilla/firefox/ 中)。 default-release 是 introduced in Firefox 67。您可以在about:profiles 查看这些设置。相同的路径在 [Profile0] 部分名称下重复,并且可以通过 here 完成访问。