Monday, November 08, 2010 at 12:04 AM.
system.verbs.builtins.radio.backup.verifyTemplates
on verifyTemplates (adrErrorCallback=nil) { <<Changes <<1/15/03; 12:46:17 PM by JES <<Rewrite: Verify the plain-text template files instead of the contents of an .fttb file. <<bundle //old version <<local (flerror = false) <<on error (s) //call the error callback <<flerror = true <<if adrErrorCallback != nil <<return (adrErrorCallback^ ("Verification of backup failed because " + s)) << <<local (pc = file.getPathChar ()) <<local (fname = "wwwTemplates.xml") <<local (fname = "wwwTemplates.fttb") <<local (f = user.radio.backup.prefs.folder + "prefs" + pc + fname) <<if not file.exists (f) <<error ("the file, \"" + fname + "\" does not exist.") <<return (false) << <<local (templates) <<bundle //old fat-page extraction code <<local (s = file.readWholeFile (f)) <<local (atts) <<if not fatPages.getPageAtts (@s, @atts) <<error ("the file, \"" + fname + "\" does not contain any data.") <<return (false) <<if not defined (atts.pageData) <<error ("the file, \"" + fname + "\" does not contain any data.") <<return (false) <<local (adr = atts.adrPageData) <<try //unpack the data and verify that it's a table <<fatPages.unpackOdbObject (@atts, @templates, flEdit:false) <<if typeOf (templates) != tabletype <<error ("the data contained in the file, \"" + fname + "\" is not of the correct type.") <<return (false) <<else //error unpacking data <<error ("the file, \"" + fname + "\" does not contain valid data.") <<return (false) <<try //verify the file contents <<table.xmlToTable (file.readWholeFile (f), @templates) <<local (floop) <<fileloop (floop in user.radio.prefs.wwwfolder) <<fname = file.filefrompath (floop) <<if fname beginsWith "#" <<local (adritem = @templates.data.[fname]) <<if defined (adritem^) <<local (s = string (file.readwholefile (f)) ) <<if adritem^.filetext != s //is the backup the same as the original? <<if not error ("the contents of the template file, \"" + fname + "\" differs from the backed up version.") <<return (false) <<else //template is not backed up at all <<if not error ("the template file, \"" + fname + "\" has not been backed up.") <<return (false) <<else //error verifying the files <<if not error ("an error occurred verifying the file, \"" + file.fileFromPath (f) + "\": " + tryerror) <<return (false) << <<return (not flerror) <<11/30/02; 4:10:12 PM by JES <<Created. Verify backed up templates. local (pc = file.getpathchar ()); local (backupfolder = user.radio.backup.prefs.folder + "templates" + pc); local (errormessage, flerror = false); on error (s) { //call the error callback flerror = true; if adrErrorCallback != nil { return (adrErrorCallback^ ("Verification of backup failed because " + s))}}; on verifyOneTemplate (f) { local (fname = file.fileFromPath (f)); local (partialpath = string.delete (f, 1, sizeOf (user.radio.prefs.wwwfolder)) ); local (fbackup = backupfolder + partialpath); fbackup = file.folderFromPath (fbackup) + string.popLeading (fname, "#"); if not file.exists (fbackup) { errormessage = "the template file, \"" + fname + "\" does not exist."; return (false)}; if not file.readWholeFile (f) == file.readWholeFile (fbackup) { errormessage = "the backup of template file, \"" + fname + "\" is different from the original."; return (false)}; return (true)}; fileloop (f in user.radio.prefs.wwwfolder) { local (fname = file.fileFromPath (f)); if not file.isVisible (f) { continue}; if fname beginsWith "." { continue}; if fname beginsWith "#" { if not verifyOneTemplate (f) { if not error (errormessage) {return (false)}}}}; return (not flerror)}; bundle { //test code on errorCallback (s) { dialog.alert (s); return (false)}; verifyTemplates (@errorCallback)}
This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.