diff core.lua @ 27:68d7b903ee17

Drycoded revision check/popup.
author Farmbuyer of US-Kilrogg <farmbuyer@gmail.com>
date Sun, 09 Oct 2011 01:02:27 +0000
parents cb9635999171
children a7376e6de73c
line wrap: on
line diff
--- a/core.lua	Fri Oct 07 03:47:45 2011 +0000
+++ b/core.lua	Sun Oct 09 01:02:27 2011 +0000
@@ -71,6 +71,10 @@
 	.." to show the main display.  You should probably browse the instructions"
 	.." if you've never used this before; %s to display the help window.  This"
 	.." welcome message will not intrude again."
+local newer_warning = "A newer version has been released. You can %s to display"
+	.." a download URL for copy-and-pasting. You can %s to ping other raiders"
+	.." for their installed versions (same as '/ouroloot ping' or clicking the"
+	.." 'Ping!' button on the options panel)."
 local qualnames = {
 	['gray'] = 0, ['grey'] = 0, ['poor'] = 0, ['trash'] = 0,
 	['white'] = 1, ['common'] = 1,
@@ -83,6 +87,7 @@
 }
 local my_name				= UnitName('player')
 local comm_cleanup_ttl		= 5   -- seconds in the cache
+local revision_large		= nil -- defaults to 1, possibly changed by revision
 local g_LOOT_ITEM_ss, g_LOOT_ITEM_MULTIPLE_sss, g_LOOT_ITEM_SELF_s, g_LOOT_ITEM_SELF_MULTIPLE_ss
 
 
@@ -94,7 +99,7 @@
 do local _G = _G setfenv (1, addon)
 
 	commrev			= 15  -- number
-	revision		= _G.GetAddOnMetadata(nametag,"Version") or "?"
+	revision		= _G.GetAddOnMetadata(nametag,"Version") or "?"  -- "x.yy.z", etc
 	ident			= "OuroLoot2"
 	identTg			= "OuroLoot2Tg"
 	status_text		= nil
@@ -177,10 +182,22 @@
 local _register_bossmod
 local makedate, create_new_cache, _init
 
+-- Try to extract numbers from the .toc "Version" and munge them into an
+-- integral form for comparison.  The result doesn't need to be meaningful as
+-- long as we can reliably feed two of them to "<" and get useful results.
+do
+	local r = 0
+	for d in addon.revision:gmatch("%d+") do
+		r = 1000*r + d
+	end
+	revision_large = math.max(r,1)
+end
+
 -- Hypertext support, inspired by DBM broadcast pizza timers
 do
 	local hypertext_format_str = "|HOuroRaid:%s|h%s[%s]|r|h"
 
+	-- text will automatically be surrounded by brackets
 	function addon.format_hypertext (code, text, color)
 		return hypertext_format_str:format (code,
 			type(color)=='number' and ITEM_QUALITY_COLORS[color].hex or color,
@@ -192,6 +209,12 @@
 		if ltype ~= "OuroRaid" then return end
 		if arg == 'openloot' then
 			addon:BuildMainDisplay()
+		elseif arg == 'popupurl' then
+			local dialog = StaticPopup_Show "OUROL_URL"
+			-- Sadly, this is not generated by the packager, so hardcode it for now
+			dialog.data = [[http://wow.curse.com/downloads/wow-addons/details/ouroloot.aspx]]
+		elseif arg == 'doping' then
+			addon:DoPing()
 		elseif arg == 'help' then
 			addon:BuildMainDisplay('help')
 		elseif arg == 'bcaston' then
@@ -392,6 +415,7 @@
 	--OuroLootSV_hist = nil
 
 	_init(self)
+	self.dprint('flow', "version strings:", revision_large, self.status_text)
 	self.OnInitialize = nil
 end
 
@@ -911,6 +935,7 @@
 	self:Print("Ouro Raid Loot is %s.  Threshold currently %s.",
 		self.enabled and "tracking" or "only broadcasting",
 		self.thresholds[self.threshold])
+	self:broadcast('revcheck',revision_large)
 end
 
 -- Note:  running '/loot off' will also avoid the popup reminder when
@@ -1017,6 +1042,28 @@
 	self.sender_list.active = {}
 	self.sender_list.names = {}
 	self:broadcast('ping')
+	self:broadcast('revcheck',revision_large)
+end
+
+function addon:_check_revision (otherrev)
+	self.dprint('comm', "revchecking against", otherrev)
+	otherrev = tonumber(otherrev)
+	if otherrev == revision_large then
+		-- normal case
+
+	elseif otherrev < revision_large then
+		self.dprint('comm', "ours is newer, notifying")
+		self:broadcast('revcheck',revision_large)
+
+	else
+		self.dprint('comm', "ours is older, yammering")
+		if newer_warning then
+			self:Print(newer_warning,
+				self.format_hypertext('popupurl',"click here",ITEM_QUALITY_UNCOMMON)
+				self.format_hypertext('doping',"click here",ITEM_QUALITY_UNCOMMON))
+			newer_warning = nil
+		end
+	end
 end
 
 -- Generic helpers
@@ -1757,6 +1804,10 @@
 		addon:Print("Echo: ", s)
 		adduser (sender, s, status=="tracking" or status=="broadcasting" or nil)
 	end
+	OCR_funcs.revcheck = function (sender, _, revlarge)
+		addon.dprint('comm', "revcheck, sender", sender)
+		addon:_check_revision (revlarge)
+	end
 
 	OCR_funcs.loot = function (sender, _, recip, item, count, extratext)
 		addon.dprint('comm', "DOTloot, sender", sender, "recip", recip, "item", item, "count", count)