Ejemplo n.º 1
0
 /// <summary>
 /// Removes the specified dependency from the package.
 /// </summary>
 /// <param name="dependency">The dependency to remove.</param>
 /// <returns></returns>
 public bool RemoveDependency(RantPackageDependency dependency)
 {
     if (dependency == null)
     {
         throw new ArgumentNullException(nameof(dependency));
     }
     return(_dependencies.Remove(dependency));
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Adds the specified dependency to the package.
 /// </summary>
 /// <param name="dependency">The dependency to add.</param>
 public void AddDependency(RantPackageDependency dependency)
 {
     if (dependency == null)
     {
         throw new ArgumentNullException(nameof(dependency));
     }
     _dependencies.Add(dependency);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Determines whether the package has the specified dependency.
 /// </summary>
 /// <param name="dependency">The dependency to check for.</param>
 /// <returns></returns>
 public bool DependsOn(RantPackageDependency dependency)
 {
     if (dependency == null)
     {
         throw new ArgumentNullException(nameof(dependency));
     }
     return(_dependencies.Contains(dependency));
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Attempts to resolve a depdendency to the appropriate package.
        /// </summary>
        /// <param name="depdendency">The depdendency to resolve.</param>
        /// <param name="package">The package loaded from the depdendency.</param>
        /// <returns></returns>
        public virtual bool TryResolvePackage(RantPackageDependency depdendency, out RantPackage package)
        {
            package = null;
            string path = Path.Combine(Environment.CurrentDirectory, $"{depdendency.ID}.rantpkg");

            if (!File.Exists(path))
            {
                RantPackageVersion version;
                // Fallback to name with version appended
#if UNITY
                path = Directory.GetFiles(Environment.CurrentDirectory, $"{depdendency.ID}*.rantpkg", SearchOption.AllDirectories).FirstOrDefault(p =>
#else
                path =
                    Directory.EnumerateFiles(Environment.CurrentDirectory, "*.rantpkg", SearchOption.AllDirectories)
                    .FirstOrDefault(p =>
#endif

                {
                    var match = FallbackRegex.Match(Path.GetFileNameWithoutExtension(p));
                    if (!match.Success)
                    {
                        return(false);
                    }
                    version = RantPackageVersion.Parse(match.Groups["version"].Value);
                    return(depdendency.AllowNewer && version >= depdendency.Version || depdendency.Version == version);
                });
                if (path == null)
                {
                    return(false);
                }
            }
            try
            {
                var pkg = RantPackage.Load(path);
                                           if (pkg.ID != depdendency.ID)
                {
                    return(false);
                }
                                           if (depdendency.AllowNewer && pkg.Version >= depdendency.Version || pkg.Version == depdendency.Version)
                {
                    package = pkg;
                    return(true);
                }
                                           return(false);
            }
            catch
            {
                return(false);
            }
        }