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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 414 - (hide annotations) (download)
Fri Jun 22 08:21:18 2012 UTC (8 years, 10 months ago) by william
File size: 41350 byte(s)

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

  ViewVC Help
Powered by ViewVC 1.1.22