public static ActionResult ConfigureApplicationSettings(Session session)
        {
            if (session == (Session)null)
                throw new ArgumentNullException("session");

            #if DEBUG
                Debugger.Launch();
            #endif

            session.Log("Start Custom Action: Configure Application Settings");

            string[] properties = session.CustomActionData.ToString().Split(new string[] { "," }, StringSplitOptions.None);

            ApplicationConfigSettings.EnvironmentType environment = GetEvironmentType(properties[0], session.Log);

            string configPath = properties[1];
            if (string.IsNullOrEmpty(configPath))
                return ActionResult.Failure;

            settingXMLPath = properties[2];
            if (string.IsNullOrEmpty(settingXMLPath))
                return ActionResult.Failure;

            List<ApplicationConfigSettings.Setting> settings = GetApplicationSettings(session.Log, environment);
            if (settings.Count == 0)
            {
                session.Log("Error: unable to load application settings");
                return ActionResult.Failure;
            }

            UpdateConfigurationFile(session.Log, settings, configPath);

            session.Log("End Custom Action: Configure Application Settings");
            return ActionResult.Success;
        }
Example #2
0
        public static ActionResult RegisterApplication(Session session)
        {
            session.Log("Begin configure web application");

            try
            {
                // parameters
                var appId = new Guid(session["APP_ID"]);
                ushort port = ushort.Parse(session["APP_PORT"]);
                string path = session["APP_PATH"];

                // init
                WebAppConfigEntry app = Metabase.GetWebAppEntry(appId);
                app.ApplicationName = "NooLite Web Control Panel";
                app.VirtualDirectory = string.Empty;
                app.PhysicalDirectory = path;

                app.ListenAddresses.Clear();
                app.ListenAddresses.AddAddresses(new ListenAddress(port));

                app.AppType = ApplicationType.AspNetOrStaticHtml;
                app.Stopped = false;

                // register webapp
                Metabase.RegisterApplication(RuntimeVersion.AspNet_4, false, app, new AppShortcut[0]);
            }
            catch (Exception ex)
            {
                session.Log("ERROR in configure web application: {0}", ex.ToString());
                return ActionResult.Failure;
            }

            session.Log("End configure web application");
            return ActionResult.Success;
        }
Example #3
0
        public static ActionResult CopyCustomisationFiles(Session session)
        {
            session.Log("Begin CopyCustomisationFiles");

            string path = session.CustomActionData["SourceDir"];

            session.Log("source dir is " + path);

            string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\iSpy\";
            path = path.Trim().Trim('\\') + @"\";
            try
            {
                if (File.Exists(path + "custom.txt"))
                {
                    TryCopy(path + @"custom.txt", appDataPath + @"custom.txt", true);
                    TryCopy(path + @"logo.jpg", appDataPath + @"logo.jpg", true);
                    TryCopy(path + @"logo.png", appDataPath + @"logo.png", true);
                }

            }
            catch
            {

            }


            return ActionResult.Success;
        }
		public static ActionResult SetPropertiesCA(Session session)
		{
			string definition = session["SETPROPERTIESDEF"];

			var errorOccurred = false;

			var result = SetPropertiesCustomAction.SetProperties(definition,
				(value) =>
				{
					session.Log(value);
				},
				(property, value) =>
				{
					session[property] = value;
				},
				(property) =>
				{
					return session[property] as string;
				},
				(value) =>
				{
					errorOccurred = true;

					session.Log(value);
				}
			);

			return (!errorOccurred && result) ? ActionResult.Success : ActionResult.Failure;
		}
        public static ActionResult PatchPropsWizFiles(Session session)
        {
            session.Log("Begin PatchPropsWizFiles");
            //Debugger.Break () ;

            string TARGETDIR = session["TARGETDIR"];
            string ARXPATH = session["ARXPATH"];
            session.Log(" >> PatchPropsWizFiles: ARXPATH = " + ARXPATH + " / TARGETDIR = " + TARGETDIR);
            //C:\Program Files (x86)\Autodesk\ObjectARX 2014 Wizards\
            string ACAD = session["ACAD"];
            session.Log(" >> PatchPropsWizFiles: ACAD = " + ACAD);

            DirectoryInfo di = new DirectoryInfo(TARGETDIR);
            FileInfo[] files = di.GetFiles("*2014*.props", SearchOption.AllDirectories).ToArray();
            session.Log(" >> PatchPropsWizFiles:   DirectoryInfo = " + files.Length.ToString());
            foreach (FileInfo file in files)
            {
                try
                {
                    session.Log(" >> PatchPropsWizFiles:   =>> " + file.FullName);
                    string szData = System.IO.File.ReadAllText(file.FullName);
                    szData = szData.Replace(@"<ArxSdkDir>C:\ObjectARX\</ArxSdkDir>", @"<ArxSdkDir>" + ARXPATH + "</ArxSdkDir>");
                    szData = szData.Replace("<AcadDir Condition=\"'$(Platform)'=='x64'\">C:\\Program Files\\Autodesk\\AutoCAD 2014\\</AcadDir>", "<AcadDir Condition=\"'$(Platform)'=='x64'\">" + ACAD + "</AcadDir>") ;
                    szData = szData.Replace("<AcadDir Condition=\"'$(Platform)'=='Win32'\">C:\\Program Files (x86)\\Autodesk\\AutoCAD 2014\\</AcadDir>", "<AcadDir Condition=\"'$(Platform)'=='Win32'\">" + ACAD + "</AcadDir>") ;
                    System.IO.File.WriteAllText(file.FullName, szData);
                }
                catch
                {
                }
            }

            session.Log("Ending PatchPropsWizFiles");
            return (ActionResult.Success);
        }
Example #6
0
 public static ActionResult GetWebSites(Session session)
 {
     try {
         string query = string.Format("select * from ComboBox where ComboBox.Property='{0}'", WebSiteNamePropertyName);
         using (View view = session.Database.OpenView(query)) {
             using (ServerManager serverManager = new ServerManager()) {
                 int index = 1;
                 foreach (Site site in serverManager.Sites) {
                     // For now only support install to default web site
                     if (site.Name == "Default Web Site") {
                         Record record = session.Database.CreateRecord(4);
                         record.SetString(1, WebSiteNamePropertyName);
                         record.SetInteger(2, index++);
                         record.SetString(3, site.Name);
                         record.SetString(4, site.Name);
                         view.Modify(ViewModifyMode.InsertTemporary, record);
                     }
                 }
             }
             return ActionResult.Success;
         }
     } catch (Exception e) {
         session.Log(e.Message);
         session.Log(e.StackTrace);
         return ActionResult.Failure;
     }
 }
        public static ActionResult PatchHTMLWizFiles(Session session)
        {
            session.Log("Begin PatchHTMLWizFiles");
            //Debugger.Break () ;

            string TARGETDIR = session["TARGETDIR"];
            string RDS = session["RDS"];
            session.Log(" >> PatchHTMLWizFiles: RDS = " + RDS +" / TARGETDIR = " + TARGETDIR);
            //C:\Program Files (x86)\Autodesk\ObjectARX 2014 Wizards\

            DirectoryInfo di = new DirectoryInfo(TARGETDIR);
            FileInfo[] files = di.GetFiles("default.htm", SearchOption.AllDirectories)
                             .Where(p => p.DirectoryName.Contains("AppWiz")).ToArray();
            session.Log(" >> PatchHTMLWizFiles:   DirectoryInfo = " + files.Length.ToString());
            foreach (FileInfo file in files)
            {
                try
                {
                    session.Log(" >> PatchHTMLWizFiles:   =>> " + file.FullName);
                    string szData = System.IO.File.ReadAllText(file.FullName);
                    szData = szData.Replace("<SYMBOL NAME='RDS_SYMB' TYPE='text' VALUE='asdk'></SYMBOL>", "<SYMBOL NAME='RDS_SYMB' TYPE='text' VALUE='" + RDS + "'></SYMBOL>");
                    System.IO.File.WriteAllText(file.FullName, szData);
                }
                catch
                {
                }
            }

            session.Log("Ending PatchHTMLWizFiles");
            return (ActionResult.Success);
        }
Example #8
0
        public static ActionResult UninstallClickOnce(Session session)
        {
            session.Log("Begin to uninstall ClickOnce deployment");

            var appName = "IPFilter Updater";

            try
            {
                var uninstallInfo = UninstallInfo.Find(appName);
                if (uninstallInfo == null)
                {
                    session.Log("No uninstall information found for " + appName);
                    return ActionResult.NotExecuted;
                }

                session.Log("Waiting for files to become free...");
                Thread.Sleep(TimeSpan.FromSeconds(10));

                session.Log("Uninstalling " + appName);
                var uninstaller = new Uninstaller();
                uninstaller.Uninstall(uninstallInfo);
            }
            catch (Exception ex)
            {
                session.Log("ERROR in ClickOnceUninstaller custom action:\n {0}", ex.ToString());
                return ActionResult.Failure;
            }

            return ActionResult.Success;
        }
Example #9
0
        public static ActionResult AddCleanProjectTool(Session session)
        {
            session.Log("Begin AddCleanProjectTool");

            // Read HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\External Tools
            var key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\VisualStudio\10.0\External Tools", true);
            if (key != null)
            {
                // The number has the value for the next tool
                // If there are 5 tools, the number will be 6
                var numTools = (int) key.GetValue("ToolNumKeys", 0);

                var tool = new ExternalTool
                {
                    Args = "/D:$(SolutionDir) /Z /R",
                    Command = Path.Combine(session["INSTALLLOCATION"], "CleanProject.exe"),
                    Directory = string.Empty,
                    Opt = 24,
                    SourceKey = string.Empty,
                    Title = "Clean, Remove Source Bindings and Zip Solution"
                };
                ExternalTool.Write(key, numTools, tool);

                // Setup for the next tool
                key.SetValue("ToolNumKeys", numTools + 1);
            }
            session.Log("End AddCleanProjectTool");
            return ActionResult.Success;
        }
Example #10
0
        public static ActionResult DeployCertificate(Session session)
        {
            session.Log("Beginning DeploySelfSignedCertificate.");
            var hostname = GetFullHostname();
            session.Log("Determined hostname of computer to be: {0}.  This name will be used for the certificate, and should be used when accessing the website.", hostname);
            session.Log("Enumerating CustomActionData.");
            //print out all the session data we have access to (helps when troubleshooting)
            foreach (var v in session.CustomActionData)
            {
                session.Log("{0}:{1}", v.Key, v.Value);
            }

            var installPath = session.CustomActionData["INSTALLLOCATION"];

            string certExportPath;
            session.CustomActionData.TryGetValue("CERTEXPORTPATH", out certExportPath);

            session.Log("Searching for existing certificates.");
            X509Certificate2 certificate;
            if (!TryRetrieveCertificate(out certificate, hostname))
            {
                session.Log("No usable certificates found, beginning generation of new self-signed certificate.");
                certificate = GenerateSelfSignCertificate(hostname);
                session.Log("Successful generation of certificate.");
            }

            session.Log("Beginning configuration of https binding.");
            AddHttpsBinding(session, installPath, certificate, certExportPath);
            session.Log("Configuration of https binding successful.");

            session.Log("DeploySelfSignedCertificate finished successfully.");
            return ActionResult.Success;
        }
Example #11
0
        public static ActionResult DeferredClientAction(Session session)
        {
            try
            {
                session.Log("Begin Server CustomAction");
                string installFolder = session["INSTALLFOLDER"];
                session.Log("Custom Action Using install folder: " + installFolder);

                DatabaseInstall databaseInstall = new DatabaseInstall(session, installFolder, "Client");

                if (databaseInstall.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    return ActionResult.Success;
                }
                else
                {
                    session.Log("OSAInstallCustomActions CustomAction - User exited");
                    return ActionResult.UserExit;
                }
            }
            catch (Exception ex)
            {
                session.Log("Exception Occured during custom action details:" + ex.Message);
                return ActionResult.Failure;
            }
        }
Example #12
0
    public static ActionResult OnInstall(Session session)
    {
        //Note if your custom action requires non-GAC assembly then you need deploy it too.
        //You can do it by setting ManagedAction.RefAssemblies.
        //See "Wix# Samples\DTF (ManagedCA)\Different Scenarios\ExternalAssembly" sample for details.

        //System.Diagnostics.Debugger.Launch();

        session.Log("------------- " + session.Property("INSTALLDIR"));
        session.Log("------------- " + session.Property("CONFIG_FILE"));
        session.Log("------------- " + session.Property("APP_FILE"));

        return session.HandleErrors(() =>
        {
            string configFile = session.Property("INSTALLDIR") + "MyApp.exe.config";

            //alternative ways of extracting 'deferred' properties
            //configFile = session.Property("APP_FILE") + ".config";
            //configFile = session.Property("CONFIG_FILE");

            UpdateAsAppConfig(configFile);

            //alternative implementations for the config manipulations
            UpdateAsXml(configFile);
            UpdateAsText(configFile);
            UpdateWithWixSharp(configFile);

            MessageBox.Show(GetContext());
        });
    }
Example #13
0
        public static ActionResult ValidateSettings(Session session)
        {
            session.Log("Begin validating warden settings...");

            ushort tcpPort;
            UInt16.TryParse(session[TcpPortPropertyName], out tcpPort);
            var portIsValid = (tcpPort > 1024 && tcpPort <= UInt16.MaxValue - 1);
            session[TcpPortValidPropertyName] = portIsValid ? "1" : "0";

            var containerPathValid = true;

            try
            {
                var containerPath = session[ContainerPathPropertyName];
                session.Log("Container Path: {0}", containerPath);

                var invalidPathChars = Path.GetInvalidPathChars();
                if (String.IsNullOrWhiteSpace(containerPath) || containerPath.Any(invalidPathChars.Contains))
                {
                    containerPathValid = false;
                }
                else
                {
                    Path.GetDirectoryName(session[ContainerPathPropertyName]);
                }
            }
            catch
            {
                containerPathValid = false;
            }

            session[ContainerPathValidPropertyName] = containerPathValid ? "1" : "0";
            return ActionResult.Success;
        }
Example #14
0
        public static ActionResult Client(Session session)
        {
            try
            {
                session.Log("Begin Client CustomAction");
                var installDir = session[INSTALLFOLDER];
                session.Log("Custom Action Using install folder: " + installDir);
                DatabaseInstall databaseInstall = new DatabaseInstall(session, installDir, "Client");
                //session.Log("Session Property Value: " + session["OSAInstallType"].ToString());

                if (databaseInstall.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    return ActionResult.Success;
                }
                else
                {
                    session.Log("OSAInstallCustomActions CustomAction - User exited");
                    return ActionResult.UserExit;
                }
            }
            catch (Exception ex)
            {
                session.Log("Exception Occured during custom action details:" + ex.Message);
                return ActionResult.Failure;
            }
        }
Example #15
0
        public static ActionResult CheckDataServiceConnection(Session session)
        {
            try
            {
                session["APPLICATIONREPOSITORY_TESTRESULT"] = "Not Checked";

                var url = session["APPLICATIONREPOSITORY_URL"];

                var request = HttpWebRequest.Create(url + "/Hermes");
                request.UseDefaultCredentials = true;

                var response = (HttpWebResponse)request.GetResponse();

                using (var stream = response.GetResponseStream())
                {
                    var buffer = new byte[4096];
                    while (stream.Read(buffer, 0, 4096) > 0) ;
                }
                session["APPLICATIONREPOSITORY_TESTRESULT"] = "1";
            }
            catch (Exception ex)
            {
                session["APPLICATIONREPOSITORY_TESTRESULT"] = "0";
                session.Log("EXCEPTION:" + Environment.NewLine + ex.ToString());
            }

            session.Log("4 ");
            return ActionResult.Success;
        }
Example #16
0
        public static ActionResult LocateInstallationPath(Session session)
        {
            session.Log("Starting sots2 location check ");
            try
            {
               var binPath = Path.Combine(Locator.GetSots2InstallLocation(), "bin\\x86");

                if (!Directory.Exists(binPath))
                {
                    session.Log("Couldn't find SOTS2 installation location. Exiting.");

                    session[Sots2InstallLocationFoundProperty] = "False";
                    //return ActionResult.Failure;
                }
                else
                {
                    session[Sots2InstallLocationFoundProperty] = "True";
                }

                session[Sots2InstallLocationProperty] = binPath;
            }
            catch (Exception ex)
            {
                session.Log("Failed to locate sots2 {0}\n{1}", ex.Message, ex.StackTrace);
                return ActionResult.Failure;
            }
            return ActionResult.Success;
        }
Example #17
0
        public static ActionResult CopySoundFiles(Session session)
        {
            session.Log("Begin CopySoundFiles");

            try
            {
                // Check that files were installed
                if (Directory.Exists(session["INSTALLLOCATION"] + @"\Sounds"))
                {
                    // Get source folder path
                    DirectoryInfo source = new DirectoryInfo(session["INSTALLLOCATION"] + @"\Sounds");

                    // Set destination folder to AGC folder in AppData
                    string destination = appdata + @"\AGC\Sounds";

                    // Create AGC folder in AppData if it doesn't exist yet
                    Directory.CreateDirectory(destination);

                    // Copy sound files to AGC folder in AppData
                    foreach (FileInfo file in source.GetFiles())
                    {
                        file.CopyTo(destination + @"\" + file.Name, true);
                    }
                }
                session.Log("End CopySoundFiles");
                return ActionResult.Success;
            }
            catch (Exception ex)
            {
                session.Log("CopySoundFiles custom action failed with exception. Exception message: " + ex.Message);
                return ActionResult.Failure;
            }
        }
        public static ActionResult UninstallClickOnce(Session session)
        {
            session.Log("Begin to uninstall ClickOnce deployment");

            var appName = session["CLICKONCEAPPNAME"];
            if (string.IsNullOrEmpty(appName))
            {
                session.Log("Please set property CLICKONCEAPPNAME.");
                return ActionResult.Failure;
            }

            try
            {
                var uninstallInfo = UninstallInfo.Find(appName);
                if (uninstallInfo == null)
                {
                    session.Log("No uninstall information found for " + appName);
                    return ActionResult.NotExecuted;
                }

                session.Log("Uninstalling " + appName);
                var uninstaller = new Uninstaller();
                uninstaller.Uninstall(uninstallInfo);
            }
            catch (Exception ex)
            {
                session.Log("ERROR in ClickOnceUninstaller custom action:\n {0}", ex.ToString());
                return ActionResult.Failure;
            }

            return ActionResult.Success;
        }
        public static ActionResult GetAppPools(Session session)
        {
            try
            {
                if (session == null) { throw new ArgumentNullException("session"); }

                // Check if running with admin rights and if not, log a message to
                // let them know why it's failing.
                if (false == HasAdminRights())
                {
                    session.Log("GetAppPools: " +
                                "ATTEMPTING TO RUN WITHOUT ADMIN RIGHTS");
                    return ActionResult.Failure;
                }

                View comboBoxView = session.Database.OpenView("select * from ComboBox");

                int order = 1;
                session.Log("Trying to retutn the app pool list");
                foreach (string appPool in IisManager.GetIisAppPools())
                {
                    Record newComboRecord = new Record("APPPOOLVALUE", order++, appPool);
                    comboBoxView.Modify(ViewModifyMode.InsertTemporary, newComboRecord);
                }

                return ActionResult.Success;
            }
            catch (Exception e)
            {
                if (session != null)
                    session.Log("Custom Action Exception " + e);
            }

            return ActionResult.Failure;
        }
Example #20
0
        public static ActionResult InstallPerformanceCounters(Session session)
        {
            session.Log("Installing NSB performance counters.");

            try
            {
                CaptureOut(() =>
                    {
                        if (PerformanceCounterSetup.SetupCounters(true))
                        {
                            session.Log("NSB performance counters installed.");
                        }
                        else
                        {
                            session.Log("NSB performance counters already installed.");
                        }
                    }, session);

                return ActionResult.Success;
            }
            catch (Exception)
            {
                return ActionResult.Failure;
            }
        }
        public static ActionResult RemoveReadOnlyAttributeCA(Session session)
        {
            // display message to allow attaching the debugger
            // MessageBox.Show("Please attach a debugger to rundll32.exe.", "Attach");

            session.Log("Begin RemoveReadOnlyAttributeCA");

            string desktopDir = System.Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory);
            string filePath   = desktopDir + "\\desktop.ini"; // full path of "desktop.ini" system file

            // Create the file if it exists.
            if (!File.Exists(filePath))
            {
                session.Log("File \"desktop.ini\" not found. Exit custom action with success.");
                return ActionResult.Success;
            }

            session.Log("File \"desktop.ini\" found at:" + filePath);

            System.IO.FileAttributes attributes = File.GetAttributes(filePath);

            if ((attributes & System.IO.FileAttributes.ReadOnly) == System.IO.FileAttributes.ReadOnly)
            {
                // Make the file RW
                attributes = RemoveAttribute(attributes, System.IO.FileAttributes.ReadOnly);
                File.SetAttributes(filePath, attributes);
                session.Log(" Read-only attribute removed for file\"desktop.ini\".");
            }

            session.Log("Exit custom action RemoveReadOnlyAttributeCA with success.");
            return ActionResult.Success;
        }
Example #22
0
        public static ActionResult UninstallDynamo07(Session session)
        {
            session.Log("Begin Dynamo uninstall.");

            try
            {
                // Dynamo 0.7.1 AppId
                // 6B5FA6CA-9D69-46CF-B517-1F90C64F7C0B
                string uninstallPath;
                if (!GetUninstallPathFromRegistry(session, out uninstallPath))
                {
                    return ActionResult.NotExecuted;
                }

                if (!string.IsNullOrEmpty(uninstallPath) && File.Exists(uninstallPath))
                {
                    Uninstall(session, uninstallPath);
                }
                else
                {
                    session.Log(string.Format("Dynamo uninstall path: {0}, could not be located.", uninstallPath));
                    return ActionResult.NotExecuted;
                }

                return ActionResult.Success;

            }
            catch (Exception ex)
            {
                session.Log("There was an error uninstalling Dynamo:");
                session.Log(ex.Message);
                return ActionResult.Failure;
            }
        }
        public static ActionResult SetUserBackupDirectorySystemFolder( Session session )
        {
            try {
                var path = session["ANDROIDBACKUPDIR"];
                if ( string.IsNullOrEmpty ( path ) ) {
                    session.Log ( "using default location for Backup path" );
                    path = Path.Combine ( Environment.GetEnvironmentVariable ( "USERPROFILE" ), "Android Backups" );
                }
                session.Log ( "Path: {0}", path );
                var dir = new DirectoryInfo ( path );
                if ( !dir.Exists ) {
                    try {
                        Directory.CreateDirectory ( path );
                    } catch ( Exception e ) {
                        session.Log ( e.ToString ( ) );
                        return ActionResult.Failure;
                    }
                }

                dir.Attributes = System.IO.FileAttributes.System | System.IO.FileAttributes.ReadOnly;

                return ActionResult.Success;
            } catch ( Exception ex ) {
                session.Log ( ex.ToString ( ) );
                return ActionResult.Failure;
            }
        }
Example #24
0
        public static ActionResult InstallMsmq(Session session)
        {
            session.Log("Installing/Starting MSMQ if necessary.");

            try
            {
                CaptureOut(() =>
                    {
                        if (MsmqSetup.StartMsmqIfNecessary(true))
                        {
                            session.Log("MSMQ installed and configured.");
                        }
                        else
                        {
                            session.Log("MSMQ already properly configured.");
                        }
                    }, session);

                return ActionResult.Success;
            }
            catch (Exception)
            {
                return ActionResult.Failure;
            }
        }
        public static ActionResult EnumerateIISWebSitesAndAppPools(Session session)
        {
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }

            session.Log("EnumerateIISWebSitesAndAppPools: Begin");

            // Check if running with admin rights and if not, log a message to let them know why it's failing.
            if (!HasAdminRights())
            {
                session.Log("EnumerateIISWebSitesAndAppPools: ATTEMPTING TO RUN WITHOUT ADMIN RIGHTS");
                return ActionResult.Failure;
            }

            session.Log("EnumerateIISWebSitesAndAppPools: Getting the IIS 7 management object");
            ActionResult result;
            using (var iisManager = new ServerManager())
            {
                result = EnumSitesIntoComboBox(session, iisManager);
                if (result == ActionResult.Success)
                {
                    result = EnumAppPoolsIntoComboBox(session, iisManager);
                }
            }

            session.Log("EnumerateIISWebSitesAndAppPools: End");
            return result;
        }
        public static ActionResult RemoveShortcuts(Session session)
        {
            try
            {
                session.Log("Removing TraceLab desktop shortcuts.");

                string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                if (String.IsNullOrEmpty(desktopPath) == false && Directory.Exists(desktopPath))
                {
                    string[] desktopShortcuts = Directory.GetFiles(desktopPath, "TraceLab*.lnk");
                    foreach (string shortcut in desktopShortcuts)
                    {
                        File.Delete(shortcut);
                    }
                }

                session.Log("Removing TraceLab start menu shortcuts.");

                string startMenuPath = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
                if (String.IsNullOrEmpty(startMenuPath) == false && Directory.Exists(startMenuPath))
                {
                    string[] startMenuFolders = Directory.GetDirectories(startMenuPath, "TraceLab", SearchOption.AllDirectories);
                    foreach (string folder in startMenuFolders)
                    {
                        Directory.Delete(folder, true);
                    }
                }
            }
            catch (Exception)
            {
            }

            return ActionResult.Success;
        }
Example #27
0
        public static ActionResult UninstallDynamo(Session session)
        {
            session.Log("Begin Dynamo uninstall.");

            try
            {
                string UninstallString;
                string UninstallParam;
                if (!GetUninstallString(session, out UninstallString, out UninstallParam))
                {
                    return ActionResult.SkipRemainingActions;
                }

                if (!string.IsNullOrEmpty(UninstallString) && File.Exists(UninstallString))
                {
                    Uninstall(session, UninstallString, UninstallParam);
                }
                else
                {
                    session.Log(string.Format("Dynamo uninstall path: {0}, could not be located.", UninstallString));
                    return ActionResult.NotExecuted;
                }

                return ActionResult.Success;
            }
            catch (Exception ex)
            {
                session.Log("There was an error uninstalling Dynamo:");
                session.Log(ex.Message);
                return ActionResult.Failure;
            }
        }
Example #28
0
    public static ActionResult CustomAction1(Session session)
    {
        session.Log("Begin CustomAction1");

           session.Log("CustomAction1: " + session.CustomActionData["INSTALLDIR"] );

           return ActionResult.Success;
    }
Example #29
0
        public static ActionResult PromptToCloseOutlook(Session session)
        {
            session.Log("Detecting running instances of Microsoft Outlook...");

            if (null != Process.GetProcessesByName("outlook").FirstOrDefault())
            {
                session.Log("Microsoft Outlook is running.");

                var record = new Record
                {
                    FormatString = "Please exit Microsoft Outlook before continuing\n" +
                    "or click Retry to close it automatically."
                };

                var result = session.Message(
                    InstallMessage.Error | (InstallMessage)MessageBoxIcon.Error |
                    (InstallMessage)MessageBoxButtons.AbortRetryIgnore, record);

                if (result == MessageResult.Abort)
                {
                    session.Log("User chose to abort the installer.");
                    return ActionResult.Failure;
                }
                if (result == MessageResult.Ignore)
                {
                    session.Log("User chose to ignore.");
                    record.FormatString = "This application will not be available until you restart Outlook.";
                    session.Message(
                    InstallMessage.Error | (InstallMessage)MessageBoxIcon.Exclamation |
                    (InstallMessage)MessageBoxButtons.OK, record);
                    return ActionResult.Success;
                }
                //check to see if it's still running
                var outlook = Process.GetProcessesByName("outlook").FirstOrDefault();
                if (outlook == null)
                {
                    session.Log("User closed Outlook");
                    return ActionResult.Success;
                }
                session.Log("User clicked Retry but Outlook is still running, attempting to kill it.");
                try
                {
                    outlook.Kill();
                }
                catch
                {
                    session.Log("Failed to kill Outlook, raising alert and returning failure.");
                    record = new Record
                    {
                        FormatString = "Outlook is still running. Open the Task Manager, end any open Outlook processes, and try this install again."
                    };
                    session.Message(
                        InstallMessage.Error | (InstallMessage)MessageBoxIcon.Error, record);
                    return ActionResult.Failure;
                }
            }
            return ActionResult.Success;
        }
        public static ActionResult UpgradeLayoutFile(Session session)
        {
            string appData = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "TraceLab");
            var path = System.IO.Path.Combine(appData, "layout.xml");

            bool resetLayout = false;
            try
            {
                if (System.IO.File.Exists(path))
                {
                    session.Log("Upgrading layout file.");

                    using (MemoryStream memStream = new MemoryStream())
                    {
                        using (var fileStream = File.OpenRead(path))
                        {
                            memStream.SetLength(fileStream.Length);
                            fileStream.Read(memStream.GetBuffer(), 0, (int)fileStream.Length);
                            memStream.Flush();
                            fileStream.Close();
                        }

                        UpgradeLayoutToCurrentVersion(memStream);

                        // The memory stream has been transformed in place, it is now time to copy it back to the file.
                        using (var fileStream = File.OpenWrite(path))
                        {
                            fileStream.Write(memStream.GetBuffer(), 0, (int)memStream.Length);
                            fileStream.SetLength(memStream.Length);
                            fileStream.Close();
                        }
                    }

                    session.Log("Done upgrading layout file.");
                }
            }
            catch (Exception e)
            {
                session.Log("Exception occurred: {0}\n{1}", e.Message, e.StackTrace);
                resetLayout = true;
            }

            if (resetLayout)
            {
                try
                {
                    session.Log("Resetting layout");
                    System.IO.File.Delete(path);
                }
                catch (Exception)
                {
                    return ActionResult.Failure;
                }
            }

            return ActionResult.Success;
        }
Example #31
0
 public static ActionResult Handle(this Microsoft.Deployment.WindowsInstaller.Session session, Func <bool> action)
 {
     try
     {
         var executed = action();
         return(executed ? ActionResult.Success : ActionResult.NotExecuted);
     }
     catch (Exception e)
     {
         session.Log(e.ToString());
         e.ToEventLog("ElasticsearchMsiInstaller");
         return(ActionResult.Failure);
     }
 }
Example #32
0
        public static int Initialize(int sessionHandle, string uiClass, int internalUILevel)
        {
            Session session = null;

            try
            {
                session = new Session((IntPtr)sessionHandle, false);

                if (String.IsNullOrEmpty(uiClass))
                {
                    throw new ArgumentNullException("uiClass");
                }

                EmbeddedUIProxy.uiInstance = EmbeddedUIProxy.InstantiateUI(session, uiClass);
            }
            catch (Exception ex)
            {
                if (session != null)
                {
                    try
                    {
                        session.Log("Exception while loading embedded UI:");
                        session.Log(ex.ToString());
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            if (EmbeddedUIProxy.uiInstance == null)
            {
                return((int)ActionResult.Failure);
            }

            try
            {
                string           resourcePath = Path.GetDirectoryName(EmbeddedUIProxy.uiInstance.GetType().Assembly.Location);
                InstallUIOptions uiOptions    = (InstallUIOptions)internalUILevel;
                if (EmbeddedUIProxy.DebugBreakEnabled("Initialize"))
                {
                    System.Diagnostics.Debugger.Launch();
                }

                if (EmbeddedUIProxy.uiInstance.Initialize(session, resourcePath, ref uiOptions))
                {
                    // The embedded UI initialized and the installation should continue
                    // with internal UI reset according to options.
                    return(((int)uiOptions) << 16);
                }
                else
                {
                    // The embedded UI did not initialize but the installation should still continue
                    // with internal UI reset according to options.
                    return((int)uiOptions);
                }
            }
            catch (InstallCanceledException)
            {
                // The installation was canceled by the user.
                return((int)ActionResult.UserExit);
            }
            catch (Exception ex)
            {
                // An unhandled exception causes the installation to fail immediately.
                session.Log("Exception thrown by embedded UI initialization:");
                session.Log(ex.ToString());
                return((int)ActionResult.Failure);
            }
        }
Example #33
0
        public static int InvokeCustomAction(int sessionHandle, string entryPoint,
                                             IntPtr remotingDelegatePtr)
        {
            Session    session = null;
            string     assemblyName, className, methodName;
            MethodInfo method;

            try
            {
                MsiRemoteInvoke remotingDelegate = (MsiRemoteInvoke)
                                                   Marshal.GetDelegateForFunctionPointer(
                    remotingDelegatePtr, typeof(MsiRemoteInvoke));
                RemotableNativeMethods.RemotingDelegate = remotingDelegate;

                sessionHandle = RemotableNativeMethods.MakeRemoteHandle(sessionHandle);
                session       = new Session((IntPtr)sessionHandle, false);
                if (String.IsNullOrEmpty(entryPoint))
                {
                    throw new ArgumentNullException("entryPoint");
                }

                if (!CustomActionProxy.FindEntryPoint(
                        session,
                        entryPoint,
                        out assemblyName,
                        out className,
                        out methodName))
                {
                    return((int)ActionResult.Failure);
                }
                session.Log("Calling custom action {0}!{1}.{2}", assemblyName, className, methodName);

                method = CustomActionProxy.GetCustomActionMethod(
                    session,
                    assemblyName,
                    className,
                    methodName);
                if (method == null)
                {
                    return((int)ActionResult.Failure);
                }
            }
            catch (Exception ex)
            {
                if (session != null)
                {
                    try
                    {
                        session.Log("Exception while loading custom action:");
                        session.Log(ex.ToString());
                    }
                    catch (Exception) { }
                }
                return((int)ActionResult.Failure);
            }

            try
            {
                // Set the current directory to the location of the extracted files.
                Environment.CurrentDirectory =
                    Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

                object[] args = new object[] { session };
                if (DebugBreakEnabled(new string[] { entryPoint, methodName }))
                {
                    string message = String.Format(
                        "To debug your custom action, attach to process ID {0} (0x{0:x}) and click OK; otherwise, click Cancel to fail the custom action.",
                        System.Diagnostics.Process.GetCurrentProcess().Id
                        );

                    MessageResult button = NativeMethods.MessageBox(
                        IntPtr.Zero,
                        message,
                        "Custom Action Breakpoint",
                        (int)MessageButtons.OKCancel | (int)MessageIcon.Asterisk | (int)(MessageBoxStyles.TopMost | MessageBoxStyles.ServiceNotification)
                        );

                    if (MessageResult.Cancel == button)
                    {
                        return((int)ActionResult.UserExit);
                    }
                }

                ActionResult result = (ActionResult)method.Invoke(null, args);
                session.Close();
                return((int)result);
            }
            catch (InstallCanceledException)
            {
                return((int)ActionResult.UserExit);
            }
            catch (Exception ex)
            {
                session.Log("Exception thrown by custom action:");
                session.Log(ex.ToString());
                return((int)ActionResult.Failure);
            }
        }