/[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 812 - (show annotations) (download)
Tue Apr 15 14:52:10 2014 UTC (5 years, 9 months ago) by william
File size: 41367 byte(s)
+ update logging to use Enterpise.Logging -- more work is still needed

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

  ViewVC Help
Powered by ViewVC 1.1.22