/// <summary> /// Validates this mod can install against a game target with respect to the list of RequiredDLC. /// </summary> /// <param name="gameTarget">Target to validate against</param> /// <returns>List of missing DLC modules, or an empty list if none</returns> internal bool ValidateSingleOptionalRequiredDLCInstalled(GameTarget gameTarget) { if (gameTarget.Game != Game) { throw new Exception(@"Cannot validate a mod against a gametarget that is not for its game"); } if (Enumerable.Any <string>(OptionalSingleRequiredDLC)) { var requiredAnyDLC = Enumerable.Select <string, string>(OptionalSingleRequiredDLC, x => { if (Enum.TryParse(x, out ModJob.JobHeader parsedHeader) && ModJob.GetHeadersToDLCNamesMap(Game) .TryGetValue(parsedHeader, out var dlcname)) { return(dlcname); } return(x); }); var installedDLC = M3Directories.GetInstalledDLC(gameTarget); return(installedDLC.FirstOrDefault(x => requiredAnyDLC.Contains(x)) != null); } return(true); }
/// <summary> /// Validates this mod can install against a game target with respect to the list of RequiredDLC. /// </summary> /// <param name="gameTarget">Target to validate against</param> /// <returns>List of missing DLC modules, or an empty list if none</returns> internal List <string> ValidateRequiredModulesAreInstalled(GameTarget gameTarget) { if (gameTarget.Game != Game) { throw new Exception(@"Cannot validate a mod against a gametarget that is not for its game"); } var requiredDLC = Enumerable.Select <string, string>(RequiredDLC, x => { if (Enum.TryParse(x, out ModJob.JobHeader parsedHeader) && ModJob.GetHeadersToDLCNamesMap(Game).TryGetValue(parsedHeader, out var dlcname)) { return(dlcname); } return(x); }); var installedDLC = M3Directories.GetInstalledDLC(gameTarget); return(requiredDLC.Except(installedDLC).ToList()); }
public void SetupInitialSelection(GameTarget target, Mod mod) { UIIsSelectable = false; //Reset IsSelected = false; //Reset if (Condition == AltDLCCondition.COND_MANUAL) { IsSelected = CheckedByDefault; if (DLCRequirementsForManual != null) { var dlc = M3Directories.GetInstalledDLC(target); if (mod.ModDescTargetVersion >= 6.3) { var requiredDLC = DLCRequirementsForManual.Where(x => !x.StartsWith(@"-") || x.StartsWith(@"+")).Select(x => x.TrimStart('+')); // none or + means 'must exist' var notPresentDLCRequired = DLCRequirementsForManual.Where(x => x.StartsWith(@"-")).Select(x => x.TrimStart('-')); UIIsSelectable = dlc.ContainsAll(requiredDLC, StringComparer.InvariantCultureIgnoreCase) && dlc.ContainsNone(notPresentDLCRequired, StringComparer.InvariantCultureIgnoreCase); } else { // Previous logic. Left here to ensure nothing changes. UIIsSelectable = dlc.ContainsAll(DLCRequirementsForManual, StringComparer.InvariantCultureIgnoreCase); } if (!UIIsSelectable && mod.ModDescTargetVersion >= 6.2) { // Mod Manager 6.2: If requirements are not met this option is forcibly not checked. // Mods targeting Moddesc 6 or 6.1 will possibly be bugged if they used this feature IsSelected = false; } CLog.Information($@" > AlternateDLC SetupInitialSelection() {FriendlyName}: UISelectable: {UIIsSelectable}, conducted DLCRequirements check.", Settings.LogModInstallation); } else { UIIsSelectable = true; } return; } var installedDLC = M3Directories.GetInstalledDLC(target); switch (Condition) { case AltDLCCondition.COND_DLC_NOT_PRESENT: case AltDLCCondition.COND_ANY_DLC_NOT_PRESENT: IsSelected = !ConditionalDLC.All(i => installedDLC.Contains(i, StringComparer.CurrentCultureIgnoreCase)); break; case AltDLCCondition.COND_DLC_PRESENT: case AltDLCCondition.COND_ANY_DLC_PRESENT: IsSelected = ConditionalDLC.Any(i => installedDLC.Contains(i, StringComparer.CurrentCultureIgnoreCase)); break; case AltDLCCondition.COND_ALL_DLC_NOT_PRESENT: IsSelected = !ConditionalDLC.Any(i => installedDLC.Contains(i, StringComparer.CurrentCultureIgnoreCase)); break; case AltDLCCondition.COND_ALL_DLC_PRESENT: IsSelected = ConditionalDLC.All(i => installedDLC.Contains(i, StringComparer.CurrentCultureIgnoreCase)); break; case AltDLCCondition.COND_SPECIFIC_SIZED_FILES: { var selected = true; foreach (var reqPair in RequiredSpecificFiles) { if (selected) { var targetFile = Path.Combine(target.TargetPath, reqPair.Key); selected &= File.Exists(targetFile) && new FileInfo(targetFile).Length == reqPair.Value; } } IsSelected = selected; } break; case AltDLCCondition.COND_SPECIFIC_DLC_SETUP: { var selected = true; foreach (var condDlc in ConditionalDLC) { if (selected) { bool existenceRule = condDlc.Substring(0, 1) == @"+"; var dlcfoldername = condDlc.Substring(1); if (existenceRule) { selected &= installedDLC.Contains(dlcfoldername, StringComparer.CurrentCultureIgnoreCase); } else { selected &= !installedDLC.Contains(dlcfoldername, StringComparer.CurrentCultureIgnoreCase); } } } IsSelected = selected; } break; } UIIsSelectable = false; //autos //IsSelected; //autos }