/[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 578 - (show annotations) (download)
Thu Jun 6 08:18:44 2013 UTC (6 years, 8 months ago) by william
File size: 41372 byte(s)

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

  ViewVC Help
Powered by ViewVC 1.1.22