ExportImport, VersionCheck & XiconProfiles fix

This commit is contained in:
Sumsebrum 2021-05-18 16:34:10 +02:00
parent edb5608a38
commit fd5183cf5d
4 changed files with 50 additions and 46 deletions

View File

@ -11,6 +11,9 @@ local IsAddOnLoaded = IsAddOnLoaded
local IsInInstance = IsInInstance
local GetBattlefieldStatus = GetBattlefieldStatus
local IsActiveBattlefieldArena = IsActiveBattlefieldArena
local RELEASE_TYPES = { alpha = "Alpha", beta = "Beta", release = "Release"}
local PREFIX = "TBC-Classic_v"
local VERSION_REGEX = PREFIX .. "(%d+%.%d+)%-(%a)"
---------------------------
@ -21,9 +24,12 @@ local IsActiveBattlefieldArena = IsActiveBattlefieldArena
local MAJOR, MINOR = "Gladdy", 4
local Gladdy = LibStub:NewLibrary(MAJOR, MINOR)
local L
Gladdy.version_major = "TBC-Classic_v1"
Gladdy.version_minor = "0.4-Beta"
Gladdy.version = Gladdy.version_major .. "." .. Gladdy.version_minor
Gladdy.version_major_num = 1
Gladdy.version_minor_num = 0.04
Gladdy.version_num = Gladdy.version_major_num + Gladdy.version_minor_num
Gladdy.version_releaseType = RELEASE_TYPES.beta
Gladdy.version = PREFIX .. Gladdy.version_num .. "-" .. Gladdy.version_releaseType
Gladdy.VERSION_REGEX = VERSION_REGEX
LibStub("AceTimer-3.0"):Embed(Gladdy)
LibStub("AceComm-3.0"):Embed(Gladdy)

View File

@ -64,9 +64,11 @@ importButton:SetText("Import\n(this will overwrite your current profile!)")
importButton:SetWidth(200)
importButton:SetHeight(50)
importButton:SetCallback("OnClick", function(widget)
ExportImport:ApplyImport(import.deserializedTable)
Gladdy:UpdateFrame()
ExportImport:ApplyImport(import.deserializedTable, Gladdy.db)
import:Hide()
Gladdy:Reset()
Gladdy:HideFrame()
Gladdy:ToggleFrame(3)
end)
import:AddChild(importButton)
import.button = importButton
@ -84,25 +86,24 @@ import:AddChild(importClearButton)
import.clearButton = importClearButton
function ExportImport:CheckDeserializedOptions(tbl, refTbl, str)
if str == nil and not tbl.version_major then
return false, "Version conflict: version_major not seen"
if str == nil and not tbl.version_major_num then
return false, "Version conflict: version_major_num not seen"
end
if str == nil and tbl.version_major ~= Gladdy.version_major then
return false, "Version conflict: " .. tbl.version_major .. " ~= " .. Gladdy.version_major
if str == nil and tbl.version_major_num ~= Gladdy.version_major_num then
return false, "Version conflict: " .. tbl.version_major_num .. " ~= " .. Gladdy.version_major_num
end
if str == nil then
str = "Gladdy.db"
tbl.version_major = nil
tbl.version_major_num = nil
end
if type(tbl) == "table" then
for k,v in pairs(tbl) do
if refTbl[k] ~= nil then
if type(v) ~= type(refTbl[k]) then
return false, str .. "." .. k .. " type error. Expected " .. type(refTbl[k]) .. " found " .. type(v)
end
for k,v in pairs(tbl) do
if refTbl[k] == nil then
return false, str .. "." .. k .. " does not exist"
else
if type(v) ~= type(refTbl[k]) then
return false, str .. "." .. k .. " type error. Expected " .. type(refTbl[k]) .. " found " .. type(v)
elseif type(v) == "table" then
ExportImport:CheckDeserializedOptions(v, refTbl[k], str .. "." .. k)
else
return false, str .. "." .. k .. " does not exist"
end
end
end
@ -122,7 +123,7 @@ function ExportImport:GetOptions()
type = "execute",
func = function()
local db = table_copy(Gladdy.db)
db.version_major = Gladdy.version_major
db.version_major_num = Gladdy.version_major_num
dump = AceSerializer:Serialize(db)
local compress_deflate = LibDeflate:CompressZlib(dump)
printable_compressed = LibDeflate:EncodeForPrint(compress_deflate)
@ -164,14 +165,11 @@ function ExportImport:GetOptions()
end
function ExportImport:ApplyImport(t, table)
if table == nil then
table = Gladdy.dbi.profile
end
for k,v in pairs(t) do
if type(v) == "table" then
ExportImport:ApplyImport(v, table[k])
else
table[k] = v;
table[k] = v
end
end
end
@ -204,7 +202,7 @@ function ExportImport:Decode(str, showError)
end
return nil
end
local statusOption, error = ExportImport:CheckDeserializedOptions(deserialized, Gladdy.db)
local statusOption, error = ExportImport:CheckDeserializedOptions(deserialized, Gladdy.defaults.profile)
if not statusOption then
if showError then
import.statustext:SetTextColor(1,0,0)

View File

@ -1,3 +1,5 @@
local str_match, tonumber, tostring = string.match, tonumber, tostring
local UnitName = UnitName
local Gladdy = LibStub("Gladdy")
@ -24,19 +26,20 @@ end
function VersionCheck:Test(unit)
if unit == "arena1" then
self:RegisterComm("GladdyVCheck", VersionCheck.OnCommReceived)
self:SendCommMessage("GladdyVCheck", Gladdy.version, "RAID", self.playerName)
self:SendCommMessage("GladdyVCheck", tostring(Gladdy.version_num), "RAID", self.playerName)
end
end
function VersionCheck.OnCommReceived(prefix, message, distribution, sender)
if sender ~= VersionCheck.playerName then
local addonVersion = Gladdy.version
if (message == addonVersion) then
local addonVersion = Gladdy.version_num
message = tonumber(message)
if message and message <= Gladdy.version_num then
--Gladdy:Print("Version", "\"".. addonVersion.."\"", "is up to date")
else
Gladdy:Warn("Current version", "\"".. addonVersion.."\"", "is outdated. Most recent version is", "\"".. message.."\"")
Gladdy:Warn("Please download the latest Gladdy version at:")
Gladdy:Warn("https://github.com/XiconQoo/Gladdy")
Gladdy:Warn("https://github.com/XiconQoo/Gladdy-TBC")
end
end
end

File diff suppressed because one or more lines are too long