OpenRA.ModMetadata.ValidateMods C# (CSharp) Method

ValidateMods() static private method

static private ValidateMods ( ) : ModMetadata>.Dictionary
return ModMetadata>.Dictionary
        static Dictionary<string, ModMetadata> ValidateMods()
        {
            var ret = new Dictionary<string, ModMetadata>();
            foreach (var pair in GetCandidateMods())
            {
                IReadOnlyPackage package = null;
                try
                {
                    if (Directory.Exists(pair.Second))
                        package = new Folder(pair.Second);
                    else
                    {
                        try
                        {
                            package = new ZipFile(null, pair.Second);
                        }
                        catch
                        {
                            throw new InvalidDataException(pair.Second + " is not a valid mod package");
                        }
                    }

                    if (!package.Contains("mod.yaml"))
                    {
                        package.Dispose();
                        continue;
                    }

                    var yaml = new MiniYaml(null, MiniYaml.FromStream(package.GetStream("mod.yaml")));
                    var nd = yaml.ToDictionary();
                    if (!nd.ContainsKey("Metadata"))
                    {
                        package.Dispose();
                        continue;
                    }

                    var metadata = FieldLoader.Load<ModMetadata>(nd["Metadata"]);
                    metadata.Id = pair.First;
                    metadata.Package = package;

                    if (nd.ContainsKey("RequiresMods"))
                        metadata.RequiresMods = nd["RequiresMods"].ToDictionary(my => my.Value);
                    else
                        metadata.RequiresMods = new Dictionary<string, string>();

                    if (nd.ContainsKey("ContentInstaller"))
                        metadata.Content = FieldLoader.Load<ContentInstaller>(nd["ContentInstaller"]);

                    // Mods in the support directory and oramod packages (which are listed later
                    // in the CandidateMods list) override mods in the main install.
                    ret[pair.First] = metadata;
                }
                catch (Exception ex)
                {
                    if (package != null)
                        package.Dispose();
                    Console.WriteLine("An exception occurred when trying to load ModMetadata for `{0}`:".F(pair.First));
                    Console.WriteLine(ex.Message);
                }
            }

            return ret;
        }