Exemple #1
0
 public Dependency(DependencyType type, string modName, DependencyComparison comparison, AccurateVersion compareVersion)
 {
     Type           = type;
     ModName        = modName;
     Comparison     = comparison;
     CompareVersion = compareVersion;
 }
Exemple #2
0
 /// <summary>
 /// Determines if a given mod matches this dependency.
 /// </summary>
 protected virtual bool Matches(string modName, AccurateVersion modVersion)
 {
     if (modName != ModName)
     {
         return(false);
     }
     return(Comparison.TestFor(modVersion, CompareVersion));
 }
Exemple #3
0
        public static bool TryParse(string value, out Dependency result)
        {
            result = null;
            if (string.IsNullOrWhiteSpace(value))
            {
                return(false);
            }

            value = value.Trim();
            var type = DependencyType.Normal;

            if (value[0] == '!')
            {
                type  = DependencyType.Inverted;
                value = value.Substring(1).TrimStart();
            }
            else if (value[0] == '?')
            {
                type  = DependencyType.Optional;
                value = value.Substring(1).TrimStart();
            }
            else if (value.StartsWith("(?)"))
            {
                type  = DependencyType.Hidden;
                value = value.Substring(3).TrimStart();
            }
            if (string.IsNullOrWhiteSpace(value))
            {
                return(false);
            }

            const string pattern = @"\A(?<name>[a-zA-Z0-9_\-]+)(?:\s*(?<op><=|>=|<|>|=)\s*(?<ver>\d+(?:\.\d+){0,3}))?\Z";
            var          match   = Regex.Match(value, pattern);

            if (!match.Success)
            {
                return(false);
            }

            string name = match.Groups["name"].Value;
            DependencyComparison comp;
            AccurateVersion      version = default;

            var opG = match.Groups["op"];

            if (opG.Success)
            {
                comp    = new DependencyComparison(opG.Value);
                version = AccurateVersion.Parse(match.Groups["ver"].Value);
            }
            else
            {
                comp = new DependencyComparison(DependencyOperator.None);
            }

            result = new Dependency(type, name, comp, version);
            return(true);
        }
Exemple #4
0
 internal ModInfo(string name, string displayName, AccurateVersion version, AccurateVersion factorioVersion, string author, string description, params Dependency[] dependencies)
 {
     Name            = name;
     DisplayName     = displayName;
     Version         = version;
     FactorioVersion = factorioVersion;
     Author          = author;
     Description     = description;
     Dependencies    = dependencies;
 }
Exemple #5
0
 /// <summary>
 /// Checks if a given mod satisfies this dependency.
 /// If the dependency is inverted, a mod is assumed to satisfy it if it does NOT match the dependency.
 /// </summary>
 /// <param name="modName">The name of the mod.</param>
 /// <param name="modVersion">The version of the mod.</param>
 public bool IsSatisfiedBy(string modName, AccurateVersion modVersion)
 {
     if (Type == DependencyType.Inverted)
     {
         return(!Matches(modName, modVersion));
     }
     else
     {
         return(Matches(modName, modVersion));
     }
 }
Exemple #6
0
 /// <summary>
 /// Applies the comparison operator to a mods version and the dependency test version
 /// </summary>
 protected internal virtual bool TestFor(AccurateVersion modVersion, AccurateVersion testVersion) => comparisonFunction(modVersion, testVersion);
Exemple #7
0
 public Dependency(DependencyType type, string modName, DependencyComparison comparison, AccurateVersion compareVersion)
 => (Type, ModName, Comparison, CompareVersion) = (type, modName, comparison, compareVersion);
Exemple #8
0
 internal ModInfo(string name, string displayName, AccurateVersion version, AccurateVersion actualFactorioVersion,
                  string author, string description, params Dependency[] dependencies)
 => (Name, DisplayName, Version, ActualFactorioVersion, FactorioVersion, Author, Description, Dependencies)