Finds matches for a given mod in a given set of mods.
Esempio n. 1
0
        /// <summary>
        /// Activates the given mod.
        /// </summary>
        /// <remarks>
        /// The given mod is either installed or upgraded, as appropriate.
        /// </remarks>
        /// <param name="p_modMod">The mod to install.</param>
        /// <param name="p_dlgUpgradeConfirmationDelegate">The delegate that is called to confirm whether an upgrade install should be performed.</param>
        /// <param name="p_dlgOverwriteConfirmationDelegate">The method to call in order to confirm an overwrite.</param>
        /// <param name="p_rolActiveMods">The list of active mods.</param>
        /// <returns>A background task set allowing the caller to track the progress of the operation.</returns>
        public IBackgroundTaskSet Activate(IMod p_modMod, ConfirmModUpgradeDelegate p_dlgUpgradeConfirmationDelegate, ConfirmItemOverwriteDelegate p_dlgOverwriteConfirmationDelegate, ReadOnlyObservableList <IMod> p_rolActiveMods, bool p_booOverrideUpgrade)
        {
            ModMatcher           mmcMatcher    = new ModMatcher(InstallationLog.ActiveMods, true);
            IMod                 modOldVersion = mmcMatcher.FindAlternateVersion(p_modMod, true);
            ConfirmUpgradeResult curAction     = ConfirmUpgradeResult.NormalActivation;

            if (!p_booOverrideUpgrade)
            {
                curAction = (modOldVersion == null) ? ConfirmUpgradeResult.NormalActivation : p_dlgUpgradeConfirmationDelegate(modOldVersion, p_modMod);
            }

            switch (curAction)
            {
            case ConfirmUpgradeResult.Upgrade:
                ModInstaller muiUpgrader = InstallerFactory.CreateUpgradeInstaller(modOldVersion, p_modMod, p_dlgOverwriteConfirmationDelegate);
                return(muiUpgrader);

            case ConfirmUpgradeResult.NormalActivation:
                ModInstaller minInstaller = InstallerFactory.CreateInstaller(p_modMod, p_dlgOverwriteConfirmationDelegate, p_rolActiveMods);
                return(minInstaller);

            case ConfirmUpgradeResult.Cancel:
                return(null);

            default:
                throw new Exception(String.Format("Unrecognized value for ConfirmUpgradeResult: {0}", curAction));
            }
        }
		/// <summary>
		/// Activates the given mod.
		/// </summary>
		/// <remarks>
		/// The given mod is either installed or upgraded, as appropriate.
		/// </remarks>
		/// <param name="p_modMod">The mod to install.</param>
		/// <param name="p_dlgUpgradeConfirmationDelegate">The delegate that is called to confirm whether an upgrade install should be performed.</param>
		/// <param name="p_dlgOverwriteConfirmationDelegate">The method to call in order to confirm an overwrite.</param>
		/// <param name="p_rolActiveMods">The list of active mods.</param>
		/// <returns>A background task set allowing the caller to track the progress of the operation.</returns>
		public IBackgroundTaskSet Activate(IMod p_modMod, ConfirmModUpgradeDelegate p_dlgUpgradeConfirmationDelegate, ConfirmItemOverwriteDelegate p_dlgOverwriteConfirmationDelegate, ReadOnlyObservableList<IMod> p_rolActiveMods)
		{
			ModMatcher mmcMatcher = new ModMatcher(InstallationLog.ActiveMods, true);
			IMod modOldVersion = mmcMatcher.FindAlternateVersion(p_modMod, true);
			ConfirmUpgradeResult curAction = (modOldVersion == null) ? ConfirmUpgradeResult.NormalActivation : p_dlgUpgradeConfirmationDelegate(modOldVersion, p_modMod);
			switch (curAction)
			{
				case ConfirmUpgradeResult.Upgrade:
					ModInstaller muiUpgrader = InstallerFactory.CreateUpgradeInstaller(modOldVersion, p_modMod, p_dlgOverwriteConfirmationDelegate);
                    return muiUpgrader;
				case ConfirmUpgradeResult.NormalActivation:
					ModInstaller minInstaller = InstallerFactory.CreateInstaller(p_modMod, p_dlgOverwriteConfirmationDelegate, p_rolActiveMods);
					return minInstaller;
				case ConfirmUpgradeResult.Cancel:
					return null;
				default:
					throw new Exception(String.Format("Unrecognized value for ConfirmUpgradeResult: {0}", curAction));
			}
		}
		/// <summary>
		/// Uninstalls mods that have been manually removed since the last time the mod manager
		/// ran.
		/// </summary>
		/// <param name="p_gmdGameMode">The game mode currently being managed.</param>
		/// <param name="p_eifEnvironmentInfo">The application's envrionment info.</param>
		/// <param name="p_mmgModManager">The mod manager to use to uninstall any missing mods.</param>
		protected bool UninstallMissingMods(IGameMode p_gmdGameMode, IEnvironmentInfo p_eifEnvironmentInfo, ModManager p_mmgModManager)
		{
			Trace.TraceInformation("Uninstalling missing Mods...");
			Trace.Indent();
			foreach (IMod modMissing in new List<IMod>(p_mmgModManager.ActiveMods))
			{
				if (!File.Exists(modMissing.Filename))
				{
					Trace.TraceInformation("{0} is missing...", modMissing.Filename);
					Trace.Indent();

					//look for another version of the mod
					List<IMod> lstInactiveMods = new List<IMod>();
					foreach (IMod modRegistered in p_mmgModManager.ManagedMods)
						if (!p_mmgModManager.ActiveMods.Contains(modRegistered))
							lstInactiveMods.Add(modRegistered);
					ModMatcher mmcMatcher = new ModMatcher(lstInactiveMods, false);
					IMod modNewVersion = mmcMatcher.FindAlternateVersion(modMissing, true);
					if (modNewVersion != null)
					{
						Trace.TraceInformation("Found alternate version...");
						string strUpgradeMessage = String.Format("'{0}' cannot be found. " + Environment.NewLine +
										"However, a different version has been detected. The installed, missing, version is {1}; the new version is {2}." + Environment.NewLine +
										"You can either upgrade the mod or uninstall it. If you Cancel, {3} will close and you will " +
										"have to put the Mod ({4}) back in the mods folder." + Environment.NewLine +
										"Would you like to upgrade the mod?", modMissing.ModName, modMissing.HumanReadableVersion, modNewVersion.HumanReadableVersion, p_eifEnvironmentInfo.Settings.ModManagerName, modMissing.Filename);

						switch ((DialogResult)ShowMessage(new ViewMessage(strUpgradeMessage, "Missing Mod", ExtendedMessageBoxButtons.Yes | ExtendedMessageBoxButtons.No | ExtendedMessageBoxButtons.Cancel, MessageBoxIcon.Warning)))
						{
							case DialogResult.Yes:
								Trace.TraceInformation("Upgrading.");
								IBackgroundTaskSet btsUpgrader = p_mmgModManager.ForceUpgrade(modMissing, modNewVersion, ConfirmItemOverwrite);
								WaitForSet(btsUpgrader, true);
								Trace.Unindent();
								continue;
							case DialogResult.Cancel:
								Trace.TraceInformation("Aborting.");
								Trace.Unindent();
								Trace.Unindent();
								return false;
							case DialogResult.No:
								break;
							default:
								throw new Exception(String.Format("Unexpected value for cofnirmation of upgrading missing mod {0}.", modMissing.ModName));
						}
					}

					string strMessage = String.Format("'{0}' cannot be found. " + Environment.NewLine + Environment.NewLine +
										"This could be caused by setting the wrong 'Mods' folder or an old config file being used." + Environment.NewLine + Environment.NewLine +
										"If you haven't deleted or moved any of your mods on your hard-drive and they're still on your hard-drive somewhere then select YES and input the proper location of your Mods folder." + Environment.NewLine + Environment.NewLine +
										"If you select NO {1} will automatically uninstall the missing mod's files." + Environment.NewLine + Environment.NewLine +
										"NOTE: The mods folder is where NMM stores your mod archives, it is not the same location as your game's mod folder.", modMissing.Filename, p_eifEnvironmentInfo.Settings.ModManagerName);
					if ((DialogResult)ShowMessage(new ViewMessage(strMessage, "Missing Mod", ExtendedMessageBoxButtons.Yes | ExtendedMessageBoxButtons.No, MessageBoxIcon.Warning)) == DialogResult.No)
					{
						Trace.TraceInformation("Removing.");
						IBackgroundTaskSet btsDeactivator = p_mmgModManager.DeactivateMod(modMissing, p_mmgModManager.ActiveMods);
						WaitForSet(btsDeactivator, true);
					}
					else
					{
						Status = TaskStatus.Retrying;
						Trace.TraceInformation("Reset Paths.");
						Trace.Unindent();
						Trace.Unindent();
						return false;
					}

					Trace.TraceInformation("Uninstalled.");
					Trace.Unindent();
				}
			}
			Trace.Unindent();
			return true;
		}