forked from multitheftauto/mtasa-blue
/
install_cef.lua
154 lines (127 loc) · 4.42 KB
/
install_cef.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
require 'utils'
premake.modules.install_cef = {}
-- Config variables
local CEF_PATH = "vendor/cef3/"
local CEF_URL_PREFIX = "http://opensource.spotify.com/cefbuilds/cef_binary_"
local CEF_URL_SUFFIX = "_windows32_minimal.tar.bz2"
-- Change here to update CEF version
local CEF_VERSION = "80.1.15+g7b802c9+chromium-80.0.3987.163"
local CEF_HASH = "d7e4243ad7002709cc9c37829a30bdd794ffe573c77c8529b5b4c3d16cd95de3"
function make_cef_download_url()
return CEF_URL_PREFIX..http.escapeUrlParam(CEF_VERSION)..CEF_URL_SUFFIX
end
function errormsg(title, message)
term.pushColor(term.red)
io.write(title)
if message then
term.setTextColor(term.purple)
print(" " .. message)
else
print()
end
term.popColor()
end
function update_install_cef(version, hash)
local filename = "utils/buildactions/install_cef.lua"
local f = io.open(filename)
local text = f:read("*all")
f:close()
-- Replace version and hash lines
local version_line = 'local CEF_VERSION = "' .. version .. '"'
local hash_line = 'local CEF_HASH = "' .. hash .. '"'
text = text:gsub('local CEF_VERSION = ".-"', version_line, 1)
text = text:gsub('local CEF_HASH = ".-"', hash_line, 1)
local f = io.open(filename, "w")
f:write(text)
f:close()
end
newaction {
trigger = "install_cef",
description = "Downloads and installs CEF",
execute = function(...)
local upgrade = #_ARGS == 1 and _ARGS[1] == "upgrade"
if upgrade then
print("Checking opensource.spotify.com for an update...")
resource, result_str, result_code = http.get("http://opensource.spotify.com/cefbuilds/index.html")
if result_str ~= "OK" or result_code ~= 200 then
errormsg(("Could not get page with status code %s: "):format(response_code), result_str)
return
end
local _, index = resource:find('Windows 32%-bit Builds.-data%-version="')
if not index then
errormsg("Could not find version string index.")
return
end
local version = resource:match("(.-)\">", index+1)
if not version then
errormsg("Could not get version string from index.")
end
if version == CEF_VERSION then
print(("CEF is already up to date (%s)"):format(version))
return
end
io.write(("Does version '%s' look OK to you? (Y/n) "):format(version))
local input = io.read():lower()
if not (input == "y" or input == "yes") then
errormsg("Aborting due to user request.")
return
end
CEF_VERSION = version
CEF_HASH = ""
end
-- Only execute on Windows in normal scenarios
if os.host() ~= "windows" and not upgrade then
return
end
-- Check file hash
local archive_path = CEF_PATH.."temp.tar.bz2"
if os.isfile(archive_path) and os.sha256_file(archive_path) == CEF_HASH then
print("CEF consistency checks succeeded")
return
end
-- Download CEF
print("Downloading CEF...")
local result_str, response_code = http.download(make_cef_download_url(), archive_path)
if result_str ~= "OK" or response_code ~= 200 then
errormsg(("Could not download CEF with status code %s: "):format(response_code), result_str)
return
end
local downloaded_hash = os.sha256_file(archive_path)
if upgrade then
print("New CEF hash is:", downloaded_hash)
CEF_HASH = downloaded_hash
io.write(("Update `install_cef.lua` file? (Y/n) "):format(version))
local input = io.read():lower()
if (input == "y" or input == "yes") then
update_install_cef(CEF_VERSION, downloaded_hash)
end
end
if downloaded_hash == CEF_HASH then
print("CEF consistency checks succeeded")
else
errormsg("CEF consistency checks failed.", ("Expected %s, got %s"):format(CEF_HASH, downloaded_hash))
os.exit(1)
return
end
-- Seriously abort now if we're not using Windows
if os.host() ~= "windows" then
return
end
-- Delete old CEF files
-- TODO: It might be better to download the files into a new folder and delete this folder at once
os.rmdir(CEF_PATH.."cmake")
os.rmdir(CEF_PATH.."include")
os.rmdir(CEF_PATH.."libcef_dll")
os.rmdir(CEF_PATH.."Release")
os.rmdir(CEF_PATH.."Resources")
os.remove_wildcard(CEF_PATH.."*.txt")
-- Extract first bz2 and then tar
os.extract_archive(archive_path, CEF_PATH, true) -- Extract .tar.bz2 to .tar
os.extract_archive(CEF_PATH.."temp.tar", CEF_PATH, true) -- Extract .tar
-- Move all files from cef_binary*/* to ./
os.expanddir_wildcard(CEF_PATH.."cef_binary*", CEF_PATH)
-- Delete .tar archive, but keep .tar.bz2 for checksumming
os.remove(CEF_PATH.."temp.tar")
end
}
return premake.modules.install_cef