예제 #1
0
        public void DuplicateBracketsSkipsNode()
        {
            const string file = "..\\..\\testdata\\fail\\duplicatebrackets.cfg";
            var parser = new Parser();
            var kc = parser.ParseConfig(file);

            Assert.AreEqual(1, kc.Count);

            var part = kc.First();
            Console.WriteLine(part);

            Assert.True(part.Values.ContainsKey("name"));
            Assert.AreEqual(3, part.Values.Count);
            Assert.AreEqual(2, part.Children.Count);

            var child1 = part.Children[0];
            var child2 = part.Children[1];

            Assert.AreEqual("RESOURCE", child1.Name);
            Assert.True(child1.Values.ContainsKey("name"));
            Assert.True(child1.Values.ContainsKey("amount"));
            Assert.AreEqual(3, child1.Values.Count);

            Assert.AreEqual("MODULE", child2.Name);
            Assert.True(child2.Values.ContainsKey("name"));
            Assert.AreEqual(2, child2.Values.Count);
        }
예제 #2
0
        public void Init()
        {
            _fileCount = 0;

            var dir = new DirectoryInfo(BaseDir);

            _configs = new List<KerbalConfig>();
            var parser = new Parser(false,true);

            foreach (var file in
                dir.GetFiles("*.cfg", SearchOption.AllDirectories))
            {
                _fileCount++;
                _configs.Add(parser.ParseConfig(file.FullName));
            }
        }
예제 #3
0
        public void FilterTest()
        {
            const string file = "..\\..\\testdata\\filter.cfg";
            var filters = new List<string> { "PART", "ANOTHER" };
            var parser = new Parser(filters, false, true);
            var kc = parser.ParseConfig(file);

            Assert.AreEqual(2, kc.Count);

            var part = kc.First();
            Console.WriteLine(part);
            var another = kc[1];
            Console.WriteLine(another);

            Assert.True(part.Values.ContainsKey("name"));
            Assert.AreEqual("partname", part.Values["name"].First());
            Assert.AreEqual(1, part.Children.Count);
            Assert.True(another.Values.ContainsKey("name"));
            Assert.AreEqual("foo", another.Values["name"].First());
        }
예제 #4
0
        public void DuplicateValues()
        {
            const string file = "..\\..\\testdata\\fail\\duplicatevalues.cfg";
            var parser = new Parser();
            var kc = parser.ParseConfig(file);

            var tree = kc.First();

            Console.WriteLine(tree);

            Assert.AreEqual(4, tree.Values.Count);
            Assert.IsTrue(tree.Values.ContainsKey("name"));
            Assert.IsTrue(tree.Values.ContainsKey("module"));
            Assert.IsTrue(tree.Values.ContainsKey("author"));
            Assert.IsTrue(tree.Values.ContainsKey("description"));
            Assert.AreEqual(3, tree.Values["name"].Count);
            Assert.AreEqual(2, tree.Values["author"].Count);
            Assert.IsTrue(tree.Values["name"].First() == "batteryBankMini");
            Assert.IsTrue(tree.Values["name"][1] == "batteryBankMini2");
            Assert.IsTrue(tree.Values["name"][2] == "spice");
            Assert.IsTrue(tree.Values["author"].First() == "Squad");
            Assert.IsTrue(tree.Values["author"][1] == "Bob");
        }
예제 #5
0
        /// <summary>
        /// Gets a list of all mod folders in GameData, then loads each .cfg file
        /// and parses it.
        /// </summary>
        private void RefreshInstalledModsList()
        {
            // Get GameData Directory
            var gameData = new DirectoryInfo(Main.Instance.CurrentInstance.GameData());

            var parser = new Parser(false, true);

            // Go through each folder in GameData
            foreach (var mod in gameData.GetDirectories("*", SearchOption.TopDirectoryOnly))
            {
                var parts = new Dictionary<string, KerbalConfig>();

                // Get all of the .cfg files from this folder
                foreach (var part in mod.GetFiles("*.cfg", SearchOption.AllDirectories))
                {
                    try
                    {
                        // Create a hash of the file name, unique storage in dictionary
                        // Add parsed file to dictionary
                        var hash = part.GetHashCode() + ":" + part.Name;
                        parts.Add(hash, parser.ParseConfig(part.FullName));
                    }
                    catch (ParseErrorException ex)
                    {
                        Console.WriteLine("Error on parse " + part.Name + " " + ex);
                        CKAN.Main.Instance.AddLogMessage("PartEditor: Error on parse " + part.Name + " " + ex);
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine("Error on " + part.Name + " " + ex);
                        CKAN.Main.Instance.AddLogMessage("PartEditor: Error on " + part.Name + " " + ex);
                    }
                }

                if (parts.Count == 0) continue;

                // Add this parts list to the list containing lists of all mods
                // and then move all parts into the "all parts" list
                _allMods.Add(mod.Name, parts);

                foreach (var part1 in parts)
                {
                    if (!_allParts.ContainsKey(part1.Key))
                        _allParts.Add(part1.Key, part1.Value);
                }
            }

            foreach (var key in _allMods.Keys)
            {
                listBox1.Items.Add(key);
            }

            foreach (var key in _allParts.Keys)
            {
                listBox2.Items.Add(key);
            }
        }
예제 #6
0
        private Dictionary<string, KerbalConfig> GetInstalledModParts(string identifier)
        {
            var registry = Main.Instance.CurrentInstance.Registry;
            var module = registry.InstalledModule(identifier);

            if (module == null)
                return null;

            var parser = new Parser(false, true);

            var parts = new Dictionary<string, KerbalConfig>();

            foreach (var item in module.Files)
            {
                parts.Add(item, parser.ParseConfig(item));
            }

            //foreach (var item in module.Files)
            //{
            //	if (_mDisabledParts.ContainsKey(item))
            //	{
            //		parts.Add(item, _mDisabledParts[item]);
            //		continue;
            //	}

            //	var filename = Path.GetFileName(item);

            //	if (filename != null && !filename.EndsWith(".cfg")) continue;

            //	var configNode = LoadPart(item);
            //	if (configNode != null)
            //		parts.Add(item, configNode);
            //}

            return parts;
        }
예제 #7
0
        /**
         * Method for load tree
         * Status: OK
         * Note: if you add a new treeLoader, update the switch...
         */
        public void LoadTree(string path, TreeType treeType = TreeType.StockTechTree)
        {
            ResetTree();

            if (_treeData == null)
            {
                return;
            }
            var parser = new Parser();
            _config = parser.ParseConfig(path);
            switch (treeType)
            {
                case TreeType.StockTechTree:
                    _treeLoader = new StockTechTreeLoader();
                    break;
                case TreeType.YongeTech:
                    _treeLoader = new YongeTechTreeLoader();
                    break;
                default:
                    throw new Exception("The techtree's file format is not reconized !");

            }
            _treeLoader.LoadTree(_config, _treeData);
            _treeData.LinkNodes();
            _treeData.WorkspaceViewModel.StatusBarText = "Tree Loaded";
        }
예제 #8
0
        public void HeadLessConfig()
        {
            const string file = "..\\..\\testdata\\headless.cfg";
            var parser = new Parser();
            var kc = parser.ParseConfig(file);

            var tree = kc.First();

            Console.WriteLine(tree);

            Assert.AreEqual("HEADLESS", tree.Name);
            Assert.AreEqual(7, tree.Values.Count);
            Assert.IsTrue(tree.Values.ContainsKey("name"));
            Assert.IsTrue(tree.Values.ContainsKey("module"));
            Assert.IsTrue(tree.Values.ContainsKey("author"));
            Assert.IsTrue(tree.Values.ContainsKey("mesh"));
            Assert.IsTrue(tree.Values.ContainsKey("rescaleFactor"));
            Assert.IsTrue(tree.Values.ContainsKey("middleprop"));
            Assert.IsTrue(tree.Values.ContainsKey("lastprop"));

            Assert.AreEqual(2, tree.Children.Count);
            Assert.AreEqual(3, tree.Children[0].Values.Count);
            Assert.AreEqual(2, tree.Children[1].Values.Count);
        }
예제 #9
0
 public void Init()
 {
     const string file = "..\\..\\testdata\\simple.cfg";
     var parser = new Parser();
     _kerbalConfig = parser.ParseConfig(file);
 }
예제 #10
0
 public void MismatchBrackets()
 {
     const string file = "..\\..\\testdata\\fail\\mismatch.cfg";
     var parser = new Parser();
     parser.ParseConfig(file);
 }
예제 #11
0
        public void SkipBrokenNodesWithValidation()
        {
            const string file = "..\\..\\testdata\\fail\\invalidnodename.cfg";
            var parser = new Parser(true);
            var kc = parser.ParseConfig(file);

            Assert.AreEqual(1, kc.Count);

            var part = kc.First();
            Console.WriteLine(part);

            Assert.True(part.Values.ContainsKey("name"));
            Assert.AreEqual(24, part.Values.Count);
            Assert.AreEqual(0, part.Children.Count);
        }
예제 #12
0
        public void ModuleManagerTwo()
        {
            const string file = "..\\..\\testdata\\fail\\mmnode2.cfg";
            var parser = new Parser(true);
            var kc = parser.ParseConfig(file);

            Assert.AreEqual(1, kc.Count);

            var tree = kc.First();

            Assert.True(tree.Values.ContainsKey("name"));
            Assert.AreEqual("test", tree.Values["name"].First());
        }
예제 #13
0
        public void ModuleManagerFour()
        {
            const string file = "..\\..\\testdata\\fail\\mmnode4.cfg";
            var parser = new Parser(true);
            var kc = parser.ParseConfig(file);

            Assert.AreEqual(3, kc.Count);

            var tree = kc.First();
            var treetwo = kc[1];
            var treethree = kc[2];

            Assert.True(tree.Values.ContainsKey("name"));
            Assert.AreEqual("test", tree.Values["name"].First());
            Assert.True(treetwo.Values.ContainsKey("name"));
            Assert.AreEqual("2ndtest", treetwo.Values["name"].First());
            Assert.True(treethree.Values.ContainsKey("name"));
            Assert.AreEqual("3rdtest", treethree.Values["name"].First());
        }
예제 #14
0
        public void HeadLessTrailConfig()
        {
            const string file = "..\\..\\testdata\\headlesstrail.cfg";
            var parser = new Parser();
            var kc = parser.ParseConfig(file);

            var tree = kc.First();

            Console.WriteLine(tree);

            Assert.AreEqual("HEADLESSTRAIL", tree.Name);
            Assert.AreEqual(2, tree.Values.Count);
            Assert.IsTrue(tree.Values.ContainsKey("middleprop"));
            Assert.IsTrue(tree.Values.ContainsKey("lastprop"));

            Assert.AreEqual(2, tree.Children.Count);
            Assert.AreEqual(3, tree.Children[0].Values.Count);
            Assert.AreEqual(2, tree.Children[1].Values.Count);
        }
예제 #15
0
        public void HeadlessFilterTest()
        {
            const string file = "..\\..\\testdata\\headlessfilter.cfg";
            var filters = new List<string> { "OTHER" };
            var parser = new Parser(filters, false, true);
            var kc = parser.ParseConfig(file);

            Assert.IsEmpty(kc);

            var filters2 = new List<string> { "HEADLESSFILTER" };
            var parser2 = new Parser(filters2, false, true);
            var kc2 = parser2.ParseConfig(file);

            Assert.AreEqual(1, kc2.Count);

            var part = kc2.First();
            Console.WriteLine(part);

            Assert.True(part.Values.ContainsKey("name"));
            Assert.AreEqual("external", part.Values["name"].First());
            Assert.AreEqual(1, part.Children.Count);
        }
예제 #16
0
 public KerbalConfig ParseTree(string path)
 {
     var parser = new Parser();
     return parser.ParseConfig(path);
 }