Exemple #1
0
        public static DefinitionConfig Build(string[] lines, string definitionsFolder, string detectRegex)
        {
            Condition.Requires(lines).IsNotEmpty();
            Condition.Requires(definitionsFolder).IsNotNullOrWhiteSpace().DoesNotContainAny(Path.GetInvalidPathChars());
            Condition.Requires(detectRegex).IsNotNullOrWhiteSpace();
            _definitionsfolder = definitionsFolder;
            Regex infoRegex = new Regex(detectRegex);
            //;)
            var DefCon = new DefinitionConfig();

            Match match = lines.Where(l => infoRegex.IsMatch(l)).Select(m => infoRegex.Match(m)).FirstOrDefault();

            if (match.Success)
            {
                DefCon.Load(FindFile(lines, match.Groups["label"].Value, match.Groups["version"].Value));
                return DefCon;
            }
            return null;
        }
Exemple #2
0
        public static Definition GetInstance(DefinitionConfig configuration, FilterMap coreFilterMap, FilterMap pluginFilterMap)
        {
            var def = new Definition();

            if (configuration.Items.ContainsKey(CORESECTION))
                def._filters.AddRange(configuration.Items[CORESECTION].Select(item => new Filter(item.Key, item.Value, new List<IFilterResult>{coreFilterMap.Get(item.Key)})));

            if (configuration.Items.ContainsKey(PLUGINSECTION))
                def._filters.AddRange(configuration.Items[PLUGINSECTION].Select(item => new Filter(item.Key, item.Value, new List<IFilterResult>{pluginFilterMap.Get(item.Key)})));

            if (configuration.Items.ContainsKey(USERSECTION))
                def._filters.AddRange(configuration.Items[USERSECTION].Select(item => new Filter(item.Key, item.Value, new List<IFilterResult>{new EmptyResult()})));

            def.Version = configuration.GetValue("version", INFOSECTION);
            def.ModRequired = Convert.ToBoolean(configuration.GetValue("mod_required", INFOSECTION));
            def.Label = configuration.GetValue("label", INFOSECTION);
            def.FullName = string.Format("{0}{1}", !string.IsNullOrWhiteSpace(def.Label) ? def.Label + " " : "", def.Version);

            return def;
        }