modify update command

test-utf-8
rubin 2 years ago
parent a1c799fa10
commit 28fb199a23
  1. 34
      TruckHUD.lua

@ -4418,6 +4418,8 @@ script_update = {
ini[name].changelog_url = script_update.changelog_url ini[name].changelog_url = script_update.changelog_url
ini[name].version = thisScript().version ini[name].version = thisScript().version
ini[name].script_name = thisScript().name ini[name].script_name = thisScript().name
local command = (thisScript().name:gsub(" ", "").."-update"):lower()
sampRegisterChatCommand(command, script_update.command)
if ini[name].check_update or ini[name].auto_update then if ini[name].check_update or ini[name].auto_update then
local fpath = os.tmpname() local fpath = os.tmpname()
local result, text = pcall(openURL, script_update.version_url, fpath) local result, text = pcall(openURL, script_update.version_url, fpath)
@ -4429,8 +4431,6 @@ script_update = {
addChatMessage( string.format("Àâòîîáíîâëåíèå ñêðèïòà âêëþ÷åíî. Ïðîöåññ çàïóùåí!") ) addChatMessage( string.format("Àâòîîáíîâëåíèå ñêðèïòà âêëþ÷åíî. Ïðîöåññ çàïóùåí!") )
script_update.command() script_update.command()
else else
local command = (thisScript().name:gsub(" ", "").."-update"):lower()
sampRegisterChatCommand(command, script_update.command)
addChatMessage( string.format("Àâòîîáíîâëåíèå ñêðèïòà âûêëþ÷åíî. Îáíîâèòü ñàìîìó: /%s", command) ) addChatMessage( string.format("Àâòîîáíîâëåíèå ñêðèïòà âûêëþ÷åíî. Îáíîâèòü ñàìîìó: /%s", command) )
end end
end end
@ -4442,16 +4442,26 @@ script_update = {
command = function() command = function()
lua_thread.create(function() lua_thread.create(function()
local fpath = os.tmpname() local fpath = os.tmpname()
local result, text = pcall(openURL, script_update.script_url, fpath) local result, text = pcall(openURL, script_update.version_url, fpath)
if result and text ~= "" and text:find(thisScript().name:gsub("%-", "%%-")) then if result then
local file, error = io.open(thisScript().path, "w") ini[name].server_version = text
if file ~= nil then if text ~= "" and not string.find(text, thisScript().version) then
file:write(text) addChatMessage( string.format("Âûøëà íîâàÿ âåðñèÿ '%s'. Òåêóùàÿ: '%s'", text, thisScript().version) )
file:flush() local fpath = os.tmpname()
io.close(file) local result, text = pcall(openURL, script_update.script_url, fpath)
addChatMessage("Îáíîâëåíèå çàâåðøåíî, ñêðèïò ïåðåçàãðóæåí!") if result and text ~= "" and text:find(thisScript().name:gsub("%-", "%%-")) then
wait(500) local file, error = io.open(thisScript().path, "w")
thisScript():reload() if file ~= nil then
file:write(text)
file:flush()
io.close(file)
addChatMessage("Îáíîâëåíèå çàâåðøåíî, ñêðèïò ïåðåçàãðóæåí!")
wait(500)
thisScript():reload()
end
end
else
addChatMessage("Ó Âàñ óñòàíîâëåíà ïîñëåäíÿÿ âåðñèÿ!")
end end
end end
end) end)

Loading…
Cancel
Save