Skip to content

Commit 0b14837

Browse files
authored
Download CEF from opensource.spotify.com (#1298)
* Download CEF from opensource.spotify.com * Switch CEF from online SHA1 to offline SHA256 * Add error handling when downloading CEF * Use sha256 for discord too
1 parent 2e02ebe commit 0b14837

File tree

3 files changed

+25
-27
lines changed

3 files changed

+25
-27
lines changed

utils/buildactions/install_cef.lua

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ premake.modules.install_cef = {}
44

55
-- Config variables
66
local CEF_PATH = "vendor/cef3/"
7-
local CEF_URL_PREFIX = "https://mirror.mtasa.com/bdata/cef/"
7+
local CEF_URL_PREFIX = "http://opensource.spotify.com/cefbuilds/cef_binary_"
88
local CEF_URL_SUFFIX = "_windows32_minimal.tar.bz2"
99

10-
local CEF_VERSION = "80.0.4+g74f7b0c+chromium-80.0.3987.122" -- Change here to update CEF version
10+
-- Change here to update CEF version
11+
local CEF_VERSION = "80.0.4+g74f7b0c+chromium-80.0.3987.122"
12+
local CEF_HASH = "8FD8E24AF196F00FEAAA1553496BAE99D8196BA023D0DD0FE44EFEEE93B04DFC"
1113

1214
function make_cef_download_url()
1315
return CEF_URL_PREFIX..http.escapeUrlParam(CEF_VERSION)..CEF_URL_SUFFIX
@@ -21,28 +23,24 @@ newaction {
2123
-- Only execute on Windows
2224
if os.host() ~= "windows" then return end
2325

24-
-- Download md5
25-
local correct_checksum, result_string = http.get(make_cef_download_url()..".md5")
26-
if result_string ~= "OK" and result_string then
27-
print("Could not check CEF checksum: "..result_string)
28-
return -- Do nothing and rely on earlier installed files (to allow working offline)
29-
30-
-- TODO(jusonex): It might make sense to fallback to spotify cef mirror
31-
end
32-
33-
-- Trim whitespace
34-
correct_checksum = correct_checksum:gsub("[%s%c]", "")
35-
36-
-- Check md5
26+
-- Check file hash
3727
local archive_path = CEF_PATH.."temp.tar.bz2"
38-
if os.isfile(archive_path) and os.md5_file(archive_path) == correct_checksum then
28+
if os.isfile(archive_path) and os.sha256_file(archive_path) == CEF_HASH then
3929
print("CEF consistency checks succeeded")
4030
return
4131
end
4232

4333
-- Download CEF
4434
print("Downloading CEF...")
45-
http.download(make_cef_download_url(), archive_path)
35+
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()
42+
return
43+
end
4644

4745
-- Delete old CEF files
4846
-- TODO: It might be better to download the files into a new folder and delete this folder at once
@@ -56,10 +54,10 @@ newaction {
5654
-- Extract first bz2 and then tar
5755
os.extract_archive(archive_path, CEF_PATH, true) -- Extract .tar.bz2 to .tar
5856
os.extract_archive(CEF_PATH.."temp.tar", CEF_PATH, true) -- Extract .tar
59-
57+
6058
-- Move all files from cef_binary*/* to ./
6159
os.expanddir_wildcard(CEF_PATH.."cef_binary*", CEF_PATH)
62-
60+
6361
-- Delete .tar archive, but keep .tar.bz2 for checksumming
6462
os.remove(CEF_PATH.."temp.tar")
6563
end

utils/buildactions/install_discord.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ local DISCORD_VENDOR = "vendor/discordgsdk"
99

1010
-- Change these to update the version
1111
local DISCORD_TAG = "v2020-11-02_21-48-56"
12-
local DISCORD_MD5 = "3d7b86f7fee560d85de3d6e9bac1efbb"
12+
local DISCORD_HASH = "4CCEEED0D8B41BDC67C44A6DDCCCF42288AF933E1F7284C591327178C391AA39"
1313

1414
newaction {
1515
trigger = "install_discord",
@@ -19,9 +19,9 @@ newaction {
1919
-- Only execute on Windows
2020
if os.host() ~= "windows" then return end
2121

22-
-- Check md5
22+
-- Check file hash
2323
local archive_path = DISCORD_VENDOR.."/"..DISCORD_FILENAME
24-
if os.isfile(archive_path) and os.md5_file(archive_path) == DISCORD_MD5 then
24+
if os.isfile(archive_path) and os.sha256_file(archive_path) == DISCORD_HASH then
2525
print("Discord Game SDK is up to date.")
2626
return
2727
end

utils/buildactions/utils.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,18 @@ end
7777
function os.expanddir_wildcard(from, to)
7878
local dir = os.matchdirs(from)[1]
7979
if not dir then return end
80-
80+
8181
-- TODO: Optimize this
8282
os.copydir(dir, to)
8383
os.rmdir(dir)
8484
end
8585

86-
function os.md5_file(path)
86+
function os.sha256_file(path)
8787
if os.host() == "windows" then
88-
local s, errc = os.outputof(string.format("CertUtil -hashfile \"%s\" MD5", path))
89-
return (s:match("\n(.*)\n(.*)") or ""):gsub(" ", "")
88+
local s, errc = os.outputof(string.format("powershell -Command (Get-FileHash \"%s\" -Algorithm SHA256).Hash", path))
89+
return (errc == 0) and s or ""
9090
else
91-
return os.outputof(string.format("md5sum \"%s\" | awk '{ print $1 }'", path))
91+
return os.outputof(string.format("sha256sum \"%s\" | awk '{ print $1 }'", path))
9292
end
9393
end
9494

0 commit comments

Comments
 (0)