Performs the mod installation based on the XML script.
Inheritance: BackgroundTask
		/// <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;
		}
Example #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);
        }