Introduction
I could not find a simple tool to keep my Firefox bookmarks from work synchronized with my bookmarks at home, so I finally decided to write some code myself.
The code does not do (too) much, it solves the problem to some extend though: the program reads the "boookmarks.html" file from Firefox and treats it like a set of nodes.
Using the code
Just start the solution in VS2005 or another appropriate tool, the main engine can be found in the merge loop in MozillaLinkMerger.cs. Identify the file you want to use as the master file and some slave files you wish to merge into the master file. Don't worry, the original master file is saved in a different name (some GUID).
public void Merge()
{
if (Stopped)
return;
string[] masterFileLines =
System.IO.File.ReadAllLines(_masterLinksFilePath);
MozillaFile masterFile = new MozillaFile(masterFileLines);
IncrementProgress();
if (Stopped)
return;
foreach (string slaveFile in _slaveFiles)
{
string[] slaveFileLines =
System.IO.File.ReadAllLines(slaveFile);
MozillaFile slave = new MozillaFile(slaveFileLines);
masterFile.Merge(slave);
this.TotalNumberOfNewLinksFound =
masterFile.NumberOfNewLinksFound;
IncrementProgress();
if (Stopped)
return;
}
if (RemoveDuplicates)
{
masterFile.RemoveDuplicateLinks();
}
masterFile.Save(_mergedLinksFilepath);
_isDone = true;
IncrementProgress();
}
Points of Interest
Well, I did try to keep it simple.. If you are familiar with regular expressions, you may find better ways to identify links and folders in Firefox-bookmarks. I don't tend to write that many comments, so hopefully the code will be somewhat self-explaining.