Fiendish wrote a wonderful auto-updater for the Aardwolf MUSHclient package. It inspired me to do the same for my plugins, since I don't want to have to have people needing to download the latest version each time I make a change. For the most part, the script works. However, it seems to crash when I call the ReloadPlugin (at least, that's where it appears to crash). See the function below:
Inside the plugin that needs to be updated, there is a "get_updater" function that accesses the raw code above, saves it to a file and loads the .xml file. It then calls UpdatePlugin with CallPlugin, which is supposed to overwrite the old plugin with new information if the version is a mismatch. Then, after the file closes, it's supposed to reload the old plugin. I'm doing it this way because I know you don't allow reloading of a plugin in itself (and the documented DoAfterSpecial does NOT work, so may want to remove that from the help file).
But as I mentioned above, it crashes, seemingly when it's supposed to reload the plugin. I know the code overwrites and saves properly; I've been able to manually reinstall with no issues. Am I missing something? My plan is to be able to release this for others to allow automatic updating, too.
Thanks!
function UpdatePlugin(pid, pfile, pversion, raw)
async_ok, async = pcall (require, "async")
ColourNote("white", "blue", pfile)
if async_ok then
raw_return = async.request(raw, "HTTPS")
end
retval, page, status, headers, full_status = raw_return:join()
raw_return = nil
if status == 200 then
raw_version = string.match(page, '%s%s+version="([0-9%.]+)"')
print("Raw version: " .. raw_version)
print("Plugin version: " .. pversion)
end
if tonumber(raw_version) == tonumber(pversion) then
ColourNote("white", "blue", "You currently have the latest version!")
elseif tonumber(raw_version) > tonumber(pversion) then
ColourNote("white", "blue", "Updating from version" .. pversion .. " to version" .. raw_version .. "!")
UnloadPlugin(pid)
local file = io.open(pfile, "w")
file:write(page)
file:close()
DoAfterSpecial(3, "ReloadPlugin(" .. pid .. ")", 12)
end
raw_version = nil
UnloadPlugin(GetPluginID())
os.remove(GetPluginInfo(GetPluginID(), 6))
endInside the plugin that needs to be updated, there is a "get_updater" function that accesses the raw code above, saves it to a file and loads the .xml file. It then calls UpdatePlugin with CallPlugin, which is supposed to overwrite the old plugin with new information if the version is a mismatch. Then, after the file closes, it's supposed to reload the old plugin. I'm doing it this way because I know you don't allow reloading of a plugin in itself (and the documented DoAfterSpecial does NOT work, so may want to remove that from the help file).
But as I mentioned above, it crashes, seemingly when it's supposed to reload the plugin. I know the code overwrites and saves properly; I've been able to manually reinstall with no issues. Am I missing something? My plan is to be able to release this for others to allow automatic updating, too.
Thanks!