views:

490

answers:

4

I know how to get the favourites from IE, but how can I access Firefox's bookmarks?

Here's the code I have for retrieving the IE favourites:

uses
  ShlObj, ActiveX;

function GetIEFavourites(const favpath: string): TStrings;
var
  searchrec: TSearchRec;
  str: TStrings;
  path, dir, FileName: string;
  Buffer: array[0..2047] of Char;
  found: Integer;
begin
  str := TStringList.Create;
  // Get all file names in the favourites path
  path  := FavPath + '\*.url';
  dir   := ExtractFilepath(path);
  found := FindFirst(path, faAnyFile, searchrec);
  while found = 0 do
  begin
    // Get now URLs from files in variable files
    Setstring(FileName, Buffer, GetPrivateProfilestring('InternetShortcut',
      PChar('URL'), nil, Buffer, SizeOf(Buffer), PChar(dir + searchrec.Name)));
    str.Add(FileName);
    found := FindNext(searchrec);
  end;
  // find Subfolders
  found := FindFirst(dir + '\*.*', faAnyFile, searchrec);
  while found = 0 do
  begin
    if ((searchrec.Attr and faDirectory) > 0) and (searchrec.Name[1] <> '.') then
      str.Addstrings(GetIEFavourites(dir + '\' + searchrec.Name));
    found := FindNext(searchrec);
  end;
  FindClose(searchrec);
  Result := str;
end;

procedure FreePidl(pidl: PItemIDList);
var
  allocator: IMalloc;
begin
  if Succeeded(SHGetMalloc(allocator)) then
  begin
    allocator.Free(pidl);
    {$IFDEF VER100}
    allocator.Release;
    {$ENDIF}
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  pidl: PItemIDList;
  FavPath: array[0..MAX_PATH] of Char;
begin
  if Succeeded(ShGetSpecialFolderLocation(Handle, CSIDL_FAVORITES, pidl)) then
  begin
    if ShGetPathfromIDList(pidl, FavPath) then
      ListBox1.Items := GetIEFavourites(StrPas(FavPath));
    // The calling application is responsible for freeing the PItemIDList-pointer
    // with the Shell's IMalloc interface
    FreePIDL(pidl);
  end;
end;

Thanks.

A: 

well considiring you need points to reply thats a very hard thing to do lol? or are you just joking? regardless please dont spam this topic I already know that..

any ideas to above question.

No, Bill, you don't need points to edit your own question or to post comments on answers to your own question. But in order for the site to recognize "your question," you *do* need to log in using the same account you used to ask it. Once you decide which account you want to use, you can use the "contact us" link at the bottom of this page to ask an admin to merge all your accounts into one.
Rob Kennedy
A: 

Well, Firefox bookmarks are a HTML file stored in <WindowsUserPath>\Application Data\Mozilla\Firefox\Profiles\ <aRamdonProfileName>\bookmark.htm as Sinan Ünür said.

So you need to get the mozilla profiles dir and retrie the folder name in there.

After that you need to parse the html file.....

So AFAIK, no, there's no API to directly get the FF bookmarks.

Fabricio Araujo
+1  A: 

TBookmarks component from MetaProduct... it's $75.00 though: http://www.metaproducts.com/mp/TBookmarks_component.htm

quote from their site:

For Borland Delphi 2, 3, 4, 5, 6, 7, 2005, 2006, 2007, 2009.

New! FireFox 3, Safari and Google Chrome Bookmarks are supported!

MetaProducts TBookmarks is a Delphi 2 - 7, 2005-2009 component that helps you to display MS Internet Explorer Favorites (4.0 - 8.0,) MSN Explorer, Opera Hotlists (3.0 - 9.0) and Netscape, Safari, Chrome, FireFox and Mozilla Bookmarks (2.0 - 8.0) in a menu.

Simply drop the TBookmarks component on the form and assign its Menu property and OnURL event. Set Enabled to True to collect all bookmark information in the specified TMenuItem.

You can also use TTreeView component to make TBookmarks populate the entries there automatically.

+2  A: 

The favorites are saved in 'places.sqlite' in the profile folder. They are in table moz_bookmarks. They refer to entries in table moz_places with their field fk. Get sqlite as dll and a delphi binding like this one.

Open the database with SQLite3_Open and use SQLite3_Exec to send ordinary sql statements to access the data, like

SELECT * FROM moz_bookmarks;

Unfortunately firefox locks places.sqlite, which means you have to copy it first (normal file copy). After you have worked on the copy you can delete it.

Ozan
When I try using the sqlite3 command-line program, I am barred access to the places.sqlite file. It says the database is locked; I assume that's because Firefox is still running. Would other programs using the DLL likely have the same problem?
Rob Kennedy
Yes, Firefox keeps a lock on the file, you need to copy it first and then work with the copy. You can copy it while Firefox is running.
Ozan