lotrointerface.com
Search Downloads

LoTROInterface SVN SequenceBars

[/] [trunk/] [Thurallor/] [SequenceBars/] [ExportWindow.lua] - Blame information for rev 199

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 Thurallor-7095
ExportWindow = class();
2 Thurallor-7095
 
3 Thurallor-7095
function ExportWindow:Constructor(title, exportData)
4 Thurallor-7095
    local prevContext = L:SetContext("/ExportWindow");
5 Thurallor-7095
    self.uncompressedData = PrettyPrint(exportData, "");
6 Thurallor-7095
    self.compactData = Serialize(exportData);
7 199 Thurallor-7095
    -- Sanity check:
8 Thurallor-7095
    local f, e = loadstring("return " .. self.compactData);
9 Thurallor-7095
    if (not f) then
10 Thurallor-7095
        Puts(L:GetText("/ImportWindow/ParseError") .. tostring(e));
11 Thurallor-7095
        return self:Close();
12 Thurallor-7095
    end
13 2 Thurallor-7095
 
14 Thurallor-7095
    self.ok = L:GetText("OK");
15 Thurallor-7095
    self.window = Alert(title, "", self.ok);
16 Thurallor-7095
    self.window:SetSize(423, 300);
17 Thurallor-7095
    self.window:SetMinimumSize(423, 300);
18 Thurallor-7095
    CenterWindow(self.window);
19 Thurallor-7095
    self.window:SetZOrder(2147483647);
20 Thurallor-7095
    self.okButton = self.window.buttons[self.ok];
21 Thurallor-7095
    self.okButton:SetEnabled(false);
22 20 Thurallor-7095
    self.okButton.Click = function()
23 2 Thurallor-7095
        self.window:Close();
24 Thurallor-7095
    end
25 199 Thurallor-7095
 
26 Thurallor-7095
    -- Workaround for a bug in the Turbine.UI.Label control: It fails to display certain sequences including "<>" even when markup is disabled.
27 Thurallor-7095
    self.window.label.SetText = function(ctl, text)
28 Thurallor-7095
        Turbine.UI.Label.SetText(ctl, "");
29 Thurallor-7095
        local firstPart = "";
30 Thurallor-7095
        repeat
31 Thurallor-7095
            Turbine.UI.Label.AppendText(ctl, firstPart);
32 Thurallor-7095
            text = text:sub(firstPart:len() + 1);
33 Thurallor-7095
            firstPart = text:match("^(.-<)>");
34 Thurallor-7095
        until (not firstPart);
35 Thurallor-7095
        Turbine.UI.Label.AppendText(ctl, text);
36 Thurallor-7095
    end
37 2 Thurallor-7095
 
38 Thurallor-7095
    self.compressed = Turbine.UI.Lotro.CheckBox();
39 Thurallor-7095
    self.compressed:SetParent(self.window);
40 Thurallor-7095
    self.compressed:SetSize(100, 20);
41 Thurallor-7095
    self.compressed:SetFont(Turbine.UI.Lotro.Font.TrajanPro14);
42 Thurallor-7095
    self.compressed:SetText(L:GetText("Compressed"));
43 Thurallor-7095
    self.compressed:SetEnabled(false);
44 Thurallor-7095
    self.compressed.CheckedChanged = function(control)
45 Thurallor-7095
        if (control:IsChecked()) then
46 Thurallor-7095
            self.window.label:SetText(self.compressedData);
47 Thurallor-7095
        else
48 Thurallor-7095
            if (#self.uncompressedData > 65535) then
49 6 Thurallor-7095
                Puts(L:GetText("/ExportWindow/UncompressedDataTooBig"));
50 2 Thurallor-7095
                control:SetChecked(true);
51 Thurallor-7095
            else
52 Thurallor-7095
                self.window.label:SetText(self.uncompressedData);
53 Thurallor-7095
            end
54 Thurallor-7095
        end
55 Thurallor-7095
    end
56 Thurallor-7095
 
57 Thurallor-7095
    -- Compress the data in the next Update cycle.
58 Thurallor-7095
    self.window:SetWantsUpdates(true);
59 Thurallor-7095
    self.window.updateCount = 0;
60 Thurallor-7095
    self.window.Update = function(w)
61 Thurallor-7095
        w.updateCount = w.updateCount + 1;
62 Thurallor-7095
        if (w.updateCount == 1) then
63 Thurallor-7095
            w.label:SetText(L:GetText("/ExportWindow/Compressing"));
64 6 Thurallor-7095
            Puts(L:GetText("/ExportWindow/Compressing"));
65 2 Thurallor-7095
        elseif (w.updateCount == 3) then
66 Thurallor-7095
            w.compressor = Thurallor.Utils.LibCompress();
67 Thurallor-7095
        elseif (w.updateCount == 4) then
68 199 Thurallor-7095
            -- Apparently the LZW encoding function can produce incorrect results, so we'll only use Huffman.
69 Thurallor-7095
            --self.compressedData = w.compressor:Compress(self.compactData);
70 Thurallor-7095
            self.compressedData = w.compressor:CompressHuffman(self.compactData);
71 Thurallor-7095
 
72 Thurallor-7095
            -- Sanity check: Uncompress the compressed data and verify that the result is the same as the original data.
73 Thurallor-7095
            if (w.compressor:Decompress(self.compressedData) ~= self.compactData) then
74 Thurallor-7095
                Puts(L:GetText("/ExportWindow/CompressionFailed"));
75 Thurallor-7095
                w.updateCount = -1; -- error; close window at next frame
76 Thurallor-7095
            end
77 2 Thurallor-7095
        elseif (w.updateCount == 5) then
78 Thurallor-7095
            w.label:SetText(w.label:GetText() .. "\n" .. L:GetText("/ExportWindow/Encoding"));
79 6 Thurallor-7095
            Puts(L:GetText("/ExportWindow/Encoding"));
80 2 Thurallor-7095
        elseif (w.updateCount == 7) then
81 Thurallor-7095
            self.compressedData = Bin2Text(self.compressedData);
82 199 Thurallor-7095
 
83 6 Thurallor-7095
--local ratio = (1 - #self.compressedData / #self.uncompressedData) * 100;
84 Thurallor-7095
--Puts("Compressed " .. tostring(#self.uncompressedData) .. " bytes by " .. string.format("%.0f%%", ratio) .. " to " .. tostring(#self.compressedData) .. " bytes.");
85 2 Thurallor-7095
            if (#self.compressedData > 65535) then
86 6 Thurallor-7095
                Puts(L:GetText("/ExportWindow/ExportFailedTooBig"));
87 199 Thurallor-7095
                w.updateCount = -1; -- error; close window at next frame
88 Thurallor-7095
                return;
89 2 Thurallor-7095
            end
90 199 Thurallor-7095
 
91 Thurallor-7095
            -- Sanity check: Decode and decompress the data and verify that the result is the same as the original data.
92 Thurallor-7095
            if (w.compressor:Decompress(Text2Bin(self.compressedData)) ~= self.compactData) then
93 Thurallor-7095
                Puts(L:GetText("/ExportWindow/EncodingFailed"));
94 Thurallor-7095
                w.updateCount = -1; -- error; close window at next frame
95 Thurallor-7095
            end
96 2 Thurallor-7095
        elseif (w.updateCount == 8) then
97 199 Thurallor-7095
            self.compressed:SetChecked(true); -- trigger CheckedChanged callback
98 2 Thurallor-7095
        elseif (w.updateCount == 9) then
99 Thurallor-7095
            w.compressor = nil;
100 Thurallor-7095
            self.compressed:SetEnabled(true);
101 Thurallor-7095
            self.okButton:SetEnabled(true);
102 7 Thurallor-7095
            self.window:Activate();
103 Thurallor-7095
            self.window.label:SelectAll();
104 Thurallor-7095
            self.window.label:Focus();
105 2 Thurallor-7095
            w:SetWantsUpdates(false);
106 199 Thurallor-7095
        elseif (w.updateCount == 0) then -- error
107 Thurallor-7095
            w:SetWantsUpdates(false);
108 Thurallor-7095
            w:Close();
109 2 Thurallor-7095
        end
110 Thurallor-7095
    end
111 Thurallor-7095
 
112 Thurallor-7095
    AddCallback(self.window, "Closing", function()
113 Thurallor-7095
        if (self.Closing) then
114 Thurallor-7095
            self:Closing();
115 Thurallor-7095
        end
116 Thurallor-7095
    end);
117 Thurallor-7095
 
118 Thurallor-7095
    AddCallback(self.window, "SizeChanged", function()
119 Thurallor-7095
        self:SizeChanged();
120 Thurallor-7095
    end);
121 Thurallor-7095
    self:SizeChanged();
122 Thurallor-7095
 
123 Thurallor-7095
    L:SetContext(prevContext);
124 Thurallor-7095
end
125 Thurallor-7095
 
126 Thurallor-7095
function ExportWindow:SizeChanged()
127 Thurallor-7095
    local left, top = self.window.buttons[self.ok]:GetPosition();
128 Thurallor-7095
    self.compressed:SetPosition(left - 120, top);
129 Thurallor-7095
end
130 Thurallor-7095
 
131 Thurallor-7095
function ExportWindow:Close()
132 Thurallor-7095
    self.window:Close();
133 Thurallor-7095
end

All times are GMT -5. The time now is 06:17 AM.


Our Network
EQInterface | EQ2Interface | Minion | WoWInterface | ESOUI | LoTROInterface | MMOUI | Swtorui