Example #1
1
        public static ActionResult Install(Session session)
        {
            // download version information
            session.Message(InstallMessage.ActionStart, new Record("callAddProgressInfo", "Downloading WifiRemote update information...", ""));
            Uri downloadUri;
            InitializeVersionInformation(session, out downloadUri);

            // bail out if installed version is the newest one
            if (installedVersion != null && installedVersion.CompareTo(onlineVersion) >= 0 && installedVersion.CompareTo(packagedVersion) >= 0)
            {
                Log.Write("WifiRemote: Installed version is the last one, doing nothing...");
                return ActionResult.Success;
            }

            // setup for installation
            string mpeiPackagePath = Path.GetTempFileName();
            bool extractFromMSI = false;

            // should we download a newer version?
            if (onlineVersion != null && packagedVersion.CompareTo(onlineVersion) < 0)
            {
                Log.Write("WifiRemote: Downloading newer version from update site");

                session.Message(InstallMessage.ActionStart, new Record("callAddProgressInfo", "Downloading WifiRemote installer...", ""));
                if (!DownloadWifiRemote(downloadUri, mpeiPackagePath))
                {
                    Log.Write("WifiRemote: Failed to download it, continuing with extracting from MSI");
                    extractFromMSI = true;
                }
            }
            else
            {
                Log.Write("WifiRemote: Not downloading version from update site");
                extractFromMSI = true;
            }

            // else extract from package
            if (extractFromMSI)
            {
                Log.Write("WifiRemote: Extracting package from MSI");
                if (!InstallerDatabase.ExtractBinaryToFile(session, "WifiRemoteInstallerBin", mpeiPackagePath))
                {
                    Log.Write("WifiRemote: Failed to extract from MSI");
                    return ActionResult.Failure;
                }
            }
            Log.Write("WifiRemote: Got WifiRemote installer in {0}", mpeiPackagePath);

            // lookup MPEI installer location
            session.Message(InstallMessage.ActionStart, new Record("callAddProgressInfo", "Installing WifiRemote MediaPortal plugin with MPEI...", ""));
            string mpei = LookupMPEI();
            if (mpei == null)
            {
                return ActionResult.NotExecuted;
            }
            Log.Write("WifiRemote: Found MPEI at {0}", mpei);

            // execute
            ProcessStartInfo param = new ProcessStartInfo();
            param.FileName = mpei;
            param.Arguments = mpeiPackagePath + " /S";
            Log.Write("WifiRemote: Starting MPEI with arguments {0}", param.Arguments);
            Process proc = new Process();
            proc.StartInfo = param;
            proc.Start();
            proc.WaitForExit();
            Log.Write("WifiRemote: MPEI finished with exit code {0}", proc.ExitCode);

            // cleanup
            File.Delete(mpeiPackagePath);
            return ActionResult.Success;
        }
        public static void ThrowInstallError(Session session, string errorMessage)
        {
            var record = new Record(1);
            record[1] = errorMessage;

            session.Message(InstallMessage.FatalExit, record);
        }
 /// <summary>
 ///     Increases the progress bar indicated the number of ticks.
 /// </summary>
 /// <param name="session">Windows Installer Session .</param>
 /// <param name="tickIncrement">Número de ticks de incremento.</param>
 /// <returns>message handler .</returns>
 public static MessageResult IncrementProgress(Session session, int tickIncrement)
 {
     var record = new Record(2);
     record[1] = "2"; // Set the progress bar increasing
     record[2] = tickIncrement.ToString(); // Number of ticks to be increased at the progress bar .
     //record[3] = 0;
     return session.Message(InstallMessage.Progress, record);
 }
Example #4
0
        /// <summary>
        /// Send an action start message. This only works with deferred custom actions
        /// </summary>
        public static MessageResult SendActionStart(this Microsoft.Deployment.WindowsInstaller.Session session, int totalTicks, string actionName, string message, string actionDataTemplate = null)
        {
            // http://www.indigorose.com/webhelp/msifact/Program_Reference/LuaScript/Actions/MSI.ProcessMessage.htm
            // [1] action name (must match the name in the MSI Tables),
            // [2] description,
            // [3] template for InstallMessage.ActionData messages e.g. [1], [2],
            //     etc. relate to the index of values sent in a proceeding ActionData
            using (var record = new Record(actionName, message, actionDataTemplate ?? message))
            {
                session.Message(InstallMessage.ActionStart, record);
            }

            // http://windows-installer-xml-wix-toolset.687559.n2.nabble.com/Update-progress-bar-from-deferred-custom-action-td4994990.html
            // reset the progress bar.
            // [1] 0 = Reset progress bar,
            // [2] N = Total ticks in bar,
            // [3] 0 = Forward progress,
            // [4] 0 = Execution in progress i.e. Time remaining
            using (var record = new Record(0, totalTicks, 0, 0))
            {
                session.Message(InstallMessage.Progress, record);
            }

            // tell the installer to use Explicit Progress messages
            using (var record = new Record(1, 1, 0))
            {
                return(session.Message(InstallMessage.Progress, record));
            }
        }
		public static ActionResult RemoveClickOnceInstalls(Session Session)
		{
			string ShortcutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Programs), "UnrealGameSync", "UnrealGameSync.appref-ms");
			if(!File.Exists(ShortcutPath))
			{
				Session.Log("Couldn't find {0} - skipping uninstall", ShortcutPath);
				return ActionResult.Success;
			}

			Record Record = new Record(1); 
			Record.FormatString = "The previous version of UnrealGameSync cannot be removed automatically.\n\nPlease uninstall from the following window.";
			MessageResult Result = Session.Message(InstallMessage.User | (InstallMessage)MessageBoxButtons.OKCancel, Record);
			if(Result == MessageResult.Cancel)
			{
				return ActionResult.UserExit;
			}

			Process NewProcess = Process.Start("rundll32.exe", "dfshim.dll,ShArpMaintain UnrealGameSync.application, Culture=neutral, PublicKeyToken=0000000000000000, processorArchitecture=msil");
			NewProcess.WaitForExit();
			
			if(File.Exists(ShortcutPath))
			{
				Record IgnoreRecord = new Record(1); 
				IgnoreRecord.FormatString = "UnrealSync is still installed. Install newer version anyway?";

				if(Session.Message(InstallMessage.User | (InstallMessage)MessageBoxButtons.YesNo, IgnoreRecord) == MessageResult.No)
				{
					return ActionResult.UserExit;
				}
			}

			return ActionResult.Success;
		}
Example #6
0
        public static ActionResult Install(Session session)
        {
            // fail very early if we can't find MPEI
            string mpei = LookupMPEI();
            if (mpei == null)
            {
                Log.Write("WifiRemote: MPEI not available");
                return ActionResult.NotExecuted;
            }
            Log.Write("WifiRemote: Found MPEI at {0}", mpei);

            // download version information
            session.Message(InstallMessage.ActionStart, new Record("callAddProgressInfo", "Downloading WifiRemote update information...", ""));
            Uri downloadUri;
            InitializeVersionInformation(session, out downloadUri);

            // fail early if we couldn't find the online version
            if (onlineVersion == null)
            {
                Log.Write("WifiRemote: Online version unavailable, aborting installation...");
                return ActionResult.Success;
            }

            // don't do anything if installed version is the newest one
            if (installedVersion != null && installedVersion >= onlineVersion)
            {
                Log.Write("WifiRemote: Installed version is the last one, doing nothing...");
                return ActionResult.Success;
            }

            // setup for installation
            string mpeiPackagePath = Path.GetTempFileName();
            session.Message(InstallMessage.ActionStart, new Record("callAddProgressInfo", "Downloading WifiRemote installer...", ""));
            if (!DownloadWifiRemote(downloadUri, mpeiPackagePath))
            {
                Log.Write("WifiRemote: Failed to download version from internet, aborting installation...");
                return ActionResult.Success;
            }
            Log.Write("WifiRemote: Got WifiRemote installer in {0}", mpeiPackagePath);

            // execute
            session.Message(InstallMessage.ActionStart, new Record("callAddProgressInfo", "Installing WifiRemote MediaPortal plugin with MPEI...", ""));
            ProcessStartInfo param = new ProcessStartInfo();
            param.FileName = mpei;
            param.Arguments = mpeiPackagePath + " /S";
            Log.Write("WifiRemote: Starting MPEI with arguments {0}", param.Arguments);
            Process proc = new Process();
            proc.StartInfo = param;
            proc.Start();
            proc.WaitForExit();
            Log.Write("WifiRemote: MPEI finished with exit code {0}", proc.ExitCode);

            // cleanup
            File.Delete(mpeiPackagePath);
            return ActionResult.Success;
        }
Example #7
0
        public static ActionResult CheckApplicationExists(Session session) {
            var deploymentManifest = new Uri(session["DeploymentManifest"]);
            var downloadTask = (Task<GetManifestCompletedEventArgs>)null;

            using(var host = new InPlaceHostingManager(deploymentManifest, false)) {
                downloadTask = host.DownloadManifestAsync();

                downloadTask.Wait();

                if(downloadTask.IsCanceled) {
                    return ActionResult.UserExit;
                }
                else if(downloadTask.IsFaulted) {
                    session.Message(InstallMessage.Error, new Record { FormatString = downloadTask.Exception.ToString() });
                    return ActionResult.Failure;
                }

                var manifest = downloadTask.Result;

                var result = manifest.ApplicationManifest.CheckApplicationExists();

                if(result == ActionResult.SkipRemainingActions) {
                    session.Log("{0} is already installed.", manifest.ProductName);
                }

                return result;
            }
        }
 public static MessageResult IncrementProgressBar(Session session, int progressPercentage)
 {
     var record = new Record(3);
     record[1] = 2; // "ProgressReport" message
     record[2] = progressPercentage; // ticks to increment
     record[3] = 0; // ignore
     return session.Message(InstallMessage.Progress, record);
 }
 /*
  * helper methods to control the progress bar
  * kudos to a fellow developer http://windows-installer-xml-wix-toolset.687559.n2.nabble.com/Update-progress-bar-from-deferred-custom-action-tt4994990.html#a4997563
  */
 public static MessageResult ResetProgressBar(Session session, int totalStatements)
 {
     var record = new Record(3);
     record[1] = 0; // "Reset" message
     record[2] = totalStatements;  // total ticks
     record[3] = 0; // forward motion
     return session.Message(InstallMessage.Progress, record);
 }
Example #10
0
        /// <summary>
        /// Send a progress message. This only works with deferred custom actions
        /// </summary>
        public static MessageResult SendProgress(this Microsoft.Deployment.WindowsInstaller.Session session, int tickIncrement, params object[] actionDataTemplateParameters)
        {
            if (actionDataTemplateParameters.Any())
            {
                // [N] = These are values for the placeholders in the ActionStart template that precedes the ActionData.
                using (var record = new Record(actionDataTemplateParameters))
                {
                    session.Message(InstallMessage.ActionData, record);
                }
            }

            // [1] 2 = Increment the progress bar,
            // [2] N = Number of ticks to move the progress bar,
            // [3] 0 = Unused (but exists in sample)
            using (var record = new Record(2, tickIncrement, 0))
            {
                return(session.Message(InstallMessage.Progress, record));
            }
        }
        /*
         * helper method used to send the actiontext message to the MSI
         * kudos to a fellow developer http://community.flexerasoftware.com/archive/index.php?t-181773.html
         */
        internal static void StatusMessage(Session session, string status)
        {
            Record record = new Record(3);
            record[1] = "callAddProgressInfo";
            record[2] = status;
            record[3] = "Incrementing tick [1] of [2]";

            session.Message(InstallMessage.ActionStart, record);
            Application.DoEvents();
        }
Example #12
0
 public ActionResult DoAction(Session session)
 {
     Record record = new Record(3);
       for (int i = 1; i <= 100; i++)
       {
     record[1] = "ProgressMessageDemo";
     record[2] = string.Format("Выполнение Demo-плагина (выполнено {0}%)", i);
     record[3] = "";
     session.Message(InstallMessage.ActionStart, record);
     Thread.Sleep(20);
       }
       return ActionResult.Success;
 }
Example #13
0
        public static ActionResult DownloadApplication(Session session) {
            var deploymentManifest = new Uri(session["DeploymentManifest"]);
            var cancellationTokenSource = new CancellationTokenSource();
            var previousProgressPercentage = 0;
            var downloadTask = (Task)null;

            DisplayActionData(session, "Hello, World!");

            ResetProgress(session);

            using(var host = new InPlaceHostingManager(deploymentManifest, false)) {
                downloadTask = host.DownloadManifestAsync();

                downloadTask.Wait();

                if(downloadTask.IsCanceled) {
                    return ActionResult.UserExit;
                }
                else if(downloadTask.IsFaulted) {
                    session.Message(InstallMessage.Error, new Record { FormatString = downloadTask.Exception.ToString() });
                    return ActionResult.Failure;
                }
                // Requirements
                host.AssertApplicationRequirements(true);

                // Download
                downloadTask = host.DownloadApplicationAsync(progress => {
                    session.Log("Downloaded {0,10}", (((double)progress.ProgressPercentage) / 100d).ToString("P"));

                    IncrementProgress(session, progress.ProgressPercentage - previousProgressPercentage);

                    previousProgressPercentage = progress.ProgressPercentage;
                });

                downloadTask.Wait();

                if(downloadTask.IsCanceled) {
                    return ActionResult.UserExit;
                }
                else if(downloadTask.IsFaulted) {
                    session.Message(InstallMessage.Error, new Record { FormatString = downloadTask.Exception.ToString() });
                    return ActionResult.Failure;
                }
            }

            return ActionResult.Success;
        }
        /// <summary>
        ///     Resets the progress bar to zero and sets a new value for total ticks..
        /// </summary>
        /// <param name="session">Windows Installer Session.</param>
        /// <param name="totalTicks">Total number of ticks.</param>
        /// <returns>Returns the message handler .</returns>
        public static MessageResult ResetProgress(Session session, int totalTicks)
        {
            var record = new Record(4);
            record[1] = "0"; // / Set reset progress bar and set the total number of ticks of the bar

            record[2] = totalTicks.ToString(); // Total ticks

            //Move progress bar
            // 0: Moving forward from left to right . 1: Way back from right to left )
            record[3] = "0";

            // 0: Execution in progress, the UI calculates and displays the time remaining 
            // 1: Creating script execution . The UI displays a message while the installer finishes preparing the installation.
            record[4] = "0";

            return session.Message(InstallMessage.Progress, record);
        }
        /// <summary>
        ///     Set the amount to increase the progress bar for each message sent ActionData .
        /// </summary>
        /// <param name="session">  Windows Installer Session.</param>
        /// <param name="ticks"> Number of ticks to be added to the progress bar.</param>
        /// <param name="increaseForActionData">
        ///     Indicates whether the progress bar increases with each message sent by ActionData:
        ///     <para>False: : Indicates send the current message to the progress report.</para>
        ///     <para>
        ///         True: Indicates increase the progress bar in each ActionData in the number of ticks <paramref name="ticks" />
        ///         .
        ///     </para>
        /// </param>
        /// <returns>Returns message handler.</returns>
        public static MessageResult NumberOfTicksPerActionData(Session session, int ticks, bool increaseForActionData)
        {
            var record = new Record(3);
            record[1] = "1"; // Provides information related to the progress message sent by the current action

            // Ticks ActionData increase in each message sent by the custom action , this value is ignored if field 3 is 0
            record[2] = ticks.ToString();

            if (increaseForActionData)
            {
                record[3] = "1";
                // Set the progress bar increasing in each ActionData in the number of ticks in field 2 espeficicados
            }
            else
            {
                record[3] = "0"; // / Set the current message to send progress report 
            }
            return session.Message(InstallMessage.Progress, record);
        }
        // Method to log to session
        private static void LogInstallMessage(Session session, InstallMessage messageType, string message)
        {
            using (Record record = new Record(0))
            {
                // Square brackets and curly braces are evaluated upon logging the message so we escape them here
                record.FormatString = Regex.Replace(message, @"[\[\]{}]", @"[\$&]");

                // session.Log and session.Message both make use of MsiProcessMessage, which cannot be used during a DoAction ControlEvent.
                // https://msdn.microsoft.com/en-us/library/aa368322(VS.85).aspx
                //
                // Fortunately, session.Message returns a code that can be used to determine whether the call actually logged a message.
                // Setting the value of a property also generates a message in the log file so we use that as a workaround.
                if (session.Message(messageType, record) == MessageResult.None)
                    session["LOGMESSAGE"] = message;
            }
        }
Example #17
0
		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;
		}
Example #18
0
 public static ActionResult SampleCustomAction2(Session session)
 {
     using (Record msgRec = new Record(0))
     {
         msgRec[0] = "Hello from SampleCA2!";
         session.Message(InstallMessage.Info, msgRec);
         session.Message(InstallMessage.User, msgRec);
     }
     return ActionResult.UserExit;
 }
Example #19
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;
 }
Example #20
0
        public static ActionResult SampleCA1(Session session)
        {
            using (Record msgRec = new Record(0))
            {
                msgRec[0] = "Hello from SampleCA1!" +
                    "\r\nCLR version is v" + Environment.Version;
                session.Message(InstallMessage.Info, msgRec);
                session.Message(InstallMessage.User, msgRec);
            }

            session.Log("Testing summary info...");
            SummaryInfo summInfo = session.Database.SummaryInfo;
            session.Log("MSI PackageCode = {0}", summInfo.RevisionNumber);
            session.Log("MSI ModifyDate = {0}", summInfo.LastSaveTime);

            string testProp = session["SampleCATest"];
            session.Log("Simple property test: [SampleCATest]={0}.", testProp);

            session.Log("Testing subdirectory extraction...");
            string testFilePath = "testsub\\SampleCAs.cs";
            if (!File.Exists(testFilePath))
            {
                session.Log("Subdirectory extraction failed. File not found: " + testFilePath);
                return ActionResult.Failure;
            }
            else
            {
                session.Log("Found file extracted in subdirectory.");
            }

            session.Log("Testing record stream extraction...");
            string tempFile = null;
            try
            {
                tempFile = Path.GetTempFileName();
                using (View binView = session.Database.OpenView(
                    "SELECT `Binary`.`Data` FROM `Binary`, `CustomAction` " +
                    "WHERE `CustomAction`.`Target` = 'SampleCA1' AND " +
                    "`CustomAction`.`Source` = `Binary`.`Name`"))
                {
                    binView.Execute();
                    using (Record binRec = binView.Fetch())
                    {
                        binRec.GetStream(1, tempFile);
                    }
                }

                session.Log("CA binary file size: {0}", new FileInfo(tempFile).Length);
                string binFileVersion = Installer.GetFileVersion(tempFile);
                session.Log("CA binary file version: {0}", binFileVersion);
            }
            finally
            {
                if (tempFile != null && File.Exists(tempFile))
                {
                    File.Delete(tempFile);
                }
            }

            session.Log("Testing record stream reading...");
            using (View binView2 = session.Database.OpenView("SELECT `Data` FROM `Binary` WHERE `Name` = 'TestData'"))
            {
                binView2.Execute();
                using (Record binRec2 = binView2.Fetch())
                {
                    Stream stream = binRec2.GetStream("Data");
                    string testData = new StreamReader(stream, System.Text.Encoding.UTF8).ReadToEnd();
                    session.Log("Test data: " + testData);
                }
            }

            session.Log("Listing components");
            using (View compView = session.Database.OpenView(
                "SELECT `Component` FROM `Component`"))
            {
                compView.Execute();
                foreach (Record compRec in compView)
                {
                    using (compRec)
                    {
                        session.Log("\t{0}", compRec["Component"]);
                    }
                }
            }

            session.Log("Testing the ability to access an external MSI database...");
            string tempDbFile = Path.GetTempFileName();
            using (Database tempDb = new Database(tempDbFile, DatabaseOpenMode.CreateDirect))
            {
                // Just create an empty database.
            }
            using (Database tempDb2 = new Database(tempDbFile))
            {
                // See if we can open and query the database.
                IList<string> tables = tempDb2.ExecuteStringQuery("SELECT `Name` FROM `_Tables`");
                session.Log("Found " + tables.Count + " tables in the newly created database.");
            }
            File.Delete(tempDbFile);

            return ActionResult.Success;
        }
Example #21
0
        private static void ResetProgress(Session session, int value = 100) {
            var record = new Record(4);
            record[1] = 0;      // "Reset" message 
            record[2] = value - (value * 0.05); // total ticks;
            record[3] = 0;      // forward motion 
            record[4] = 0;
            session.Message(InstallMessage.Progress, record);

            record = new Record(4);
            record[1] = 1;
            record[2] = 1;
            record[3] = 0;
            session.Message(InstallMessage.Progress, record);
        }
 /// <summary>
 ///     Updates the status message displayed to the user
 /// </summary>
 /// <param name="session">Windows Installer Session.</param>
 /// <param name="actionName">Name of the action to be executed.</param>
 /// <param name="status">
 ///     text with the state. The text is presented in the control that subscribes to the event
 ///     "ActionText".
 /// </param>
 /// <param name="template">
 ///     Text Template advance process.
 ///     ElThe text is presented in a control that subscribes to the event: ActionData
 ///     Example: " Running the task [1 ] of [2 ]"
 /// </param>
 /// <returns>Returns message handler .</returns>
 public static MessageResult DisplayStatusActionStart(Session session, string actionName, string status,
     string template)
 {
     var record = new Record(3);
     record[1] = actionName;
     record[2] = status;
     record[3] = template;
     return session.Message(InstallMessage.ActionStart, record);
 }
Example #23
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;
        }
Example #24
0
 private static void DisplayActionData(Session session, string message) {
     Record record = new Record(3);
     record[1] = "DownloadApplication";
     record[2] = "Hello WOrld";
     record[3] = "Hello record three";
     session.Message(InstallMessage.ActionStart, record);
 }
Example #25
0
 private static void IncrementProgress(Session session, int value) {
     var record = new Record(3);
     record[1] = 2;      // ProgressReport message 
     record[2] = value;  // ticks to increment 
     record[3] = 0;      // ignore 
     session.Message(InstallMessage.Progress, record);
 }
 /// <summary>
 ///     Presents a dialog ActionData message and increases the progress bar.
 ///     The template is set to the <see cref="DisplayStatusActionStart()" /> method should look like:
 ///     "Script [1] / [2]"
 /// </summary>
 /// <param name="session">Windows Installer Session .</param>
 /// <param name="parameter1">Parameter  1.</param>
 /// <param name="parameter2">Parameter  2.</param>
 /// <returns> Returns message handler.</returns>
 public static MessageResult DisplayActionData2(Session session, string parameter1, string parameter2)
 {
     var record = new Record(2);
     record[1] = parameter1;
     record[2] = parameter2;
     //record[3] = "Executing job  [1] de [2]";
     return session.Message(InstallMessage.ActionData, record);
 }
 /// <summary>
 ///     Presents a dialog ActionData message and increases the progress bar .
 /// </summary>
 /// <param name="session">  Windows Installer Session.</param>
 /// <param name="message">message to be presented.</param>
 /// <returns>returns message handler .</returns>
 public static MessageResult DisplayActionData(Session session, string message)
 {
     var record = new Record(1);
     record[1] = message;
     return session.Message(InstallMessage.ActionData, record);
 }
 /// <summary>
 ///     Presents a dialog ActionData message and increases the progress bar.
 ///     The template is set to the <see cref="DisplayStatusActionStart()" /> method should look like:
 ///     "Script [1] / [2]: [3]"
 /// </summary>
 /// <param name="session">  Windows Installer Session.</param>
 /// <param name="parameter1">Parameter  1.</param>
 /// <param name="parameter2">Parameter  2.</param>
 /// <param name="parameter3">Parameter  3.</param>
 /// <returns> Returns message handler.</returns>
 public static MessageResult DisplayActionData3(Session session, string parameter1, string parameter2,
     string parameter3)
 {
     var record = new Record(3);
     record[1] = parameter1;
     record[2] = parameter2;
     record[3] = parameter3;
     return session.Message(InstallMessage.ActionData, record);
 }
Example #29
0
 static void DisplayMSIError(Session session, string msg)
 {
     var r = new Record();
     r.SetString(0, msg);
     session.Message(InstallMessage.Error, r);
 }
Example #30
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;
		}
Example #31
0
        public static bool Install(Session session)
        {
            // download WifiRemote update information
            session.Message(InstallMessage.ActionStart, new Record("callAddProgressInfo", "Downloading WifiRemote update information...", ""));
            Uri downloadUri;
            WifiRemoteState infoState = GetWifiRemoteVersionInfo(session, out downloadUri);
            Dictionary<WifiRemoteState, string> messages = new Dictionary<WifiRemoteState,string>() {
                { WifiRemoteState.Error, "WifiRemote: failed to download update information, using packaged version" },
                { WifiRemoteState.OlderVersionAvailable, "WifiRemote: older version available online then we shipped... strange, using packaged version" },
                { WifiRemoteState.SameVersion, "WifiRemote: last version packaged, installing from MSI" },
                { WifiRemoteState.NewerVersionAvailable, "WifiRemote: newer version available, downloading it" }
            };
            Log.Write(messages[infoState]);

            // download newer WifiRemote if needed
            string mpeiPackagePath = Path.GetTempFileName();
            bool downloadFailed = false;
            if (infoState == WifiRemoteState.NewerVersionAvailable)
            {
                session.Message(InstallMessage.ActionStart, new Record("callAddProgressInfo", "Downloading WifiRemote installer...", ""));
                if (!DownloadWifiRemote(downloadUri, mpeiPackagePath))
                {
                    Log.Write("WifiRemote: failed to download it, continuing with extracting from MSI");
                    downloadFailed = true;
                }
            }

            // else extract from package
            if(infoState != WifiRemoteState.NewerVersionAvailable || downloadFailed)
            {
                Log.Write("WifiRemote: extracting package from MSI");
                if (!InstallerDatabase.ExtractBinaryToFile(session, "WifiRemoteInstallerBin", mpeiPackagePath))
                {
                    Log.Write("WifiRemote: failed to extract from MSI");
                    return false;
                }
            }
            Log.Write("WifiRemote: got WifiRemote installer in {0}", mpeiPackagePath);

            // lookup MPEI installer location
            session.Message(InstallMessage.ActionStart, new Record("callAddProgressInfo", "Installing WifiRemote MediaPortal plugin with MPEI...", ""));
            string mpei = LookupMPEI();
            if (mpei == null)
            {
                return false;
            }
            Log.Write("WifiRemote: found MPEI at {0}", mpei);

            // execute
            ProcessStartInfo param = new ProcessStartInfo();
            param.FileName = mpei;
            param.Arguments = mpeiPackagePath + " /S";
            Log.Write("WifiRemote: starting MPEI with arguments {0}", param.Arguments);
            Process proc = new Process();
            proc.StartInfo = param;
            proc.Start();
            proc.WaitForExit();
            Log.Write("WifiRemote: MPEI finished with exit code {0}", proc.ExitCode);

            // cleanup
            File.Delete(mpeiPackagePath);
            return true;
        }
 /// <summary>
 ///     / Increase the current value of all ticks in the specified amount.
 ///     You can use this method the UI phase , a custom action with attribute Execute="immediate"
 ///     When executing prepared scripts.
 /// </summary>
 /// <param name="session">Windows Installer Session .</param>
 /// <param name="totalTicks">number of ticks to be added .</param>
 /// <returns>message handler .</returns>
 public static MessageResult IncrementTotalTicks(Session session, int totalTicks)
 {
     var record = new Record(2);
     record[1] = "3"; // Indicates increase the total number of ticks of the progress bar.
     record[2] = totalTicks.ToString(); // Number of ticks to be added to the current total of the progress bar.
     return session.Message(InstallMessage.Progress, record);
 }