Salts (I think) TreeNode implementation. Extends to allow some extra stuff to be stored in each node.
Inheritance: System.Windows.Forms.TreeNode
        public int LoadExternal(string file, bool isDef)
        {
            EnableSecondProgressBar(false);
            TPFTexInfo tmpTex = new TPFTexInfo(Path.GetFileName(file), -1, Path.GetDirectoryName(file), null, WhichGame);
            // KFreon: Get hash
            if (!isDef)
            {
                string hash = "";

                // KFreon: Check if hash in filename
                // Heff: fix weird uppercase X
                file = Path.GetFileName(file).Replace("0X", "0x");
                if (file.Contains("0x"))
                    hash = file.Substring(file.IndexOf("0x"), 10);
                else  // KFreon: If not in filename, look in all non TPF .defs
                    foreach (TPFTexInfo tex in LoadedTexes)
                    {
                        if (tex.isDef && tex.isExternal)
                        {
                            using (StreamReader sr = new StreamReader(Path.Combine(tex.FilePath, tex.FileName)))
                                while (!sr.EndOfStream)
                                {
                                    string line = sr.ReadLine();
                                    if (line.Contains(file + '|'))
                                    {
                                        int start = line.IndexOf('|');
                                        hash = line.Substring(start + 1, line.Length - (start + 1));
                                        break;
                                    }
                                }
                            if (hash != "")
                                break;
                        }
                    }


                // KFreon: Convert hash to uint
                if (hash != "")
                    tmpTex.Hash = KFreonLib.Textures.Methods.FormatTexmodHashAsUint(hash);

                tmpTex.OriginalHash = tmpTex.Hash;
            }


            // KFreon: Get details
            if (!tmpTex.isDef)
                tmpTex.EnumerateDetails();

            // KFreon: Add node and its index to current node
            myTreeNode temp = new myTreeNode(Path.GetFileName(file));
            temp.TexInd = LoadedTexes.Count;
            // Heff: cancellation check
            if (!cts.IsCancellationRequested)
            {
                this.Invoke(new Action(() =>
                {
                    MainTreeView.Nodes.Add(temp);
                    OverallProg.IncrementBar();
                }));
            }

            LoadedTexes.Add(tmpTex);

            return temp.TexInd;
        }
Example #2
0
 public void AddNode(myTreeNode node)
 {
     nodeList.Add(node);
 }
        public void RedrawTreeView()
        {
            //Heff: if cancellation was requested, this was most likely called by a background thread, so don't try to interact with the form.
            if (cts.IsCancellationRequested)
                return;

            if (MainTreeView.InvokeRequired)
                this.Invoke(new Action(() =>
                {
                    MainTreeView.BeginUpdate();
                    RedrawTreeView();
                    MainTreeView.EndUpdate();
                }));
            else
            {
                MainTreeView.BeginUpdate();
                List<myTreeNode> nodes = new List<myTreeNode>();
                ResetImageList();
                for (int i = 0; i < LoadedTexes.Count; i++)
                {
                    TPFTexInfo curr = LoadedTexes[i];

                    // KFreon: If analysed, add visual cues
                    string text = curr.FormatTexDetails(isAnalysed);
                    myTreeNode node = new myTreeNode(text);
                    node.TexInd = i;

                    // KFreon: Make tree dups obvious
                    if (curr.TreeDuplicates.Count != 0)
                    {
                        Font tempfont = node.NodeFont ?? MainTreeView.Font;
                        node.NodeFont = new Font(tempfont, FontStyle.Italic);
                    }

                    if (!curr.isDef)
                    {
                        // KFreon: Deal with File dups
                        if (curr.FileDuplicates.Count != 0)
                            for (int j = 0; j < curr.FileDuplicates.Count; j++)
                            {
                                TPFTexInfo trr = curr.FileDuplicates[j];
                                text = trr.FormatTexDetails(isAnalysed);
                                trr.ThumbInd = -1;
                                myTreeNode temp = new myTreeNode(text);
                                temp.TexInds.Add(i);
                                temp.TexInds.Add(j);
                                node.Nodes.Add(temp);
                                curr.FileDuplicates[j] = trr;
                            }

                        try
                        {
                            Bitmap bmp = new Bitmap(curr.Thumbnail);
                            bmp = UsefulThings.WinForms.Imaging.PadImageToSquare(bmp, 64);
                            curr.ThumbInd = MainTreeViewImageList.Images.Count;
                            MainTreeViewImageList.Images.Add(bmp);
                        }
                        catch
                        {
                            curr.ThumbInd = 2;
                        }
                    }
                    else
                        curr.ThumbInd = 1;

                    nodes.Add(node);
                    LoadedTexes[i] = curr;

                }

                MainTreeView.Nodes.Clear();
                MainTreeView.Nodes.AddRange(nodes.ToArray());
                SetTreeImages(MainTreeView);
                MainTreeView.EndUpdate();
            }
        }
        private void SetTreeImagesInternal(myTreeNode treeNode)
        {
            int index = 0;
            if (treeNode.TexInd != -1)
            {
                TPFTexInfo tex = LoadedTexes[treeNode.TexInd];
                index = tex.ThumbInd;
            }
            else
                index = 0;

            treeNode.ImageIndex = index;
            treeNode.SelectedImageIndex = index;

            // Print each node recursively.
            foreach (myTreeNode tn in treeNode.Nodes)
                SetTreeImagesInternal(tn);
        }
        private int GetTexFromNode(myTreeNode node, out TPFTexInfo tex)
        {
            tex = null;

            // Heff: Cancellation check
            if (cts.IsCancellationRequested)
                return -1;

            if (node.TexInd >= LoadedTexes.Count)
                return 0;

            if (node.TexInds.Count != 0)
                tex = LoadedTexes[node.TexInds[0]].FileDuplicates[node.TexInds[1]];
            else
                tex = LoadedTexes[node.TexInd];
            return node.TexInd;
        }
Example #6
0
        /// <summary>
        /// Loads thumbnails from disk, generated during treescan.
        /// </summary>
        /// <param name="nod">Node to load textures into.</param>
        private void UpdateThumbnailDisplays(myTreeNode nod)
        {
            if (!MainListView.InvokeRequired)
            {
                Task.Run(new Action(() => UpdateThumbnailDisplays(nod)));
                return;
            }
            myTreeNode SelectedNode = nod;
            List<Image> thumbs = new List<Image>();
            List<int> thuminds = new List<int>();

            for (int i = 0; i < SelectedNode.TexInds.Count; i++)
            {
                TreeTexInfo tex = Tree.GetTex(SelectedNode.TexInds[i]);
                int ind = i + 1;

                // KFreon: If no thumbnail, try again
                if (tex.ThumbnailPath == null)
                {
                    ind = 0;
                    continue;
                }
                else if (tex.ThumbnailPath.Contains("placeholder.ico") && !tex.TriedThumbUpdate)
                {
                    try
                    {
                        using (Bitmap img = tex.GetImage(pathBIOGame))
                        {

                            using (PCCObjects.IPCCObject pcc = PCCObjects.Creation.CreatePCCObject(tex.Files[0], WhichGame))
                            {
                                using (Textures.ITexture2D tex2D = pcc.CreateTexture2D(tex.ExpIDs[0], pathBIOGame))
                                {
                                    if (img != null)
                                    {
                                        string savepath = Path.Combine(ThumbnailPath, tex.ThumbName);
                                        if (File.Exists(savepath))
                                        {
                                            ind = i + 1;
                                            tex.ThumbnailPath = savepath;
                                        }
                                        else
                                        {
                                            try
                                            {
                                                byte[] data = UsefulThings.WinForms.Imaging.GetPixelDataFromBitmap(img);
                                                ImageEngine.GenerateThumbnailToFile(new MemoryStream(data), savepath, 128);
                                                tex.ThumbnailPath = savepath;
                                                ind = i + 1;
                                            }
                                            catch
                                            {
                                                ind = 0;
                                                // IGNORE
                                            }
                                        }
                                        tex.TriedThumbUpdate = true;
                                        Tree.ReplaceTex(SelectedNode.TexInds[i], tex);
                                    }
                                }
                            }                                
                        }
                    }
                    catch (Exception e)
                    {
                        thumbs.Add(new Bitmap(1,1));
                    }
                }

                Image thumb;
                try
                {
                    thumb = UsefulThings.WinForms.Imaging.PadImageToSquare(tex.ThumbnailPath, 128);
                    thumbs.Add(thumb);
                }
                catch
                {
                    DebugOutput.PrintLn("Thumbnail: " + tex.ThumbnailPath + "  not found.");
                    ind = 0;
                }
                thuminds.Add(ind);
            }

            // KFreon: Set images to show in ListView
            if (!MainListView.IsDisposed)
            {
                this.Invoke(new Action(() =>
                {
                    ListViewImageList.Images.Clear();
                    ListViewImageList.Images.Add(new Bitmap(Path.Combine(ExecFolder, "placeholder.ico")));
                    ListViewImageList.Images.AddRange(thumbs.ToArray());


                    for (int i = 0; i < MainListView.Items.Count; i++)
                    {
                        try
                        {
                            MainListView.Items[i].ImageIndex = thuminds[i];
                        }
                        catch (Exception e)
                        {
                            DebugOutput.PrintLn("Error setting thumbnails in display: " + e.Message);
                        }
                    }

                    MainListView.Refresh();
                }));
            }
        }
Example #7
0
        private void ConstructTree()
        {
            Dictionary<string, string> things = new Dictionary<string, string>();


            DebugOutput.PrintLn("Number of texes = " + Tree.TexCount);
            OutputBoxPrintLn("Constructing tree...");
            StatusUpdater.UpdateText("Constructing Tree...");
            if (!noWindow)
            {
                this.Invoke(new Action(() =>
                {
                    MainTreeView.Nodes.Clear();
                    MainTreeView.BeginUpdate();
                }));
            }
            t = new myTreeNode("All Texture Files", "All Texture Files");

            // KFreon:  Loop over all textures and add them to a node
            for (int i = 0; i < Tree.TexCount; i++)
            {
                TreeTexInfo currentTex = Tree.GetTex(i);
                string[] packs = currentTex.FullPackage.Split('.');
                myTreeNode node = null;
                myTreeNode prevNode = t;
                int NodeCount = Tree.NodeCount;

                for (int j = 0; j < packs.Length; j++)
                {
                    node = null;
                    string tempPack = String.Join(".", packs, 0, j + 1);
                    for (int k = 0; k < NodeCount; k++)
                    {
                        myTreeNode current = Tree.GetNode(k);
                        if (current.Name == tempPack)
                        {
                            node = current;
                            break;
                        }
                    }


                    if (node == null)
                    {
                        node = new myTreeNode(packs[j], tempPack);
                        prevNode.Nodes.Add(node);
                        Tree.AddNode(node);
                    }
                    prevNode = node;
                }
                string texname = currentTex.TexName;
                node.TexInds.Add(i);

                Textures.ITexture2D tex2D = Textures.Creation.CreateTexture2D(texname, currentTex.Files, currentTex.ExpIDs, WhichGame, pathBIOGame, currentTex.Hash);               

                tex2D.Mips = currentTex.NumMips;
                currentTex.Textures.Add(tex2D);
                currentTex.ParentNode = node;
                if (!Tree.ReplaceTex(i, currentTex))
                    MessageBox.Show("Replace in tree failed! Index: " + i + ", thisTex: " + currentTex.TexName);

            }

            if (!noWindow)
            {
                this.Invoke(new Action(() =>
                {
                    MainTreeView.Sort();
                    MainTreeView.Nodes.Add(t);
                    MainTreeView.EndUpdate();
                }));
            }
            DebugOutput.PrintLn("Tree constructed!");
        }
Example #8
0
        private void GetTexesRecursive(myTreeNode node, List<TreeTexInfo> temptexes)
        {
            for (int i = 0; i < node.TexInds.Count; i++)
                temptexes.Add(Tree.GetTex(node.TexInds[i]));

            var nodecount = node.Nodes?.Count ?? 0;
            if (nodecount != 0)
                foreach (myTreeNode n in node.Nodes)
                    GetTexesRecursive(n, temptexes);
        }
        public void RedrawTreeView()
        {
            if (MainTreeView.InvokeRequired)
                this.Invoke(new Action(() =>
                {
                    MainTreeView.BeginUpdate();
                    RedrawTreeView();
                    MainTreeView.EndUpdate();
                }));
            else
            {
                MainTreeView.BeginUpdate();
                List<myTreeNode> nodes = new List<myTreeNode>();
                ResetImageList();
                for (int i = 0; i < LoadedTexes.Count; i++)
                {
                    TPFTexInfo curr = LoadedTexes[i];

                    // KFreon: If analysed, add visual cues
                    string text = curr.FormatTexDetails(isAnalysed);
                    myTreeNode node = new myTreeNode(text);
                    node.TexInd = i;

                    // KFreon: Make tree dups obvious
                    if (curr.TreeDuplicates.Count != 0)
                    {
                        Font tempfont = node.NodeFont ?? MainTreeView.Font;
                        node.NodeFont = new Font(tempfont, FontStyle.Italic);
                    }

                    if (!curr.isDef)
                    {
                        // KFreon: Deal with File dups
                        if (curr.FileDuplicates.Count != 0)
                            for (int j = 0; j < curr.FileDuplicates.Count; j++)
                            {
                                TPFTexInfo trr = curr.FileDuplicates[j];
                                text = trr.FormatTexDetails(isAnalysed);
                                trr.ThumbInd = -1;
                                myTreeNode temp = new myTreeNode(text);
                                temp.TexInds.Add(i);
                                temp.TexInds.Add(j);
                                node.Nodes.Add(temp);
                                curr.FileDuplicates[j] = trr;
                            }

                        try
                        {
                            Bitmap bmp = new Bitmap(curr.Thumbnail);
                            curr.ThumbInd = MainTreeViewImageList.Images.Count;
                            MainTreeViewImageList.Images.Add(bmp);
                        }
                        catch
                        {
                            curr.ThumbInd = 2;
                        }
                    }
                    else
                        curr.ThumbInd = 1;

                    nodes.Add(node);
                    LoadedTexes[i] = curr;

                }

                MainTreeView.Nodes.Clear();
                MainTreeView.Nodes.AddRange(nodes.ToArray());
                SetTreeImages(MainTreeView);
                MainTreeView.EndUpdate();
            }
        }