Exemple #1
0
        public static void ExportToMySQL(ArmaClass configFile)
        {
            Console.Write("Connecting to MySQL Database... ");
            Util.ConnectToMySQL();
            Console.WriteLine(" Finished");

            Console.WriteLine("Exporting to MySQL... ");
            ExportConfigFile(configFile.Children);
            Console.WriteLine("Finished export!");
        }
Exemple #2
0
        public static void ExportToJSON(ArmaClass configFile)
        {
            Console.Write("Creating JSON export... ");
            string configJSON = configFile.ToJSON();

            Console.WriteLine(" Finished");

            Console.Write("Beautifying... ");
            configJSON = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(configJSON), Formatting.Indented);
            Console.WriteLine(" Finished");

            Console.Write("Saving to file... ");
            File.WriteAllText("configFile.json", configJSON);
            Console.WriteLine(" Finished");
        }
Exemple #3
0
        public static void ReadAllConfigs()
        {
            using (var progress = new ProgressBar())
            {
                int numberOfAddons  = CfgPatches.Count;
                int processedAddons = 0;
                Console.Write("Processing addons... ");
                foreach (ArmaAddon addon in Config.CfgPatches)
                {
                    _currentNode = new ArmaClass();
                    _parentNode  = new ArmaClass();
                    _parents.Clear();
                    _currentAddon = addon.Name;
                    foreach (string line in addon.FileContents)
                    {
                        ParseConfigLine(line);
                    }
                    processedAddons++;
                    progress.Report((double)processedAddons / numberOfAddons);
                }
            }

            Console.WriteLine(" Finished");
        }
Exemple #4
0
        private static void ParseConfigLine(string line)
        {
            // CLASS
            Match match = Util.ClassRegex.Match(line);

            if (match.Success)
            {
                if (Util.ExternalClassRegex.IsMatch(line))
                {
                    return;
                }

                string currentClass = match.Groups[1].ToString();
                string inheritClass = match.Groups[2].ToString();

                if (string.IsNullOrWhiteSpace(inheritClass))
                {
                    inheritClass = "";
                }

                _parents.Add(currentClass);

                if (_parents.Count == 0)
                {
                    _parentNode = ConfigFile;
                }
                else
                {
                    ArmaClass temp_node = ConfigFile;

                    foreach (string parent in _parents.GetRange(0, _parents.Count - 1))
                    {
                        temp_node = temp_node.Children[parent];
                    }

                    _parentNode = temp_node;
                }

                _currentNode = new ArmaClass
                {
                    InheritsFrom  = inheritClass,
                    ExtractedFrom = _currentAddon
                };

                if (!_parentNode.Children.ContainsKey(currentClass))
                {
                    _parentNode.Children.Add(currentClass, _currentNode);
                }

                if (Util.EmptyClassRegex.IsMatch(line))
                {
                    _parents.RemoveAt(_parents.Count - 1);
                }

                return;
            }

            // END OF CLASS
            if (Util.EndOfClassRegex.IsMatch(line))
            {
                _parents.RemoveAt(_parents.Count - 1);
                _currentNode = _parentNode;
                TotalEntries++;
                return;
            }

            // ATTRIBUTE
            match = Util.AttributeRegex.Match(line);
            if (match.Success)
            {
                string name  = match.Groups[1].ToString();
                string value = match.Groups[2].ToString();

                // ARRAY
                match = Util.ArrayRegex.Match(value);
                if (match.Success)
                {
                    List <object> array       = new List <object>();
                    string        arrayString = match.Groups[1].ToString();
                    if (!string.IsNullOrWhiteSpace(arrayString))
                    {
                        array = Util.ParseArray(arrayString);
                    }

                    if (_currentNode.Attributes.ContainsKey(name))
                    {
                        _currentNode.Attributes[name] = new ArmaAttribute(2, array);
                    }
                    else
                    {
                        _currentNode.Attributes.Add(name, new ArmaAttribute(2, array));
                    }
                    TotalEntries++;
                    return;
                }

                // STRING
                if (Util.StringRegex.IsMatch(value))
                {
                    if (_currentNode.Attributes.ContainsKey(name))
                    {
                        _currentNode.Attributes[name] = new ArmaAttribute(1, value);
                    }
                    else
                    {
                        _currentNode.Attributes.Add(name, new ArmaAttribute(1, value));
                    }
                    TotalEntries++;
                    return;
                }

                // SCALAR
                if (Util.ScalarRegex.IsMatch(value))
                {
                    if (_currentNode.Attributes.ContainsKey(name))
                    {
                        _currentNode.Attributes[name] = new ArmaAttribute(0, double.Parse(value));
                    }
                    else
                    {
                        _currentNode.Attributes.Add(name, new ArmaAttribute(0, double.Parse(value)));
                    }
                    TotalEntries++;
                    return;
                }

                if (_currentNode.Attributes.ContainsKey(name))
                {
                    _currentNode.Attributes[name] = new ArmaAttribute(1, value);
                }
                else
                {
                    _currentNode.Attributes.Add(name, new ArmaAttribute(1, value));
                }

                TotalEntries++;

                return;
            }
        }