From 1d58f6d8ce6461150ab43460f76339b403f89d78 Mon Sep 17 00:00:00 2001
From: Patrick <14859495+Patrick2562@users.noreply.github.com>
Date: Wed, 7 Apr 2021 15:26:44 +0200
Subject: [PATCH] [Modify] Update check
---
meta.xml | 2 +-
updatecheck.lua | 69 +++++++++++++++++++++----------------------------
2 files changed, 31 insertions(+), 40 deletions(-)
diff --git a/meta.xml b/meta.xml
index abdba92..959a706 100644
--- a/meta.xml
+++ b/meta.xml
@@ -1,6 +1,6 @@
-
+
true
diff --git a/updatecheck.lua b/updatecheck.lua
index a33403f..02d2a36 100644
--- a/updatecheck.lua
+++ b/updatecheck.lua
@@ -1,8 +1,12 @@
--- SETTINGS -------------------------------------------------------------------------------------------
+-- SETTINGS - You can modify these variables ----------------------------------------------------------
local CHECK_FOR_UPDATES = true -- change this to 'false' if you don't want to check for new releases!
-------------------------------------------------------------------------------------------------------
+-- DON'T MODIFY THESE VARIABLES ---------------
+local VERSION = 113
+-----------------------------------------------
+
if CHECK_FOR_UPDATES then
addEventHandler("onResourceStart", resourceRoot, function()
fetchRemote("https://api.github.com/repos/Patrick2562/mtasa-pAttach/releases/latest", function(data, status)
@@ -11,46 +15,33 @@ if CHECK_FOR_UPDATES then
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
+ local tag_name = tostring(data["tag_name"])
+ local latest_version = tonumber( (tag_name:gsub("v",""):gsub("%.","")) )
+
+ if latest_version then
+ if latest_version > VERSION 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
-
- fileClose(file)
end
end
end