private void AddExports()
        {
            // remove WorkingNode
            TreeView.BeginUpdate();
            try
            {
                if (parser == null)
                {
                    return;
                }
                if (parser.Errors.Count > 0)
                {
                    WorkingNode wnode = Nodes[0] as WorkingNode;
                    if (wnode == null)
                    {
                        Nodes.Clear();
                        wnode = new WorkingNode(BackingPath);
                        Nodes.Add(wnode);
                    }
                    wnode.SetErrorText(parser.Errors[0]);
                    return;
                }

                Nodes.Clear();
                ExportComparer classesComp = new ExportComparer();
                if (parser.Classes.Count == 1)
                {
                    classesComp.Compare(parser.Classes[0], parser.Classes[0]);
                }
                parser.Classes.Sort(classesComp);
                ExportComparer symbolsComp = new ExportComparer();
                if (parser.Symbols.Count == 1)
                {
                    symbolsComp.Compare(parser.Symbols[0], parser.Symbols[0]);
                }
                parser.Symbols.Sort(symbolsComp);
                ExportComparer fontsComp = new ExportComparer();
                if (parser.Fonts.Count == 1)
                {
                    fontsComp.Compare(parser.Fonts[0], parser.Fonts[0]);
                }
                parser.Fonts.Sort(fontsComp);

                if (parser.Classes.Count > 0)
                {
                    ClassesNode node   = new ClassesNode(BackingPath);
                    string[]    groups = new string[classesComp.groups.Keys.Count];
                    classesComp.groups.Keys.CopyTo(groups, 0);
                    Array.Sort(groups);
                    foreach (string groupName in groups)
                    {
                        if (node.Nodes.Count > 0)
                        {
                            SwfFrameNode frame = new SwfFrameNode(BackingPath, groupName);
                            frame.Text = groupName;
                            node.Nodes.Add(frame);
                        }
                        List <String> names = classesComp.groups[groupName];
                        names.Sort(); // TODO Add setting?
                        foreach (string cls in names)
                        {
                            node.Nodes.Add(new ClassExportNode(BackingPath, cls.Replace(':', '.')));
                        }
                    }
                    Nodes.Add(node);
                }

                if (parser.Symbols.Count > 0)
                {
                    SymbolsNode node2  = new SymbolsNode(BackingPath);
                    string[]    groups = new string[symbolsComp.groups.Keys.Count];
                    symbolsComp.groups.Keys.CopyTo(groups, 0);
                    Array.Sort(groups);
                    foreach (string groupName in groups)
                    {
                        if (node2.Nodes.Count > 0)
                        {
                            SwfFrameNode frame = new SwfFrameNode(BackingPath, groupName);
                            frame.Text = groupName;
                            node2.Nodes.Add(frame);
                        }
                        List <String> names = symbolsComp.groups[groupName];
                        names.Sort(); // TODO Add setting?
                        foreach (string symbol in names)
                        {
                            node2.Nodes.Add(new ExportNode(BackingPath, symbol));
                        }
                    }
                    Nodes.Add(node2);
                }

                if (parser.Fonts.Count > 0)
                {
                    FontsNode node2  = new FontsNode(BackingPath);
                    string[]  groups = new string[fontsComp.groups.Keys.Count];
                    fontsComp.groups.Keys.CopyTo(groups, 0);
                    Array.Sort(groups);
                    foreach (string groupName in groups)
                    {
                        if (node2.Nodes.Count > 0)
                        {
                            SwfFrameNode frame = new SwfFrameNode(BackingPath, groupName);
                            frame.Text = groupName;
                            node2.Nodes.Add(frame);
                        }
                        List <String> names = fontsComp.groups[groupName];
                        names.Sort(); // TODO Add setting?
                        foreach (string font in names)
                        {
                            node2.Nodes.Add(new FontExportNode(BackingPath, font));
                        }
                    }
                    Nodes.Add(node2);
                }
            }
            finally
            {
                // free parsed model
                parser = null;
                TreeView.EndUpdate();
            }
        }
Esempio n. 2
0
        private void AddExports()
        {
            // remove WorkingNode
            TreeView.BeginUpdate();
            try
            {
                if (parser == null)
                {
                    return;
                }
                if (parser.Errors.Count > 0)
                {
                    WorkingNode wnode = Nodes[0] as WorkingNode;
                    if (wnode == null)
                    {
                        Nodes.Clear();
                        wnode = new WorkingNode(BackingPath);
                        Nodes.Add(wnode);
                    }
                    wnode.SetErrorText(parser.Errors[0]);
                    return;
                }

                Nodes.Clear();
                ExportComparer classesComp = new ExportComparer(parser.Frames);
                if (parser.Classes.Count == 1)
                {
                    classesComp.Compare(parser.Classes[0], parser.Classes[0]);
                }
                parser.Classes.Sort(classesComp);
                ExportComparer symbolsComp = new ExportComparer(parser.Frames);
                if (parser.Symbols.Count == 1)
                {
                    symbolsComp.Compare(parser.Symbols[0], parser.Symbols[0]);
                }
                parser.Symbols.Sort(symbolsComp);
                ExportComparer fontsComp = new ExportComparer(parser.Frames);
                if (parser.Fonts.Count == 1)
                {
                    fontsComp.Compare(parser.Fonts[0], parser.Fonts[0]);
                }
                parser.Fonts.Sort(fontsComp);

                SwfHeaderNode hnode = new SwfHeaderNode(BackingPath);
                string        ext   = Path.GetExtension(BackingPath).ToLower();
                hnode.Nodes.Add(new HeaderInfoNode("File Size", FormatBytes(new FileInfo(BackingPath).Length)));
                hnode.Nodes.Add(new HeaderInfoNode("SWF Version", parser.Header.Version));
                hnode.Nodes.Add(new HeaderInfoNode("AVM", parser.FileAttributes.Actionscript3 ? 2 : 1));
                if (parser.FileAttributes.UseNetwork)
                {
                    hnode.Nodes.Add(new HeaderInfoNode("Use Network"));
                }
                if (parser.FileAttributes.UseDirectBlit)
                {
                    hnode.Nodes.Add(new HeaderInfoNode("Use DirectBlit"));
                }
                if (parser.FileAttributes.UseGPU)
                {
                    hnode.Nodes.Add(new HeaderInfoNode("Use GPU"));
                }
                if (ext == ".swf")
                {
                    hnode.Nodes.Add(new HeaderInfoNode("Dimensions", FormatDimensions(GetSwfRect(parser.Header.Rect))));
                    hnode.Nodes.Add(new HeaderInfoNode("Background", parser.FileAttributes.Background));
                }
                hnode.Nodes.Add(new HeaderInfoNode("Framerate", parser.Header.Fps / 256));
                hnode.Nodes.Add(new HeaderInfoNode("Frames", parser.Header.Frames));
                Nodes.Add(hnode);

                if (parser.Classes.Count > 0)
                {
                    ClassesNode node = new ClassesNode(BackingPath);
                    node.Text += " (" + FormatBytes(parser.AbcSize) + ")";
                    int[] groups = new int[classesComp.groups.Keys.Count];
                    classesComp.groups.Keys.CopyTo(groups, 0);
                    Array.Sort(groups);
                    foreach (int index in groups)
                    {
                        DeclEntry    group     = parser.Frames[index];
                        string       groupName = group.Name;
                        SwfFrameNode frame     = new SwfFrameNode(BackingPath, groupName);
                        frame.Text = groupName + " (" + FormatBytes(group.AbcSize) + ")";
                        if (parser.Frames.Count > 1)
                        {
                            node.Nodes.Add(frame);
                        }

                        List <String> names = classesComp.groups[index];
                        names.Sort(); // TODO Add setting?
                        foreach (string cls in names)
                        {
                            string name = cls.Replace(':', '.');
                            if (cls.EndsWithOrdinal("()"))
                            {
                                node.Nodes.Add(new MemberExportNode(BackingPath, name.Replace("()", ""), Icons.Method.Index));
                            }
                            else if (cls.EndsWith('$'))
                            {
                                node.Nodes.Add(new MemberExportNode(BackingPath, name.Replace("$", ""), Icons.Variable.Index));
                            }
                            else if (cls.EndsWith('#'))
                            {
                                node.Nodes.Add(new MemberExportNode(BackingPath, name.Replace("#", ""), Icons.Const.Index));
                            }
                            else
                            {
                                node.Nodes.Add(new ClassExportNode(BackingPath, name));
                            }
                        }
                    }
                    Nodes.Add(node);
                }

                if (parser.Symbols.Count > 0)
                {
                    SymbolsNode node2 = new SymbolsNode(BackingPath);
                    node2.Text += " (" + FormatBytes(parser.TotalSize - parser.AbcSize - parser.FontsSize) + ")";

                    int[] groups = new int[symbolsComp.groups.Keys.Count];
                    symbolsComp.groups.Keys.CopyTo(groups, 0);
                    Array.Sort(groups);
                    foreach (int index in groups)
                    {
                        DeclEntry    group     = parser.Frames[index];
                        string       groupName = group.Name;
                        SwfFrameNode frame     = new SwfFrameNode(BackingPath, groupName);
                        frame.Text = groupName + " (" + FormatBytes(group.DataSize) + ")";
                        if (parser.Frames.Count > 1)
                        {
                            node2.Nodes.Add(frame);
                        }

                        List <String> names = symbolsComp.groups[index];
                        names.Sort(); // TODO Add setting?
                        foreach (string symbol in names)
                        {
                            node2.Nodes.Add(new ExportNode(BackingPath, symbol));
                        }
                    }
                    Nodes.Add(node2);
                }

                if (parser.Fonts.Count > 0)
                {
                    FontsNode node2 = new FontsNode(BackingPath);
                    node2.Text += " (" + FormatBytes(parser.FontsSize) + ")";
                    int[] groups = new int[fontsComp.groups.Keys.Count];
                    fontsComp.groups.Keys.CopyTo(groups, 0);
                    Array.Sort(groups);
                    foreach (int index in groups)
                    {
                        DeclEntry    group     = parser.Frames[index];
                        string       groupName = group.Name;
                        SwfFrameNode frame     = new SwfFrameNode(BackingPath, groupName);
                        frame.Text = groupName + " (" + FormatBytes(group.FontSize) + ")";
                        if (parser.Frames.Count > 1)
                        {
                            node2.Nodes.Add(frame);
                        }

                        List <String> names = fontsComp.groups[index];
                        names.Sort(); // TODO Add setting?
                        foreach (string font in names)
                        {
                            node2.Nodes.Add(new FontExportNode(BackingPath, font));
                        }
                    }
                    Nodes.Add(node2);
                }
            }
            finally
            {
                // free parsed model
                parser = null;
                TreeView.EndUpdate();
            }
        }