Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

Commit

Permalink
small tweaks to decompression code
Browse files Browse the repository at this point in the history
  • Loading branch information
brittyazel committed Jun 16, 2021
1 parent 3465192 commit 86a5360
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions Localizations/Neuron_X-enUS.lua
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ L["Export"] = true
L["Import or Export the current profile:"] = true
L["ImportExport_Desc"] = "Copying the profile can be a time consuming experience. It may stall your game for multiple seconds. WARNING: It will overwrite the current profile."
L["ImportWarning"] = "Are you absolutely certain you wish to import this profile? The current profile will be overwritten."
L["No data to import."] = true
L["Decoding failed."] = true
L["Decompression failed."] = true
L["Data import Failed."] = true
Expand Down
15 changes: 12 additions & 3 deletions Neuron.lua
Original file line number Diff line number Diff line change
Expand Up @@ -693,21 +693,30 @@ end


function Neuron:SetSerializedAndCompressedProfile(input)
--check if the input is empty
if input == "" then
Neuron:Print(L["No data to import."].." "..L["Aborting."])
return
end

--decode and check if decoding worked properly
local decoded = LibDeflate:DecodeForPrint(input)
if decoded == nil then
Neuron:Print(L["Decoding failed."].." "..L["Aborting."])
return
end

--uncompress and check if uncompresion worked properly
local uncompressed = LibDeflate:DecompressZlib(decoded)
if uncompressed == nil then
Neuron:Print(L["Decompression failed"].." "..L["Aborting."])
Neuron:Print(L["Decompression failed."].." "..L["Aborting."])
return
end

--deserialize the data and return it back into a table format
local result, newProfile = Neuron:Deserialize(uncompressed)

if result == true and newProfile then
if result == true and newProfile then --if we successfully deserialize, load the new table and reload
for k,v in pairs(newProfile) do
if type(v) == "table" then
Neuron.db.profile[k] = CopyTable(v)
Expand All @@ -717,6 +726,6 @@ function Neuron:SetSerializedAndCompressedProfile(input)
end
ReloadUI()
else
Neuron:Print(L["Data import Failed"].." "..L["Aborting."])
Neuron:Print(L["Data import Failed."].." "..L["Aborting."])
end
end

0 comments on commit 86a5360

Please sign in to comment.