Well Perkin, this is annoying.
The exported FireFox bookmarks have a <DD> description field and the IE bookmarks file do not. And that's the only way to tell the difference between the two, even though they both declare themselves to be "!DOCTYPE NETSCAPE-Bookmark-file-1>" at the front!!
I'd have to pre-read both files completely to find out which file is which as my current method uses a toggle flag to read a description from a bookmark file if it exists and when the IE exported bookmarks file is processed, it's all blank lines.
I've edited my current example code below to read out URL/TITLE/DESCRIPTION/CATEGORY/OWNER from the FireFox bookmarks file, give that a test and tell me if you want me to add the pre-read code.
Code: Select all
Enumeration 1
#Window_BookMarks
EndEnumeration
#WindowIndex = #PB_Compiler_EnumerationValue
Enumeration 1
#Gadget_BookMarks_fmain
#Gadget_BookMarks_BookMarks
#Gadget_BookMarks_fcontrol
#Gadget_BookMarks_OpenFile
#Gadget_BookMarks_ExitProgram
EndEnumeration
#GadgetIndex = #PB_Compiler_EnumerationValue
Enumeration 1
#Image_BookMarks_OpenFile
#Image_BookMarks_ExitProgram
EndEnumeration
#ImageIndex = #PB_Compiler_EnumerationValue
CatchImage(#Image_BookMarks_OpenFile, ?_OPT_BookMarks_OpenFile)
CatchImage(#Image_BookMarks_ExitProgram, ?_OPT_BookMarks_ExitProgram)
DataSection
_OPT_BookMarks_OpenFile : IncludeBinary "Images\open32x32.ico"
_OPT_BookMarks_ExitProgram : IncludeBinary "Images\exit32x32.ico"
EndDataSection
Procedure.l Window_BookMarks()
If OpenWindow(#Window_BookMarks,65,76,750,600,"",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered|#PB_Window_Invisible)
Frame3DGadget(#Gadget_BookMarks_fmain,5,0,740,530,"")
ListIconGadget(#Gadget_BookMarks_BookMarks,15,15,720,505,"Bookmark",200,#PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(#Gadget_BookMarks_BookMarks,1,"Title",200)
AddGadgetColumn(#Gadget_BookMarks_BookMarks,2,"Description",200)
AddGadgetColumn(#Gadget_BookMarks_BookMarks,3,"Category",100)
AddGadgetColumn(#Gadget_BookMarks_BookMarks,4,"Owner",100)
SetGadgetFont(#Gadget_BookMarks_BookMarks,LoadFont(#Gadget_BookMarks_BookMarks,"Arial",11,0))
Frame3DGadget(#Gadget_BookMarks_fcontrol,5,530,740,65,"")
ButtonImageGadget(#Gadget_BookMarks_OpenFile,15,545,40,40,ImageID(#Image_BookMarks_OpenFile))
ButtonImageGadget(#Gadget_BookMarks_ExitProgram,695,545,40,40,ImageID(#Image_BookMarks_ExitProgram))
HideWindow(#Window_BookMarks,0)
ProcedureReturn WindowID(#Window_BookMarks)
EndIf
EndProcedure
Declare OpenBookMarks()
Declare.s XMLToText(XMLString.s) ; Strip illegal characters from text strings
; My personal constants
#Author = "Miklós G Bolváry" ; Author's name
#CopyRight = "PeriTek Visions 2010" ; Copyright holder
#Version = "v0.00" ; Program version
#Regstring = " --* Freeware *-- " ; Registration string
#Fish = "<°)))o><²³ " ; Love the fish!
#Basename = "PeriTek Firemarks " ; Base name for ini and dataabse
#Program = #Fish + #Basename + #Version + #Regstring ; Copyright string
#Traynote = #Fish + #Basename + #Version ; Copyright string
#Eol = Chr(13) + Chr(10) ; End of line marker
#TitleTime = 1
; All program variables
Structure ProgramData
QuitValue.i ; Program quit flag
Mutex.i ; Open window flag
TrayState.i ; Is the form minimised to the system tray
CurrentDir.s ; The current program startup directory
CurrentLine.i ; Current line int he list, any program
EndStructure
; Any global variables, lists etc
Global Program.ProgramData ; Structure to hold program data
Global TitleString.s ; The old window title string
; Get working directories variables and create the physical dirs that go with them
Program\CurrentDir = GetCurrentDirectory() ; Get the current directory name
Procedure OpenBookMarks()
BookMarkFile.s = OpenFileRequester("Select FireFix Bookmarks file", Program\CurrentDir, "HTM (*.htm)|*.htm;*.html", 1)
If BookMarkFile.s
ExpressionId.i = CreateRegularExpression(#PB_Any, "\<[^\<]+\>")
OwnerName.s = StringField(GetHomeDirectory(), 3, "\")
InFileId.i = ReadFile(#PB_Any, BookMarkFile.s)
If InFileId.i
While Eof(InFileId) = 0
TempString.s = ReadString(InFileId.i)
If FindString(TempString.s, "<DT>", 1) And FindString(TempString.s, "A HREF", 1)
MainData = 1
TempURL.s = StringField(TempString.s, 2, Chr(34))
TempTitle.s = LTrim(RTrim(ReplaceRegularExpression(ExpressionId.i, TempString.s, "")))
TempTitle.s = XMLToText(TempTitle.s)
If LCase(Right(TempTitle.s, 4)) = ".url"
TempTitle.s = Left(TempTitle.s, Len(TempTitle.s) - 4)
EndIf
;AddGadgetItem(#Gadget_BookMarks_BookMarks, -1, TempURL.s + Chr(10) + TempTitle.s + Chr(10) + "FireFox BookMark" + Chr(10) + OwnerName.s)
EndIf
If FindString(TempString.s, "<DD>", 1) And MainData = 1
Description.s = LTrim(RTrim(ReplaceRegularExpression(ExpressionId.i, TempString.s, "")))
XMLToText(Description.s)
AddGadgetItem(#Gadget_BookMarks_BookMarks, -1, TempURL.s + Chr(10) + TempTitle.s + Chr(10) + Description.s + Chr(10) + "Imported BookMark" + Chr(10) + OwnerName.s)
MainData = 0
EndIf
Wend
Else
Debug "Could not open the file off disk."
EndIf
Else
Debug "User cancelled the file load."
EndIf
EndProcedure
; Strip illegal characters from text strings
Procedure.s XMLToText(XMLString.s)
TextString.s = RemoveString(XMLString.s, Chr(13))
If Left(TextString.s, 1) = Chr(10)
TextString.s = Mid(TextString.s, 2)
EndIf
TextString.s = ReplaceString(TextString.s, "&", "&")
TextString.s = ReplaceString(TextString.s, "<", "<")
TextString.s = ReplaceString(TextString.s, ">", ">")
TextString.s = ReplaceString(TextString.s, "'", "'")
TextString.s = ReplaceString(TextString.s, """, Chr(34))
TextString.s = ReplaceString(TextString.s, "€", "€")
TextString.s = ReplaceString(TextString.s, "'", "'")
;TextString.s = ReplaceString(TextString.s, Chr(10), "")
;TextString.s = ReplaceString(TextString.s, Chr(182), Chr(10))
;TextString.s = ReplaceString(TextString.s, Chr(13), "")
ProcedureReturn Trim(TextString.s)
EndProcedure
XIncludeFile "FireFoxMarks_Constants.pb" ;
XIncludeFile "FireFoxMarks_Windows.pb" ;
XIncludeFile "FireFoxMarks_Mydeclarations.pb" ; All procedural declarations
XIncludeFile "FireFoxMarks_Myconstants.pb" ; All my personal constants
XIncludeFile "Modules\_OpenBookMarks.pbi" ; Open FireFox Bookmarks file
XIncludeFile "Modules\_XMLToText.pbi" ; Strip illegal characters from text strings
If Window_BookMarks()
Program\QuitValue = 0
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Select EventWindow()
Case #Window_BookMarks : Program\QuitValue = 1
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case #Gadget_BookMarks_BookMarks
Select EventType()
Case #PB_EventType_LeftDoubleClick
Case #PB_EventType_RightDoubleClick
Case #PB_EventType_RightClick
Default
EndSelect
Case #Gadget_BookMarks_OpenFile : OpenBookMarks()
Case #Gadget_BookMarks_ExitProgram
EndSelect
EndSelect
Until Program\QuitValue
CloseWindow(#Window_BookMarks)
EndIf
End