@@ -9,19 +9,86 @@ local CEF_URL_SUFFIX = "_windows32_minimal.tar.bz2"
99
1010-- Change here to update CEF version
1111local CEF_VERSION = " 80.0.4+g74f7b0c+chromium-80.0.3987.122"
12- local CEF_HASH = " 8FD8E24AF196F00FEAAA1553496BAE99D8196BA023D0DD0FE44EFEEE93B04DFC "
12+ local CEF_HASH = " 8fd8e24af196f00feaaa1553496bae99d8196ba023d0dd0fe44efeee93b04dfc "
1313
1414function make_cef_download_url ()
1515 return CEF_URL_PREFIX .. http .escapeUrlParam (CEF_VERSION ).. CEF_URL_SUFFIX
1616end
1717
18+ function errormsg (title , message )
19+ term .pushColor (term .red )
20+ io.write (title )
21+ if message then
22+ term .setTextColor (term .purple )
23+ print (" " .. message )
24+ else
25+ print ()
26+ end
27+ term .popColor ()
28+ end
29+
30+ function update_install_cef (version , hash )
31+ local filename = " utils/buildactions/install_cef.lua"
32+ local f = io.open (filename )
33+ local text = f :read (" *all" )
34+ f :close ()
35+
36+ -- Replace version and hash lines
37+ local version_line = ' local CEF_VERSION = "' .. version .. ' "'
38+ local hash_line = ' local CEF_HASH = "' .. hash .. ' "'
39+ text = text :gsub (' local CEF_VERSION = ".-"' , version_line , 1 )
40+ text = text :gsub (' local CEF_HASH = ".-"' , hash_line , 1 )
41+
42+ local f = io.open (filename , " w" )
43+ f :write (text )
44+ f :close ()
45+ end
46+
1847newaction {
1948 trigger = " install_cef" ,
2049 description = " Downloads and installs CEF" ,
2150
22- execute = function ()
23- -- Only execute on Windows
24- if os .host () ~= " windows" then return end
51+ execute = function (...)
52+ local upgrade = # _ARGS == 1 and _ARGS [1 ] == " upgrade"
53+ if upgrade then
54+ print (" Checking opensource.spotify.com for an update..." )
55+ resource , result_str , result_code = http .get (" http://opensource.spotify.com/cefbuilds/index.html" )
56+ if result_str ~= " OK" or result_code ~= 200 then
57+ errormsg ((" Could not get page with status code %s: " ):format (response_code ), result_str )
58+ return
59+ end
60+
61+ local _ , index = resource :find (' Windows 32%-bit Builds.-data%-version="' )
62+ if not index then
63+ errormsg (" Could not find version string index." )
64+ return
65+ end
66+
67+ local version = resource :match (" (.-)\" >" , index + 1 )
68+ if not version then
69+ errormsg (" Could not get version string from index." )
70+ end
71+
72+ if version == CEF_VERSION then
73+ print ((" CEF is already up to date (%s)" ):format (version ))
74+ return
75+ end
76+
77+ io.write ((" Does version '%s' look OK to you? (Y/n) " ):format (version ))
78+ local input = io.read ():lower ()
79+ if not (input == " y" or input == " yes" ) then
80+ errormsg (" Aborting due to user request." )
81+ return
82+ end
83+
84+ CEF_VERSION = version
85+ CEF_HASH = " "
86+ end
87+
88+ -- Only execute on Windows in normal scenarios
89+ if os .host () ~= " windows" and not upgrade then
90+ return
91+ end
2592
2693 -- Check file hash
2794 local archive_path = CEF_PATH .. " temp.tar.bz2"
@@ -33,12 +100,33 @@ newaction {
33100 -- Download CEF
34101 print (" Downloading CEF..." )
35102 local result_str , response_code = http .download (make_cef_download_url (), archive_path )
36- if result_str ~= " OK" and response_code ~= 200 then
37- term .pushColor (term .red )
38- io.write ((" Could not download CEF with status code %d: " ):format (response_code ))
39- term .setTextColor (term .purple )
40- print (result_str )
41- term .popColor ()
103+ if result_str ~= " OK" or response_code ~= 200 then
104+ errormsg ((" Could not download CEF with status code %s: " ):format (response_code ), result_str )
105+ return
106+ end
107+
108+ local downloaded_hash = os .sha256_file (archive_path )
109+ if upgrade then
110+ print (" New CEF hash is:" , downloaded_hash )
111+ CEF_HASH = downloaded_hash
112+
113+ io.write ((" Update `install_cef.lua` file? (Y/n) " ):format (version ))
114+ local input = io.read ():lower ()
115+ if (input == " y" or input == " yes" ) then
116+ update_install_cef (CEF_VERSION , downloaded_hash )
117+ end
118+ end
119+
120+ if downloaded_hash == CEF_HASH then
121+ print (" CEF consistency checks succeeded" )
122+ else
123+ errormsg (" CEF consistency checks failed." , (" Expected %s, got %s" ):format (CEF_HASH , downloaded_hash ))
124+ os.exit (1 )
125+ return
126+ end
127+
128+ -- Seriously abort now if we're not using Windows
129+ if os .host () ~= " windows" then
42130 return
43131 end
44132
0 commit comments