20 |
|
{ |
21 |
|
private bool isRefreshing = false; |
22 |
|
private bool isAutoRefreshing = false; |
23 |
+ |
private bool isAttachingToProcess = false; |
24 |
|
//private IConfigPlugin plugin = null; |
25 |
|
//bool isInError = false; |
26 |
|
public PIDSelector() { InitializeComponent(); this.ProcessPID = -1; OnSelectedProcessChanged = null; this.AcceptedPlugin = null; } |
72 |
|
|
73 |
|
private void PerformListViewItemSelect(ListViewItem li) |
74 |
|
{ |
75 |
< |
if (isAutoRefreshing) return; |
75 |
> |
if (isAutoRefreshing && !isAttachingToProcess) return; |
76 |
|
this.ProcessPID = Convert.ToInt32(li.SubItems[1].Text); |
77 |
|
Process SelectedProcess = Process.GetProcessById(this.ProcessPID); |
78 |
|
logger.Debug.WriteLine("Using Process: ({0} : {1})", SelectedProcess.Id, SelectedProcess.ProcessName); |
79 |
|
//this.Close(); |
80 |
|
if (OnSelectedProcessChanged != null) |
81 |
|
OnSelectedProcessChanged(new ProcessChangedEventArgs(this, this.ProcessPID)); |
82 |
+ |
if (isAttachingToProcess) |
83 |
+ |
isAttachingToProcess = false; |
84 |
|
} |
85 |
|
private void btnOK_Click(object sender, EventArgs e) |
86 |
|
{ |
153 |
|
lstProcessList.LargeImageList = large_image_list; |
154 |
|
this.lstProcessList.Items.AddRange(items.ToArray()); |
155 |
|
|
156 |
< |
if (lstProcessList.Items.Count > 1) |
156 |
> |
if (lstProcessList.Items.Count > 1 && !isAttachingToProcess) |
157 |
|
{ |
158 |
|
lstProcessList.Items[0].Selected = true; |
159 |
|
} |
217 |
|
{ |
218 |
|
DialogResult result = EXESelector.ShowDialog(); |
219 |
|
if (result != DialogResult.OK) return; |
217 |
– |
|
220 |
|
FileInfo fi = new FileInfo(EXESelector.FileName); |
221 |
|
if (!fi.Exists) { logger.Warn.WriteLine("Cannot load and attach to non-existing exe file: {0}", fi.FullName); return; } |
222 |
< |
|
223 |
< |
Process p = Process.Start(fi.FullName); |
224 |
< |
ProcContainer container = null; |
223 |
< |
try |
224 |
< |
{ |
225 |
< |
container = new ProcContainer(p); |
226 |
< |
} |
227 |
< |
catch (FileNotFoundException) { } |
228 |
< |
catch (Exception) { } |
229 |
< |
ListViewItem item = new ListViewItem(); |
230 |
< |
ImageList small_image_list = new ImageList(); |
231 |
< |
ImageList large_image_list = new ImageList(); |
232 |
< |
|
233 |
< |
int small_width = 32; |
234 |
< |
int large_width = 48; |
235 |
< |
|
236 |
< |
small_image_list.ImageSize = new Size(small_width, small_width); |
237 |
< |
large_image_list.ImageSize = new Size(large_width, large_width); |
238 |
< |
//foreach (ProcContainer pc in proc_list) |
239 |
< |
//{ |
240 |
< |
Bitmap small_image = null; |
241 |
< |
Bitmap large_image = null; |
242 |
< |
string image_key = string.Empty; |
243 |
< |
this.AddProcessItem(container, small_image_list.ImageSize, large_image_list.ImageSize, out image_key, out small_image, out large_image); |
244 |
< |
if (image_key != string.Empty) |
245 |
< |
{ |
246 |
< |
if (small_image != null) { lstProcessList.SmallImageList.Images.Add(image_key, small_image); } |
247 |
< |
if (large_image != null) { lstProcessList.LargeImageList.Images.Add(image_key, large_image); } |
248 |
< |
item.Name = container.GetHashCode().ToString(); |
249 |
< |
// process name |
250 |
< |
item.Text = container.Name; |
251 |
< |
// pid |
252 |
< |
item.SubItems.Add(container.ProcessInfo.Id.ToString()); |
253 |
< |
// FullPath |
254 |
< |
item.SubItems.Add(container.FileName); |
255 |
< |
// image key |
256 |
< |
item.ImageKey = container.FileName; |
257 |
< |
//if (!items.Contains(item)) items.Add(item); |
258 |
< |
} |
259 |
< |
this.lstProcessList.Items.Add(item); |
260 |
< |
if (lstProcessList.Items.Count == 2) |
261 |
< |
{ |
262 |
< |
lstProcessList.Items[0].Selected = false; |
263 |
< |
lstProcessList.Items[1].Selected = true; |
264 |
< |
} |
265 |
< |
else |
266 |
< |
{ |
267 |
< |
if (lstProcessList.SelectedItems.Count > 0) |
268 |
< |
lstProcessList.Items[lstProcessList.SelectedItems[0].Index].Selected = false; |
269 |
< |
lstProcessList.Items[lstProcessList.Items.IndexOf(item)].Selected = true; |
270 |
< |
} |
222 |
> |
Process p = Process.Start(fi.FullName); |
223 |
> |
this.ProcessPID = p.Id; |
224 |
> |
isAttachingToProcess = true; |
225 |
|
} |
226 |
|
|
227 |
|
private void ProcessWatcherTimer_Tick(object sender, EventArgs e) |
245 |
|
} |
246 |
|
if (pid_still_exists) |
247 |
|
{ |
248 |
< |
//logger.Debug.WriteLine("Pid: {0} still exists", pid); |
248 |
> |
//logger.Debug.WriteLine("Pid: {0} still exists", pid); |
249 |
|
if (lstProcessList.SelectedItems.Count > 0) |
250 |
|
{ |
251 |
|
if (lstProcessList.SelectedItems[0] != null) |