/[RomCheater]/trunk/RomCheater/Docking/MemorySearch/AddressValuePairList.cs
ViewVC logotype

Contents of /trunk/RomCheater/Docking/MemorySearch/AddressValuePairList.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 398 - (show annotations) (download)
Wed Jun 20 12:16:34 2012 UTC (8 years, 10 months ago) by william
File size: 40924 byte(s)
MemmoryProvider: using statements

1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Drawing;
5 using System.Data;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using Utilities.TransparentControls.ListView;
10 using System.IO;
11 using RomCheater.Logging;
12 using RomCheater.Docking.MemorySearch;
13 using Sojaner.MemoryScanner.MemoryProviers;
14 using System.Diagnostics;
15 using RomCheater.PluginFramework.Interfaces;
16
17 namespace System.Windows.Forms
18 {
19 [Serializable]
20 public partial class AddressValuePairList :
21 dbufferedListView, IAvpExport, IAvpImport, IAvpLvSupport, IAvpLvColumnSupport, IAvpFreeze,
22 IAcceptsProcess<Process>,
23 IAcceptsPlugin<IConfigPlugin>
24 {
25 #region IAcceptsProcess<Process> Members
26 public Process AcceptedProcess { get; set; }
27 #endregion
28 #region IAcceptsPlugin<IConfigPlugin> Members
29 public IConfigPlugin AcceptedPlugin { get; set; }
30 #endregion
31
32 public class AddressValuePairListSorter : System.Collections.IComparer
33 {
34
35 public int Compare(object o1, object o2)
36 {
37 if (!(o1 is ListViewItem))
38 return (0);
39 if (!(o2 is ListViewItem))
40 return (0);
41 ListViewItem lvi1 = (ListViewItem)o1;
42 ListViewItem lvi2 = (ListViewItem)o2;
43 int result = 0;
44 if (ByColumn > 0)
45 {
46 string str1 = lvi1.SubItems[ByColumn].Text;
47 string str2 = lvi2.SubItems[ByColumn].Text;
48 if (lvi1.ListView.Sorting == SortOrder.Ascending)
49 result = String.Compare(str1, str2);
50 else
51 result = String.Compare(str2, str1);
52 }
53 else
54 {
55 if (lvi1.ListView.Sorting == SortOrder.Ascending)
56 result = String.Compare(lvi1.ImageKey, lvi2.ImageKey);
57 else
58 result = String.Compare(lvi2.ImageKey, lvi1.ImageKey);
59 }
60
61 //LastSort = ByColumn;
62
63 return (result);
64 }
65 public int ByColumn
66 {
67 get { return Column; }
68 set { Column = value; }
69 }
70 int Column = 0;
71
72 //public int LastSort
73 //{
74 // get { return LastColumn; }
75 // set { LastColumn = value; }
76 //}
77 //int LastColumn = 0;
78 }
79
80 private delegate ListViewItem ThreadSafe_GetResultItem(int index);
81 private ResultItem GetResultItem(int index)
82 {
83 AddressValuePairList lv = this;
84 ResultItem item = (ResultItem)lv.Items[index].Clone();
85 return item;
86 }
87
88 private ImageList icon_list;
89
90 int UKNOWN_COLUMN_COUNT = 0;
91
92 private string ColumnTextChecker(string ColumnName)
93 {
94 string _column_text = ColumnName;
95 if (_column_text == new AVPColumnText(AVPColumnType.UKNOWN).ColumnText)
96 {
97 _column_text = string.Format("{0} {1:00}", ColumnName, UKNOWN_COLUMN_COUNT);
98 UKNOWN_COLUMN_COUNT++;
99 return _column_text;
100 }
101 else
102 {
103 return _column_text;
104 }
105 }
106
107 public AddressValuePairList()
108 : base()
109 {
110 InitializeComponent();
111
112 icon_list = new ImageList();
113 icon_list.Images.Add(AVPIconKeys.FROZEN, RomCheater.Properties.Resources.freeze);
114 icon_list.Images.Add(AVPIconKeys.NOTFROZEN, RomCheater.Properties.Resources.notfreeze);
115
116 this.SmallImageList = icon_list;
117 this.LargeImageList = icon_list;
118 this.FullRowSelect = true;
119 this.AllowColumnReorder = true;
120
121 this.HideSelection = false;
122 this.MultiSelect = true;
123
124 _Items = new ResultItemCollection(this);
125 AVPColumnText col_text = new AVPColumnText();
126 // Icon
127 col_text = new AVPColumnText(AVPColumnType.ICON);
128 this.Columns.Add(col_text.ColumnKey, ColumnTextChecker(col_text.ColumnText), col_text.ColumnWidth);
129 // Address
130 col_text = new AVPColumnText(AVPColumnType.ADDRESS);
131 this.Columns.Add(col_text.ColumnKey, ColumnTextChecker(col_text.ColumnText), col_text.ColumnWidth);
132 // Value
133 col_text = new AVPColumnText(AVPColumnType.VALUE);
134 this.Columns.Add(col_text.ColumnKey, ColumnTextChecker(col_text.ColumnText), col_text.ColumnWidth);
135 // Is Frozen
136 col_text = new AVPColumnText(AVPColumnType.FROZEN);
137 this.Columns.Add(col_text.ColumnKey, ColumnTextChecker(col_text.ColumnText), col_text.ColumnWidth);
138 #if HAVE_LISTVIEW_FREEZE_BUTTON
139 // Freeze button
140 col_text = new AVPColumnText(AVPColumnType.FREEZE_BUTTON);
141 this.Columns.Add(col_text.ColumnKey, ColumnTextChecker(col_text.ColumnText), col_text.ColumnWidth);
142 #endif
143 #if USE_FAKE_LV_ITEM
144 uint address = 0x200;
145 byte value = 0x10;
146 bool frozen = true;
147 ResultItem item = new ResultItem(address, frozen, value);
148 ResultDataType result = (ResultDataType)item.Tag;
149 //// if USE_FAKE_LV_ITEM is defined these will assert that everything is correct
150 //// Debug Assert: Address
151 //Debug.Assert(result.Address == address, string.Format("Address: 0x{0:x8} != 0x{1:x8}", result.Address, address));
152 //// Debug Assert: Value
153 //Debug.Assert((short)result.Value == value, string.Format("Value: 0x{0:x16} != 0x{1:x16}", result.Value, (object)value));
154 //// Debug Assert: IsFrozen
155 //Debug.Assert(result.IsFrozen == frozen, string.Format("Frozen: {0} != {1}", result.IsFrozen, frozen));
156 this.Items.Add(item);
157 #endif
158
159 this.ColumnClick += new ColumnClickEventHandler(AddressValuePairList_ColumnClick);
160
161 this.AcceptedPlugin = null;
162 this.AcceptedProcess = null;
163
164 }
165
166 void AddressValuePairList_ColumnClick(object sender, ColumnClickEventArgs e)
167 {
168 AddressValuePairListSorter sorter = new AddressValuePairListSorter();
169 this.ListViewItemSorter = sorter;
170 if (!(this.ListViewItemSorter is AddressValuePairListSorter))
171 return;
172 sorter = (AddressValuePairListSorter)this.ListViewItemSorter;
173 //if (sorter.LastSort == e.Column)
174 //{
175 // if (this.Sorting == SortOrder.Ascending)
176 // this.Sorting = SortOrder.Descending;
177 // else
178 // this.Sorting = SortOrder.Ascending;
179 //}
180 //else
181 //{
182 // this.Sorting = SortOrder.Descending;
183 //}
184 if (this.Sorting == SortOrder.Ascending)
185 {
186 this.Sorting = SortOrder.Descending;
187 }
188 else
189 {
190 this.Sorting = SortOrder.Ascending;
191 }
192 sorter.ByColumn = e.Column;
193
194 this.Sort();
195 }
196
197 private string WriteResultItem(ResultItem item)
198 {
199 ResultDataType _result = (ResultDataType)item.Tag;
200
201 return string.Format("{0},{1},{2},{3},{4}",
202 item.SubItems[GetColumnByType(AVPColumnType.ADDRESS)].Text,
203 item.SubItems[GetColumnByType(AVPColumnType.VALUE)].Text,
204 item.SubItems[GetColumnByType(AVPColumnType.FROZEN)].Text,
205 _result.ValueType,
206 _result.IsUnsigned);
207 }
208
209 #region IAvpExport Members
210 public bool ExportToClipboard()
211 {
212 if (!(this.Items.Count > 0)) return false;
213 try
214 {
215 StringBuilder builder = new StringBuilder();
216 foreach (ResultItem item in this.Items)
217 {
218 builder.Append(this.WriteResultItem(item));
219 builder.AppendLine();
220 }
221 Clipboard.SetText(builder.ToString());
222 return true;
223 }
224 catch { return false; }
225 }
226 public bool ExportToFile(string filename)
227 {
228 if (!(this.Items.Count > 0)) return false;
229
230 FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write);
231 StreamWriter sw = new StreamWriter(fs);
232 foreach (ResultItem item in this.Items)
233 {
234 sw.Write(this.WriteResultItem(item));
235 sw.WriteLine();
236 }
237 sw.Flush();
238 sw.Close();
239
240 return true;
241 }
242 public bool ExportToFile()
243 {
244 DialogResult result = ResultsSaver.ShowDialog();
245 if (result != DialogResult.OK) return false;
246 string filename = ResultsSaver.FileName;
247 return this.ExportToFile(filename);
248 }
249 #endregion
250 #region IAvpImport Members
251 public bool ImportFromClipboard()
252 {
253 try
254 {
255 string clipboard_data = (string)Clipboard.GetData(System.Windows.Forms.DataFormats.Text);
256
257 MemoryStream ms = new MemoryStream(ASCIIEncoding.ASCII.GetBytes(clipboard_data));
258 StreamReader sr = new StreamReader(ms);
259 this.Items.Clear();
260 List<ResultItem> patch_item_list = new List<ResultItem>();
261
262 while (!sr.EndOfStream)
263 {
264 string line = sr.ReadLine();
265 string[] tokenized_line = line.Split(',');
266 string Address = tokenized_line[0];
267 string Value = tokenized_line[1];
268 string Frozen = tokenized_line[2];
269
270 string _data_type = tokenized_line[3];
271 string IsUnsigned = tokenized_line[4];
272 bool _IsUnsigned = false;
273 switch (IsUnsigned.ToLower())
274 {
275 case "true": _IsUnsigned = true; break;
276 case "false": _IsUnsigned = false; break;
277 }
278 int BIT_SIZE = -1;
279
280 foreach (int val in Enum.GetValues(typeof(SearchDataTypes)))
281 {
282 if (Enum.GetName(typeof(SearchDataTypes), val) == _data_type)
283 {
284 BIT_SIZE = val;
285 break;
286 }
287 }
288
289 ResultItem item = new ResultItem(Address, Value, Frozen, (SearchDataTypes)BIT_SIZE, _IsUnsigned);
290 patch_item_list.Add(item);
291 }
292 this.Items.AddRange(patch_item_list.ToArray());
293 sr.Close();
294 return true;
295 }
296 catch { return false; }
297
298 }
299 public bool ImportFromFile(string filename)
300 {
301 FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
302 StreamReader sr = new StreamReader(fs);
303
304 this.Items.Clear();
305 List<ResultItem> patch_item_list = new List<ResultItem>();
306
307 while (!sr.EndOfStream)
308 {
309 string line = sr.ReadLine();
310 string[] tokenized_line = line.Split(',');
311 string Address = tokenized_line[0];
312 string Value = tokenized_line[1];
313 string Frozen = tokenized_line[2];
314
315 string _data_type = tokenized_line[3];
316 string IsUnsigned = tokenized_line[4];
317 bool _IsUnsigned = false;
318 switch (IsUnsigned.ToLower())
319 {
320 case "true": _IsUnsigned = true; break;
321 case "false": _IsUnsigned = false; break;
322 }
323 int BIT_SIZE = -1;
324
325 foreach (int val in Enum.GetValues(typeof(SearchDataTypes)))
326 {
327 if (Enum.GetName(typeof(SearchDataTypes), val) == _data_type)
328 {
329 BIT_SIZE = val;
330 break;
331 }
332 }
333
334 ResultItem item = new ResultItem(Address, Value, Frozen, (SearchDataTypes)BIT_SIZE, _IsUnsigned);
335 patch_item_list.Add(item);
336 }
337 this.Items.AddRange(patch_item_list.ToArray());
338 sr.Close();
339 return true;
340 }
341 public bool ImportFromFile()
342 {
343 DialogResult result = ResultsLoader.ShowDialog();
344 if (result != DialogResult.OK) return false;
345 string filename = ResultsLoader.FileName;
346 return this.ImportFromFile(filename);
347 }
348 #endregion
349 #region IAvpLvSupport Members
350 private bool DONOT_USE_DETAILS_VIEW_BY_DEFAULT = false;
351 public bool OverrideDetailsViewByDefault { get { return DONOT_USE_DETAILS_VIEW_BY_DEFAULT; } set { DONOT_USE_DETAILS_VIEW_BY_DEFAULT = value; } }
352 public new System.Windows.Forms.View View { get { return base.View; } set { if (this.OverrideDetailsViewByDefault) { base.View = value; } else { base.View = View.Details; } } }
353 public new ListView.ColumnHeaderCollection Columns
354 {
355 get
356 {
357 return base.Columns;
358 }
359 }
360 private ResultItemCollection _Items;
361 public new ResultItemCollection Items
362 {
363 get
364 {
365 return _Items;
366 }
367 }
368 #endregion
369 #region IAvpLvColumnSupport Members
370 public int GetColumnByType(AVPColumnType AVPColType)
371 {
372 return GetColumnByKey(Enum.GetName(typeof(AVPColumnType), AVPColType));
373 }
374 public int GetColumnByKey(string AVPColType)
375 {
376 List<string> avp_cols = new List<string>();
377
378 foreach (int val in Enum.GetValues(typeof(AVPColumnType)))
379 {
380 avp_cols.Add(Enum.GetName(typeof(AVPColumnType), val));
381 }
382
383 int index = -1;
384 bool foundColumn = false;
385 foreach (string col in avp_cols)
386 {
387 if (AVPColType == col)
388 {
389 foundColumn = true;
390 break;
391 }
392 }
393 if (!foundColumn)
394 {
395 index = -1;
396 }
397 else
398 {
399 index = this.Columns[AVPColType].Index;
400 }
401
402 return index;
403 }
404 #endregion
405 #region IAvpFreeze Members
406 private List<int> FrozenIndexes = new List<int>();
407 public bool ItemIsFrozen(int index)
408 {
409 return FrozenIndexes.Contains(index) && (this.Items[index].Tag as ResultDataType).IsFrozen;
410 }
411 public void FreezeItem(int index)
412 {
413 if (!(this.ItemIsFrozen(index)))
414 {
415 FrozenIndexes.Add(index);
416 this.Items[index].ImageKey = AVPIconKeys.FROZEN;
417 this.Items[index].SubItems[new AVPColumnText(AVPColumnType.FROZEN).ColumnIndex].Text = true.ToString();
418 ResultDataType tmp_result = (ResultDataType)this.Items[index].Tag;
419
420 string Address = this.Items[index].SubItems[new AVPColumnText(AVPColumnType.ADDRESS).ColumnIndex].Text;
421 string Frozen = this.Items[index].SubItems[new AVPColumnText(AVPColumnType.FROZEN).ColumnIndex].Text;
422 object Value = Convert.ToUInt64(this.Items[index].SubItems[new AVPColumnText(AVPColumnType.FROZEN).ColumnIndex].Text, 16);
423
424 SearchDataTypes ValueType = tmp_result.ValueType;
425
426 ResultDataType result = new ResultDataType(Convert.ToUInt32(Address, 16), Convert.ToBoolean(Frozen), Value, ValueType);
427 result.IsFrozen = true;
428 this.Items[index].Tag = result;
429 ResultItem temp = (ResultItem)this.Items[index];
430 this.Items[index].Remove();
431 this.Items.Insert(index, temp);
432 this.Refresh();
433 this.Update();
434 }
435 }
436 public void ThawItem(int index)
437 {
438 if (this.ItemIsFrozen(index))
439 {
440 FrozenIndexes.Remove(index);
441 this.Items[index].ImageKey = AVPIconKeys.NOTFROZEN;
442 this.Items[index].SubItems[new AVPColumnText(AVPColumnType.FROZEN).ColumnIndex].Text = false.ToString();
443 ResultDataType result = (ResultDataType)this.Items[index].Tag;
444 result.IsFrozen = false;
445 this.Items[index].Tag = result;
446 ResultItem temp = (ResultItem)this.Items[index];
447 this.Items[index].Remove();
448 this.Items.Insert(index, temp);
449 this.Refresh();
450 this.Update();
451 }
452 }
453 private int _ProcessID;
454 public int ProcessID { get { return _ProcessID; } set { _ProcessID = value; } }
455 #endregion
456
457 private void freezer_Tick(object sender, EventArgs e)
458 {
459 if (!(FrozenIndexes.Count > 0)) return;
460 if (!(patcherwriter.IsBusy))
461 patcherwriter.RunWorkerAsync();
462 }
463
464 private void patcherwriter_DoWork(object sender, DoWorkEventArgs e)
465 {
466 for (int i = 0; i < FrozenIndexes.Count; i++)
467 {
468 if (patcherwriter.CancellationPending)
469 {
470 e.Cancel = true;
471 return;
472 }
473 int index = FrozenIndexes[i];
474 ResultItem iter = null;
475 if (this.InvokeRequired)
476 {
477 ThreadSafe_GetResultItem _get_item = new ThreadSafe_GetResultItem(GetResultItem);
478 object item = this.Invoke(_get_item, new object[] { index });
479 if (item != null)
480 iter = (ResultItem)item;
481 }
482 else
483 {
484 iter = (ResultItem)this.Items[index];
485 }
486 using (GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
487 {
488 provider.OpenProvider();
489 ResultDataType result = (ResultDataType)iter.Tag;
490 uint Address = result.Address;
491 byte[] bitData = new byte[] { };
492 switch (result.ValueType)
493 {
494 case SearchDataTypes._8bits:
495 if (result.IsUnsigned) { provider.PatchMemory(Address, Convert.ToByte(result.Value)); }
496 else { provider.PatchMemory(Address, Convert.ToSByte(result.Value)); }
497 break;
498 case SearchDataTypes._16bits:
499 if (result.IsUnsigned) { provider.PatchMemory(Address, Convert.ToUInt16(result.Value)); }
500 else { provider.PatchMemory(Address, Convert.ToInt16(result.Value)); }
501 break;
502 case SearchDataTypes._32bits:
503 if (result.IsUnsigned) { provider.PatchMemory(Address, Convert.ToUInt32(result.Value)); }
504 else { provider.PatchMemory(Address, Convert.ToInt32(result.Value)); }
505 break;
506 case SearchDataTypes._64bits:
507 if (result.IsUnsigned) { provider.PatchMemory(Address, Convert.ToUInt64(result.Value)); }
508 else { provider.PatchMemory(Address, Convert.ToInt64(result.Value)); }
509 break;
510 }
511 result = null;
512 provider.CloseProvider();
513 }
514 }
515 }
516
517 private void patcherwriter_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
518 {
519 if (FrozenIndexes.Count > 0) // only run if we have frozen patches
520 patcherwriter.RunWorkerAsync(); // restart the freeze operation
521 }
522 }
523
524 public enum AVPColumnType
525 {
526 ICON,
527 ADDRESS,
528 VALUE,
529 FROZEN,
530 #if HAVE_LISTVIEW_FREEZE_BUTTON
531 FREEZE_BUTTON,
532 #endif
533 UKNOWN = 0x6000
534 }
535
536 #region ResultItem
537
538 #if HAVE_LISTVIEW_FREEZE_BUTTON
539 public class ListviewSubItemButton : ListViewItem.ListViewSubItem
540 {
541 }
542 public class ListViewFreezeToggle : ListviewSubItemButton
543 {
544 public ListViewFreezeToggle() : this(false) { }
545 public ListViewFreezeToggle(bool frozen) { this.ToggleText(frozen); }
546
547 public void ToggleText(bool frozen)
548 {
549 _Frozen = frozen;
550 if (frozen) { this.Text = "UnFreeze"; }
551 else { this.Text = "Freeze"; }
552 }
553 public ListViewFreezeToggle Toggle(bool frozen)
554 {
555 _Frozen = frozen;
556 if (frozen) { this.Text = "UnFreeze"; }
557 else { this.Text = "Freeze"; }
558
559 return this;
560 }
561 private bool _Frozen;
562 public bool Frozen
563 {
564 get { return _Frozen; }
565 }
566
567 }
568 #endif
569
570 public class ResultItem : ListViewItem
571 {
572 #if HAVE_LISTVIEW_FREEZE_BUTTON
573 private ListViewFreezeToggle btnFreezeToggle;
574 #endif
575
576 public override string ToString()
577 {
578 StringBuilder builder = new StringBuilder();
579 builder.Append("{");
580 builder.AppendFormat("{0},{1},{2}",
581 this.SubItems[new AVPColumnText(AVPColumnType.ADDRESS).ColumnIndex].Text,
582 this.SubItems[new AVPColumnText(AVPColumnType.VALUE).ColumnIndex].Text,
583 this.SubItems[new AVPColumnText(AVPColumnType.FROZEN).ColumnIndex].Text);
584 builder.Append(" {");
585 builder.AppendFormat("tag:{0}", (this.Tag as ResultDataType).ToString());
586 builder.Append("} ");
587 builder.Append("}");
588 return builder.ToString();
589 }
590
591 public ResultItem()
592 : base()
593 {
594 }
595 private void initialize() { this.initialize(false); }
596 private void initialize(bool frozen)
597 {
598 #if HAVE_LISTVIEW_FREEZE_BUTTON
599 btnFreezeToggle = new ListViewFreezeToggle();
600 btnFreezeToggle.Name = "btnFreezeToggle";
601 //btnFreezeToggle.Click += new EventHandler(btnFreezeToggle_Click);
602 #endif
603 this.Text = "";
604 if (frozen)
605 {
606 this.ImageKey = AVPIconKeys.FROZEN;
607 _isFrozen = true;
608 }
609 else
610 {
611 this.ImageKey = AVPIconKeys.NOTFROZEN;
612 _isFrozen = false;
613 }
614 }
615
616 private bool _isFrozen = false;
617 public bool ItemIsFrozen()
618 {
619 return _isFrozen;
620 }
621
622 public void FreezeItem()
623 {
624 this.ImageKey = AVPIconKeys.FROZEN;
625 _isFrozen = true;
626 }
627 public void ThawItem()
628 {
629 this.ImageKey = AVPIconKeys.NOTFROZEN;
630 _isFrozen = false;
631 }
632
633 //void btnFreezeToggle_Click(object sender, EventArgs e)
634 //{
635 // throw new NotImplementedException();
636 //}
637 public ResultItem(string address)
638 : base()
639 {
640 this.initialize();
641 this.SubItems.Add(address);
642 }
643 public ResultItem(string address, string value, string frozen, SearchDataTypes bit_size, bool unsigned)
644 : base()
645 {
646 bool _frozen = false;
647 if (frozen.ToLower() == "true") _frozen = true;
648 this.initialize(_frozen);
649 this.SubItems.Add(address);
650 this.SubItems.Add(value);
651 this.SubItems.Add(frozen);
652 #if HAVE_LISTVIEW_FREEZE_BUTTON
653 this.SubItems.Add(btnFreezeToggle.Toggle(frozen));
654 #endif
655 ResultDataType resulttype = null;
656
657 switch (bit_size)
658 {
659 case SearchDataTypes._8bits:
660 if (unsigned) { resulttype = new ResultDataType(Convert.ToUInt32(address, 16), _frozen, Convert.ToByte(value, 16)); }
661 else { resulttype = new ResultDataType(Convert.ToUInt32(address, 16), _frozen, Convert.ToByte(value, 16)); }
662 break;
663 case SearchDataTypes._16bits:
664 if (unsigned) { resulttype = new ResultDataType(Convert.ToUInt32(address, 16), _frozen, Convert.ToUInt16(value, 16)); }
665 else { resulttype = new ResultDataType(Convert.ToUInt32(address, 16), _frozen, Convert.ToInt16(value, 16)); }
666 break;
667 case SearchDataTypes._32bits:
668 if (unsigned) { resulttype = new ResultDataType(Convert.ToUInt32(address, 16), _frozen, Convert.ToUInt32(value, 16)); }
669 else { resulttype = new ResultDataType(Convert.ToUInt32(address, 16), _frozen, Convert.ToInt32(value, 16)); }
670 break;
671 case SearchDataTypes._64bits:
672 if (unsigned) { resulttype = new ResultDataType(Convert.ToUInt32(address, 16), _frozen, Convert.ToUInt64(value, 16)); }
673 else { resulttype = new ResultDataType(Convert.ToUInt32(address, 16), _frozen, Convert.ToInt64(value, 16)); }
674 break;
675
676 }
677 this.Tag = resulttype;
678 }
679 public ResultItem(uint address)
680 : base()
681 {
682 this.initialize();
683 this.SubItems.Add(string.Format("0x{0:x8}", address));
684 }
685 public ResultItem(uint address, bool frozen)
686 : base()
687 {
688 this.initialize(frozen);
689 this.SubItems.Add(string.Format("0x{0:x8}", address));
690 }
691 public ResultItem(uint address, bool frozen, byte value)
692 : base()
693 {
694 this.initialize(frozen);
695 this.SubItems.Add(string.Format("0x{0:x8}", address));
696 this.SubItems.Add(string.Format("0x{0:x2}", value));
697 this.SubItems.Add(frozen.ToString());
698 #if HAVE_LISTVIEW_FREEZE_BUTTON
699 this.SubItems.Add(btnFreezeToggle.Toggle(frozen));
700 #endif
701 ResultDataType resulttype = new ResultDataType(address, frozen, value);
702 this.Tag = resulttype;
703 }
704 public ResultItem(uint address, bool frozen, sbyte value)
705 : base()
706 {
707 this.initialize(frozen);
708 this.SubItems.Add(string.Format("0x{0:x8}", address));
709 this.SubItems.Add(string.Format("0x{0:x2}", value));
710 this.SubItems.Add(frozen.ToString());
711 #if HAVE_LISTVIEW_FREEZE_BUTTON
712 this.SubItems.Add(btnFreezeToggle.Toggle(frozen));
713 #endif
714 ResultDataType resulttype = new ResultDataType(address, frozen, value);
715 this.Tag = resulttype;
716 }
717 public ResultItem(uint address, bool frozen, ushort value)
718 : base()
719 {
720 this.initialize(frozen);
721 this.SubItems.Add(string.Format("0x{0:x8}", address));
722 this.SubItems.Add(string.Format("0x{0:x4}", value));
723 this.SubItems.Add(frozen.ToString());
724 #if HAVE_LISTVIEW_FREEZE_BUTTON
725 this.SubItems.Add(btnFreezeToggle.Toggle(frozen));
726 #endif
727 ResultDataType resulttype = new ResultDataType(address, frozen, value);
728 this.Tag = resulttype;
729 }
730 public ResultItem(uint address, bool frozen, short value)
731 : base()
732 {
733 this.initialize(frozen);
734 this.SubItems.Add(string.Format("0x{0:x8}", address));
735 this.SubItems.Add(string.Format("0x{0:x4}", value));
736 this.SubItems.Add(frozen.ToString());
737 #if HAVE_LISTVIEW_FREEZE_BUTTON
738 this.SubItems.Add(btnFreezeToggle.Toggle(frozen));
739 #endif
740 ResultDataType resulttype = new ResultDataType(address, frozen, value);
741 this.Tag = resulttype;
742 }
743 public ResultItem(uint address, bool frozen, uint value)
744 : base()
745 {
746 this.initialize(frozen);
747 this.SubItems.Add(string.Format("0x{0:x8}", address));
748 this.SubItems.Add(string.Format("0x{0:x8}", value));
749 this.SubItems.Add(frozen.ToString());
750 #if HAVE_LISTVIEW_FREEZE_BUTTON
751 this.SubItems.Add(btnFreezeToggle.Toggle(frozen));
752 #endif
753 ResultDataType resulttype = new ResultDataType(address, frozen, value);
754 this.Tag = resulttype;
755 }
756 public ResultItem(uint address, bool frozen, int value)
757 : base()
758 {
759 this.initialize(frozen);
760 this.SubItems.Add(string.Format("0x{0:x8}", address));
761 this.SubItems.Add(string.Format("0x{0:x8}", value));
762 this.SubItems.Add(frozen.ToString());
763 #if HAVE_LISTVIEW_FREEZE_BUTTON
764 this.SubItems.Add(btnFreezeToggle.Toggle(frozen));
765 #endif
766 ResultDataType resulttype = new ResultDataType(address, frozen, value);
767 this.Tag = resulttype;
768 }
769 public ResultItem(uint address, bool frozen, ulong value)
770 : base()
771 {
772 this.initialize(frozen);
773 this.SubItems.Add(string.Format("0x{0:x8}", address));
774 this.SubItems.Add(string.Format("0x{0:x16}", value));
775 this.SubItems.Add(frozen.ToString());
776 #if HAVE_LISTVIEW_FREEZE_BUTTON
777 this.SubItems.Add(btnFreezeToggle.Toggle(frozen));
778 #endif
779 ResultDataType resulttype = new ResultDataType(address, frozen, value);
780 this.Tag = resulttype;
781 }
782 public ResultItem(uint address, bool frozen, long value)
783 : base()
784 {
785 this.initialize(frozen);
786 this.SubItems.Add(string.Format("0x{0:x8}", address));
787 this.SubItems.Add(string.Format("0x{0:x16}", value));
788 this.SubItems.Add(frozen.ToString());
789 #if HAVE_LISTVIEW_FREEZE_BUTTON
790 this.SubItems.Add(btnFreezeToggle.Toggle(frozen));
791 #endif
792 ResultDataType resulttype = new ResultDataType(address, frozen, value);
793 this.Tag = resulttype;
794 }
795 }
796 public class ResultSubItem : ListViewItem.ListViewSubItem
797 {
798 }
799 [Serializable]
800 public class ResultItemCollection : System.Windows.Forms.ListView.ListViewItemCollection
801 {
802 public ResultItemCollection(ListView owner)
803 : base(owner)
804 {
805 }
806
807
808
809 #region Overriden Members
810 //#region This Members
811 //public new ResultItem this[int index]
812 //{
813 // get
814 // {
815 // return base[index] as ResultItem;
816 // }
817 // set
818 // {
819 // base[index] = value as ListViewItem;
820 // }
821 //}
822 //public new ResultItem this[string key]
823 //{
824 // get
825 // {
826 // return base[key] as ResultItem;
827 // }
828 //}
829 //#endregion
830 #region Add Members
831
832 public ResultItem Add(ResultItem value)
833 {
834 return (ResultItem)base.Add(value);
835 }
836
837 public override ListViewItem Add(ListViewItem value)
838 {
839 return base.Add(value);
840 }
841 public override ListViewItem Add(string key, string text, int imageIndex)
842 {
843 return base.Add(key, text, imageIndex);
844 }
845 public override ListViewItem Add(string key, string text, string imageKey)
846 {
847 return base.Add(key, text, imageKey);
848 }
849 public override ListViewItem Add(string text)
850 {
851 return base.Add(text);
852 }
853 public override ListViewItem Add(string text, int imageIndex)
854 {
855 return base.Add(text, imageIndex);
856 }
857 public override ListViewItem Add(string text, string imageKey)
858 {
859 return base.Add(text, imageKey);
860 }
861 #endregion
862 #region Remove Members
863 public override void Remove(ListViewItem item)
864 {
865 base.Remove(item);
866 }
867 #endregion
868
869 #region Contains Members
870 public new bool Contains(ListViewItem item)
871 {
872 try
873 {
874 return this.Contains((ResultItem)item);
875 }
876 catch (InvalidCastException ex)
877 {
878 Exception ex1 = new Exception("Unable to Convert ListViewItem to ResultItem in ResultItemCollection.Contains(ListViewItem item)", ex);
879 logger.Error.WriteLine("avp.contains(ListViewItem item): invalid cast");
880 logger.Error.WriteLine(ex1.ToString());
881 return false;
882 }
883 catch (Exception ex)
884 {
885 logger.Error.WriteLine("avp.contains(): exception");
886 logger.Error.WriteLine(ex.ToString());
887 return false;
888 }
889 }
890 public bool Contains(ResultItem item)
891 {
892 try
893 {
894 //ResultItem _item = (ResultItem)item;
895
896 bool contains = false;
897 if (!(this.Count > 0)) return false;
898 foreach (ResultItem iter in this)
899 {
900 if (item.ToString() == iter.ToString()) contains = true;
901 }
902 return contains;
903 }
904 catch (IndexOutOfRangeException)
905 {
906 return false;
907 }
908 catch (ArgumentOutOfRangeException)
909 {
910 return false;
911 }
912 catch (Exception ex)
913 {
914 Exception ex1 = new Exception("Caught non-Argument or Index OutOfRangeException in: ResultItemCollection.Contains(ListViewItem item, int index)", ex);
915 logger.Error.WriteLine("avp.contains(ResultItem item): Exception");
916 logger.Error.WriteLine(ex1.ToString());
917 return false;
918 }
919 }
920 public override bool ContainsKey(string key)
921 {
922 return base.ContainsKey(key);
923 }
924 #endregion
925
926 #endregion
927 }
928 #endregion
929
930 public interface IAvpFreeze
931 {
932 bool ItemIsFrozen(int index);
933 void FreezeItem(int index);
934 void ThawItem(int index);
935 int ProcessID { get; set; }
936 }
937
938 public interface IAvpExport
939 {
940 bool ExportToClipboard();
941 bool ExportToFile();
942 bool ExportToFile(string filename);
943 }
944 public interface IAvpImport
945 {
946 bool ImportFromClipboard();
947 bool ImportFromFile();
948 bool ImportFromFile(string filename);
949 }
950 public interface IAvpLvSupport
951 {
952 System.Windows.Forms.View View { get; set; }
953 bool OverrideDetailsViewByDefault { get; set; }
954 ListView.ColumnHeaderCollection Columns { get; }
955 ResultItemCollection Items { get; }
956 }
957 public interface IAvpLvColumnSupport
958 {
959 int GetColumnByType(AVPColumnType AVPColumnType);
960 int GetColumnByKey(string AVPColumnType);
961 }
962
963 public class AVPIconKeys
964 {
965 public const string FROZEN = "FROZEN";
966 public const string NOTFROZEN = "NOTFROZEN";
967 }
968
969 #region AVPColumnText Sub-Class
970 public interface IAVPColumnText
971 {
972 string ColumnText { get; }
973 string ColumnKey { get; }
974 int ColumnIndex { get; }
975 int ColumnWidth { get; }
976 }
977 public class AVPColumnText : IAVPColumnText
978 {
979 private const string FREEZE_ICON = "";
980 private const int FREEZE_ICON_WIDTH = 32;
981 private const int FREEZE_ICON_INDEX = 0;
982 private const string ADDRESS = "Address";
983 private const int ADDRESS_WIDTH = 120;
984 private const int ADDRESS_INDEX = 1;
985 private const string VALUE = "Value";
986 private const int VALUE_WIDTH = 220;
987 private const int VALUE_INDEX = 2;
988 private const string FROZEN = "Is Frozen";
989 private const int FROZEN_WIDTH = 120;
990 private const int FROZEN_INDEX = 3;
991 #if HAVE_LISTVIEW_FREEZE_BUTTON
992 private const string FREEZEBUTTON = "Freeze Toggle";
993 private const int FREEZEBUTTON_WIDTH = 160;
994 #endif
995 private const string UKNOWN = "Unknown";
996 private const int UKNOWN_WIDTH = 125;
997 private const int UKNOWN_INDEX = -1;
998
999 private AVPColumnType _AVPColumnType;
1000 public AVPColumnText()
1001 {
1002 _AVPColumnType = AVPColumnType.UKNOWN;
1003 }
1004 public AVPColumnText(AVPColumnType AVPColumnType)
1005 {
1006 _AVPColumnType = AVPColumnType;
1007 }
1008
1009 #region IAVPColumnText Members
1010 #region ColumnText
1011 public string ColumnText
1012 {
1013 get
1014 {
1015 switch (_AVPColumnType)
1016 {
1017 case AVPColumnType.ICON:
1018 return FREEZE_ICON;
1019 case AVPColumnType.ADDRESS:
1020 return ADDRESS;
1021 case AVPColumnType.VALUE:
1022 return VALUE;
1023 case AVPColumnType.FROZEN:
1024 return FROZEN;
1025 #if HAVE_LISTVIEW_FREEZE_BUTTON
1026 case AVPColumnType.FREEZE_BUTTON:
1027 return FREEZEBUTTON;
1028 #endif
1029 default:
1030 return UKNOWN;
1031 }
1032 }
1033 }
1034 #endregion
1035 #region ColumnKey
1036 public string ColumnKey
1037 {
1038 get
1039 {
1040 return Enum.GetName(typeof(AVPColumnType), _AVPColumnType);
1041 }
1042 }
1043 #endregion
1044 #region ColumnWidth
1045 public int ColumnWidth
1046 {
1047 get
1048 {
1049 switch (_AVPColumnType)
1050 {
1051 case AVPColumnType.ICON:
1052 return FREEZE_ICON_WIDTH;
1053 case AVPColumnType.ADDRESS:
1054 return ADDRESS_WIDTH;
1055 case AVPColumnType.VALUE:
1056 return VALUE_WIDTH;
1057 case AVPColumnType.FROZEN:
1058 return FROZEN_WIDTH;
1059 #if HAVE_LISTVIEW_FREEZE_BUTTON
1060 case AVPColumnType.FREEZE_BUTTON:
1061 return FREEZEBUTTON_WIDTH;
1062 #endif
1063 default:
1064 return UKNOWN_WIDTH;
1065 }
1066 }
1067 }
1068 #endregion
1069 #region ColumnIndex
1070 public int ColumnIndex
1071 {
1072 get
1073 {
1074 switch (_AVPColumnType)
1075 {
1076 case AVPColumnType.ICON:
1077 return FREEZE_ICON_INDEX;
1078 case AVPColumnType.ADDRESS:
1079 return ADDRESS_INDEX;
1080 case AVPColumnType.VALUE:
1081 return VALUE_INDEX;
1082 case AVPColumnType.FROZEN:
1083 return FROZEN_INDEX;
1084 #if HAVE_LISTVIEW_FREEZE_BUTTON
1085 case AVPColumnType.FREEZE_BUTTON:
1086 return FREEZEBUTTON_WIDTH;
1087 #endif
1088 default:
1089 return UKNOWN_INDEX;
1090 }
1091 }
1092 }
1093 #endregion
1094 #endregion
1095 }
1096 #endregion
1097
1098 }

  ViewVC Help
Powered by ViewVC 1.1.22