-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.lua
155 lines (134 loc) · 6.1 KB
/
build.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
155
-- build script for xmake
local package_path = vformat("$(buildir)/package")
-- embed settings
local embeds_path = "src/Installer/embeds"
local embed_files = {
"LICENSE",
"Third_Party_LICENSES",
"README.md",
"README_zh.md",
}
local function check_game_installation(install_path)
assert(install_path, format("Install path not set.\n\tUse the follow command to set install path:\n\txmake f --installpath=%s", [["C:\Program Files (x86)\Steam\steamapps\common\Cyberpunk 2077"]]))
local exe_path = path.join(install_path, "bin", "x64", "Cyberpunk2077.exe")
assert(os.exists(exe_path), format("Can't find the game installation. Make sure the install path is set to game root directory.\n\tUse the follow command to set install path:\n\txmake f --installpath=%s", [["C:\Program Files (x86)\Steam\steamapps\common\Cyberpunk 2077"]]))
end
local function generate_version_lua(git_tag)
local file = io.open("scripts/modules/version.lua", "w")
assert(file, "can't open file scripts/modules/version.lua")
local content = format([[return "%s"]], git_tag)
file:write(content)
file:close()
end
-- Export functions
function UpdateVersion()
local git_tag = os.iorun("git describe --tags"):gsub("\n", "")
generate_version_lua(git_tag)
cprint("generating scripts\\modules\\version.lua ... ${bright green}ok")
if os.exists("src/Common/Version.h.in") then
local file = io.open("src/Common/Version.h.in", "r")
local content = file:read("*a")
file:close()
cprint("generating src\\Common\\Version.h.in ... ${bright green}ok")
content = content:gsub("${GIT_TAG}", git_tag)
cprint("updating the git tag in src\\Common\\Version.h ... ${bright green}ok")
file = io.open("src/Common/Version.h", "w")
file:write(content)
file:close()
end
end
function GenerateEmbeds()
-- clear embed directories
if os.isdir(embeds_path) then
os.tryrm(path.join(embeds_path, "**"))
end
-- create directories for embed files
local embeds_lua_path = path.join(embeds_path, "lua")
local embeds_red4ext_path = path.join(embeds_path, "red4ext")
os.mkdir(embeds_lua_path)
os.mkdir(embeds_red4ext_path)
-- embed red4ext plugin
import("core.project.config")
config.load()
import("core.project.project")
local target = project.target("cet_mod_manager")
print(target:targetfile())
assert(os.exists(target:targetfile()), "target file for cet_mod_manager doesn't exist, run xmake build cet_mod_manager to build the target first.")
os.exec([[.\vendor\bin2cpp\bin2cpp.exe --file=%s --managerfile=EmbedFileManager_Red4ExtPlugin.h --registerfile --namespace=bin2cppRed4ExtPlugin --output=%s --noheader]], target:targetfile(), path.translate(embeds_red4ext_path))
-- embed loose files
for _, file in ipairs(embed_files) do
os.exec([[.\vendor\bin2cpp\bin2cpp.exe --file=%s --managerfile=EmbedFileManager_LooseFiles.h --registerfile --output=%s --namespace=bin2cppLooseFiles --noheader]], file, path.translate(embeds_lua_path))
end
-- embed lua files
os.exec([[.\vendor\bin2cpp\bin2cpp.exe --dir=scripts --managerfile=EmbedFileManager_Lua.h --output=%s --namespace=bin2cppLua --keepdirs --noheader]], path.translate(embeds_lua_path))
cprint("generating files for embedding to %s ... ${bright green}ok", embeds_path)
end
function Package(target)
if os.tryrm(path.join(package_path, "**")) then
cprint("cleaning old package files ... ${bright green}ok")
else
cprint("cleaning old package files ... ${bright red}failed")
end
local output_path = path.join(package_path, "bin/x64/plugins")
os.mkdir(output_path)
cprint("creating file structure ... ${bright green}ok")
if target then
os.cp(target:targetfile(), output_path)
cprint("copying cet_mod_manager.asi ... ${bright green}ok")
end
end
function Install()
import("core.project.config")
config.load()
import("core.project.project")
local target = project.target("installer")
local install_path = config.get("installpath")
cprint("${green bright}Installing CET Mod Manager ..")
check_game_installation(install_path)
assert(os.exists(target:targetfile()), "target file doesn't exist, run xmake to build the target first.")
local output_dir = path.join(install_path, "bin/x64/plugins")
os.cp(target:targetfile(), output_dir)
cprint("CET Mod Manager installed at: ${underline}%s", output_dir)
end
function InstallLua()
import("core.project.config")
config.load()
local install_path = config.get("installpath")
cprint("${green bright}Installing CET Mod Manager Lua ..")
check_game_installation(install_path)
local from_path = path.translate("./scripts")
local to_path = path.translate(path.join(install_path, "bin/x64/plugins/cyber_engine_tweaks/mods/cet_mod_manager"))
os.execv("xcopy", {from_path, to_path, "/s", "/e", "/y", "/q"}) -- Don't use os.cp(), it will remove the contents from the destination directory.
cprint("CET Mod Manager Lua installed at: ${underline}%s", path.translate(path.join(install_path, "bin/x64/plugins/cyber_engine_tweaks/mods/cet_mod_manager")))
end
function InstallExt()
import("core.project.config")
config.load()
import("core.project.project")
local target = project.target("cet_mod_manager")
local install_path = config.get("installpath")
cprint("${green bright}Installing CET Mod Manager Red4ext plugin ..")
check_game_installation(install_path)
assert(os.exists(target:targetfile()), "target file doesn't exist, run xmake to build the target first.")
local output_dir = path.join(install_path, "red4ext/plugins/cet_mod_manager")
os.mkdir(output_dir)
os.cp(target:targetfile(), output_dir)
cprint("CET Mod Manager Lua installed at: ${underline}%s", path.translate(output_dir))
end
function Clean()
if os.tryrm(path.join(embeds_path, "**")) then
cprint("cleaning embed files ... ${bright green}ok")
else
cprint("cleaning embed files ... ${bright red}failed")
end
if os.tryrm(path.join(package_path, "**")) then
cprint("cleaning package files ... ${bright green}ok")
else
cprint("cleaning package files ... ${bright red}failed")
end
end
function BuildAll()
os.execv("xmake", {"b", "cet_mod_manager"})
GenerateEmbeds()
os.execv("xmake", {"b", "installer"})
end