<commit_before>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace FXStudio
{
    public partial class AssetsView : ViewWindow
    {
        private string m_ProjectLocation;
        private UpdatePropertiesDelegate m_NodeDelegate = null;
        private UpdateOutputDelegate m_OuputDeleagate = null;

        public AssetsView()
        {
            InitializeComponent();
        }

        public void UpdateAssets(string assetFile, UpdatePropertiesDelegate updateProps, UpdateOutputDelegate updateOutput)
        {
            if (!File.Exists(assetFile))
            {
                return;
            }

            m_ProjectLocation = Path.GetDirectoryName(assetFile);
            m_NodeDelegate = updateProps;
            m_OuputDeleagate = updateOutput;

            XmlDocument doc = new XmlDocument();
            doc.Load(assetFile);
            XmlElement rootXml = doc.DocumentElement;

            foreach (XmlNode node in rootXml.ChildNodes)
            {
                TreeNode treeNode = treeViewAssets.Nodes[node.Name];
                if (treeNode != null)
                {
                    treeNode.Tag = node;
                    foreach (XmlNode child in node.ChildNodes)
                    {
                        if (node.Name == "Effects")
                        {
                            AddEffect(treeNode, child);
                        }
                        else
                        {
                            XmlNode nameNode = child.Attributes["name"];
                            if (nameNode != null)
                                treeNode.Nodes.Add(new TreeNode(nameNode.Value) { Tag = child });
                        }
                    }
                }
            }
        }

        public void AddEffect(string sourceFileName, string effectName, bool fromExist)
        {
            string destOjbect = m_ProjectLocation + @"\Effects\" + Path.GetFileNameWithoutExtension(sourceFileName) + ".fxo";
            var processInfo = new ProcessStartInfo
            {
                FileName = "fxc.exe",
#if (Debug)
                Arguments = "/Od /Zi /T fx_5_0 /nologo /Fo \"" + destOjbect + "\" \"" + sourceFileName + "\"",
#else
                    Arguments = "/T fx_5_0 /nologo /Fo \"" + destOjbect + "\" \"" + sourceFileName + "\"",
#endif
                CreateNoWindow = true,
                UseShellExecute = false,
                RedirectStandardOutput = true,
                RedirectStandardError = true,
                WindowStyle = ProcessWindowStyle.Hidden
            };
            var fxcProcess = Process.Start(processInfo);
            string compileInfo = fxcProcess.StandardOutput.ReadToEnd();
            string errorInfo = fxcProcess.StandardError.ReadToEnd();
            fxcProcess.WaitForExit();

            m_OuputDeleagate?.Invoke(compileInfo, errorInfo);

            if (!string.IsNullOrEmpty(compileInfo))
            {
                uint size = RenderMethods.AddEffect(@"Effects\" + Path.GetFileName(destOjbect), sourceFileName, effectName);
                if (size > 0)
                {
                    StringBuilder effectXml = new StringBuilder((int)size);
                    RenderMethods.GetEffectXml(@"Effects\" + Path.GetFileName(destOjbect), effectXml, size);
                    AddEffect(effectXml.ToString());
                }
            }
        }

        private void AddEffect(string effectXmlString)
        {
            if (string.IsNullOrEmpty(effectXmlString))
                return;

            XmlDocument effectDoc = new XmlDocument();
            effectDoc.LoadXml(effectXmlString);
            XmlElement effectXmlNode = effectDoc.DocumentElement;

            TreeNode effectsTreeNode = treeViewAssets.Nodes["Effects"];
            if (effectsTreeNode != null)
            {
                AddEffect(effectsTreeNode, effectXmlNode);
            }<commit_msg>to do<commit_after>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace FXStudio
{
    public partial class AssetsView : ViewWindow
    {
        private string m_ProjectLocation;
        private UpdatePropertiesDelegate m_NodeDelegate = null;
        private UpdateOutputDelegate m_OuputDeleagate = null;
        private string m_AssetPath;
        private XmlDocument m_XmlDoc;

        public AssetsView()
        {
            m_XmlDoc = new XmlDocument();
            InitializeComponent();
        }

        public void UpdateAssets(string assetFile, UpdatePropertiesDelegate updateProps, UpdateOutputDelegate updateOutput)
        {
            if (!File.Exists(assetFile))
            {
                return;
            }

            m_AssetPath = assetFile;
            m_ProjectLocation = Path.GetDirectoryName(assetFile);
            m_NodeDelegate = updateProps;
            m_OuputDeleagate = updateOutput;

            m_XmlDoc.Load(assetFile);
            XmlElement rootXml = m_XmlDoc.DocumentElement;

            treeViewAssets.BeginUpdate();

            foreach (XmlNode node in rootXml.ChildNodes)
            {
                TreeNode treeNode = treeViewAssets.Nodes[node.Name];
                if (treeNode != null)
                {
                    treeNode.Tag = node;
                    treeNode.Nodes.Clear();
                    foreach (XmlNode child in node.ChildNodes)
                    {
                        if (node.Name == "Effects")
                        {
                            AddEffect(treeNode, child);
                        }
                        else
                        {
                            XmlNode nameNode = child.Attributes["name"];
                            if (nameNode != null)
                                treeNode.Nodes.Add(new TreeNode(nameNode.Value) { Tag = child });
                        }
                    }
                }
            }

            treeViewAssets.EndUpdate();
            treeViewAssets.ExpandAll();
        }

        public void SaveAssetsFile()
        {
            m_XmlDoc.Save(XmlWriter.Create(m_AssetPath, new XmlWriterSettings()
            {
                Indent = true,
                IndentChars = "\t",
                OmitXmlDeclaration = false
            }));
        }

        public void AddEffect(string sourceFileName, string effectName, bool fromExist)
        {
            string destOjbect = m_ProjectLocation + @"\Effects\" + Path.GetFileNameWithoutExtension(sourceFileName) + ".fxo";
            var processInfo = new ProcessStartInfo
            {
                FileName = "fxc.exe",
#if (Debug)
                Arguments = "/Od /Zi /T fx_5_0 /nologo /Fo \"" + destOjbect + "\" \"" + sourceFileName + "\"",
#else
                    Arguments = "/T fx_5_0 /nologo /Fo \"" + destOjbect + "\" \"" + sourceFileName + "\"",
#endif
                CreateNoWindow = true,
                UseShellExecute = false,
                RedirectStandardOutput = true,
                RedirectStandardError = true,
                WindowStyle = ProcessWindowStyle.Hidden
            };
            var fxcProcess = Process.Start(processInfo);
            string compileInfo = fxcProcess.StandardOutput.ReadToEnd();
            string errorInfo = fxcProcess.StandardError.ReadToEnd();
            fxcProcess.WaitForExit();

            m_OuputDeleagate?.Invoke(compileInfo, errorInfo);

            if (!string.IsNullOrEmpty(compileInfo))
            {
                uint size = RenderMethods.AddEffect(@"Effects\" + Path.GetFileName(destOjbect), sourceFileName, effectName);
                if (size > 0)
                {
                    StringBuilder effectXml = new StringBuilder((int)size);
                    RenderMethods.GetEffectXml(@"Effects\" + Path.GetFileName(destOjbect), effectXml, size);

                    XmlDocument effectDoc = new XmlDocument();
                    effectDoc.LoadXml(effectXml.ToString());
                    XmlElement effectXmlNode = effectDoc.DocumentElement;

                    XmlNode effectRoot = m_XmlDoc.DocumentElement.SelectSingleNode("Effects");
                    if (effectRoot != null)
                    {
                        effectRoot.AppendChild(m_XmlDoc.ImportNode(effectXmlNode, true));
                        TreeNode effectsTreeNode = treeViewAssets.Nodes["Effects"];
                        if (effectsTreeNode != null)
                        {
                            AddEffect(effectsTreeNode, effectRoot.LastChild);
                        }
                    }
                }
            }
{'fraction_non_alphanumeric': 0.08461707746478873, 'fraction_numerical': 0.0011003521126760564, 'mean_word_length': 1.5495091164095371, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6411532', 'n_tokens_mistral': 2293, 'n_tokens_neox': 2152, 'n_words': 446}