Skip to content

Commit

Permalink
[Added] Update check
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick2562 committed Apr 7, 2021
1 parent 3554a2d commit 6397aa9
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This resource doesn't match with well known bone_attach, you can not use the sam

# Performance Comparison
\- There is not so much similiar resources but I will run some performance tests on them.
CPU usages (Ryzen 5 2600), streamed-in/out attached objects to a ped, on default MTA server with play mod.
CPU usages (Ryzen 5 2600), streamed-in/out attached objects to a ped, on default MTA server with play gamemode.

| Objects count | pAttach (in_stream) | pAttach (out_of_stream) | attachToBones (in_stream) | attachToBones (out_of_stream) | bone_attach (in_stream) | bone_attach (out_of_stream) |
| :------------ | :-----------------: | :---------------------: | :-----------------------: | :---------------------------: | :---------------------: | :-------------------------: |
Expand Down
5 changes: 3 additions & 2 deletions meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
<min_mta_version client="1.5.8-0.20837" />
<oop>true</oop>

<script src="client.lua" type="client" />
<script src="exports.lua" type="shared" />
<script src="updatecheck.lua" type="server" />
<script src="client.lua" type="client" />
<script src="exports.lua" type="shared" />

<export function="attach" type="shared" />
<export function="detach" type="shared" />
Expand Down
59 changes: 59 additions & 0 deletions updatecheck.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
-- SETTINGS -------------------------------------------------------------------------------------------
local CHECK_FOR_UPDATES = true -- change this to 'false' if you don't want to check for new releases!
-------------------------------------------------------------------------------------------------------


if CHECK_FOR_UPDATES then
addEventHandler("onResourceStart", resourceRoot, function()
fetchRemote("https://api.github.com/repos/Patrick2562/mtasa-pAttach/releases/latest", function(data, status)
assert(status == 0 and data, "[pAttach] Can't fetch 'api.github.com' for new releases! (Status code: "..tostring(status)..")")

data = fromJSON(data)

if data then
local latest_id = tonumber(data["id"])
local tag_name = tostring(data["tag_name"])

if latest_id then
local file = fileExists("release") and fileOpen("release") or fileCreate("release")

if file then
local current_id = tonumber(fileRead(file, fileGetSize(file)))

fileSetPos(file, 0)

if not current_id then
fileWrite(file, tostring(latest_id))

elseif latest_id > current_id then
local asset = data["assets"][1]

if asset then
local path = "releases/"..asset["name"]

if fileExists(path) then
print("[pAttach] New release ("..tag_name..") available on Github! It's already downloaded into 'releases' directory inside pAttach, just replace the old one!")

else
fetchRemote(asset["browser_download_url"], function(data, status)
assert(status == 0 and data, "[pAttach] Can't download latest release ("..tag_name..") from Github! (Status code: "..tostring(status)..")")

local zip = fileCreate(path)
if zip then
fileWrite(zip, data)
fileClose(zip)

print("[pAttach] New release ("..tag_name..") available on Github! Automatically downloaded into 'releases' directory inside pAttach, just replace the old one!")
end
end)
end
end
end

fileClose(file)
end
end
end
end)
end)
end

0 comments on commit 6397aa9

Please sign in to comment.