【问题标题】:How to get path of Firefox history.sqlite file programatically?如何以编程方式获取 Firefox history.sqlite 文件的路径?
【发布时间】:2013-08-24 22:36:58
【问题描述】:

firefox 历史文件的路径包含一个配置文件编号我如何在 C# 中动态获取此编号

C:\Users\\AppData\Roaming\Mozilla\Firefox\Profiles\.default\formhistory.sqlite

【问题讨论】:

    标签: c# sqlite firefox


    【解决方案1】:

    您可以读出以下包含每个 firefoxprofile 的配置文件名称的 ini 文件:

    "C:\Users\Username\AppData\Roaming\Mozilla\Firefox\profiles.ini"
    

    【讨论】:

      【解决方案2】:

      单击 Windows 开始按钮并在“开始”菜单底部的“搜索”框中键入 %APPDATA%\Mozilla\Firefox\Profiles\,而不按 Enter。配置文件列表将显示在“开始”菜单的顶部。
      单击名称中带有“默认”的配置文件以在窗口中打开它。

      【讨论】:

      • OP 以编程方式明确询问
      【解决方案3】:

      您需要阅读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 "";
              }
          }
      }
      

      【讨论】:

      • 此代码返回 xxxxxx.default 文件夹,而所有必要的文件都位于 xxxxxx.default-release 文件夹中。
      • @AmolPawar 我在 6 年前回答了这个问题。所以现在我猜现在不同了。我稍后再看看。感谢您提供的信息
      • 这段代码使用profiles.ini文件中的第一个Path键,在我的系统上似乎有一个[Install<HASH>]部分,其<HASH>值对应于[的部分名称仅] installs.ini 文件中的部分(对我来说,所有这些文件都在 ~/.mozilla/firefox/ 中)。 default-releaseintroduced in Firefox 67。您可以在about:profiles 查看这些设置。相同的路径在 [Profile0] 部分名称下重复,并且可以通过 here 完成访问。
      猜你喜欢
      • 1970-01-01
      • 2013-06-03
      • 1970-01-01
      • 2011-06-24
      • 1970-01-01
      • 2013-10-25
      • 2016-09-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多