REBOL [ Title: "RebGUI update system" Owner: "Ashley G. Trüter" Version: 0.4.37 Date: 22-Oct-2006 Purpose: "Syncs locally cached RebGUI files against internet copy." Acknowledgements: { Anton Rolls wrote all the hard bits, I just tidied it up a bit! ;) Cursor control sequences from http://www.rebolforces.com/articles/tui-dialect.html "You have to stare at read-net for a while to understand how to implement the read-thru/progress callback." - Anton } History: { 1.0.0 Initial version (Anton) 1.0.1 Swapped manifest fields around (check then file) Removed dirs and dir handling exception condition as per Anton's suggestion Changed checksum to checksum/secure 1.0.2 Fixed "rebpress" tag after incorrectly assuming it was the file name! Added /expand option to read-thru 1.0.3 Tidied up display and added /update refinement to read-thru 1.0.4 Changed site path Cleaned up header 30 Added old/new version comparison to end 32 Check for header/version where download is new 37 Allow specific rebgui.r build to be requested (e.g. do/args %get-rebgui.r 36) } ToDo: { Full report: - did all files exist and checksum or not? - if not, give advice what to do. Use read-thru/check (seems to be info-based, not checksum/secure?) } ] context [ quiet?: system/options/quiet ; remember previous setting system/options/quiet: yes ; prevent "connecting to: www.dobeash.com" messages site: http://www.dobeash.com/RebGUI/ either system/script/args [ unless exists? url: rejoin [site %rebgui-b system/script/args %.r] [ make error! join url " not found!" ] read-thru/expand/update/to url view-root/public/www.dobeash.com/RebGUI/rebgui.r ][ header: none if exists-thru? site/rebgui.r [ header: first load/header path-thru site/rebgui.r print ["Local RebGUI build ====>" header/version] ] print ["Remote directory ======>" site "^/Local directory =======>" to-local-file path-thru site] backspace: "^(1B)[D^(1B)[P" ; cursor control sequence; left followed by delete download: func [url [url!] /local report data][ if data: read-thru/progress/expand/update url func [total bytes][ if report [loop length? report [prin backspace]] ; delete previous report ;report: rejoin [bytes " bytes of " total " total = " round (100 * bytes / total) "% "] report: join round (100 * bytes / total) "%" prin report bytes <= total ; only return false to interrupt download ][ write/binary path-thru url data data ] ] prin "Downloading manifest ==> " if none? manifest: load-thru/update site/manifest.txt [ make error! "Download failed!" ] print "OK^/^/Checking files in manifest against your local directory:" url: none foreach [check file] manifest [ url: site/:file prin [" " copy/part join file " ............................." 32 " "] either exists-thru? url [ ; file exists locally? either check = checksum/secure read-thru url [ ; local file's checksum matches checksum in manifest ? print "OK" ][ either download url [ loop 4 [prin backspace] print either check = checksum/secure read-thru url ["OK"]["Bad checksum!"] ][ print "Download failed!" ] ] ][ download url loop 4 [prin backspace] print "OK" ] ] header2: first load/header path-thru site/rebgui.r all [header print ["Old RebGUI build ======>" header/version]] print ["New RebGUI build ======>" header2/version] print "Finished processing manifest." ; <-- should be a full report wait 1 ] system/options/quiet: quiet? ]