コード例 #1
0
 private static void CreateComboBoxRecordItem(View view, int numRows, string propertyName, string text, string value)
 {
     Record record = new Record(4);
     record.SetString(1, propertyName);
     record.SetInteger(2, numRows);
     record.SetString(3, value);
     record.SetString(4, text);
     view.Modify(ViewModifyMode.InsertTemporary, record);
 }
コード例 #2
0
        /// <summary>
        /// Logs a message to the MSI log using the MSI error table.
        /// </summary>
        /// <param name="id">Error message id</param>
        /// <param name="args">Arguments to the error message (will be inserted into the formatted error message).</param>
        public void Log(int id, params string[] args)
        {
            // field 0 is free, field 1 is the id, fields 2..n are arguments
            using (Record rec = new Record(1 + args.Length))
            {
                rec.SetInteger(1, id);
                for (int i = 0; i < args.Length; i++)
                {
                    rec.SetString(2 + i, args[i]);
                }

                this.session.Message(InstallMessage.User, rec);
            }
        }
コード例 #3
0
ファイル: CustomAction.cs プロジェクト: uw-it-cte/fog-client
 static void DisplayMSIError(Session session, string msg)
 {
     var r = new Record();
     r.SetString(0, msg);
     session.Message(InstallMessage.Error, r);
 }
コード例 #4
0
 public static ActionResult PrereqCheck(Session session)
 {
     var SecMsg = "You do not have the appropriate permissions to perform this operation. Make sure you are running the application from the local disk and you have local system administrator privileges.";
     var NetMsg = "Microsoft .NET {0} is {1}.";
     Action<string> ShowMsg = (string Text) =>
     {
         using(var Rec = new Record(0))
         {
             Rec.SetString(0, Text);
             session.Message(InstallMessage.Error, Rec);
         }
     };
     Action<Session, string, string> FxLog = (Session SesCtx, string Ver, string StrVer) =>
     {
         if (YesNo.Get(session[Ver]) == YesNo.Yes)
             AddLog(SesCtx, string.Format(NetMsg, StrVer, "available"));
         else
             AddLog(SesCtx, string.Format(NetMsg, StrVer, "not available"));
     };
     if (!Adapter.CheckSecurity() || !Adapter.IsAdministrator())
     {
         ShowMsg(SecMsg);
         return ActionResult.Failure;
     }            
     string Msg;
     var Ctx = Tool.GetSetupVars(session);
     var ros = Adapter.CheckOS(Ctx, out Msg);
     AddLog(session, Msg);
     var riis = Adapter.CheckIIS(Ctx, out Msg);
     AddLog(session, Msg);
     var raspnet = Adapter.CheckASPNET(Ctx, out Msg);
     AddLog(session, Msg);
     session[Prop.REQ_OS] = ros == CheckStatuses.Success ? YesNo.Yes : YesNo.No;
     session[Prop.REQ_IIS] = riis == CheckStatuses.Success ? YesNo.Yes : YesNo.No; ;
     session[Prop.REQ_ASPNET] = raspnet == CheckStatuses.Success ? YesNo.Yes : YesNo.No; ;
     FxLog(session, Prop.REQ_NETFRAMEWORK20, "2.0");
     FxLog(session, Prop.REQ_NETFRAMEWORK35, "3.5");
     FxLog(session, Prop.REQ_NETFRAMEWORK40FULL, "4.0");
     return ActionResult.Success;
 }
コード例 #5
0
        public static ActionResult InstallWebFeatures(Session session)
        {
            PopUpDebugger();

            var Ctx = session;
            Ctx.AttachToSetupLog();
            Log.WriteStart("InstallWebFeatures");
            var Result = ActionResult.Success;
            var Scheduled = Ctx.GetMode(InstallRunMode.Scheduled);
            var Components = new List<string>();
            var InstallIis = false;
            var InstallAspNet = false;
            var InstallNetFx3 = false;
            if (Scheduled)
            {
                InstallIis = Ctx.CustomActionData["PI_PREREQ_IIS_INSTALL"] != YesNo.No;
                InstallAspNet = Ctx.CustomActionData["PI_PREREQ_ASPNET_INSTALL"] != YesNo.No;
                InstallNetFx3 = Ctx.CustomActionData["PI_PREREQ_NETFX_INSTALL"] != YesNo.No;
            }
            else
            {
                InstallIis = Ctx["PI_PREREQ_IIS_INSTALL"] != YesNo.No;
                InstallAspNet = Ctx["PI_PREREQ_ASPNET_INSTALL"] != YesNo.No;
                InstallNetFx3 = Ctx["PI_PREREQ_NETFX_INSTALL"] != YesNo.No;
            }
            if (InstallIis)
                Components.AddRange(Tool.GetWebRoleComponents());
            if (InstallAspNet)
                Components.AddRange(Tool.GetWebDevComponents());
            if (InstallNetFx3)
                Components.AddRange(Tool.GetNetFxComponents());
            if (Scheduled)
            {
                Action<int, int> ProgressReset = (int Total, int Mode) =>
                {
                    using (var Tmp = new Record(4))
                    {
                        Tmp.SetInteger(1, 0);
                        Tmp.SetInteger(2, Total);
                        Tmp.SetInteger(3, 0);
                        Tmp.SetInteger(4, Mode);
                        Ctx.Message(InstallMessage.Progress, Tmp);
                    }
                };
                Action<int> ProgressIncrement = (int Value) =>
                {
                    using (var Tmp = new Record(2))
                    {
                        Tmp.SetInteger(1, 2);
                        Tmp.SetInteger(2, Value);
                        Ctx.Message(InstallMessage.Progress, Tmp);
                    }
                };
                Action<string> ProgressText = (string Text) =>
                {
                    using (var Tmp = new Record(2))
                    {
                        Tmp.SetString(1, "CA_InstallWebFeaturesDeferred");
                        Tmp.SetString(2, Text);
                        Ctx.Message(InstallMessage.ActionStart, Tmp);
                    }
                };
                var Frmt = "Installing web component the {0} a {1} of {2}";
                Log.WriteStart("InstallWebFeatures: components");
                ProgressReset(Components.Count + 1, 0);
                ProgressText("Installing necessary web components ...");
                var Msg = new StringBuilder();
                try
                {
                    InstallToolDelegate InstallTool = Tool.GetInstallTool();
                    if (InstallTool == null)
                        throw new ApplicationException("Install tool for copmonents is not found.");                    
                    for (int i = 0; i < Components.Count; i ++)
                    {
                        var Component = Components[i];
                        ProgressText(string.Format(Frmt, Component, i + 1, Components.Count));
                        ProgressIncrement(1);
                        Msg.AppendLine(InstallTool(Component));
                    }
                    if (InstallAspNet)
                        Tool.PrepareAspNet();                    
                    Log.WriteInfo("InstallWebFeatures: done.");
                }
                catch (Exception ex)
                {
                    Log.WriteError(string.Format("InstallWebFeatures: fail - {0}.", ex.ToString()));
                    Result = ActionResult.Failure;
                }
                finally
                {
                    ProgressReset(Components.Count * 3 + 1, 0);
                    if (Msg.Length > 0)
                        Log.WriteInfo(string.Format("InstallWebFeatures Tool Log: {0}.", Msg.ToString()));
                    Log.WriteEnd("InstallWebFeatures: components"); 
                }                               
            }
            else
            {
                Log.WriteStart("InstallWebFeatures: prepare");
                using (var ProgressRecord = new Record(2))
                {     
                    ProgressRecord.SetInteger(1, 3);
                    ProgressRecord.SetInteger(2, Components.Count);
                    Ctx.Message(InstallMessage.Progress, ProgressRecord);
                }
                Log.WriteEnd("InstallWebFeatures: prepare");
            }
            Log.WriteEnd("InstallWebFeatures");
            return Result;
        }        
コード例 #6
0
        public static ActionResult PreFillSettings(Session session)
        {
            Func<string, bool> HaveInstalledComponents = (string CfgFullPath) =>
            {
                var ComponentsPath = "//components";
                return File.Exists(CfgFullPath) ? BackupRestore.HaveChild(CfgFullPath, ComponentsPath) : false;
            };
            Func<IEnumerable<string>, string> FindMainConfig = (IEnumerable<string> Dirs) =>
            {
                // Looking into directories with next priority: 
                // Previous installation directory and her backup, "WebsitePanel" directories on fixed drives and their backups.
                // The last chance is an update from an installation based on previous installer version that installed to "Program Files".
                // Regular directories.
                foreach (var Dir in Dirs)
                {
                    var Result = Path.Combine(Dir, BackupRestore.MainConfig);
                    if (HaveInstalledComponents(Result))
                    {
                        return Result;
                    }
                    else
                    {
                        var ComponentNames = new string[] { Global.Server.ComponentName, Global.EntServer.ComponentName, Global.WebPortal.ComponentName };
                        foreach (var Name in ComponentNames)
                        {
                            var Backup = BackupRestore.Find(Dir, Global.DefaultProductName, Name);
                            if (Backup != null && HaveInstalledComponents(Backup.BackupMainConfigFile))
                                return Backup.BackupMainConfigFile;
                        }
                    }
                }
                // Looking into platform specific Program Files.
                {
                    var InstallerMainCfg = "WebsitePanel.Installer.exe.config";
                    var InstallerName = "WebsitePanel Installer";
                    var PFolderType = Environment.Is64BitOperatingSystem ? Environment.SpecialFolder.ProgramFilesX86 : Environment.SpecialFolder.ProgramFiles;
                    var PFiles = Environment.GetFolderPath(PFolderType);
                    var Result = Path.Combine(PFiles, InstallerName, InstallerMainCfg);
                    if (HaveInstalledComponents(Result))
                        return Result;
                }
                return null;
            };
            Action<Session, SetupVariables> VersionGuard = (Session SesCtx, SetupVariables CtxVars) =>
            {
                var Current = SesCtx["ProductVersion"];
                var Found = string.IsNullOrWhiteSpace(CtxVars.Version) ? "0.0.0" : CtxVars.Version;
                if ((new Version(Found) > new Version(Current)) && !CtxVars.InstallerType.ToLowerInvariant().Equals("msi"))
                    throw new InvalidOperationException("New version must be greater than previous always.");
            };
            Func<string, string> NormalizeDir = (string Dir) =>
            {
                string nds = Path.DirectorySeparatorChar.ToString();
                string ads = Path.AltDirectorySeparatorChar.ToString();
                var Result = Dir.Trim();
                if (!Result.EndsWith(nds) && !Result.EndsWith(ads))
                {
                    if (Result.Contains(nds))
                        Result += nds;
                    else
                        Result += ads;
                }
                return Result;
            };
            try
            {
                var Ctx = session;
                Ctx.AttachToSetupLog();

                PopUpDebugger();

                Log.WriteStart("PreFillSettings");

                TryApllyNewPassword(Ctx, "PI_SERVER_PASSWORD");
                TryApllyNewPassword(Ctx, "PI_ESERVER_PASSWORD");
                TryApllyNewPassword(Ctx, "PI_PORTAL_PASSWORD");

                var WSP = Ctx["WSP_INSTALL_DIR"];
                var DirList = new List<string>();
                DirList.Add(WSP);
                DirList.AddRange(from Drive in DriveInfo.GetDrives()
                                 where Drive.DriveType == DriveType.Fixed
                                 select Path.Combine(Drive.RootDirectory.FullName, Global.DefaultProductName));
                var CfgPath = FindMainConfig(DirList);
                if (!string.IsNullOrWhiteSpace(CfgPath))
                {
                    try
                    {
                        var EServerUrl = string.Empty;
                        AppConfig.LoadConfiguration(new ExeConfigurationFileMap { ExeConfigFilename = CfgPath });
                        var CtxVars = new SetupVariables();
                        CtxVars.ComponentId = WiXSetup.GetComponentID(CfgPath, Global.Server.ComponentCode);
                        if (!string.IsNullOrWhiteSpace(CtxVars.ComponentId))
                        {
                            AppConfig.LoadComponentSettings(CtxVars);
                            VersionGuard(Ctx, CtxVars);

                            SetProperty(Ctx, "COMPFOUND_SERVER_ID", CtxVars.ComponentId);
                            SetProperty(Ctx, "COMPFOUND_SERVER_MAIN_CFG", CfgPath);

                            SetProperty(Ctx, "PI_SERVER_IP", CtxVars.WebSiteIP);
                            SetProperty(Ctx, "PI_SERVER_PORT", CtxVars.WebSitePort);
                            SetProperty(Ctx, "PI_SERVER_HOST", CtxVars.WebSiteDomain);
                            SetProperty(Ctx, "PI_SERVER_LOGIN", CtxVars.UserAccount);
                            SetProperty(Ctx, "PI_SERVER_DOMAIN", CtxVars.UserDomain);

                            SetProperty(Ctx, "PI_SERVER_INSTALL_DIR", CtxVars.InstallFolder);
                            SetProperty(Ctx, "WSP_INSTALL_DIR", NormalizeDir(new DirectoryInfo(CtxVars.InstallFolder).Parent.FullName));

                            Ctx["SERVER_ACCESS_PASSWORD"] = string.Empty;
                            Ctx["SERVER_ACCESS_PASSWORD_CONFIRM"] = string.Empty;

                            var HaveAccount = SecurityUtils.UserExists(CtxVars.UserDomain, CtxVars.UserAccount);
                            bool HavePool = Tool.AppPoolExists(CtxVars.ApplicationPool);

                            Ctx["COMPFOUND_SERVER"] = (HaveAccount && HavePool) ? YesNo.Yes : YesNo.No;
                        }
                        CtxVars.ComponentId = WiXSetup.GetComponentID(CfgPath, Global.EntServer.ComponentCode);
                        if (!string.IsNullOrWhiteSpace(CtxVars.ComponentId))
                        {
                            AppConfig.LoadComponentSettings(CtxVars);
                            VersionGuard(Ctx, CtxVars);

                            SetProperty(Ctx, "COMPFOUND_ESERVER_ID", CtxVars.ComponentId);
                            SetProperty(Ctx, "COMPFOUND_ESERVER_MAIN_CFG", CfgPath);

                            SetProperty(Ctx, "PI_ESERVER_IP", CtxVars.WebSiteIP);
                            SetProperty(Ctx, "PI_ESERVER_PORT", CtxVars.WebSitePort);
                            SetProperty(Ctx, "PI_ESERVER_HOST", CtxVars.WebSiteDomain);
                            SetProperty(Ctx, "PI_ESERVER_LOGIN", CtxVars.UserAccount);
                            SetProperty(Ctx, "PI_ESERVER_DOMAIN", CtxVars.UserDomain);
                            EServerUrl = string.Format("http://{0}:{1}", CtxVars.WebSiteIP, CtxVars.WebSitePort);

                            SetProperty(Ctx, "PI_ESERVER_INSTALL_DIR", CtxVars.InstallFolder);
                            SetProperty(Ctx, "WSP_INSTALL_DIR", NormalizeDir(new DirectoryInfo(CtxVars.InstallFolder).Parent.FullName));

                            var ConnStr = new SqlConnectionStringBuilder(CtxVars.DbInstallConnectionString);
                            SetProperty(Ctx, "DB_CONN", ConnStr.ToString());
                            SetProperty(Ctx, "DB_SERVER", ConnStr.DataSource);
                            SetProperty(Ctx, "DB_AUTH", ConnStr.IntegratedSecurity ? SQL_AUTH_WINDOWS : SQL_AUTH_SERVER);
                            if (!ConnStr.IntegratedSecurity)
                            {
                                SetProperty(Ctx, "DB_LOGIN", ConnStr.UserID);
                                SetProperty(Ctx, "DB_PASSWORD", ConnStr.Password);
                            }
                            ConnStr = new SqlConnectionStringBuilder(CtxVars.ConnectionString);
                            SetProperty(Ctx, "DB_DATABASE", ConnStr.InitialCatalog);
                            SetProperty(Ctx, "PI_ESERVER_CONN_STR", ConnStr.ToString());
                            SetProperty(Ctx, "PI_ESERVER_CRYPTO_KEY", CtxVars.CryptoKey);

                            try
                            {
                                var SqlQuery = string.Format("USE [{0}]; SELECT [dbo].[Users].[Password] FROM [dbo].[Users] WHERE [dbo].[Users].[UserID] = 1;", ConnStr.InitialCatalog);
                                using (var Reader = SqlUtils.ExecuteSql(CtxVars.DbInstallConnectionString, SqlQuery).CreateDataReader())
                                {
                                    if (Reader.Read())
                                    {
                                        var Hash = Reader[0].ToString();
                                        var Password = IsEnctyptionEnabled(string.Format(@"{0}\Web.config", CtxVars.InstallationFolder)) ? Utils.Decrypt(CtxVars.CryptoKey, Hash) : Hash;
                                        Ctx["SERVERADMIN_PASSWORD"] = Password;
                                        Ctx["SERVERADMIN_PASSWORD_CONFIRM"] = Password;
                                    }
                                }
                            }
                            catch
                            {
                                // Nothing to do.
                            }

                            var HaveAccount = SecurityUtils.UserExists(CtxVars.UserDomain, CtxVars.UserAccount);
                            bool HavePool = Tool.AppPoolExists(CtxVars.ApplicationPool);

                            Ctx["COMPFOUND_ESERVER"] = (HaveAccount && HavePool) ? YesNo.Yes : YesNo.No;
                        }
                        CtxVars.ComponentId = WiXSetup.GetComponentID(CfgPath, Global.WebPortal.ComponentCode);
                        if (!string.IsNullOrWhiteSpace(CtxVars.ComponentId))
                        {
                            AppConfig.LoadComponentSettings(CtxVars);
                            VersionGuard(Ctx, CtxVars);

                            SetProperty(Ctx, "COMPFOUND_PORTAL_ID", CtxVars.ComponentId);
                            SetProperty(Ctx, "COMPFOUND_PORTAL_MAIN_CFG", CfgPath);

                            SetProperty(Ctx, "PI_PORTAL_IP", CtxVars.WebSiteIP);
                            SetProperty(Ctx, "PI_PORTAL_PORT", CtxVars.WebSitePort);
                            SetProperty(Ctx, "PI_PORTAL_HOST", CtxVars.WebSiteDomain);
                            SetProperty(Ctx, "PI_PORTAL_LOGIN", CtxVars.UserAccount);
                            SetProperty(Ctx, "PI_PORTAL_DOMAIN", CtxVars.UserDomain);
                            if (!SetProperty(Ctx, "PI_ESERVER_URL", CtxVars.EnterpriseServerURL))
                                if (!SetProperty(Ctx, "PI_ESERVER_URL", EServerUrl))
                                    SetProperty(Ctx, "PI_ESERVER_URL", Global.WebPortal.DefaultEntServURL);

                            SetProperty(Ctx, "PI_PORTAL_INSTALL_DIR", CtxVars.InstallFolder);
                            SetProperty(Ctx, "WSP_INSTALL_DIR", NormalizeDir(new DirectoryInfo(CtxVars.InstallFolder).Parent.FullName));

                            var HaveAccount = SecurityUtils.UserExists(CtxVars.UserDomain, CtxVars.UserAccount);
                            bool HavePool = Tool.AppPoolExists(CtxVars.ApplicationPool);

                            Ctx["COMPFOUND_PORTAL"] = (HaveAccount && HavePool) ? YesNo.Yes : YesNo.No;
                        }
                        CtxVars.ComponentId = WiXSetup.GetComponentID(CfgPath, Global.Scheduler.ComponentCode);
                        var HaveComponentId = !string.IsNullOrWhiteSpace(CtxVars.ComponentId);
                        var HaveSchedulerService = ServiceController.GetServices().Any(x => x.DisplayName.Equals(Global.Parameters.SchedulerServiceName, StringComparison.CurrentCultureIgnoreCase));
                        var EServerConnStr = Ctx["PI_ESERVER_CONN_STR"];
                        var HaveConn = !string.IsNullOrWhiteSpace(EServerConnStr);
                        if (HaveComponentId || HaveSchedulerService || HaveConn)
                        {
                            Ctx["COMPFOUND_SCHEDULER"] = YesNo.No;
                            try
                            {
                                SqlConnectionStringBuilder ConnInfo = null;
                                if (HaveComponentId)
                                {
                                    AppConfig.LoadComponentSettings(CtxVars);
                                    VersionGuard(Ctx, CtxVars);
                                    SetProperty(Ctx, "COMPFOUND_SCHEDULER_ID", CtxVars.ComponentId);
                                    SetProperty(Ctx, "COMPFOUND_SCHEDULER_MAIN_CFG", CfgPath);
                                    SetProperty(Ctx, "PI_SCHEDULER_CRYPTO_KEY", CtxVars.CryptoKey);
                                    ConnInfo = new SqlConnectionStringBuilder(CtxVars.ConnectionString);                                    
                                }
                                else if (HaveConn)
                                {                                    
                                    SetProperty(Ctx, "PI_SCHEDULER_CRYPTO_KEY", Ctx["PI_ESERVER_CRYPTO_KEY"]);
                                    ConnInfo = new SqlConnectionStringBuilder(EServerConnStr);
                                }
                                if(ConnInfo != null)
                                {
                                    SetProperty(Ctx, "PI_SCHEDULER_DB_SERVER", ConnInfo.DataSource);
                                    SetProperty(Ctx, "PI_SCHEDULER_DB_DATABASE", ConnInfo.InitialCatalog);
                                    SetProperty(Ctx, "PI_SCHEDULER_DB_LOGIN", ConnInfo.UserID);
                                    SetProperty(Ctx, "PI_SCHEDULER_DB_PASSWORD", ConnInfo.Password);
                                }
                                Ctx["COMPFOUND_SCHEDULER"] = HaveSchedulerService? YesNo.Yes : YesNo.No;
                            }
                            catch (Exception ex)
                            {
                                Log.WriteError("Detection of existing Scheduler Service failed.", ex);
                            }                                
                        }
                    }
                    catch (InvalidOperationException ioex)
                    {
                        Log.WriteError(ioex.ToString());
                        var Text = new Record(1);
                        Text.SetString(0, ioex.Message);
                        Ctx.Message(InstallMessage.Error, Text);
                        return ActionResult.Failure;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.WriteError(ex.ToString());
                return ActionResult.Failure;
            }
            Log.WriteEnd("PreFillSettings");
            return ActionResult.Success;
        }
コード例 #7
0
        public static ActionResult ScanNetworkForSqlServers(Session session)
        {
            sessionObj = session;
            if (xmlSettings == null)
                xmlSettings = new XMLSettingsManager();

            if ((session["HASSCANNEDFORSQL"].CompareTo("0") == 0) && (session["ISSERVERINSTALL"] != "0")) {
                if (xmlSettings.SettingsFileExists()) {
                    return ActionResult.SkipRemainingActions;
                } else {
                    DataTable dt = SqlDataSourceEnumerator.Instance.GetDataSources();
                    View sqlComboBox = session.Database.OpenView("SELECT * FROM `ComboBox`");
                    sqlComboBox.Execute();
                    int numRows = 0;
                    while (sqlComboBox.Fetch() != null) {
                        numRows++;
                    }
                    if (numRows == 1) {
                        CustomActions.LogToSession(string.Format("found {0} sql servers", dt.Rows.Count));
                        int itemNumber = 2;
                        foreach (DataRow row in dt.Rows) {
                            Record rec = new Record(3);
                            rec.SetString(1, "OMLProp_SqlServers");
                            rec.SetInteger(2, itemNumber);
                            string description = string.Format("{0} - {1}", row["ServerName"], row["InstanceName"]);
                            rec.SetString(3, description);

                            CustomActions.LogToSession(string.Format("Adding a new record, its number will be {0} and its value will be {1}", itemNumber, string.Format("{0} ({1})", row["ServerName"], row["InstanceName"])));
                            sqlComboBox.Modify(ViewModifyMode.InsertTemporary, rec);
                            itemNumber++;
                        }
                    }
                }
                session["HASSCANNEDFORSQL"] = "1";
            }
            return ActionResult.Success;
        }
コード例 #8
0
		public static ActionResult ValidateInstall(Session session)
		{
			session.Log("Begin ValidateInstall");

			// check the required properties have been set
			string definition_to_use = session["INSTALLVALIDATORDEF"];
			string path_to_validate = session["INSTALLVALIDATORPATH"];

			if ((definition_to_use == null) || (definition_to_use.Length == 0))
			{
				session.Log("InstallValidator: ERROR : INSTALLVALIDATORDEF not set");
				return ActionResult.Failure;
			}
			if ((path_to_validate == null) || (path_to_validate.Length == 0))
			{
				session.Log("InstallValidator: ERROR : INSTALLVALIDATORPATH not set");
				return ActionResult.Failure;
			}

			// log the properties for debugging if necessary
			session.Log("LOG: INSTALLVALIDATORDEF : " + definition_to_use);
			session.Log("LOG: INSTALLVALIDATORPATH : " + path_to_validate);

			// validate the installation path
			ValidateInstallPath(definition_to_use, path_to_validate);

			// show warning messages
			if (g_validator.WarningMessages.Count != 0)
			{
				Record message_record = new Record(1);
				MessageResult view_warnings_result;

				// ask the user if they want to see the warnings that were raised
				message_record.SetString(0, String.Format("{0} warnings were raised when validating your installation.\n\nDo you want to view them (Recommended)?",
					g_validator.WarningMessages.Count));
				view_warnings_result = session.Message(InstallMessage.Warning | (InstallMessage)(MessageIcon.Warning) | (InstallMessage)MessageButtons.YesNo, message_record);
				if(MessageResult.Yes == view_warnings_result)
				{
					// display each warning in a seperate dialog
					foreach (var message in g_validator.WarningMessages)
					{
						session.Log("InstallValidator: {0}", message);
						message_record.SetString(0, message);
						session.Message(InstallMessage.Warning | (InstallMessage)(MessageIcon.Warning) | (InstallMessage)MessageButtons.OK, message_record);
					}

					// see if the user still wants to continue the installation
					message_record.SetString(0, "Do you want to continue the installation?");
					view_warnings_result = session.Message(InstallMessage.Warning | (InstallMessage)(MessageIcon.Warning) | (InstallMessage)MessageButtons.YesNo, message_record);

					// if the user wants to cancel the installation return user exit
					if (view_warnings_result == MessageResult.No)
						return ActionResult.UserExit;
				}
			}

			// show error messages
			if (g_validator.ErrorMessages.Count != 0)
			{
				Record record = new Record(g_validator.ErrorMessages.Count);
				
				// there should only ever be one error message since it returns immediately after finding one
				// but just in case, log and display all in the list
				int index = 0;
				foreach (var message in g_validator.ErrorMessages)
				{
					session.Log("InstallValidator: {0}", message);
					record.SetString(index, message);
					index++;
				}

				// present an error message to the user
				session.Message(InstallMessage.Error | (InstallMessage)(MessageIcon.Error) | (InstallMessage)MessageButtons.OK, record);
				return ActionResult.Failure;
			}

			return ActionResult.Success;
		}
コード例 #9
0
 public static void SendMessage(this Session session, string message)
 {
     var record = new Record();
     record.SetString(0, message);
     session.Message(InstallMessage.Warning, record);
 }
コード例 #10
0
ファイル: FilePatcher.cs プロジェクト: CodeAsm/open-sauce
		public static ActionResult PatchFile(Session session)
		{
			session.Log("Begin FilePatcher");

			string patch_arguments = session["CustomActionData"];

			// check the custom action arguments have been set
			if ((patch_arguments == null) || (patch_arguments.Length == 0))
			{
				session.Log("FilePatcher: ERROR : CustomActionData not set");
				return ActionResult.Failure;
			}

			// split the patch arguments string, the count should be a multiple of 3
			string[] split_arguments = patch_arguments.Split(new char[] {';'}, StringSplitOptions.RemoveEmptyEntries);
			if((split_arguments.Length == 0) || ((split_arguments.Length % 3) > 0))
			{
				session.Log("Invalid number of arguments passed to the FilePatcher");
				return ActionResult.Failure;
			}

			// populate the patch list
			List<PatchInstance> files_to_patch = new List<PatchInstance>();
			for(int i = 0; i < split_arguments.Length; i+=3)
			{
				PatchInstance patch = new PatchInstance();

				patch.FileID = split_arguments[i];
				patch.FilePath = split_arguments[i + 1];
				patch.OutputPath = split_arguments[i + 2];

				files_to_patch.Add(patch);
			}

			// patch each file in order
			foreach(var patch_instance in files_to_patch)
			{
				// log the properties for debugging if necessary
				session.Log("LOG: FILEPATCHERID : " + patch_instance.FileID);
				session.Log("LOG: FILEPATCHERSRCFILE : " + patch_instance.FilePath);
				session.Log("LOG: FILEPATCHEROUTPATH : " + patch_instance.OutputPath);

				// patch the file
				ApplyPatch(patch_instance.FileID, patch_instance.FilePath, patch_instance.OutputPath);

				// show error messages
				if (g_file_patcher.ErrorMessages.Count != 0)
				{
					Record record = new Record(g_file_patcher.ErrorMessages.Count);

					// there should only ever be one error message since it returns immediately after
					// but just in case, log and display all in the list
					int index = 0;
					foreach (var message in g_file_patcher.ErrorMessages)
					{
						session.Log("FilePatcher: {0}", message);
						record.SetString(index, message);
						index++;
					}

					// present an error message to the user
					session.Message(InstallMessage.Error | (InstallMessage)(MessageIcon.Error) | (InstallMessage)MessageButtons.OK, record);
					return ActionResult.Failure;
				}
			}

			return ActionResult.Success;
		}
コード例 #11
0
    public static void SendProgressMessageToBA(Session session, string message, int progress)
    {
        Record messageRecord = new Record(4);
        messageRecord.SetInteger(1, (int)MessageId.Progress);
        messageRecord.SetString(2, message);
        messageRecord.SetInteger(3, progress);

        session.Message(InstallMessage.Warning, messageRecord);
    }
コード例 #12
0
    public static void SendMessageBoxMessageToBA(Session session, string message)
    {
        Record messageRecord = new Record(3);
        messageRecord.SetInteger(1, (int)MessageId.MessageBox);
        messageRecord.SetString(2, message);

        session.Message(InstallMessage.Warning, messageRecord);
    }