From 6397aa93cf931956c0379143034e59afa5c08d0a Mon Sep 17 00:00:00 2001
From: Patrick <14859495+Patrick2562@users.noreply.github.com>
Date: Wed, 7 Apr 2021 15:09:52 +0200
Subject: [PATCH] [Added] Update check
---
README.md | 2 +-
meta.xml | 5 +++--
updatecheck.lua | 59 +++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 63 insertions(+), 3 deletions(-)
create mode 100644 updatecheck.lua
diff --git a/README.md b/README.md
index 4008c0d..e3dead8 100644
--- a/README.md
+++ b/README.md
@@ -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) |
| :------------ | :-----------------: | :---------------------: | :-----------------------: | :---------------------------: | :---------------------: | :-------------------------: |
diff --git a/meta.xml b/meta.xml
index 580cefd..abdba92 100644
--- a/meta.xml
+++ b/meta.xml
@@ -3,8 +3,9 @@
true
-
-
+
+
+
diff --git a/updatecheck.lua b/updatecheck.lua
new file mode 100644
index 0000000..a33403f
--- /dev/null
+++ b/updatecheck.lua
@@ -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
\ No newline at end of file