/[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 245 - (hide annotations) (download)
Sun Jun 3 14:50:09 2012 UTC (8 years, 10 months ago) by william
File size: 40747 byte(s)
+ add exception logic to ensure provider is open

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 245 GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this);
487     provider.OpenProvider();
488 william 229 ResultDataType result = (ResultDataType)iter.Tag;
489     uint Address = result.Address;
490     byte[] bitData = new byte[] { };
491     switch (result.ValueType)
492     {
493     case SearchDataTypes._8bits:
494 william 243 if (result.IsUnsigned) { provider.PatchMemory(Address, Convert.ToByte(result.Value)); }
495     else { provider.PatchMemory(Address, Convert.ToSByte(result.Value)); }
496 william 229 break;
497     case SearchDataTypes._16bits:
498 william 243 if (result.IsUnsigned) { provider.PatchMemory(Address, Convert.ToUInt16(result.Value)); }
499     else { provider.PatchMemory(Address, Convert.ToInt16(result.Value)); }
500 william 229 break;
501     case SearchDataTypes._32bits:
502 william 243 if (result.IsUnsigned) { provider.PatchMemory(Address, Convert.ToUInt32(result.Value)); }
503     else { provider.PatchMemory(Address, Convert.ToInt32(result.Value)); }
504 william 229 break;
505     case SearchDataTypes._64bits:
506 william 243 if (result.IsUnsigned) { provider.PatchMemory(Address, Convert.ToUInt64(result.Value)); }
507     else { provider.PatchMemory(Address, Convert.ToInt64(result.Value)); }
508 william 229 break;
509     }
510 william 245 provider.CloseProvider();
511 william 229 }
512     }
513    
514     private void patcherwriter_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
515     {
516     if (FrozenIndexes.Count > 0) // only run if we have frozen patches
517     patcherwriter.RunWorkerAsync(); // restart the freeze operation
518     }
519     }
520    
521     public enum AVPColumnType
522     {
523     ICON,
524     ADDRESS,
525     VALUE,
526     FROZEN,
527     #if HAVE_LISTVIEW_FREEZE_BUTTON
528     FREEZE_BUTTON,
529     #endif
530     UKNOWN = 0x6000
531     }
532    
533     #region ResultItem
534    
535     #if HAVE_LISTVIEW_FREEZE_BUTTON
536     public class ListviewSubItemButton : ListViewItem.ListViewSubItem
537     {
538     }
539     public class ListViewFreezeToggle : ListviewSubItemButton
540     {
541     public ListViewFreezeToggle() : this(false) { }
542     public ListViewFreezeToggle(bool frozen) { this.ToggleText(frozen); }
543    
544     public void ToggleText(bool frozen)
545     {
546     _Frozen = frozen;
547     if (frozen) { this.Text = "UnFreeze"; }
548     else { this.Text = "Freeze"; }
549     }
550     public ListViewFreezeToggle Toggle(bool frozen)
551     {
552     _Frozen = frozen;
553     if (frozen) { this.Text = "UnFreeze"; }
554     else { this.Text = "Freeze"; }
555    
556     return this;
557     }
558     private bool _Frozen;
559     public bool Frozen
560     {
561     get { return _Frozen; }
562     }
563    
564     }
565     #endif
566    
567     public class ResultItem : ListViewItem
568     {
569     #if HAVE_LISTVIEW_FREEZE_BUTTON
570     private ListViewFreezeToggle btnFreezeToggle;
571     #endif
572    
573     public override string ToString()
574     {
575     StringBuilder builder = new StringBuilder();
576     builder.Append("{");
577     builder.AppendFormat("{0},{1},{2}",
578     this.SubItems[new AVPColumnText(AVPColumnType.ADDRESS).ColumnIndex].Text,
579     this.SubItems[new AVPColumnText(AVPColumnType.VALUE).ColumnIndex].Text,
580     this.SubItems[new AVPColumnText(AVPColumnType.FROZEN).ColumnIndex].Text);
581     builder.Append(" {");
582     builder.AppendFormat("tag:{0}", (this.Tag as ResultDataType).ToString());
583     builder.Append("} ");
584     builder.Append("}");
585     return builder.ToString();
586     }
587    
588     public ResultItem()
589     : base()
590     {
591     }
592     private void initialize() { this.initialize(false); }
593     private void initialize(bool frozen)
594     {
595     #if HAVE_LISTVIEW_FREEZE_BUTTON
596     btnFreezeToggle = new ListViewFreezeToggle();
597     btnFreezeToggle.Name = "btnFreezeToggle";
598     //btnFreezeToggle.Click += new EventHandler(btnFreezeToggle_Click);
599     #endif
600     this.Text = "";
601     if (frozen)
602     {
603     this.ImageKey = AVPIconKeys.FROZEN;
604     _isFrozen = true;
605     }
606     else
607     {
608     this.ImageKey = AVPIconKeys.NOTFROZEN;
609     _isFrozen = false;
610     }
611     }
612    
613     private bool _isFrozen = false;
614     public bool ItemIsFrozen()
615     {
616     return _isFrozen;
617     }
618    
619     public void FreezeItem()
620     {
621     this.ImageKey = AVPIconKeys.FROZEN;
622     _isFrozen = true;
623     }
624     public void ThawItem()
625     {
626     this.ImageKey = AVPIconKeys.NOTFROZEN;
627     _isFrozen = false;
628     }
629    
630     //void btnFreezeToggle_Click(object sender, EventArgs e)
631     //{
632     // throw new NotImplementedException();
633     //}
634     public ResultItem(string address)
635     : base()
636     {
637     this.initialize();
638     this.SubItems.Add(address);
639     }
640     public ResultItem(string address, string value, string frozen, SearchDataTypes bit_size, bool unsigned)
641     : base()
642     {
643     bool _frozen = false;
644     if (frozen.ToLower() == "true") _frozen = true;
645     this.initialize(_frozen);
646     this.SubItems.Add(address);
647     this.SubItems.Add(value);
648     this.SubItems.Add(frozen);
649     #if HAVE_LISTVIEW_FREEZE_BUTTON
650     this.SubItems.Add(btnFreezeToggle.Toggle(frozen));
651     #endif
652     ResultDataType resulttype = null;
653    
654     switch (bit_size)
655     {
656     case SearchDataTypes._8bits:
657     if (unsigned) { resulttype = new ResultDataType(Convert.ToUInt32(address, 16), _frozen, Convert.ToByte(value, 16)); }
658     else { resulttype = new ResultDataType(Convert.ToUInt32(address, 16), _frozen, Convert.ToByte(value, 16)); }
659     break;
660     case SearchDataTypes._16bits:
661     if (unsigned) { resulttype = new ResultDataType(Convert.ToUInt32(address, 16), _frozen, Convert.ToUInt16(value, 16)); }
662     else { resulttype = new ResultDataType(Convert.ToUInt32(address, 16), _frozen, Convert.ToInt16(value, 16)); }
663     break;
664     case SearchDataTypes._32bits:
665     if (unsigned) { resulttype = new ResultDataType(Convert.ToUInt32(address, 16), _frozen, Convert.ToUInt32(value, 16)); }
666     else { resulttype = new ResultDataType(Convert.ToUInt32(address, 16), _frozen, Convert.ToInt32(value, 16)); }
667     break;
668     case SearchDataTypes._64bits:
669     if (unsigned) { resulttype = new ResultDataType(Convert.ToUInt32(address, 16), _frozen, Convert.ToUInt64(value, 16)); }
670     else { resulttype = new ResultDataType(Convert.ToUInt32(address, 16), _frozen, Convert.ToInt64(value, 16)); }
671     break;
672    
673     }
674     this.Tag = resulttype;
675     }
676     public ResultItem(uint address)
677     : base()
678     {
679     this.initialize();
680     this.SubItems.Add(string.Format("0x{0:x8}", address));
681     }
682     public ResultItem(uint address, bool frozen)
683     : base()
684     {
685     this.initialize(frozen);
686     this.SubItems.Add(string.Format("0x{0:x8}", address));
687     }
688     public ResultItem(uint address, bool frozen, byte value)
689     : base()
690     {
691     this.initialize(frozen);
692     this.SubItems.Add(string.Format("0x{0:x8}", address));
693     this.SubItems.Add(string.Format("0x{0:x2}", value));
694     this.SubItems.Add(frozen.ToString());
695     #if HAVE_LISTVIEW_FREEZE_BUTTON
696     this.SubItems.Add(btnFreezeToggle.Toggle(frozen));
697     #endif
698     ResultDataType resulttype = new ResultDataType(address, frozen, value);
699     this.Tag = resulttype;
700     }
701     public ResultItem(uint address, bool frozen, sbyte value)
702     : base()
703     {
704     this.initialize(frozen);
705     this.SubItems.Add(string.Format("0x{0:x8}", address));
706     this.SubItems.Add(string.Format("0x{0:x2}", value));
707     this.SubItems.Add(frozen.ToString());
708     #if HAVE_LISTVIEW_FREEZE_BUTTON
709     this.SubItems.Add(btnFreezeToggle.Toggle(frozen));
710     #endif
711     ResultDataType resulttype = new ResultDataType(address, frozen, value);
712     this.Tag = resulttype;
713     }
714     public ResultItem(uint address, bool frozen, ushort value)
715     : base()
716     {
717     this.initialize(frozen);
718     this.SubItems.Add(string.Format("0x{0:x8}", address));
719     this.SubItems.Add(string.Format("0x{0:x4}", value));
720     this.SubItems.Add(frozen.ToString());
721     #if HAVE_LISTVIEW_FREEZE_BUTTON
722     this.SubItems.Add(btnFreezeToggle.Toggle(frozen));
723     #endif
724     ResultDataType resulttype = new ResultDataType(address, frozen, value);
725     this.Tag = resulttype;
726     }
727     public ResultItem(uint address, bool frozen, short value)
728     : base()
729     {
730     this.initialize(frozen);
731     this.SubItems.Add(string.Format("0x{0:x8}", address));
732     this.SubItems.Add(string.Format("0x{0:x4}", value));
733     this.SubItems.Add(frozen.ToString());
734     #if HAVE_LISTVIEW_FREEZE_BUTTON
735     this.SubItems.Add(btnFreezeToggle.Toggle(frozen));
736     #endif
737     ResultDataType resulttype = new ResultDataType(address, frozen, value);
738     this.Tag = resulttype;
739     }
740     public ResultItem(uint address, bool frozen, uint value)
741     : base()
742     {
743     this.initialize(frozen);
744     this.SubItems.Add(string.Format("0x{0:x8}", address));
745     this.SubItems.Add(string.Format("0x{0:x8}", value));
746     this.SubItems.Add(frozen.ToString());
747     #if HAVE_LISTVIEW_FREEZE_BUTTON
748     this.SubItems.Add(btnFreezeToggle.Toggle(frozen));
749     #endif
750     ResultDataType resulttype = new ResultDataType(address, frozen, value);
751     this.Tag = resulttype;
752     }
753     public ResultItem(uint address, bool frozen, int value)
754     : base()
755     {
756     this.initialize(frozen);
757     this.SubItems.Add(string.Format("0x{0:x8}", address));
758     this.SubItems.Add(string.Format("0x{0:x8}", value));
759     this.SubItems.Add(frozen.ToString());
760     #if HAVE_LISTVIEW_FREEZE_BUTTON
761     this.SubItems.Add(btnFreezeToggle.Toggle(frozen));
762     #endif
763     ResultDataType resulttype = new ResultDataType(address, frozen, value);
764     this.Tag = resulttype;
765     }
766     public ResultItem(uint address, bool frozen, ulong value)
767     : base()
768     {
769     this.initialize(frozen);
770     this.SubItems.Add(string.Format("0x{0:x8}", address));
771     this.SubItems.Add(string.Format("0x{0:x16}", value));
772     this.SubItems.Add(frozen.ToString());
773     #if HAVE_LISTVIEW_FREEZE_BUTTON
774     this.SubItems.Add(btnFreezeToggle.Toggle(frozen));
775     #endif
776     ResultDataType resulttype = new ResultDataType(address, frozen, value);
777     this.Tag = resulttype;
778     }
779     public ResultItem(uint address, bool frozen, long value)
780     : base()
781     {
782     this.initialize(frozen);
783     this.SubItems.Add(string.Format("0x{0:x8}", address));
784     this.SubItems.Add(string.Format("0x{0:x16}", value));
785     this.SubItems.Add(frozen.ToString());
786     #if HAVE_LISTVIEW_FREEZE_BUTTON
787     this.SubItems.Add(btnFreezeToggle.Toggle(frozen));
788     #endif
789     ResultDataType resulttype = new ResultDataType(address, frozen, value);
790     this.Tag = resulttype;
791     }
792     }
793     public class ResultSubItem : ListViewItem.ListViewSubItem
794     {
795     }
796     [Serializable]
797     public class ResultItemCollection : System.Windows.Forms.ListView.ListViewItemCollection
798     {
799     public ResultItemCollection(ListView owner)
800     : base(owner)
801     {
802     }
803    
804    
805    
806     #region Overriden Members
807     //#region This Members
808     //public new ResultItem this[int index]
809     //{
810     // get
811     // {
812     // return base[index] as ResultItem;
813     // }
814     // set
815     // {
816     // base[index] = value as ListViewItem;
817     // }
818     //}
819     //public new ResultItem this[string key]
820     //{
821     // get
822     // {
823     // return base[key] as ResultItem;
824     // }
825     //}
826     //#endregion
827     #region Add Members
828    
829     public ResultItem Add(ResultItem value)
830     {
831     return (ResultItem)base.Add(value);
832     }
833    
834     public override ListViewItem Add(ListViewItem value)
835     {
836     return base.Add(value);
837     }
838     public override ListViewItem Add(string key, string text, int imageIndex)
839     {
840     return base.Add(key, text, imageIndex);
841     }
842     public override ListViewItem Add(string key, string text, string imageKey)
843     {
844     return base.Add(key, text, imageKey);
845     }
846     public override ListViewItem Add(string text)
847     {
848     return base.Add(text);
849     }
850     public override ListViewItem Add(string text, int imageIndex)
851     {
852     return base.Add(text, imageIndex);
853     }
854     public override ListViewItem Add(string text, string imageKey)
855     {
856     return base.Add(text, imageKey);
857     }
858     #endregion
859     #region Remove Members
860     public override void Remove(ListViewItem item)
861     {
862     base.Remove(item);
863     }
864     #endregion
865    
866     #region Contains Members
867     public new bool Contains(ListViewItem item)
868     {
869     try
870     {
871     return this.Contains((ResultItem)item);
872     }
873     catch (InvalidCastException ex)
874     {
875     Exception ex1 = new Exception("Unable to Convert ListViewItem to ResultItem in ResultItemCollection.Contains(ListViewItem item)", ex);
876     logger.Error.WriteLine("avp.contains(ListViewItem item): invalid cast");
877     logger.Error.WriteLine(ex1.ToString());
878     return false;
879     }
880     catch (Exception ex)
881     {
882     logger.Error.WriteLine("avp.contains(): exception");
883     logger.Error.WriteLine(ex.ToString());
884     return false;
885     }
886     }
887     public bool Contains(ResultItem item)
888     {
889     try
890     {
891     //ResultItem _item = (ResultItem)item;
892    
893     bool contains = false;
894     if (!(this.Count > 0)) return false;
895     foreach (ResultItem iter in this)
896     {
897     if (item.ToString() == iter.ToString()) contains = true;
898     }
899     return contains;
900     }
901     catch (IndexOutOfRangeException)
902     {
903     return false;
904     }
905     catch (ArgumentOutOfRangeException)
906     {
907     return false;
908     }
909     catch (Exception ex)
910     {
911     Exception ex1 = new Exception("Caught non-Argument or Index OutOfRangeException in: ResultItemCollection.Contains(ListViewItem item, int index)", ex);
912     logger.Error.WriteLine("avp.contains(ResultItem item): Exception");
913     logger.Error.WriteLine(ex1.ToString());
914     return false;
915     }
916     }
917     public override bool ContainsKey(string key)
918     {
919     return base.ContainsKey(key);
920     }
921     #endregion
922    
923     #endregion
924     }
925     #endregion
926    
927     public interface IAvpFreeze
928     {
929     bool ItemIsFrozen(int index);
930     void FreezeItem(int index);
931     void ThawItem(int index);
932 william 236 int ProcessID { get; set; }
933 william 229 }
934    
935     public interface IAvpExport
936     {
937     bool ExportToClipboard();
938     bool ExportToFile();
939     bool ExportToFile(string filename);
940     }
941     public interface IAvpImport
942     {
943     bool ImportFromClipboard();
944     bool ImportFromFile();
945     bool ImportFromFile(string filename);
946     }
947     public interface IAvpLvSupport
948     {
949     System.Windows.Forms.View View { get; set; }
950     bool OverrideDetailsViewByDefault { get; set; }
951     ListView.ColumnHeaderCollection Columns { get; }
952     ResultItemCollection Items { get; }
953     }
954     public interface IAvpLvColumnSupport
955     {
956     int GetColumnByType(AVPColumnType AVPColumnType);
957     int GetColumnByKey(string AVPColumnType);
958     }
959    
960     public class AVPIconKeys
961     {
962     public const string FROZEN = "FROZEN";
963     public const string NOTFROZEN = "NOTFROZEN";
964     }
965    
966     #region AVPColumnText Sub-Class
967     public interface IAVPColumnText
968     {
969     string ColumnText { get; }
970     string ColumnKey { get; }
971     int ColumnIndex { get; }
972     int ColumnWidth { get; }
973     }
974     public class AVPColumnText : IAVPColumnText
975     {
976     private const string FREEZE_ICON = "";
977     private const int FREEZE_ICON_WIDTH = 32;
978     private const int FREEZE_ICON_INDEX = 0;
979     private const string ADDRESS = "Address";
980     private const int ADDRESS_WIDTH = 120;
981     private const int ADDRESS_INDEX = 1;
982     private const string VALUE = "Value";
983     private const int VALUE_WIDTH = 220;
984     private const int VALUE_INDEX = 2;
985     private const string FROZEN = "Is Frozen";
986     private const int FROZEN_WIDTH = 120;
987     private const int FROZEN_INDEX = 3;
988     #if HAVE_LISTVIEW_FREEZE_BUTTON
989     private const string FREEZEBUTTON = "Freeze Toggle";
990     private const int FREEZEBUTTON_WIDTH = 160;
991     #endif
992     private const string UKNOWN = "Unknown";
993     private const int UKNOWN_WIDTH = 125;
994     private const int UKNOWN_INDEX = -1;
995    
996     private AVPColumnType _AVPColumnType;
997     public AVPColumnText()
998     {
999     _AVPColumnType = AVPColumnType.UKNOWN;
1000     }
1001     public AVPColumnText(AVPColumnType AVPColumnType)
1002     {
1003     _AVPColumnType = AVPColumnType;
1004     }
1005    
1006     #region IAVPColumnText Members
1007     #region ColumnText
1008     public string ColumnText
1009     {
1010     get
1011     {
1012     switch (_AVPColumnType)
1013     {
1014     case AVPColumnType.ICON:
1015     return FREEZE_ICON;
1016     case AVPColumnType.ADDRESS:
1017     return ADDRESS;
1018     case AVPColumnType.VALUE:
1019     return VALUE;
1020     case AVPColumnType.FROZEN:
1021     return FROZEN;
1022     #if HAVE_LISTVIEW_FREEZE_BUTTON
1023     case AVPColumnType.FREEZE_BUTTON:
1024     return FREEZEBUTTON;
1025     #endif
1026     default:
1027     return UKNOWN;
1028     }
1029     }
1030     }
1031     #endregion
1032     #region ColumnKey
1033     public string ColumnKey
1034     {
1035     get
1036     {
1037     return Enum.GetName(typeof(AVPColumnType), _AVPColumnType);
1038     }
1039     }
1040     #endregion
1041     #region ColumnWidth
1042     public int ColumnWidth
1043     {
1044     get
1045     {
1046     switch (_AVPColumnType)
1047     {
1048     case AVPColumnType.ICON:
1049     return FREEZE_ICON_WIDTH;
1050     case AVPColumnType.ADDRESS:
1051     return ADDRESS_WIDTH;
1052     case AVPColumnType.VALUE:
1053     return VALUE_WIDTH;
1054     case AVPColumnType.FROZEN:
1055     return FROZEN_WIDTH;
1056     #if HAVE_LISTVIEW_FREEZE_BUTTON
1057     case AVPColumnType.FREEZE_BUTTON:
1058     return FREEZEBUTTON_WIDTH;
1059     #endif
1060     default:
1061     return UKNOWN_WIDTH;
1062     }
1063     }
1064     }
1065     #endregion
1066     #region ColumnIndex
1067     public int ColumnIndex
1068     {
1069     get
1070     {
1071     switch (_AVPColumnType)
1072     {
1073     case AVPColumnType.ICON:
1074     return FREEZE_ICON_INDEX;
1075     case AVPColumnType.ADDRESS:
1076     return ADDRESS_INDEX;
1077     case AVPColumnType.VALUE:
1078     return VALUE_INDEX;
1079     case AVPColumnType.FROZEN:
1080     return FROZEN_INDEX;
1081     #if HAVE_LISTVIEW_FREEZE_BUTTON
1082     case AVPColumnType.FREEZE_BUTTON:
1083     return FREEZEBUTTON_WIDTH;
1084     #endif
1085     default:
1086     return UKNOWN_INDEX;
1087     }
1088     }
1089     }
1090     #endregion
1091     #endregion
1092     }
1093     #endregion
1094    
1095     }

  ViewVC Help
Powered by ViewVC 1.1.22