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

  ViewVC Help
Powered by ViewVC 1.1.22