Delicious transfers backup files to Firefox bookmarks, delicious2firefox-original and Open Source

Source: Internet
Author: User
Delicious (delicious bookmarks) has been plagued by new pages since its revision at the end of September. It is no longer useful and bookmarks are not normal, forcing me to make changes. Soon after finding a solution, I found that Firefox Bookmarks can be synchronized on different machines, as long as you log on to the same account, so I backed up the bookmarks on delicious into HTML files and prepared to import them to Firefox. The problem arises: Firefox is not compatible with delicious backup files. So I wrote a set Program , Change this file to a format recognized by Firefox, Code Paste it out and share it with friends who have encountered the same problem. The development environment is vs2010.

Download the source code:/files/benjaminyao/delicious2firefox.7z

 

View code Private Void Btnbrowers_click ( Object Sender, eventargs E)
{
Openfiledialog ofd = New Openfiledialog ();
Ofd. Filter = " HTM files (*. htm) | *. htm " ;

If (OFD. showdialog () = dialogresult. OK)
{
Try
{
Createfirefoxfile (OFD. filename );
}
Catch
{
MessageBox. Show ( " The file you selected may not be a backup file of the delicious bookmarks, or may cause program errors due to other unknown causes. Welcome to the http://www.cnblogs.com/BenjaminYao and the author contact, joint improvement. " ,
" Error " , Messageboxbuttons. OK, messageboxicon. Error );
Return ;
}
}
}

///   <Summary>
/// Hash Table separator, used to connect to keys, to avoid being the same as normal separators, such as "-"
///   </Summary>
Private Static Readonly String Keyseparator = " *#*#* " ;

Private Void Createfirefoxfile (String Filename)
{
If (! File. exists (filename ))
{
MessageBox. Show ( " File does not exist " , " Error " , Messageboxbuttons. OK, messageboxicon. Error );
Return ;
}

String Oldall = file. readalltext (filename, encoding. utf8 );

String Head = oldall. substring ( 0 , Oldall. indexof ( " <DL> <p> " ) + 7 );
String Oldbody = oldall. substring (head. length, oldall. indexof ( " </Dl> <p> " )-Head. Length );
String Foot = oldall. substring (oldall. indexof ( " </Dl> <p> " ));

// Generate a hash table
Hashtable hstbody = New Hashtable ();
Int I = 1 ; // Avoid identical keys in the hash table
Foreach ( String Bookmark In RegEx. Split (oldbody, " <DT> " ))
{
If (Bookmark. indexof ( " A href " )> = 0 )
{
// Retrieve Tag Name
String Key = bookmark. substring (
Bookmark. indexof ( " Tags = \" " ) + 6 ,
Bookmark. indexof ( " \ "> " )-(Bookmark. indexof ( " Tags = \" " ) + 6 ))
+ Keyseparator
+ Convert. tostring (I ++ );
Hstbody. Add (Key, Bookmark );
}
}

If (hstbody. count = 0 )
{< br> MessageBox. show ( " NO bookmarks " , " warning " , messageboxbuttons. OK, messageboxicon. warning);
return ;
}

//Sort hash tables
Arraylist akeys =NewArraylist (hstbody. Keys );
Akeys. Sort ();

StringTempkey =String. Empty;
BoolIshead =True;

Stringbuilder sbnewbody =New Stringbuilder ();
Foreach ( String Akey In Akeys)
{
// Insert tags (labels are Directories)
If (Tempkey. tolower ()! = Akey. substring ( 0 , Akey. indexof (keyseparator). tolower ())
{
Tempkey = akey. substring ( 0 , Akey. indexof (keyseparator ));

If(Ishead)
{
Sbnewbody. appendformat ("\ N <DT> <H3 folded add_date = \ "\"> {0} ", Tempkey );

Ishead = False ;
}
Else
{
Sbnewbody. appendformat ( " </Dl> <p> \ n <DT> <H3 folded add_date = \ "\"> {0} " , Tempkey );
}
}

Sbnewbody. append ("<DT>"+ Hstbody [akey]. tostring ());
}

Sbnewbody. append ("</Dl> <p> \ n");

string newbody = sbnewbody. tostring ();
head = head. replace ( " charset = UTF-8 " , " charset = gb2312 " );
string Newall = head + newbody + foot;

// Generate a file
string newfilename = filename. substring ( 0 , filename. lastindexof ( ' \\ ') + 1 );
newfilename + = " delicious2firefox.htm " ;

File. writealltext (newfilename, Newall, encoding. getencoding ("Gb2312"));

MessageBox. Show ("Congratulations! The conversion is successful. Import the generated delicious2firefox.htm to the Firefox bookmarks.","Successful", Messageboxbuttons. OK, messageboxicon. Asterisk );
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.