示例#1
0
        public static void SortCfgPatches()
        {
            List <ArmaAddon> temp = new List <ArmaAddon>();

            do
            {
                for (int i = 0; i < CfgPatches.Count; i++)
                {
                    ArmaAddon addon = CfgPatches[i];

                    if (_patchNames.Contains(addon.Name.ToLower()))
                    {
                        continue;
                    }

                    if (addon.RequiredAddons.Count == 0)
                    {
                        _patchNames.Add(addon.Name.ToLower());
                        temp.Add(addon);
                        CfgPatches.Remove(addon);
                        continue;
                    }

                    bool success = false;
                    foreach (string requiredAddon in addon.RequiredAddons)
                    {
                        success = _patchNames.Contains(requiredAddon.ToLower());
                    }

                    if (!success)
                    {
                        continue;
                    }

                    _patchNames.Add(addon.Name.ToLower());
                    temp.Add(addon);
                    CfgPatches.Remove(addon);
                }
            }while (CfgPatches.Count > 0);

            CfgPatches = new List <ArmaAddon>(temp);
        }
示例#2
0
        public static void CompileCfgPatches(string path)
        {
            Console.Write("Compiling CfgPatches...");
            using (var progress = new ProgressBar())
            {
                int  numberOfFiles = Util.GetFileCount(path), processedFiles = 0;
                bool inCfgPatches = false, inAddon = false;

                foreach (string file in Directory.GetFiles(path, "*.cpp", SearchOption.AllDirectories))
                {
                    foreach (string line in File.ReadAllLines(file))
                    {
                        if (!inCfgPatches)
                        {
                            Match cfgPatchesMatch = Util.CfgPatchesRegex.Match(line);
                            if (cfgPatchesMatch.Success)
                            {
                                inCfgPatches = true;
                            }
                            continue;
                        }
                        if (!inAddon)
                        {
                            Match classMatch = Util.CfgPatchesClassRegex.Match(line);
                            if (classMatch.Success)
                            {
                                inAddon    = true;
                                _addonName = classMatch.Groups[1].ToString().Trim();
                            }
                            else
                            {
                                Match endMatch = Util.EndOfClassRegex.Match(line);
                                if (endMatch.Success)
                                {
                                    inCfgPatches = false;
                                }
                            }
                            continue;
                        }

                        Match addonsMatch = Util.RequiredAddonsRegex.Match(line);
                        if (addonsMatch.Success)
                        {
                            List <object> addons = Util.ParseArray(addonsMatch.Groups[1].ToString());

                            ArmaAddon addon = new ArmaAddon(_addonName, addons, SanitizeFile(File.ReadAllText(file)));
                            CfgPatches.Add(addon);
                            _tempNames.Add(_addonName.ToLower());
                        }

                        Match eocMatch = Util.EndOfClassRegex.Match(line);
                        if (eocMatch.Success)
                        {
                            inAddon = false;
                        }
                    }

                    processedFiles++;
                    progress.Report((double)processedFiles / numberOfFiles);
                }
            }

            Console.WriteLine(" Finished");

            if (CfgPatches.Count() > 0)
            {
                VerifyRequiredAddons();
                SortCfgPatches();
            }
            else
            {
                Console.Write("Unable to find class CfgPatches. This may return inaccurate configs if overwriting. Continue? (Y/N): ");

                if (Console.ReadLine().ToLower() == "n")
                {
                    Environment.Exit(0);
                }

                foreach (string file in Directory.GetFiles(path, "*.cpp", SearchOption.AllDirectories))
                {
                    ArmaAddon addon = new ArmaAddon
                    {
                        FileContents = SanitizeFile(File.ReadAllText(file)).ToList()
                    };
                }
            }
        }