示例#1
0
        private bool PerformInstallation(VsHive hive)
        {
            var codebase    = new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath;
            var hostProcess = Path.Combine(Path.GetDirectoryName(codebase), "HostProcess.exe");
            var arguments   = $"\"{vsix.PackagePath}\" \"{hive.VsVersion.DevEnvPath}\" {hive.RootSuffix}";

            Log($"Executing '{hostProcess} {arguments}'");

            var p = new Process
            {
                StartInfo =
                {
                    FileName  = hostProcess,
                    Arguments = arguments,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    CreateNoWindow         = true,
                    UseShellExecute        = false
                }
            };

            p.OutputDataReceived += (sender, args) =>
            {
                if (!string.IsNullOrWhiteSpace(args.Data))
                {
                    Log(args.Data);
                }
            };
            p.ErrorDataReceived += (sender, args) =>
            {
                if (!string.IsNullOrWhiteSpace(args.Data))
                {
                    LogError(args.Data);
                }
            };

            try
            {
                p.Start();
                p.BeginOutputReadLine();
                p.BeginErrorReadLine();

                p.WaitForExit();
                return(p.ExitCode == 0);
            }
            catch (Exception ex)
            {
                LogError($"An error ocurred while executing HostProcess with arguments '{p.StartInfo.Arguments}'", ex);
                return(false);
            }
            finally
            {
                p.Dispose();
            }
        }
示例#2
0
        private void InstallVsix(VsHive hive)
        {
            if (vsix.Header.AllUsers && !hive.IsMainHive)
            {
                if (MessageBox.Show("This extension is configured to be installed for all users, " +
                                    $"and will be installed in the per-machine location (Common7\\IDE\\Extensions) instead of {hive}.\n\n" +
                                    "Proceed with installation?", "VSIX PowerToys", MessageBoxButtons.OKCancel,
                                    MessageBoxIcon.Warning) != DialogResult.OK)
                {
                    return;
                }
            }

            SystemCursor.SetSystemCursor(Cursors.WaitCursor);
            bool result = false;

            try
            {
                result = PerformInstallation(hive);
            }
            catch (Exception ex)
            {
                LogError("An error ocurred while installing the extension", ex);
                Debugger.Launch();
            }
            finally
            {
                SystemCursor.RestoreSystemCursor();
            }

            if (result)
            {
                MessageBox.Show($"Installation of '{vsix.Header.Name}' into '{hive}' was successful!",
                                "VSIX PowerToys",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show($"Installation of '{vsix.Header.Name}' into '{hive}' was unsuccessful.\n\n" +
                                "Please check the log file at %TEMP%\\VSIXPowerToys.log",
                                "VSIX PowerToys",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
            }
        }