/[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 243 - (hide annotations) (download)
Sun Jun 3 13:21:51 2012 UTC (8 years, 7 months ago) by william
File size: 40674 byte(s)

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

  ViewVC Help
Powered by ViewVC 1.1.22