| 1 | REBOL [
|
|---|
| 2 | Title: "RebGUI update system"
|
|---|
| 3 | Owner: "Ashley G. Trüter"
|
|---|
| 4 | Purpose: "Syncs locally cached RebGUI files against internet copy."
|
|---|
| 5 | Acknowledgements: {
|
|---|
| 6 | Anton Rolls wrote all the hard bits, I just tidied it up a bit! ;)
|
|---|
| 7 |
|
|---|
| 8 | Cursor control sequences from http://www.rebolforces.com/articles/tui-dialect.html
|
|---|
| 9 |
|
|---|
| 10 | "You have to stare at read-net for a while to understand how to implement the read-thru/progress
|
|---|
| 11 | callback." - Anton
|
|---|
| 12 | }
|
|---|
| 13 | History: {
|
|---|
| 14 | 30 Added old/new version comparison to end
|
|---|
| 15 | 32 Check for header/version where download is new
|
|---|
| 16 | 37 Allow specific rebgui.r build to be requested (e.g. do/args %get-rebgui.r 36)
|
|---|
| 17 | 65 Cleaned up comments
|
|---|
| 18 | }
|
|---|
| 19 | ToDo: {
|
|---|
| 20 | Full report:
|
|---|
| 21 | - did all files exist and checksum or not?
|
|---|
| 22 | - if not, give advice what to do.
|
|---|
| 23 | Use read-thru/check (seems to be info-based, not checksum/secure?)
|
|---|
| 24 | }
|
|---|
| 25 | ]
|
|---|
| 26 |
|
|---|
| 27 | context [
|
|---|
| 28 |
|
|---|
| 29 | quiet?: system/options/quiet ; remember previous setting
|
|---|
| 30 | system/options/quiet: yes ; prevent "connecting to: www.dobeash.com" messages
|
|---|
| 31 | site: http://www.dobeash.com/RebGUI/
|
|---|
| 32 |
|
|---|
| 33 | either system/script/args [
|
|---|
| 34 | unless exists? url: rejoin [site %rebgui-b system/script/args %.r] [
|
|---|
| 35 | make error! join url " not found!"
|
|---|
| 36 | ]
|
|---|
| 37 | read-thru/expand/update/to url view-root/public/www.dobeash.com/RebGUI/rebgui.r
|
|---|
| 38 | ][
|
|---|
| 39 | header: none
|
|---|
| 40 | if exists-thru? site/rebgui.r [
|
|---|
| 41 | header: first load/header path-thru site/rebgui.r
|
|---|
| 42 | print ["Local RebGUI build ====>" header/version]
|
|---|
| 43 | ]
|
|---|
| 44 |
|
|---|
| 45 | print ["Remote directory ======>" site "^/Local directory =======>" to-local-file path-thru site]
|
|---|
| 46 |
|
|---|
| 47 | backspace: "^(1B)[D^(1B)[P" ; cursor control sequence; left followed by delete
|
|---|
| 48 |
|
|---|
| 49 | download: func [url [url!] /local report data][
|
|---|
| 50 | if data: read-thru/progress/expand/update url func [total bytes][
|
|---|
| 51 | if report [loop length? report [prin backspace]] ; delete previous report
|
|---|
| 52 | ;report: rejoin [bytes " bytes of " total " total = " round (100 * bytes / total) "% "]
|
|---|
| 53 | report: join round (100 * bytes / total) "%"
|
|---|
| 54 | prin report
|
|---|
| 55 | bytes <= total ; only return false to interrupt download
|
|---|
| 56 | ][
|
|---|
| 57 | write/binary path-thru url data
|
|---|
| 58 | data
|
|---|
| 59 | ]
|
|---|
| 60 | ]
|
|---|
| 61 |
|
|---|
| 62 | prin "Downloading manifest ==> "
|
|---|
| 63 | if none? manifest: load-thru/update site/manifest.txt [
|
|---|
| 64 | make error! "Download failed!"
|
|---|
| 65 | ]
|
|---|
| 66 | print "OK^/^/Checking files in manifest against your local directory:"
|
|---|
| 67 | url: none
|
|---|
| 68 | foreach [check file] manifest [
|
|---|
| 69 | url: site/:file
|
|---|
| 70 | prin [" " copy/part join file " ............................." 32 " "]
|
|---|
| 71 | either exists-thru? url [ ; file exists locally?
|
|---|
| 72 | either check = checksum/secure read-thru url [ ; local file's checksum matches checksum in manifest ?
|
|---|
| 73 | print "OK"
|
|---|
| 74 | ][
|
|---|
| 75 | either download url [
|
|---|
| 76 | loop 4 [prin backspace]
|
|---|
| 77 | print either check = checksum/secure read-thru url ["OK"]["Bad checksum!"]
|
|---|
| 78 | ][
|
|---|
| 79 | print "Download failed!"
|
|---|
| 80 | ]
|
|---|
| 81 | ]
|
|---|
| 82 | ][
|
|---|
| 83 | download url
|
|---|
| 84 | loop 4 [prin backspace]
|
|---|
| 85 | print "OK"
|
|---|
| 86 | ]
|
|---|
| 87 | ]
|
|---|
| 88 |
|
|---|
| 89 | header2: first load/header path-thru site/rebgui.r
|
|---|
| 90 | all [header print ["Old RebGUI build ======>" header/version]]
|
|---|
| 91 | print ["New RebGUI build ======>" header2/version]
|
|---|
| 92 |
|
|---|
| 93 | print "Finished processing manifest." ; <-- should be a full report
|
|---|
| 94 | wait 1
|
|---|
| 95 | ]
|
|---|
| 96 | system/options/quiet: quiet?
|
|---|
| 97 | ] |
|---|