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

Contents of /trunk/RomCheater/Docking/MemorySearch/SearchType.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 409 - (show annotations) (download)
Thu Jun 21 20:02:40 2012 UTC (8 years ago) by william
File size: 12815 byte(s)

1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using Utilities.TransparentControls;
6 using RomCheater.Logging;
7
8 namespace RomCheater.Docking.MemorySearch
9 {
10 public class SearchType : ISearchType//, ISerializable
11 {
12 #region Implicit Concersion
13 public static implicit operator SearchType(OnlySearchType search)
14 {
15 SearchType _search_type = new SearchType(search.DataType, search.IsUnsignedDataType, search.CompareType, search.CompareValueType, search.CompareStartValue, search.CompareEndValue, null);
16 _search_type.IsFirstSearch = search.IsFirstSearch;
17 //_search_type.Results = search.Results;
18 return _search_type;
19 }
20 #endregion
21 //const SearchDataTypes Default_DataType = SearchDataTypes._8bits;
22 const bool Default_UnsignedState = true;
23 const SearchDataTypes Default_SarechType = SearchDataTypes._32bits;
24 const SearchCompareTypes Default_CompareType = SearchCompareTypes.Equal;
25 const CompareValueTypes Default_CompareValueType = CompareValueTypes.OldValue;
26 const byte Default_CompareValue = 0;
27
28 #region default constructors
29 public SearchType() : this(Default_SarechType, Default_UnsignedState, Default_CompareType, Default_CompareValueType, Default_CompareValue) { }
30 public SearchType(SearchDataTypes _data_type, bool _is_unsigned, SearchCompareTypes _compare_type, CompareValueTypes _compare_value_type, object value)
31 : this(_data_type, _is_unsigned, _compare_type, _compare_value_type, value, null, null)
32 {
33 }
34 public SearchType(SearchDataTypes _data_type, bool _is_unsigned, SearchCompareTypes _compare_type, CompareValueTypes _compare_value_type, object start_value, object end_value, ProgressBarWithPercentageLabel _progress_logger)
35 {
36 this.DataType = _data_type;
37 this.IsUnsignedDataType = _is_unsigned;
38 this.CompareType = _compare_type;
39 this.CompareValueType = _compare_value_type;
40 this.CompareStartValue = start_value;
41 this.CompareEndValue = end_value;
42 this.ProgressLogger = _progress_logger;
43 }
44 #endregion
45
46 #region 8bit specific constructors
47 public SearchType(byte start_value, byte end_value, bool _is_unsigned, SearchCompareTypes _compare_type, CompareValueTypes _compare_value_type)
48 : this(start_value, end_value, _is_unsigned, _compare_type, _compare_value_type, null)
49 {
50 }
51 public SearchType(byte start_value, byte end_value, bool _is_unsigned, SearchCompareTypes _compare_type, CompareValueTypes _compare_value_type, ProgressBarWithPercentageLabel _progress_logger)
52 : this((ulong)start_value, (ulong)end_value, _is_unsigned, _compare_type, _compare_value_type, _progress_logger)
53 {
54 this.DataType = SearchDataTypes._8bits;
55 }
56 #endregion
57
58 #region 16bit specific constructors
59 public SearchType(ushort start_value, ushort end_value, bool _is_unsigned, SearchCompareTypes _compare_type, CompareValueTypes _compare_value_type)
60 : this(start_value, end_value, _is_unsigned, _compare_type, _compare_value_type, null)
61 {
62 }
63 public SearchType(ushort start_value, ushort end_value, bool _is_unsigned, SearchCompareTypes _compare_type, CompareValueTypes _compare_value_type, ProgressBarWithPercentageLabel _progress_logger)
64 : this((ulong)start_value, (ulong)end_value, _is_unsigned, _compare_type, _compare_value_type, _progress_logger)
65 {
66 this.DataType = SearchDataTypes._16bits;
67 }
68 #endregion
69
70 #region 32bit specific constructors
71 public SearchType(uint start_value, uint end_value, bool _is_unsigned, SearchCompareTypes _compare_type, CompareValueTypes _compare_value_type)
72 : this(start_value, end_value, _is_unsigned, _compare_type, _compare_value_type, null)
73 {
74 }
75 public SearchType(uint start_value, uint end_value, bool _is_unsigned, SearchCompareTypes _compare_type, CompareValueTypes _compare_value_type, ProgressBarWithPercentageLabel _progress_logger)
76 : this((ulong)start_value, (ulong)end_value, _is_unsigned, _compare_type, _compare_value_type, _progress_logger)
77 {
78 this.DataType = SearchDataTypes._32bits;
79 }
80 #endregion
81
82 #region 64bit specific constructors
83 public SearchType(ulong start_value, ulong end_value, bool _is_unsigned, SearchCompareTypes _compare_type, CompareValueTypes _compare_value_type)
84 : this(start_value, end_value, _is_unsigned, _compare_type, _compare_value_type, null)
85 {
86 }
87 public SearchType(ulong start_value, ulong end_value, bool _is_unsigned, SearchCompareTypes _compare_type, CompareValueTypes _compare_value_type, ProgressBarWithPercentageLabel _progress_logger)
88 {
89 this.DataType = SearchDataTypes._64bits;
90 this.IsUnsignedDataType = _is_unsigned;
91 this.CompareType = _compare_type;
92 this.CompareValueType = _compare_value_type;
93 this.CompareStartValue = start_value;
94 this.CompareEndValue = end_value;
95 this.ProgressLogger = null;
96 }
97 #endregion
98 #region ISearchType Members
99
100 private SearchDataTypes _DataType;
101 private bool _IsUnsignedDataType;
102 private SearchCompareTypes _CompareType;
103 private CompareValueTypes _CompareValueType;
104 private object _CompareStartValue;
105 private object _CompareEndValue;
106 private ProgressBarWithPercentageLabel _ProgressLogger;
107
108 private bool _IsFirstSearch;
109 //private List<ResultType<object>> _Results = new List<ResultType<object>>();
110
111 public SearchDataTypes DataType { get { return _DataType; } set { _DataType = value; } }
112 public bool IsUnsignedDataType { get { return _IsUnsignedDataType; } set { _IsUnsignedDataType = value; } }
113 public SearchCompareTypes CompareType { get { return _CompareType; } set { _CompareType = value; } }
114 public CompareValueTypes CompareValueType { get { return _CompareValueType; } set { _CompareValueType = value; } }
115
116 public object CompareStartValue { get { return _CompareStartValue; } set { _CompareStartValue = value; } }
117 public object CompareEndValue { get { return _CompareEndValue; } set { _CompareEndValue = value; } }
118
119 public ProgressBarWithPercentageLabel ProgressLogger { get { return _ProgressLogger; } set { if (value != null) value.ShowPercentageLabel = true; _ProgressLogger = value; } }
120
121 public bool IsFirstSearch { get { return _IsFirstSearch; } set { _IsFirstSearch = value; } }
122
123 //public List<ResultType<object>> Results { get { return _Results; } set { _Results = value; } }
124
125 public void LogSearchOptions()
126 {
127
128 //StringBuilder builder = new StringBuilder();
129
130 logger.Info.WriteLine("Current Search Options:");
131 // write Data type
132 logger.Info.WriteLine("Data Type: {0}", Enum.GetName(typeof(SearchDataTypes), this.DataType));
133 // write Signed/Unsigned
134 if (this.IsUnsignedDataType) { logger.Info.WriteLine("Signed/Unsigned: {0}", "Unsigned"); }
135 else { logger.Info.WriteLine("Signed/Unsigned: {0}", "Signed"); }
136 // Write Compare Type
137 logger.Info.WriteLine("Comparison Type: {0}", Enum.GetName(typeof(SearchCompareTypes), this.CompareType));
138 // Write Compare Value Tupe
139 logger.Info.WriteLine("Comparison Value Type: {0}", Enum.GetName(typeof(CompareValueTypes), this.CompareValueType));
140 // Write Value
141 if (this.CompareType != SearchCompareTypes.Between && this.CompareType != SearchCompareTypes.NotBetween)
142 {
143 #region Non-Ranged Comparison Value(s)
144 if (this.CompareValueType == CompareValueTypes.SpecificValue)
145 {
146 switch (this.DataType)
147 {
148 case SearchDataTypes._8bits:
149 if (this.IsUnsignedDataType) { logger.Info.WriteLine("Comparison Value: 0x{0}", Convert.ToByte(this.CompareStartValue).ToString("x2")); }
150 else { logger.Info.WriteLine("Comparison Value: 0x{0}", Convert.ToSByte(this.CompareStartValue).ToString("x2")); }
151 break;
152 case SearchDataTypes._16bits:
153 if (this.IsUnsignedDataType) { logger.Info.WriteLine("Comparison Value: 0x{0}", Convert.ToUInt16(this.CompareStartValue).ToString("x4")); }
154 else { logger.Info.WriteLine("Comparison Value: 0x{0}", Convert.ToInt16(this.CompareStartValue).ToString("x4")); }
155 break;
156 case SearchDataTypes._32bits:
157 if (this.IsUnsignedDataType) { logger.Info.WriteLine("Comparison Value: 0x{0}", Convert.ToUInt32(this.CompareStartValue).ToString("x8")); }
158 else { logger.Info.WriteLine("Comparison Value: 0x{0}", Convert.ToInt32(this.CompareStartValue).ToString("x8")); }
159 break;
160 case SearchDataTypes._64bits:
161 if (this.IsUnsignedDataType) { logger.Info.WriteLine("Comparison Value: 0x{0}", Convert.ToUInt64(this.CompareStartValue).ToString("x16")); }
162 else { logger.Info.WriteLine("Comparison Value: 0x{0}", Convert.ToInt64(this.CompareStartValue).ToString("x16")); }
163 break;
164 default: throw new InvalidOperationException("In SearchType(): Encounterd an Unkown Search Data Type.");
165 }
166 }
167 else
168 {
169 logger.Info.WriteLine("Comparison Value: {0}\n", "ignored");
170 }
171 #endregion
172 }
173 else
174 {
175 #region Ranged Comparison Value(s)
176 switch (this.DataType)
177 {
178 case SearchDataTypes._8bits:
179 if (this.IsUnsignedDataType) { logger.Info.WriteLine("Comparison Range: 0x{0:x2} to 0x{1:x2}", Convert.ToByte(this.CompareStartValue), Convert.ToByte(this.CompareEndValue)); }
180 else { logger.Info.WriteLine("Comparison Range: 0x{0:x2} to 0x{1:x2}", Convert.ToSByte(this.CompareStartValue), Convert.ToSByte(this.CompareEndValue)); }
181 break;
182 case SearchDataTypes._16bits:
183 if (this.IsUnsignedDataType) { logger.Info.WriteLine("CComparison Range: 0x{0:x2} to 0x{1:x4}", Convert.ToUInt16(this.CompareStartValue), Convert.ToUInt16(this.CompareEndValue)); }
184 else { logger.Info.WriteLine("Comparison Range: 0x{0:x4} to 0x{1:x4}", Convert.ToInt16(this.CompareStartValue), Convert.ToUInt16(this.CompareEndValue)); }
185 break;
186 case SearchDataTypes._32bits:
187 if (this.IsUnsignedDataType) { logger.Info.WriteLine("Comparison Range: 0x{0:x8} to 0x{1:x8}", Convert.ToUInt32(this.CompareStartValue), Convert.ToUInt32(this.CompareEndValue)); }
188 else { logger.Info.WriteLine("Comparison Range: 0x{0:x8} to 0x{1:x8}", Convert.ToInt32(this.CompareStartValue), Convert.ToInt32(this.CompareEndValue)); }
189 break;
190 case SearchDataTypes._64bits:
191 if (this.IsUnsignedDataType) { logger.Info.WriteLine("Comparison Range: 0x{0:x16} to 0x{1:x16}", Convert.ToUInt64(this.CompareStartValue), Convert.ToUInt64(this.CompareEndValue)); }
192 else { logger.Info.WriteLine("Comparison Range: 0x{0:x16} to 0x{1:x16}", Convert.ToInt64(this.CompareStartValue), Convert.ToInt64(this.CompareEndValue)); }
193 break;
194 default: throw new InvalidOperationException("In SearchType(): Encounterd an Unkown Search Data Type.");
195 }
196 #endregion
197 }
198
199 //logger.Info.WriteLine(builder.ToString());
200 }
201 #endregion
202
203 //#region ISerializable Members
204
205 //void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
206 //{
207 // throw new NotImplementedException();
208 //}
209
210 //#endregion
211 }
212 }

  ViewVC Help
Powered by ViewVC 1.1.22