Exemplo n.º 1
0
        private void On_btnDump_Click(object sender, EventArgs e)
        {
            var initialFile   = _txtInitialFile.Text;
            var workingFolder = Path.GetDirectoryName(initialFile);

            var(rootNode, processedFiles) = DtsProcessor.Parse(workingFolder, initialFile);
            var contents = rootNode.Dump(_chkPrintNodesPaths.Checked);

            File.WriteAllText($"{initialFile}.lst", string.Join("\n", processedFiles));
            File.WriteAllText($"{initialFile}.dump", contents);

            MessageBox.Show($@"All done!");
        }
Exemplo n.º 2
0
        private void On_btnCreateOverlay_Click(object sender, EventArgs e)
        {
            var initialFileA   = _txtInitialFileA.Text;
            var workingFolderA = Path.GetDirectoryName(initialFileA);

            var initialFileB   = _txtInitialFileB.Text;
            var workingFolderB = Path.GetDirectoryName(initialFileB);

            var(rootNodeA, _) = DtsProcessor.Parse(workingFolderA, initialFileA);
            var(rootNodeB, _) = DtsProcessor.Parse(workingFolderB, initialFileB);

            var overlay = _cbSource.SelectedIndex == 0 ? rootNodeA.Overlay(rootNodeB) : rootNodeB.Overlay(rootNodeA);

            File.WriteAllText(Path.Combine($"{workingFolderA}", $"{Path.GetFileNameWithoutExtension(initialFileA)}-overlay.dtsi"), overlay);
            MessageBox.Show(@"All done!");
        }
Exemplo n.º 3
0
        private static bool TryParseNodeDefinition(string text, Node parentNode, out Node newNode, DtsProcessor dts)
        {
            var pos = 0;

            if (!text.MoveTo(ref pos, "{", MoveStrategy.AllAllowed))
            {
                newNode = null;
                return(false);
            }
            var nodeNameAndLabel = text.Substring(0, pos - 1);
            var parts            = nodeNameAndLabel.Split(':');

            var    nodeLabel = string.Empty;
            string nodeName;

            if (parts.Length == 1)
            {
                nodeName = parts[0].Trim();
            }
            else
            {
                nodeLabel = parts[0].Trim();
                nodeName  = parts[1].Trim();
            }

            newNode = parentNode.AddChild(nodeName, nodeLabel);

            text = text.TrimEnd(';', '}');
            pos  = text.IndexOf('{') + 1;
            text = text.Substring(pos);
            pos  = 0;
            while (true)
            {
                if (!TryFetchPropertyDefinition(text, pos, out var endPos, out var fetchedText, newNode, dts, out var itWasInclude))
                {
                    break;
                }
                if (itWasInclude)
                {
                    pos += endPos;
                    continue;
                }

                var tmp = endPos;
                if (TryFetchNodeDefinition(fetchedText, 0, out endPos, out fetchedText))
                {
                    if (!TryParseNodeDefinition(fetchedText, newNode, out var _, dts))
                    {
                        newNode = null;
                        return(false);
                    }
                    pos += endPos;
                    continue;
                }

                var propertyNameAndValue = text.Substring(pos, tmp - pos).Trim().TrimEnd(';');
                parts = propertyNameAndValue.Split('=');
                var propName  = parts[0].Trim();
                var propValue = string.Empty;
                if (parts.Length == 2)
                {
                    propValue = parts[1].Trim();
                }
                newNode.AddProperty(new NodeProperty(propName, propValue));

                pos = tmp;
            }

            return(true);
        }
Exemplo n.º 4
0
        private static bool TryFetchPropertyDefinition(string text, int startPos, out int endPos, out string fetchedText, Node parentNode, DtsProcessor dts, out bool itWasInclude)
        {
            itWasInclude = false;
            var pos = startPos;

            if (!text.MoveTo(ref pos, ";", MoveStrategy.AllAllowed))
            {
                if (!text.MoveTo(ref pos, "#include", MoveStrategy.AllAllowed))
                {
                    fetchedText = null;
                    endPos      = startPos;
                    return(false);
                }

                pos -= "#include".Length;
                if (!TryFetchInclude(text, pos, out endPos, out fetchedText))
                {
                    fetchedText = null;
                    endPos      = startPos;
                    return(false);
                }

                var path = fetchedText.Trim().Trim('"');
                dts._processedFiles.Add(path);
                ProcessFileExt(dts._workingFolder, path, parentNode, dts._processedFiles);
                itWasInclude = true;
            }

            var property       = text.Substring(startPos, pos - startPos);
            var openBracketPos = property.IndexOf('{');

            if (openBracketPos < 0)
            {
                fetchedText = property;
                endPos      = pos;
                return(true);
            }

            pos = startPos + openBracketPos;
            while (text.MoveTo(ref pos, "};", MoveStrategy.AllAllowed))
            {
                var nodeDefinition = text.Substring(startPos, pos - startPos);

                var ob = nodeDefinition.Count('{');
                var oc = nodeDefinition.Count('}');
                if (ob != oc)
                {
                    continue;
                }
                endPos      = pos;
                fetchedText = nodeDefinition;
                return(true);
            }

            fetchedText = null;
            endPos      = startPos;
            return(false);
        }