Ejemplo n.º 1
0
        internal static void EnsureSyncedDependencyStability(TopoSort <LocalMod> synced, TopoSort <LocalMod> full)
        {
            var errored  = new HashSet <LocalMod>();
            var errorLog = new StringBuilder();

            foreach (var mod in synced.list)
            {
                var chains = new List <List <LocalMod> >();
                //define recursive chain finding method
                Action <LocalMod, Stack <LocalMod> > FindChains = null;
                FindChains = (search, stack) =>
                {
                    stack.Push(search);

                    if (search.properties.side == ModSide.Both && stack.Count > 1)
                    {
                        if (stack.Count > 2)                        //direct Both -> Both references are ignored
                        {
                            chains.Add(stack.Reverse().ToList());
                        }
                    }
                    else
                    {                    //recursively build the chain, all entries in stack should be unsynced
                        foreach (var dep in full.Dependencies(search))
                        {
                            FindChains(dep, stack);
                        }
                    }

                    stack.Pop();
                };
                FindChains(mod, new Stack <LocalMod>());

                if (chains.Count == 0)
                {
                    continue;
                }

                var syncedDependencies = synced.AllDependencies(mod);
                foreach (var chain in chains)
                {
                    if (!syncedDependencies.Contains(chain.Last()))
                    {
                        errored.Add(mod);
                        errorLog.AppendLine(mod + " indirectly depends on " + chain.Last() + " via " + string.Join(" -> ", chain));
                    }
                }
            }

            if (errored.Count > 0)
            {
                errorLog.AppendLine("Some of these mods may not exist on both client and server. Add a direct sort entries or weak references.");
                throw new ModSortingException(errored, errorLog.ToString());
            }
        }