Ejemplo n.º 1
0
            /// <summary>
            /// Load a mod from a directory at runtime.
            /// </summary>
            /// <param name="dir">The path to the mod directory.</param>
            public static void LoadDir(string dir)
            {
                if (!Flags.SupportRuntimeMods)
                {
                    Logger.Log(LogLevel.Warn, "loader", "Loader disabled!");
                    return;
                }

                if (!Directory.Exists(dir)) // Relative path?
                {
                    dir = Path.Combine(PathMods, dir);
                }
                if (!Directory.Exists(dir)) // It just doesn't exist.
                {
                    return;
                }

                Logger.Log(LogLevel.Verbose, "loader", $"Loading mod directory: {dir}");

                EverestModuleMetadata meta = null;

                EverestModuleMetadata[] multimetas = null;

                string metaPath = Path.Combine(dir, "metadata.yaml");

                if (File.Exists(metaPath))
                {
                    using (StreamReader reader = new StreamReader(metaPath)) {
                        try {
                            meta = YamlHelper.Deserializer.Deserialize <EverestModuleMetadata>(reader);
                            meta.PathDirectory = dir;
                            meta.PostParse();
                        } catch (Exception e) {
                            Logger.Log(LogLevel.Warn, "loader", $"Failed parsing metadata.yaml in {dir}: {e}");
                            FilesWithMetadataLoadFailures.Add(dir);
                        }
                    }
                }

                metaPath = Path.Combine(dir, "multimetadata.yaml");
                if (!File.Exists(metaPath))
                {
                    metaPath = Path.Combine(dir, "everest.yaml");
                }
                if (!File.Exists(metaPath))
                {
                    metaPath = Path.Combine(dir, "everest.yml");
                }
                if (File.Exists(metaPath))
                {
                    using (StreamReader reader = new StreamReader(metaPath)) {
                        try {
                            if (!reader.EndOfStream)
                            {
                                multimetas = YamlHelper.Deserializer.Deserialize <EverestModuleMetadata[]>(reader);
                                foreach (EverestModuleMetadata multimeta in multimetas)
                                {
                                    multimeta.PathDirectory = dir;
                                    multimeta.PostParse();
                                }
                            }
                        } catch (Exception e) {
                            Logger.Log(LogLevel.Warn, "loader", $"Failed parsing everest.yaml in {dir}: {e}");
                            FilesWithMetadataLoadFailures.Add(dir);
                        }
                    }
                }

                FileSystemModContent  contentMeta       = new FileSystemModContent(dir);
                EverestModuleMetadata contentMetaParent = null;

                Action contentCrawl = () => {
                    if (contentMeta == null)
                    {
                        return;
                    }
                    if (contentMetaParent != null)
                    {
                        contentMeta.Mod  = contentMetaParent;
                        contentMeta.Name = contentMetaParent.Name;
                    }
                    OnCrawlMod?.Invoke(dir, contentMetaParent);
                    Content.Crawl(contentMeta);
                    contentMeta = null;
                };

                if (multimetas != null)
                {
                    foreach (EverestModuleMetadata multimeta in multimetas)
                    {
                        multimeta.Multimeta = multimetas;
                        if (contentMetaParent == null)
                        {
                            contentMetaParent = multimeta;
                        }
                        LoadModDelayed(multimeta, contentCrawl);
                    }
                }
                else
                {
                    if (meta == null)
                    {
                        meta = new EverestModuleMetadata()
                        {
                            Name          = "_dir_" + Path.GetFileName(dir),
                            VersionString = "0.0.0-dummy",
                            PathDirectory = dir
                        };
                        meta.PostParse();
                    }
                    contentMetaParent = meta;
                    LoadModDelayed(meta, contentCrawl);
                }
            }
Ejemplo n.º 2
0
            /// <summary>
            /// Load a mod from a directory at runtime.
            /// </summary>
            /// <param name="dir">The path to the mod directory.</param>
            public static void LoadDir(string dir)
            {
                if (!Flags.SupportRuntimeMods)
                {
                    Logger.Log(LogLevel.Warn, "loader", "Loader disabled!");
                    return;
                }

                if (!Directory.Exists(dir)) // Relative path?
                {
                    dir = Path.Combine(PathMods, dir);
                }
                if (!Directory.Exists(dir)) // It just doesn't exist.
                {
                    return;
                }

                Logger.Log(LogLevel.Verbose, "loader", $"Loading mod directory: {dir}");

                EverestModuleMetadata meta = null;

                EverestModuleMetadata[] multimetas = null;

                string metaPath = Path.Combine(dir, "metadata.yaml");

                if (File.Exists(metaPath))
                {
                    using (StreamReader reader = new StreamReader(metaPath)) {
                        try {
                            meta = YamlHelper.Deserializer.Deserialize <EverestModuleMetadata>(reader);
                            meta.PathDirectory = dir;
                            meta.PostParse();
                        } catch (Exception e) {
                            Logger.Log(LogLevel.Warn, "loader", $"Failed parsing metadata.yaml in {dir}: {e}");
                        }
                    }
                }

                metaPath = Path.Combine(dir, "multimetadata.yaml");
                if (!File.Exists(metaPath))
                {
                    metaPath = Path.Combine(dir, "everest.yaml");
                }
                if (!File.Exists(metaPath))
                {
                    metaPath = Path.Combine(dir, "everest.yml");
                }
                if (File.Exists(metaPath))
                {
                    using (StreamReader reader = new StreamReader(metaPath)) {
                        try {
                            if (!reader.EndOfStream)
                            {
                                multimetas = YamlHelper.Deserializer.Deserialize <EverestModuleMetadata[]>(reader);
                                foreach (EverestModuleMetadata multimeta in multimetas)
                                {
                                    multimeta.PathDirectory = dir;
                                    multimeta.PostParse();
                                }
                            }
                        } catch (Exception e) {
                            Logger.Log(LogLevel.Warn, "loader", $"Failed parsing multimetadata.yaml in {dir}: {e}");
                        }
                    }
                }

                FileSystemModContent contentMeta = new FileSystemModContent(dir);

                Action contentCrawl = () => {
                    if (contentMeta == null)
                    {
                        return;
                    }
                    Content.Crawl(contentMeta);
                    contentMeta = null;
                };

                if (multimetas != null)
                {
                    foreach (EverestModuleMetadata multimeta in multimetas)
                    {
                        LoadModDelayed(multimeta, contentCrawl);
                    }
                }
                else
                {
                    LoadModDelayed(meta, contentCrawl);
                }
            }