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."); } }; var Ctx = session; Ctx.AttachToSetupLog(); PopUpDebugger(); Log.WriteStart("PreFillSettings"); 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", Directory.GetParent(CtxVars.InstallFolder).FullName); 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", Directory.GetParent(CtxVars.InstallFolder).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); 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", Directory.GetParent(CtxVars.InstallFolder).FullName); var HaveAccount = SecurityUtils.UserExists(CtxVars.UserDomain, CtxVars.UserAccount); bool HavePool = Tool.AppPoolExists(CtxVars.ApplicationPool); Ctx["COMPFOUND_PORTAL"] = (HaveAccount && HavePool) ? YesNo.Yes : YesNo.No; } } 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); } } TryApllyNewPassword(Ctx, "PI_SERVER_PASSWORD"); TryApllyNewPassword(Ctx, "PI_ESERVER_PASSWORD"); TryApllyNewPassword(Ctx, "PI_PORTAL_PASSWORD"); TryApllyNewPassword(Ctx, "SERVER_ACCESS_PASSWORD"); TryApllyNewPassword(Ctx, "SERVERADMIN_PASSWORD"); Log.WriteEnd("PreFillSettings"); return(ActionResult.Success); }