Skip to content

Commit

Permalink
mtaserver.conf.template add header comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando-A-Rocha committed Nov 22, 2024
1 parent 620e1d7 commit d3d5740
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
8 changes: 4 additions & 4 deletions utils/buildactions/compose_files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ local WINDOWS = os.host() == "windows"
newaction {
trigger = "compose_files",
description = "Composes files that are required for building the installer",

execute = function()
os.mkdir(OUTPUT_DIR)

-- Copy data files
if WINDOWS then
os.copydir(DATA_DIR.."/MTA", OUTPUT_DIR.."/MTA")
Expand All @@ -25,9 +25,9 @@ newaction {

-- Copy configs
os.copydir("Server/mods/deathmatch", OUTPUT_DIR.."/server/mods/deathmatch", "*.conf")
os.copyfile(OUTPUT_DIR.."/server/mods/deathmatch/mtaserver.conf", OUTPUT_DIR.."/server/mods/deathmatch/mtaserver.conf.template")
os.makeconfigtemplate(OUTPUT_DIR.."/server/mods/deathmatch/mtaserver.conf", OUTPUT_DIR.."/server/mods/deathmatch/mtaserver.conf.template")
os.copydir("Server/mods/deathmatch", OUTPUT_DIR.."/server/mods/deathmatch", "*.xml")

-- Copy compiled binaries
if WINDOWS then
os.copydir(BIN_DIR, OUTPUT_DIR, "**.exe")
Expand Down
4 changes: 2 additions & 2 deletions utils/buildactions/install_data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ newaction {
return
end

if not os.copyfile(BIN_DIR.."/server/mods/deathmatch/mtaserver.conf", BIN_DIR.."/server/mods/deathmatch/mtaserver.conf.template") then
if not os.makeconfigtemplate(BIN_DIR.."/server/mods/deathmatch/mtaserver.conf", BIN_DIR.."/server/mods/deathmatch/mtaserver.conf.template") then
errormsg("ERROR: Could not copy mtaserver.conf to mtaserver.conf.template")
os.exit(1)
return
Expand All @@ -75,7 +75,7 @@ newaction {
success = success and http.download_print_errors(NET_PATH_X64_WIN, BIN_DIR.."/server/x64/net.dll")
success = success and http.download_print_errors(NET_PATH_ARM64_WIN, BIN_DIR.."/server/arm64/net.dll")
success = success and http.download_print_errors(NETC_PATH_WIN, BIN_DIR.."/MTA/netc.dll")

-- A download failed
if not success then
os.exit(1)
Expand Down
22 changes: 22 additions & 0 deletions utils/buildactions/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,25 @@ function errormsg(title, message)
end
term.popColor()
end

-- Does a normal file copy and adds hardcoded text to the beginning of the resulting file
-- Used in compose_files.lua and install_data.lua
function os.makeconfigtemplate(file_path, result_path)
if not os.copyfile(file_path, result_path) then
return false
end
local result_file = io.open(result_path, "r")
if not result_file then
return false
end
local file_content = result_file:read("*all")
result_file:close()
result_file = io.open(result_path, "w")
if not result_file then
return false, "Failed to open result file for writing."
end
result_file:write("<!-- DELETING THIS FILE IS NOT RECOMMENDED ('mtaserver.conf.template')!\n It is automatically used by the server for inserting missing settings into 'mtaserver.conf' on startup.\n-->\n")
result_file:write(file_content)
result_file:close()
return true
end

0 comments on commit d3d5740

Please sign in to comment.