Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(506)

Side by Side Diff: experimental/visual_studio_plugin/src/NaClVsx.Package/Installation/InstallHelp.cs

Issue 10928195: First round of dead file removal (Closed) Base URL: https://github.com/samclegg/nativeclient-sdk.git@master
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 using System;
2 using System.Collections;
3 using System.Collections.Generic;
4 using System.ComponentModel;
5 using System.Configuration.Install;
6 using System.Data;
7 using System.Diagnostics;
8 using System.Linq;
9 using System.Windows.Forms;
10 using Google.NaClVsx.Installation;
11 using Microsoft.Win32;
12
13
14 namespace Google.NaClVsx
15 {
16 [RunInstaller(true)]
17 public partial class InstallHelp : Installer
18 {
19 private static readonly string kVsName = "devenv";
20
21 private static readonly string[] kVsRegKeys = new string[] {
22 @"HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\Setup\VS",
23 @"HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\9.0\Setup\VS",
24 };
25
26 private static readonly string kVsRegValue = "EnvironmentPath";
27
28 private static readonly int kTimeout = 100;
29
30
31 public InstallHelp()
32 {
33 InitializeComponent();
34 progress_.Cancelled += new EventHandler(OnProgressCancelled);
35 worker_.RunWorkerCompleted += new RunWorkerCompletedEventHandler(WorkerCom pleted);
36 }
37
38 void OnProgressCancelled(object sender, EventArgs e)
39 {
40 worker_.CancelAsync();
41 }
42
43 void WorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
44 {
45 if (e.Error != null) {
46 MessageBox.Show(progress_, e.Error.Message, "Install Error");
47 progress_.Cancel();
48 } else {
49 progress_.DialogResult = DialogResult.OK;
50 progress_.Close();
51 }
52 }
53
54 public override void Install(IDictionary stateSaver) {
55 var vsProcesses = new List<Process>(Process.GetProcessesByName(kVsName));
56 if (vsProcesses.Count > 0) {
57 progress_.Text = "Preparing to install";
58 progress_.Message = "Closing Visual Studio...";
59 var onLoad = new EventHandler(OnProgressLoadInstall);
60 progress_.Load += onLoad;
61
62 var workerfn = new DoWorkEventHandler(KillVsWorker);
63 worker_.DoWork += workerfn;
64
65 var result = progress_.ShowDialog();
66
67 worker_.DoWork -= workerfn;
68 progress_.Load -= onLoad;
69
70 // If we canceled, we need to let the installer know.
71 if (result == DialogResult.Cancel) {
72 throw new InstallException("Operation cancelled");
73 }
74 }
75
76 base.Install(stateSaver);
77 }
78
79 private void OnProgressLoadInstall(object sender, EventArgs e) {
80 var workerfn = new DoWorkEventHandler(KillVsWorker);
81 worker_.DoWork += workerfn;
82
83 var result = MessageBox.Show(
84 null,
85 "Installation cannot proceed until Visual Studio is closed.\n" +
86 "Close Visual Studio automatically?\n" +
87 "(Select 'Yes' to close Visual Studio automatically. Select 'No' to cl ose it yourself. Select 'Cancel' to abort the install process.",
88 "Installer",
89 MessageBoxButtons.YesNoCancel,
90 MessageBoxIcon.Question,
91 MessageBoxDefaultButton.Button1,
92 MessageBoxOptions.ServiceNotification);
93 if (result != DialogResult.Cancel) {
94 worker_.RunWorkerAsync(result);
95 } else {
96 progress_.DialogResult = result;
97 progress_.Close();
98 }
99 }
100
101 public override void Commit(IDictionary savedState)
102 {
103 var workerfn = new DoWorkEventHandler(RunDevenvSetupWorker);
104 worker_.DoWork += workerfn;
105 progress_.Text = "Finalizing";
106 progress_.Message = "Registering package with Visual Studio...";
107
108 var onLoad = new EventHandler(OnProgressLoadCommit);
109 progress_.Load += onLoad;
110 var result = progress_.ShowDialog();
111 worker_.DoWork -= workerfn;
112
113 if (result == DialogResult.Cancel) {
114 MessageBox.Show(
115 null,
116 "Setup was unable to automatically register " +
117 "components with Visual Studio.\n" +
118 "To register the Native Client support components manually, " +
119 "run 'devenv.exe /setup' from a Visual Studio command prompt.",
120 "Registration Failure",
121 MessageBoxButtons.OK,
122 MessageBoxIcon.Warning,
123 MessageBoxDefaultButton.Button1,
124 MessageBoxOptions.ServiceNotification);
125 }
126
127 }
128
129 private void OnProgressLoadCommit(object sender, EventArgs e) {
130 worker_.RunWorkerAsync();
131 }
132
133 void KillVsWorker(object sender, DoWorkEventArgs e)
134 {
135 BackgroundWorker worker = sender as BackgroundWorker;
136 DialogResult shouldKill = (DialogResult)e.Argument;
137
138 var vsProcesses = new List<Process>(Process.GetProcessesByName(kVsName));
139 foreach (var vsProcess in vsProcesses)
140 {
141 while (!vsProcess.HasExited && !worker.CancellationPending)
142 {
143 if (shouldKill == DialogResult.Yes) {
144 vsProcess.CloseMainWindow();
145 }
146 vsProcess.WaitForExit(kTimeout);
147 }
148 }
149 }
150
151 private void RunDevenvSetupWorker(object sender, DoWorkEventArgs e)
152 {
153 BackgroundWorker worker = sender as BackgroundWorker;
154 string devenv = null;
155
156 foreach (var vsRegKey in kVsRegKeys) {
157 devenv = (string)Registry.GetValue(vsRegKey, kVsRegValue, null);
158 if (devenv != null) break;
159 }
160
161 if (devenv == null) {
162 throw new InstallException("Could not find devenv.exe");
163 }
164 var vsProcess = Process.Start(devenv, "/setup");
165 while (!vsProcess.HasExited && !worker.CancellationPending)
166 {
167 vsProcess.WaitForExit(kTimeout);
168 }
169 }
170
171
172 private ProgressForm progress_ = new ProgressForm();
173 }
174 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698