diff --git a/aard_inventory.changelog b/aard_inventory.changelog index 5f59123..e536e52 100644 --- a/aard_inventory.changelog +++ b/aard_inventory.changelog @@ -2,6 +2,13 @@ dbot.changelog = {} +dbot.changelog[2.0006] = +{ + { change = drlDbotChangeLogTypeMisc, + desc = "Refactored update framework and removed duplicate code" + } +} + dbot.changelog[2.0005] = { { change = drlDbotChangeLogTypeNew, @@ -16,7 +23,7 @@ dbot.changelog[2.0004] = { { change = drlDbotChangeLogTypeMisc, desc = "Refresh code now forces your first refresh in a new session to use a full refresh scan. " .. - "This is necessary because items have have been moved or modified in a different client and " .. + "This is necessary because items might have moved or changed outside of this client and " .. "we need to know the current location of all items. This also allows us to detect if a no-" .. "save item was removed after the last session." }, diff --git a/aard_inventory.xml b/aard_inventory.xml index 04a889d..18d1e84 100644 --- a/aard_inventory.xml +++ b/aard_inventory.xml @@ -87,7 +87,7 @@ dbot.version : Module to track version and changelog information and update the save_state="y" date_written="2017-08-12 08:45:15" requires="4.98" - version="2.0005" + version="2.0006" > v2.version end) + table.sort(sortedLog, function (v1, v2) return v1.version < v2.version end) for _, clog in ipairs(sortedLog) do if (clog.version > minVersion) then - dbot.version.displayChange(clog) + dbot.version.changelog.displayChange(clog) end -- if end -- for return DRL_RET_SUCCESS -end -- dbot.version.displayChanges +end -- dbot.version.changelog.displayChanges -- Format of entry is: { version = 2.0004, -- changes = { { change = drlDbotChangeLogTypeXYZ, desc = "what changed" } -- } -- } -function dbot.version.displayChange(changeLogEntries) +function dbot.version.changelog.displayChange(changeLogEntries) local retval = DRL_RET_SUCCESS if (changeLogEntries == nil) then - dbot.warn("dbot.version.displayChange: Change entries are missing!") + dbot.warn("dbot.version.changelog.displayChange: Change entries are missing!") return DRL_RET_INVALID_PARAM end -- if @@ -19668,84 +19677,59 @@ function dbot.version.displayChange(changeLogEntries) end -- for return retval -end -- dbot.version.displayChange - - - - - - - - - ---FIXME: rename this version.update??? -dbot.update = {} -dbot.update.url = "https://raw.githubusercontent.com/Aardurel/aard-plugins/master/aard_inventory.xml" -dbot.update.protocol = "HTTPS" -dbot.update.pkg = nil +end -- dbot.version.changelog.displayChange -drlDbotUpdateCheck = "check" -drlDbotUpdateInstall = "install" -function dbot.update.version(mode, endTag) - local retval = DRL_RET_SUCCESS +function dbot.version.update.release(mode, endTag) + local url = "https://raw.githubusercontent.com/Aardurel/aard-plugins/master/aard_inventory.xml" + local protocol = "HTTPS" + local retval = DRL_RET_SUCCESS if (mode == nil) or ((mode ~= drlDbotUpdateCheck) and (mode ~= drlDbotUpdateInstall)) then - dbot.warn("dbot.update.version: Missing or invalid mode parameter") + dbot.warn("dbot.version.update.release: Missing or invalid mode parameter") return inv.tags.stop(invTagsVersion, endTag, DRL_RET_INVALID_PARAM) end -- if - if (dbot.update.pkg ~= nil) then + if (dbot.version.update.pkg ~= nil) then dbot.info("Skipping update request: another update request is in progress") return inv.tags.stop(invTagsVersion, endTag, DRL_RET_BUSY) end -- if - -- Pull in the async package if it exists - local asyncOk, async = pcall (require, "async") - if (not asyncOk) or (async == nil) then - dbot.warn("dbot.update.version: Failed to find \"async\" package, skipping update request") - return inv.tags.stop(invTagsVersion, endTag, DRL_RET_UNSUPPORTED) - end -- if + dbot.version.update.pkg = {} + dbot.version.update.pkg.mode = mode + dbot.version.update.pkg.url = url + dbot.version.update.pkg.protocol = protocol + dbot.version.update.pkg.endTag = endTag - dbot.update.pkg = {} - dbot.update.pkg.mode = mode - dbot.update.pkg.endTag = endTag - - -- Make a request to grab the latest plugin file. Newer versions of mush have nice async - -- capabilities and we use that if possible. Otherwise, we fall back to an old-style request. - -- Both methods of making the request will call dbot.update.callback upon completion. - if (async.doAsyncRemoveRequest ~= nil) then - async.doAsyncRemoteRequest(dbot.update.url, dbot.update.callback, dbot.update.protocol) - else - wait.make(dbot.updateCR) -- Fall back to a co-routine running the old-style async code - end + wait.make(dbot.version.update.releaseCR) return retval -end -- dbot.update +end -- dbot.version.update.release --- Scan the file we just (hopefully) downloaded and check the file's version. If the user --- requested a version check, we report the current and latest available versions. If the --- user requested an installation of the latest plugin, do the upgrade if everything looks --- sane. -function dbot.update.callback(retval, page, status, headers, fullStatus, requestUrl) - local retval = DRL_RET_SUCCESS +function dbot.version.update.releaseCR() - if (dbot.update.pkg == nil) or (dbot.update.pkg.mode == nil) then - dbot.error("dbot.update.callback: Missing or invalid update package detected") + if (dbot.version.update.pkg == nil) or (dbot.version.update.pkg.mode == nil) then + dbot.error("dbot.version.update.releaseCR: Missing or invalid update package detected") return inv.tags.stop(invTagsVersion, "end tag is nil", DRL_RET_INVALID_PARAM) end -- if - local endTag = dbot.update.pkg.endTag + local endTag = dbot.version.update.pkg.endTag - if (status ~= 200) then - dbot.warn("dbot.update.callback: Failed to retrieve remote plugin information") - retval = DRL_RET_INTERNAL_ERROR + -- This blocks until the plugin file is returned, an error is detected, or we time out + local pluginData, retval = dbot.remote.get(dbot.version.update.pkg.url, dbot.version.update.pkg.protocol) + if (retval ~= DRL_RET_SUCCESS) then + dbot.warn("dbot.version.update.releaseCR: Failed to retrieve latest plugin file: " .. + dbot.retval.getString(retval)) + + elseif (pluginData == nil) then + dbot.info("Could not find a remote plugin release") + retval = DRL_RET_MISSING_ENTRY else local currentVersion = GetPluginInfo(GetPluginID(), 19) or 0 local currentVerStr = string.format("%1.4f", currentVersion) - local remoteVerStr = string.match(page, '%s%s+version="([0-9%.]+)"') + local remoteVerStr = string.match(pluginData, '%s%s+version="([0-9%.]+)"') local remoteVersion = tonumber(remoteVerStr or "") or 0 if (remoteVersion == currentVersion) then @@ -19756,68 +19740,34 @@ function dbot.update.callback(retval, page, status, headers, fullStatus, request "is newer than the latest official release (v" .. remoteVerStr .. ")") retval = DRL_RET_VER_MISMATCH - elseif (dbot.update.pkg.mode == drlDbotUpdateCheck) then + elseif (dbot.version.update.pkg.mode == drlDbotUpdateCheck) then dbot.info("You are running v" .. currentVerStr .. ", latest version is v" .. remoteVerStr) dbot.info("Changes since your last update:") - dbot.update.pkg = nil - return dbot.version.changelog(currentVersion, endTag) + dbot.version.update.pkg = nil + return dbot.version.changelog.get(currentVersion, endTag) - elseif (dbot.update.pkg.mode == drlDbotUpdateInstall) then + elseif (dbot.version.update.pkg.mode == drlDbotUpdateInstall) then dbot.info("Updating plugin from version " .. currentVerStr .. " to version " .. remoteVerStr) dbot.info("Please do not enter anything until the update completes") local pluginFile = GetPluginInfo(GetPluginID(), 6) local file = io.open(pluginFile, "w") - file:write(page) + file:write(pluginData) file:close() dbot.reload() else - dbot.error("dbot.update.callback: Detected invalid mode \"@R" .. (dbot.update.pkg.mode or "nil") .. - "@W\"") + dbot.error("dbot.version.update.callback: Detected invalid mode \"@R" .. + (dbot.version.update.pkg.mode or "nil") .. "@W\"") end -- if end -- if - dbot.update.pkg = nil - return inv.tags.stop(invTagsVersion, endTag, retval) - -end -- dbot.update.callback - - -function dbot.updateCR() - local urlThread = async.request(dbot.update.url, dbot.update.protocol) - local updateRet, page, status, headers, fullStatus = -1, nil, -1, nil, nil, dbot.update.url - - if (urlThread == nil) then - dbot.warn("dbot.updateCR: Failed to create thread requesting update") - - else - local timeout = 10 - local totTime = 0 - while (urlThread:alive()) do - if (totTime > timeout) then - retval = DRL_RET_TIMEOUT - break - end -- if - - wait.time(drlSpinnerPeriodDefault) - totTime = totTime + drlSpinnerPeriodDefault - end -- while - ---FIXME: this is broken!!! retval is never defined!!! - if (retval ~= DRL_RET_SUCCESS) then - updateRet, page, status, headers, fullStatus = urlThread:join() - end -- if - - end -- if - - dbot.update.callback(updateRet, page, status, headers, fullStatus) - -end -- dbot.updateCR - + dbot.version.update.pkg = nil + return inv.tags.stop(invTagsVersion, endTag, retval) +end -- dbot.version.update.releaseCR ]]>