/// <summary> /// Loads a collection of mods with their associated dependencies. /// </summary> private void LoadModsWithDependencies(IEnumerable <ModConfig> modsToLoad, List <PathTuple <ModConfig> > allMods = null) { // Cache configuration paths for all mods. if (allMods == null) { allMods = ModConfig.GetAllMods(LoaderConfig.GetModConfigDirectory()); } var configToPathDictionary = new Dictionary <ModConfig, string>(); foreach (var mod in allMods) { configToPathDictionary[mod.Config] = mod.Path; } // Get dependencies, sort and load in order. var dependenciesToLoad = GetDependenciesForMods(modsToLoad, allMods.Select(x => x.Config), LoaderConfig.GetModConfigDirectory()); var allUniqueModsToLoad = modsToLoad.Concat(dependenciesToLoad).Distinct(); var allSortedModsToLoad = ModConfig.SortMods(allUniqueModsToLoad); var modPaths = new List <PathTuple <ModConfig> >(); foreach (var modToLoad in allSortedModsToLoad) { // Reloaded does not allow loading same mod multiple times. if (!Manager.IsModLoaded(modToLoad.ModId)) { modPaths.Add(new PathTuple <ModConfig>(configToPathDictionary[modToLoad], modToLoad)); } } Manager.LoadMods(modPaths); }
public TestData() { // Backup config and override on filesystem with new. OriginalConfig = IConfig <LoaderConfig> .FromPathOrDefault(Paths.LoaderConfigPath); TestConfig = MakeTestConfig(); IConfig <LoaderConfig> .ToPath(TestConfig, Paths.LoaderConfigPath); try { // Populate configurations. ModConfigurations = ModConfig.GetAllMods().Select(x => x.Config).ToArray(); AppConfigurations = ApplicationConfig.GetAllApplications().Select(x => x.Config).ToArray(); ThisApplication = new ApplicationConfig(IdOfThisApp, "Reloaded Mod Loader Tests", Environment.CurrentProcessLocation.Value, new[] { TestModConfigA.ModId, TestModConfigB.ModId, TestModConfigD.ModId }); ConfigurationPathOfThisApp = Path.Combine(TestConfig.ApplicationConfigDirectory, IdOfThisApp, ApplicationConfig.ConfigFileName); IConfig <ApplicationConfig> .ToPath(ThisApplication, ConfigurationPathOfThisApp); // Populate nonexisting dependencies. NonexistingDependencies.Add(TestModB.Program.NonexistingDependencyName); NonexistingDependencies.Add(TestModC.Program.NonexistingDependencyName); } catch (Exception) { IConfig <LoaderConfig> .ToPath(OriginalConfig, Paths.LoaderConfigPath); throw; } }
/// <summary> /// Gets a list of all mods from filesystem and returns a mod with a matching ModId. /// </summary> /// <param name="modId">The modId to find.</param> /// <param name="allMods">List of all mod configurations, read during the operation.</param> /// <exception cref="ReloadedException">A mod to load has not been found.</exception> public PathTuple <ModConfig> FindMod(string modId, out List <PathTuple <ModConfig> > allMods) { // Get mod with ID allMods = ModConfig.GetAllMods(LoaderConfig.GetModConfigDirectory()); var mod = allMods.FirstOrDefault(x => x.Config.ModId == modId); if (mod != null) { var dllPath = mod.Config.GetDllPath(mod.Path); return(new PathTuple <ModConfig>(dllPath, mod.Config)); } throw new ReloadedException(Errors.ModToLoadNotFound(modId)); }
/// <summary> /// Populates the mod list governed by <see cref="Mods"/>. /// </summary> private void GetModifications(CancellationToken cancellationToken = default) { try { var modConfigs = ModConfig.GetAllMods(IoC.Get <LoaderConfig>().ModConfigDirectory, cancellationToken); if (!cancellationToken.IsCancellationRequested) { var mods = modConfigs.Select(x => new ImageModPathTuple(GetImageForModConfig(x), x.Object, x.Path)); ExecuteWithApplicationDispatcher(() => Collections.ModifyObservableCollection(Mods, mods)); OnGetModifications(); } } catch (Exception) { // ignored } }
/// <summary> /// Populates the mod list governed by <see cref="Mods"/>. /// </summary> private void GetModifications(CancellationToken cancellationToken = default) { try { var modConfigs = ModConfig.GetAllMods(ConfigDirectory, cancellationToken); if (cancellationToken.IsCancellationRequested) { return; } _context.Post(() => Collections.ModifyObservableCollection(Mods, modConfigs)); } catch (Exception) { // ignored } }
/// <summary> /// Retrieves all of the dependencies for a given set of mods. /// </summary> /// <exception cref="FileNotFoundException">A dependency for any of the mods has not been found.</exception> private HashSet <ModConfig> GetDependenciesForMods(IEnumerable <ModConfig> mods, IEnumerable <ModConfig> allMods, string modDirectory) { if (allMods == null) { allMods = ModConfig.GetAllMods(LoaderConfig.GetModConfigDirectory()).Select(x => x.Config); } var dependencies = ModConfig.GetDependencies(mods, allMods, modDirectory); if (dependencies.MissingConfigurations.Count > 0 && !IsTesting) { string missingMods = String.Join(",", dependencies.MissingConfigurations); throw new FileNotFoundException($"Reloaded II was unable to find all dependencies for the mod(s) to be loaded.\n" + $"Aborting load.\n" + $"Missing dependencies: {missingMods}"); } return(dependencies.Configurations); }
static GitHubLatestUpdateResolver() { try { GitHubClient = new GitHubClient(new ProductHeaderValue("Reloaded-II")); // Get list of mods allowed to be updated this time around. var allMods = ModConfig.GetAllMods(); var allModsWithConfigs = allMods.Where(x => File.Exists(GitHubConfig.GetFilePath(GetModDirectory(x)))); MakeTimestampsIfNotExist(allModsWithConfigs); var orderedModsWithConfigs = allModsWithConfigs.OrderBy(x => IConfig <GitHubUserConfig> .FromPath(GitHubUserConfig.GetFilePath(GetModDirectory(x))).LastCheckTimestamp); var allowedMods = orderedModsWithConfigs.Take(UnregisteredRateLimit).Select(x => x.Config); AllowedMods = new HashSet <ModConfig>(allowedMods); } catch (Exception) { Debugger.Break(); } }
public TestData() { // Backup config and override on filesystem with new. bool configExists = File.Exists(LoaderConfigReader.ConfigurationPath()); if (configExists) { OriginalConfig = LoaderConfigReader.ReadConfiguration(); } TestConfig = MakeTestConfig(); LoaderConfigReader.WriteConfiguration(TestConfig); try { // Populate configurations. ModConfigurations = ModConfig.GetAllMods().Select(x => x.Object).ToArray(); AppConfigurations = ApplicationConfig.GetAllApplications().Select(x => x.Object).ToArray(); ThisApplication = new ApplicationConfig(IdOfThisApp, "Reloaded Mod Loader Tests", Process.GetCurrentProcess().GetExecutablePath(), new[] { TestModConfigA.ModId, TestModConfigB.ModId, TestModConfigD.ModId }); ConfigurationPathOfThisApp = Path.Combine(TestConfig.ApplicationConfigDirectory, IdOfThisApp, ApplicationConfig.ConfigFileName); ApplicationConfig.WriteConfiguration(ConfigurationPathOfThisApp, ThisApplication); // Populate nonexisting dependencies. NonexistingDependencies.Add(TestModB.Program.NonexistingDependencyName); NonexistingDependencies.Add(TestModC.Program.NonexistingDependencyName); } catch (Exception) { if (OriginalConfig != null) { LoaderConfigReader.WriteConfiguration(OriginalConfig); } throw; } }
/// <summary> /// Returns all mods for this application in load order. /// Note: Dependencies are not taken into account in load order - but the mod loader itself does reorder the list taking them into account. /// </summary> /// <param name="config">The application to get all mods for.</param> /// <param name="modDirectory">(Optional) Directory containing all of the mods.</param> public static List <BooleanGenericTuple <PathTuple <ModConfig> > > GetAllMods(IApplicationConfig config, string modDirectory = null) { var modifications = ModConfig.GetAllMods(modDirectory); return(GetAllMods(config, modifications)); }
/// <summary> /// Returns all mods for this application in load order. This overload also provides list of all mods. /// Note: Dependencies are not taken into account in load order - but the mod loader itself does reorder the list taking them into account. /// </summary> /// <param name="config">The application to get all mods for.</param> /// <param name="allMods">A list of all available modifications, including those not in use by the config.</param> /// <param name="modDirectory">(Optional) Directory containing all of the mods.</param> public static List <BooleanGenericTuple <PathTuple <ModConfig> > > GetAllMods(IApplicationConfig config, out List <PathTuple <ModConfig> > allMods, string modDirectory = null) { allMods = ModConfig.GetAllMods(modDirectory); return(GetAllMods(config, allMods)); }