/[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 812 - (show annotations) (download)
Tue Apr 15 14:52:10 2014 UTC (5 years, 9 months ago) by william
File size: 13574 byte(s)
+ update logging to use Enterpise.Logging -- more work is still needed

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

  ViewVC Help
Powered by ViewVC 1.1.22