Example #1
0
		public static bool MatchesRequirements(PackageInfo packageInfo)
		{
			var properties = packageInfo.Properties;

			string netFrameworkVersion;

			if (properties.ContainsKey(PropertyKeyNetFrameworkVersion))
				netFrameworkVersion = properties[PropertyKeyNetFrameworkVersion];
			else
				netFrameworkVersion = "4.0";

			if (!NetFrameworkVersionDetermination.IsVersionInstalled(netFrameworkVersion))
				return false;

			return true;
		}
Example #2
0
		/// <summary>
		/// Create a package info from a single line.
		/// </summary>
		/// <param name="line">The line to parse.</param>
		/// <param name="lineNumber">The line number (1-based; the first line has line number 1).</param>
		/// <returns>The package info parsed from that line.</returns>
		/// <exception cref="InvalidOperationException">Occurs if the line is not properly formatted.</exception>
		public static PackageInfo FromLine(string line, int lineNumber)
		{
			line = line.Trim();
			var entries = line.Split(new char[] { '\t' }, StringSplitOptions.None);

			if (entries.Length < 4)
				throw new InvalidOperationException(string.Format("Line number {0} of the package info file doesn't contain at least 4 words, separated by tabulators", lineNumber));

			PackageInfo result = new PackageInfo();

			bool isUnstableVersion;
			if (!IsValidStableIdentifier(entries[0].Trim(), out isUnstableVersion))
				throw new InvalidOperationException(string.Format("First item in line number {0} of the package info file is neither 'stable' nor 'unstable'", lineNumber));
			result.IsUnstableVersion = isUnstableVersion;
			result.Version = new Version(entries[1].Trim());
			result.FileLength = long.Parse(entries[2].Trim());
			result.Hash = entries[3].Trim();

			// All other entries should be in the form PropertyName = PropertyValue

			for (int i = 4; i < entries.Length; ++i)
			{
				var pv = entries[i].Split(new char[] { '=' }, 2);
				if (pv.Length != 2)
					throw new InvalidOperationException(string.Format("Line number {0} of the package info file contains an ill formated property in column {1}: {2}", lineNumber, i + 1, entries[i]));

				string key = pv[0].Trim();
				string val = pv[1].Trim();

				if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(val))
					throw new InvalidOperationException(string.Format("Line number {0} of the package info file contains an ill formated property in column {1}: {2}", lineNumber, i + 1, entries[i]));

				result.Properties[key] = val;
			}

			if (lineNumber > 1 && !result.Properties.ContainsKey(SystemRequirements.PropertyKeyNetFrameworkVersion))
				throw new InvalidOperationException(string.Format("Line number {0} of the package info file does not contain the mandatory property {1}", lineNumber, SystemRequirements.PropertyKeyNetFrameworkVersion));

			return result;
		}
Example #3
0
		public static PackageInfo GetHighestVersion(PackageInfo[] packageInfos)
		{
			// from all parsed versions, choose that one that matches the requirements
			PackageInfo parsedVersion = null;
			for (int i = packageInfos.Length - 1; i >= 0; --i) // from higher indices to lower indices in order to download the most advanced version that can be used by this system
			{
				if (SystemRequirements.MatchesRequirements(packageInfos[i]))
				{
					parsedVersion = packageInfos[i];
					break;
				}
			}

			return parsedVersion;
		}