public static List <ModInfo> DiscoverManagedMods()
        {
            var mods = new List <ModInfo>();

            foreach (string modDirectory in Directory.GetDirectories(GetModLoadPath()))
            {
                // No manifest, no mod
                var manifestPath = Path.Combine(modDirectory, "manifest.json");
                if (!File.Exists(manifestPath))
                {
                    continue;
                }

                try
                {
                    var manifestString = File.ReadAllText(manifestPath);
                    var manifest       = JsonConvert.DeserializeObject <ModManifestV2>(manifestString);
                    var modInfo        = new ModInfo(manifest, modDirectory);

                    if (manifest.InstallMode == ModInstallMode.Managed)
                    {
                        mods.Add(modInfo);
                    }
                    else
                    {
                        Log($"    Skipping unmanaged mod {modInfo.FullVersionName} found in managed mod directory", ConsoleColor.Yellow);
                    }
                }
                catch (Exception e)
                {
                    Log($"    Failed to parse mod manifest {manifestPath}", ConsoleColor.Red);
                    Log(e.ToString(), ConsoleColor.Red);
                }
            }

            return(mods);
        }
 private static void SortMods(List <ModInfo> result, Dictionary <string, ModInfo> modsByName, ModInfo currentMod)
 {
     foreach (var dependency in currentMod.GetDependencies())
     {
         var versionless = dependency.Substring(0, dependency.LastIndexOf('-'));
         if (modsByName.ContainsKey(dependency))
         {
             SortMods(result, modsByName, modsByName[dependency]);
         }
         else if (modsByName.ContainsKey(versionless))
         {
             SortMods(result, modsByName, modsByName[versionless]);
         }
     }
     result.Add(currentMod);
 }