Example #1
0
        private static void UninstallMsiPackage(InstallPackage ip)
        {
            string argsPatt;

            if (!string.IsNullOrEmpty(ip.InstallArgs))
            {
                argsPatt = ip.UninstallArgs;
            }
            else if (!string.IsNullOrEmpty(ip.QuietInstallArgs))
            {
                argsPatt = ip.QuietUninstallArgs;
            }
            else
            {
                argsPatt = @"/uninstall ""{0}"" /qn /norestart /lv ""{1}""";
            }

            var args = string.Format(
                argsPatt, ip.FilePath, ip.FilePath + ".uninstall.log");

            var p = new Process
            {
                StartInfo =
                    new ProcessStartInfo
                    {
                        FileName = @"msiexec",
                        Arguments = args,
                        UseShellExecute = false,
                        CreateNoWindow = true,
                    }
            };

            p.Start();

            p.WaitForExit();
        }
Example #2
0
        private static void UninstallExePackage(InstallPackage ip)
        {
            var argsPatt = !string.IsNullOrEmpty(ip.InstallArgs)
                ? ip.UninstallArgs
                : ip.QuietUninstallArgs;

            var logPath = string.Format(@"\""{0}.uninstall.log\""", ip.FilePath);
            
            var args = string.Format(argsPatt, logPath);

            var p = new Process
            {
                StartInfo =
                    new ProcessStartInfo
                    {
                        FileName = ip.FilePath,
                        Arguments = args,
                        UseShellExecute = false,
                        CreateNoWindow = true,
                    }
            };

            p.Start();

            p.WaitForExit();
        }
Example #3
0
        private static void InstallMsiPackage(
            InstallPackage ip, bool lastPackage)
        {
            string argsPatt;

            var showInstaller = false;

            // If this is the last package being installed then
            // it should be considered the target package of the
            // bootstrapper. Check to see if a package with the
            // same ProductCode is already installed, and if it
            // is then show the installer.
            if (lastPackage)
            {
                var newPc = MsiUtil.GetProductCode(new FileInfo(ip.FilePath));

                // Find the old product code if it exists.
                foreach (var prod in MsiUtil.Products)
                {
                    if (prod.ProductCode == newPc)
                    {
                        showInstaller = true;
                        break;
                    }
                }
            }

            if (showInstaller)
            {
                argsPatt = !string.IsNullOrEmpty(ip.InstallArgs)
                    ? ip.InstallArgs
                    : @"/i ""{0}"" /norestart /lv ""{1}""";
            }
            else
            {
                if (!string.IsNullOrEmpty(ip.InstallArgs))
                {
                    argsPatt = ip.InstallArgs;
                }
                else if (!string.IsNullOrEmpty(ip.QuietInstallArgs))
                {
                    argsPatt = ip.QuietInstallArgs;
                }
                else
                {
                    argsPatt = @"/i ""{0}"" /qn /norestart /lv ""{1}""";
                }
            }

            var args = string.Format(
                argsPatt, ip.FilePath, ip.FilePath + ".install.log");

            // Launch the target installer.
            var p = new Process
            {
                StartInfo =
                    new ProcessStartInfo
                    {
                        FileName = @"msiexec",
                        Arguments = args,
                        UseShellExecute = false,
                        CreateNoWindow = !showInstaller,
                    }
            };

            p.Start();

            if (showInstaller)
            {
                Application.Exit();
                return;
            }

            p.WaitForExit();
            ProcessExitCode(ip, p.ExitCode);
        }
Example #4
0
        private static void ProcessExitCode(InstallPackage ip, int exitCode)
        {
            var success = false;

            foreach (var i in ip.ExitCodes)
            {
                if (i == exitCode)
                {
                    success = true;
                    break;
                }
            }

            if (!success)
            {
                InstallError =
                    string.Format(
                        @"An error occurred while installing {0}. An exit code of '{1}' was returned.",
                        ip.Name,
                        exitCode);
            }
        }
Example #5
0
        private static void UninstallInstallPackage(InstallPackage ip)
        {
            SendInstallMessage(@"Unnstalling " + ip.Name);

            switch (ip.Extension)
            {
                case @"msi":
                {
                    UninstallMsiPackage(ip);
                    break;
                }
                case @"exe":
                {
                    UninstallExePackage(ip);
                    break;
                }
            }

            DecrementInstallProgress();
        }
Example #6
0
        private static void InstallInstallPackage(
            InstallPackage ip, bool lastPackage)
        {
            SendInstallMessage(@"Installing " + ip.Name);

            switch (ip.Extension)
            {
                case @"msi":
                {
                    InstallMsiPackage(ip, lastPackage);
                    break;
                }
                case @"exe":
                {
                    InstallExePackage(ip);
                    break;
                }
            }

            IncrementInstallProgress();
        }
Example #7
0
        private static void ExtractInstallPackage(InstallPackage ip)
        {
            SendInstallMessage(@"Extracting " + ip.Name);

            var fs = new FileStream(ip.FilePath, FileMode.Create);

            foreach (var rk in ip.ResourceKeys)
            {
                var fd = (byte[]) ResourceManager.GetObject(rk);
                // ReSharper disable PossibleNullReferenceException
                fs.Write(fd, 0, fd.Length);
                // ReSharper restore PossibleNullReferenceException
            }

            fs.Close();

            IncrementInstallProgress();
        }
Example #8
0
        private static bool ValidateInstallPackage(InstallPackage ip)
        {
            foreach (var x in ip.RegKeys)
            {
                if (!ProcessRegKey(x))
                {
                    return false;
                }
            }

            foreach (var x in ip.RegValues)
            {
                if (!ProcessRegValue(x))
                {
                    return false;
                }
            }

            foreach (var x in ip.RunningProcesses)
            {
                if (!ProcessRunningProcess(x))
                {
                    return false;
                }
            }

            return true;
        }
Example #9
0
        private static void InstallMsiPackage(InstallPackage ip)
        {
            string argsPatt;

            if (!string.IsNullOrEmpty(ip.InstallArgs))
            {
                argsPatt = ip.InstallArgs;
            }
            else if (!string.IsNullOrEmpty(ip.QuietInstallArgs))
            {
                argsPatt = ip.QuietInstallArgs;
            }
            else
            {
                argsPatt = @"/i ""{0}"" /qn /norestart /l ""{1}""";
            }

            var args = string.Format(
                argsPatt, ip.FilePath, ip.FilePath + ".install.log");

            // Launch the target installer.
            var p = new Process
            {
                StartInfo =
                    new ProcessStartInfo
                    {
                        FileName = @"msiexec",
                        Arguments = args,
                        UseShellExecute = false,
                        CreateNoWindow = true,
                    }
            };

            p.Start();

            p.WaitForExit();

            var xit = p.ExitCode;

            if (xit != ip.SuccessfulExitCode)
            {
                InstallError =
                    string.Format(
                        @"An error occurred while installing {0}. An exit code of '{1}' was returned.",
                        ip.Name,
                        xit);
            }
        }