internal static bool IsRecursive(this ModDependencyResolveStrategy strategy)
 {
     return(strategy == ModDependencyResolveStrategy.CreateRecursive ||
            strategy == ModDependencyResolveStrategy.FromExistingModsRecursive);
 }
        public bool ResolveDependencies(ModDependencyResolveStrategy resolveStrategy)
        {
            if (_isResolving)
            {
                throw new PetroglyphModException("Detected a cycle while resolving Mod dependencies.");
            }

            var result = true;

            try
            {
                _isResolving = true;
                if (ExpectedDependencies == 0 || DependenciesResolved)
                {
                    return(true);
                }


                if (ModInfo is null)
                {
                    return(true);
                }

                foreach (var dependency in ModInfo.Dependencies)
                {
                    if (dependency.Type == ModType.Virtual)
                    {
                        throw new NotImplementedException("Virtual linking not supported yet");
                    }

                    var searchOptions = ModSearchOptions.Registered;
                    if (resolveStrategy.IsCreative())
                    {
                        searchOptions |= ModSearchOptions.FileSystem;
                    }

                    var dm = Game.SearchMod(dependency, searchOptions, true);
                    if (dm is null)
                    {
                        return(false);
                    }
                    if (dm.Equals(this))
                    {
                        throw new PetroglyphModException($"The mod '{Name}' can not be dependent on itself!");
                    }

                    DependenciesInternal.Add(dm);

                    if (resolveStrategy.IsRecursive())
                    {
                        dm.ResolveDependencies(resolveStrategy);
                    }
                }
            }
            finally
            {
                _isResolving         = false;
                DependenciesResolved = true;
            }

            return(result);
        }
 internal static bool IsCreative(this ModDependencyResolveStrategy strategy)
 {
     return(strategy == ModDependencyResolveStrategy.Create ||
            strategy == ModDependencyResolveStrategy.CreateRecursive);
 }