Install() public method

Performs the mod installation based on the XML script.
public Install ( string p_strModName, XmlScript p_xscScript, ConditionStateManager p_csmStateManager, ICollection p_colFilesToInstall, ICollection p_colPluginsToActivate ) : bool
p_strModName string The name of the mod whose script in executing.
p_xscScript XmlScript The script that is executing.
p_csmStateManager ConditionStateManager The state manager managing the install state.
p_colFilesToInstall ICollection The list of files to install.
p_colPluginsToActivate ICollection The list of plugins to activate.
return bool
		/// <summary>
		/// Executes the script.
		/// </summary>
		/// <param name="p_scpScript">The XMl Script to execute.</param>
		/// <returns><c>true</c> if the script completes successfully;
		/// <c>false</c> otherwise.</returns>
		/// <exception cref="ArgumentException">Thrown if <paramref name="p_scpScript"/> is not an
		/// <see cref="XmlScript"/>.</exception>
		public override bool DoExecute(IScript p_scpScript)
		{
			if (!(p_scpScript is XmlScript))
				throw new ArgumentException("The given script must be of type XmlScript.", "p_scpScript");

			XmlScript xscScript = (XmlScript)p_scpScript;

			ConditionStateManager csmStateManager = ((XmlScriptType)xscScript.Type).CreateConditionStateManager(Mod, GameMode, Installers.PluginManager, EnvironmentInfo);
			if ((xscScript.ModPrerequisites != null) && !xscScript.ModPrerequisites.GetIsFulfilled(csmStateManager))
				throw new DependencyException(xscScript.ModPrerequisites.GetMessage(csmStateManager));

			IList<InstallStep> lstSteps = xscScript.InstallSteps;
			HeaderInfo hifHeaderInfo = xscScript.HeaderInfo;
			if (String.IsNullOrEmpty(hifHeaderInfo.ImagePath))
				hifHeaderInfo.ImagePath = Mod.ScreenshotPath;
			if ((hifHeaderInfo.Height < 0) && hifHeaderInfo.ShowImage)
				hifHeaderInfo.Height = 75;
			OptionsForm ofmOptions = null;
			if (m_scxSyncContext == null)
				ofmOptions = new OptionsForm(xscScript, hifHeaderInfo, csmStateManager, lstSteps);
			else
				m_scxSyncContext.Send(x => ofmOptions = new OptionsForm(xscScript, hifHeaderInfo, csmStateManager, lstSteps), null);
			ofmOptions.Name = "OptionForm";
			bool booPerformInstall = false;
			if (lstSteps.Count == 0)
				booPerformInstall = true;
			else
			{
				if (m_scxSyncContext == null)
					booPerformInstall = (ofmOptions.ShowDialog() == DialogResult.OK);
				else
					m_scxSyncContext.Send(x => booPerformInstall = (ofmOptions.ShowDialog() == DialogResult.OK), null);
			}

			if (booPerformInstall)
			{
				XmlScriptInstaller xsiInstaller = new XmlScriptInstaller(Mod, GameMode, Installers);
				OnTaskStarted(xsiInstaller);
				return xsiInstaller.Install(hifHeaderInfo.Title, xscScript, csmStateManager, ofmOptions.FilesToInstall, ofmOptions.PluginsToActivate);				
			}
			return false;
		}
示例#2
0
        /// <summary>
        /// Executes the script.
        /// </summary>
        /// <param name="p_scpScript">The XMl Script to execute.</param>
        /// <returns><c>true</c> if the script completes successfully;
        /// <c>false</c> otherwise.</returns>
        /// <exception cref="ArgumentException">Thrown if <paramref name="p_scpScript"/> is not an
        /// <see cref="XmlScript"/>.</exception>
        public override bool DoExecute(IScript p_scpScript)
        {
            if (!(p_scpScript is XmlScript))
            {
                throw new ArgumentException("The given script must be of type XmlScript.", "p_scpScript");
            }

            XmlScript xscScript = (XmlScript)p_scpScript;

            ConditionStateManager csmStateManager = ((XmlScriptType)xscScript.Type).CreateConditionStateManager(Mod, GameMode, Installers.PluginManager, EnvironmentInfo);

            if ((xscScript.ModPrerequisites != null) && !xscScript.ModPrerequisites.GetIsFulfilled(csmStateManager))
            {
                throw new DependencyException(xscScript.ModPrerequisites.GetMessage(csmStateManager));
            }

            IList <InstallStep> lstSteps      = xscScript.InstallSteps;
            HeaderInfo          hifHeaderInfo = xscScript.HeaderInfo;

            if (String.IsNullOrEmpty(hifHeaderInfo.ImagePath))
            {
                hifHeaderInfo.ImagePath = Mod.ScreenshotPath;
            }
            if ((hifHeaderInfo.Height < 0) && hifHeaderInfo.ShowImage)
            {
                hifHeaderInfo.Height = 75;
            }
            OptionsForm ofmOptions = null;

            if (m_scxSyncContext == null)
            {
                ofmOptions = new OptionsForm(xscScript, hifHeaderInfo, csmStateManager, lstSteps);
            }
            else
            {
                m_scxSyncContext.Send(x => ofmOptions = new OptionsForm(xscScript, hifHeaderInfo, csmStateManager, lstSteps), null);
            }
            ofmOptions.Name = "OptionForm";
            bool booPerformInstall = false;

            if (lstSteps.Count == 0)
            {
                booPerformInstall = true;
            }
            else
            {
                if (m_scxSyncContext == null)
                {
                    booPerformInstall = (ofmOptions.ShowDialog() == DialogResult.OK);
                }
                else
                {
                    m_scxSyncContext.Send(x => booPerformInstall = (ofmOptions.ShowDialog() == DialogResult.OK), null);
                }
            }

            if (booPerformInstall)
            {
                XmlScriptInstaller xsiInstaller = new XmlScriptInstaller(Mod, GameMode, Installers);
                OnTaskStarted(xsiInstaller);
                return(xsiInstaller.Install(hifHeaderInfo.Title, xscScript, csmStateManager, ofmOptions.FilesToInstall, ofmOptions.PluginsToActivate));
            }
            return(false);
        }