-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathExportImportHelper.lua
67 lines (62 loc) · 2.94 KB
/
ExportImportHelper.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
local SwitchSwitch, L = unpack(select(2, ...))
local LibDeflate = LibStub("LibDeflate")
function SwitchSwitch:ProfilesToString(profilesList, includePVP)
local encodeTableProfiles = {
[self:GetPlayerClass()] = {
[self:GetCurrentSpec()] = {
}
}
}
local profilesData = encodeTableProfiles[self:GetPlayerClass()][self:GetCurrentSpec()]
for _, name in ipairs(profilesList) do
local profileData = self:deepcopy(self:GetProfileData(name))
if(not includePVP) then
profileData["pvp"] = nil
end
profilesData[name] = profileData
end
local serialized = "@SWITCHSWITCH_1@" .. self:Serialize({["TalentData"] = encodeTableProfiles})
local compressed = LibDeflate:CompressDeflate(serialized, {["level"] = 9})
local encoded = LibDeflate:EncodeForPrint(compressed)
return encoded
end
function SwitchSwitch:ImportEncodedProfiles(encoded)
local compressed = LibDeflate:DecodeForPrint(encoded)
local uncompressed = LibDeflate:DecompressDeflate(compressed, {["level"] = 9})
local version, serializedData = string.match( uncompressed or "", "^@SWITCHSWITCH_(%d+)@(.+)$" )
local infoText = ""
if(version == nil) then return false end
if(tonumber(version) == 1) then
local suceess, unserializedData = self:Deserialize(serializedData)
if(not suceess) then return false end
if(unserializedData["TalentData"] ~= nil) then
for classID, classData in pairs(unserializedData["TalentData"]) do
local className = select(1, GetClassInfo(classID))
for specID, profilesData in pairs(classData) do
local specName = select(2, GetSpecializationInfoByID(specID))
local currentSavedData = self:GetCustomProfilesTable(classID, specID)
local profilesCount = 0
local namesList = ""
for name, data in pairs(profilesData) do
local saveName = name
local counter = 1
while(self:DoesProfileExits(saveName, classID, specID)) do
saveName = name .. "_imported_" .. tostring(counter)
counter = counter + 1
end
currentSavedData[saveName] = data
namesList = namesList .. "'" .. saveName .. "'" .. ", "
profilesCount = profilesCount + 1
end
namesList = namesList:sub(1, -3)
infoText = infoText .. L["Imported %d profile(s) for class %s-%s: %s"]:format(profilesCount, className, specName, namesList)
end
infoText = infoText .. "\n"
end
end
else
return false
end
SwitchSwitch:RefreshCurrentConfigID()
return true, infoText
end