Skip to content

Commit

Permalink
Merge pull request #230 from fiendish/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
fiendish committed Nov 25, 2015
2 parents bff96fa + 544b929 commit 3d07e9f
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 63 deletions.
4 changes: 4 additions & 0 deletions MUSHclient/AardwolfPackageChanges.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Aardwolf Client Package Major Changes List

r1845 snapshot:
- bug fix: detect file download failures during updates and gently retry a few times.
- misc change: move version file checks to a more central location to hopefully avoid the file handle being held open accidentally by bad copy+pastes.

r1843 snapshot:
- bug fix: two plugins didn't close the version file after opening it, leading to access permission errors in the updater

Expand Down
36 changes: 36 additions & 0 deletions MUSHclient/lua/aard_lua_extras.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module (..., package.seeall)

-- Returns an array of {start, end, text}
function findURLs(text)
local URLs = {}
Expand All @@ -13,3 +15,37 @@ function findURLs(text)
return URLs
end -- function findURL

version_file = "AardwolfPackageChanges.txt"
function PackageVersion()
local ver = "missing"
-- borrowed from the package update checker
local file,err = io.open(version_file, "r")
if file then -- the file exists
--- read the snapshot revision from the third line
line = file:read("*l") -- read one line
line = file:read("*l") -- read one line
line = file:read("*l") -- read one line
file:close()
if line then -- if we got something
ver = tonumber(string.match(line, "r(%d+)")) or "modified"
end
end

return ver, err
end

function PackageVersionExtended()
local version, err = PackageVersion()
local msg = ""
local succ = false
if version == "missing" then -- the file is missing or unreadable
msg = "The file "..version_file.." appears to be missing or unreadable (this is bad), so the version check cannot proceed.\nThe system gave the error: "..err
elseif version == "modified" then
msg = "The file "..version_file.." appears to have been modified (this is bad), so the version check cannot proceed."
else
succ = true
msg = "You are currently using Aardwolf MUSHclient Package version: r"..version
end

return succ, version, msg
end
19 changes: 2 additions & 17 deletions MUSHclient/worlds/plugins/aard_GMCP_handler.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ have been a better lua idiom', please do let me know at wolf@aardwolf.com - than
<script>
<![CDATA[
aard_extras = require "aard_lua_extras"
require "json"
require "serialize"
require "gmcphelper"
Expand Down Expand Up @@ -199,30 +200,14 @@ function OnPluginTelnetRequest (msg_type, data)
if msg_type == GMCP and data == "SENT_DO" then
Note ("Enabling GMCP.")
-- This hard-coded block may need to be made into a config table as we add more message types.
Send_GMCP_Packet (string.format ('Core.Hello { "client": "MUSHclient", "version": "%s" }', Version().." "..PackageVersion()))
Send_GMCP_Packet (string.format ('Core.Hello { "client": "MUSHclient", "version": "%s" }', Version().." r"..aard_extras.PackageVersion()))
Send_GMCP_Packet ('Core.Supports.Set [ "Char 1", "Comm 1", "Room 1" ]')
return true
end -- if GMCP login needed (just sent DO)
return false
end -- function OnPluginTelnetRequest
function PackageVersion()
local ret = "unknown"
-- borrowed from the package update checker
version_file,err = io.open ("AardwolfPackageChanges.txt", "r")
if version_file then -- the file exists
--- read the snapshot revision from the third line
line = version_file:read ("*l") -- read one line
line = version_file:read ("*l") -- read one line
line = version_file:read ("*l") -- read one line
if line then -- if we got something
ret = string.match(line, "(r%d+)") or "unknown"
end
end
version_file:close()
return ret
end
---------------------------------------------------------------------------------------------------
-- FUNCTION:: init_gmcpdata
Expand Down
25 changes: 6 additions & 19 deletions MUSHclient/worlds/plugins/aard_helper_aliases.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,13 @@
sequence="100"
>
<send>
-- code taken from the package update checker
version_file,err = io.open (GetInfo(56).."AardwolfPackageChanges.txt", "r")
if not version_file then -- the file is missing or unreadable
ColourNote("white","red","The file \'AardwolfPackageChanges.txt\' appears to be missing or unreadable (this is bad), so the version check cannot proceed.")
return
end
--- read the snapshot revision from the third line
line = version_file:read ("*l") -- read one line
line = version_file:read ("*l") -- read one line
line = version_file:read ("*l") -- read one line
local_version = nil
if line then -- if we got something
local_version = tonumber(string.match(line, "r(%d+) snapshot"))
end
version_file:close()
if not local_version then -- the file is messed up such that the third line doesn't contain "r### snapshot"
ColourNote("white","red","The file \'AardwolfPackageChanges.txt\' appears to have been modified (this is bad), so the version check cannot proceed.")
return
aard_extras = require "aard_lua_extras"
local succ, version, msg = aard_extras.PackageVersionExtended()
if succ then
ColourNote("white", "blue", msg)
else
ColourNote("white","red", msg)
end
ColourNote("white","blue","You are currently using Aardwolf MUSHclient Package version: r"..local_version)
</send>
</alias>

Expand Down
60 changes: 33 additions & 27 deletions MUSHclient/worlds/plugins/aard_package_update_checker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ You can also run a manual check by typing: package update check
<script>
<![CDATA[
aard_extras = require "aard_lua_extras"
async = require "async"
require "json"
require "wait"
version_url = "https://raw.githubusercontent.com/fiendish/aardwolfclientpackage/MUSHclient/MUSHclient/AardwolfPackageChanges.txt"
version_url = "https://raw.githubusercontent.com/fiendish/aardwolfclientpackage/MUSHclient/MUSHclient/"..aard_extras.version_file
download_url = "https://github.com/fiendish/aardwolfclientpackage/archive/MUSHclient.zip"
window_title = "Aardwolf MUSHclient Package Update Checker"
ErrorMessage = ""
Expand Down Expand Up @@ -88,7 +89,7 @@ backgroundUpdate = string.dump(function(githubjson_t, mushpath)
require "gitsha"
local files = {}
local ignored_files = {"/worlds/plugins/state/", "%.db$", "%.mcl$", "%.sqlite", "%.HLP", "%.GID", "%.ini"}
local ignored_files = {"/worlds/plugins/state/", "Aardwolf%.db$", "%.mcl$", "%.sqlite$", "%.ini$"}
for i,v in ipairs(githubjson_t) do
if v.type == "blob" then
local ignored = false
Expand All @@ -114,6 +115,7 @@ local files_to_fetch = {}
local fetch_list = {}
local still_downloading = false
function doUpdate(retval, page, status, headers, full_status, requested_url)
num_retries = {}
local githubjson_t = json.decode(page)
if githubjson_t.tree == nil then
Expand Down Expand Up @@ -179,7 +181,23 @@ ffi.cdef[[
]]
num_retries = {}
function saveNewFile(retval, page, status, headers, full_status, requested_url)
if page == nil then
num_retries[requested_url] = num_retries[requested_url] or 0
if num_retries[requested_url] < 5 then
num_retries[requested_url] = num_retries[requested_url] + 1
print("Download of "..requested_url:match("/([^/]+)$").." failed. Retrying ["..num_retries[requested_url].."/5]")
wait.make(function()
wait.time(5)
async.doAsyncRemoteRequest(requested_url, saveNewFile, "HTTPS", 1200, cancel_update_on_timeout)
end)
else
cancel_update_on_timeout("Too many download retries.")
end
return
end
local filepath = files_to_fetch[requested_url]
files_to_fetch[requested_url] = nil
Expand Down Expand Up @@ -217,7 +235,8 @@ function files_left_in_progress()
for k,v in pairs(files_to_fetch) do
table.insert(left, v)
end
print("Still waiting for download of: ", table.concat(left, ","))
print("Still waiting for download of: ", table.concat(left, ", "))
print("")
end
Expand Down Expand Up @@ -329,11 +348,14 @@ function checkIfFinishedDownloading()
end
function cancel_update_on_timeout()
function cancel_update_on_timeout(reason)
DeleteTimer("in_progress")
if still_downloading then
ColourNote("yellow", "red", "Cancelling MUSHclient update. Downloads are taking too long.") -- flaming output
files_left_in_progress()
if reason then
ColourNote("yellow", "red", "Cancelling MUSHclient update. "..reason) -- flaming output
else
ColourNote("yellow", "red", "Cancelling MUSHclient update. Downloads are taking too long.") -- flaming output
end
still_downloading = false
end
end
Expand Down Expand Up @@ -430,27 +452,11 @@ function main(retval, page, status, headers, full_status, request_url)
end
function checkLocalFile()
-- open the local version file
local version_file, err = io.open (GetInfo(66).."AardwolfPackageChanges.txt", "r")
if version_file == nil then -- the file is missing or unreadable
ErrorMessage = "The file \'AardwolfPackageChanges.txt\' appears to be missing or unreadable (this is bad), so the version check cannot proceed.\n\nThe system returned the error:\n"..err
return false
end
--- read the snapshot revision from the third line
local line = version_file:read ("*l") -- read one line
line = version_file:read ("*l") -- read one line
line = version_file:read ("*l") -- read one line
version_file:close ()
local_version = nil
if line then -- if we got something
local_version = tonumber(string.match(line, "r(%d+) snapshot"))
succ, local_version, msg = aard_extras.PackageVersionExtended()
if not succ then
ErrorMessage = msg
end
if not local_version then -- the file is messed up such that the third line doesn't contain "r<###> snapshot"
ErrorMessage = "The file \'AardwolfPackageChanges.txt\' appears to have been mangled (this is bad), so the version check cannot proceed."
return false
end
return true
return succ
end
function checkRemoteFile(page, status)
Expand Down Expand Up @@ -480,7 +486,7 @@ end
function showUpdate()
if local_version and latest_version then -- sanity check
if local_version < latest_version then
final_update_list = (string.match(update_list,"(.*)r"..local_version.." snapshot") or "<ERROR! Please don't modify your AardwolfPackageChanges.txt file>\r\n")
final_update_list = (string.match(update_list,"(.*)r"..local_version.." snapshot") or "<ERROR! Please don't modify your "..aard_extras.version_file.." file>\r\n")
final_update_list = "( Get it from: "..download_url.." )\n\n"..convertHTMLcodesToStandardText(final_update_list)
message = "THIS UPDATER WILL USE DATA AND ASK TO RESTART YOUR CLIENT WHEN FINISHED\n\n\nThere's a new Aardwolf MUSHclient Package development snapshot available. You currently have version r"..local_version.." and the newest version is r"..latest_version..".\n\nThe major differences between your version and the latest version are:"
updateDialog(message,final_update_list)
Expand Down

0 comments on commit 3d07e9f

Please sign in to comment.