Ejemplo n.º 1
0
        /// <summary>
        /// Determines if the given version is part of the range.
        /// </summary>
        /// <param name="version">The verison to test</param>
        /// <returns>True if <paramref name="version"/> is part of this range, false otherwise.</returns>
        public bool Includes(PluginVersion version)
        {
            bool minCondition;

            if (MinimumInclusive)
            {
                minCondition = version >= (MinimumVersion ?? PluginVersion.MinValue);
            }
            else
            {
                minCondition = version > (MinimumVersion ?? PluginVersion.MinValue);
            }

            bool maxCondition;

            if (MaximumInclusive)
            {
                maxCondition = version <= (MaximumVersion ?? PluginVersion.MaxValue);
            }
            else
            {
                maxCondition = version < (MaximumVersion ?? PluginVersion.MaxValue);
            }

            return(minCondition && maxCondition);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Attempt to convert a string to an equivalent PackageVersionRange.
        /// </summary>
        /// <param name="value">The string to convert.</param>
        /// <param name="range">The converted PackageVersionRange.</param>
        /// <returns>True if the conversion succeeded, false otherwise.</returns>
        public static bool TryParse(string value, out PluginVersionRange range)
        {
            range = default;

            if (string.IsNullOrEmpty(value))
            {
                return(false);
            }

            var match = PackageVersionRangeRegex.Match(value);

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

            if (match.Groups["equal"].Success)
            {
                if (!PluginVersion.TryParse(match.Groups["equal"].Value, out var equalVer))
                {
                    return(false);
                }

                range = new PluginVersionRange(equalVer, true, new PluginVersion(equalVer.Major ?? int.MaxValue, equalVer.Minor ?? int.MaxValue, equalVer.Patch ?? int.MaxValue), true);
                return(true);
            }

            var min = default(PluginVersion?);
            var max = default(PluginVersion?);

            if (match.Groups["min"].Success)
            {
                if (!PluginVersion.TryParse(match.Groups["min"].Value, out var minVer))
                {
                    return(false);
                }
                min = minVer;
            }

            if (match.Groups["max"].Success)
            {
                if (!PluginVersion.TryParse(match.Groups["max"].Value, out var maxVer))
                {
                    return(false);
                }
                max = maxVer;
            }

            range = new PluginVersionRange(min, match.Groups["left"].Value == "[", max, match.Groups["right"].Value == "]");
            return(true);
        }
Ejemplo n.º 3
0
 public bool VerifyManifest() => !Name.Intersect(Path.GetInvalidFileNameChars()).Any() &&
 PluginVersion.TryParse(Version, out _) &&
 (Homepage == null || Uri.TryCreate(Homepage, UriKind.Absolute, out _)) &&
 (Update == null || Uri.TryCreate(Update, UriKind.Absolute, out _)) &&
 Files.All(x => x.VerifyFile());