ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater/Serialization/SearchResultReader.cs
(Generate patch)

Comparing trunk/RomCheater/Serialization/SearchResultReader.cs (file contents):
Revision 538 by william, Wed Jun 5 10:33:38 2013 UTC vs.
Revision 539 by william, Wed Jun 5 10:35:29 2013 UTC

# Line 338 | Line 338 | namespace RomCheater.Serialization
338          }
339          #endregion
340  
341 +
342 +        #region private StructResultType<ulong> GetResultAtIndex(int index, bool unsigned, SearchDataTypes datatype, Action<int, string> update_progress)
343 +        private static StructResultType<ulong> GetResultAtIndex(SearchResultReader reader, int index, bool unsigned, SearchDataTypes datatype, Action<int, string> update_progress, Func<bool> cancelmethod)
344 +        {
345 +            try
346 +            {
347 +                //update_progress.Invoke(0, string.Empty);
348 +                int data_size = sizeof(uint); // address size ... should be 4 bytes (could be 8, if we have a 64-bit address)
349 +                StructResultType<ulong> result = StructResultType<ulong>.Empty;
350 +                if (cancelmethod.Invoke()) { return result; }
351 +                using (FileStream fs = reader.CreateReader())
352 +                {
353 +                    using (BinaryReader binReader = new BinaryReader(fs))
354 +                    {
355 +                        binReader.BaseStream.Seek(reader.ResultDataOffset, SeekOrigin.Begin); // seek to start of result data
356 +                        data_size += (int)datatype / 8;
357 +                        long offset = data_size * index;
358 +                        binReader.BaseStream.Seek(offset, SeekOrigin.Current);
359 +                        uint Address = binReader.ReadUInt32();
360 +                        ulong Value = 0;
361 +                        switch (datatype)
362 +                        {
363 +                            case SearchDataTypes._8bits:
364 +                                if (unsigned) { Value = binReader.ReadByte(); } else { Value = (ulong)binReader.ReadSByte(); }
365 +                                break;
366 +                            case SearchDataTypes._16bits:
367 +                                if (unsigned) { Value = binReader.ReadUInt16(); } else { Value = (ulong)binReader.ReadInt16(); }
368 +                                break;
369 +                            case SearchDataTypes._32bits:
370 +                                if (unsigned) { Value = binReader.ReadUInt32(); } else { Value = (ulong)binReader.ReadInt32(); }
371 +                                break;
372 +                            case SearchDataTypes._64bits:
373 +                                if (unsigned) { Value = binReader.ReadUInt64(); } else { Value = (ulong)binReader.ReadInt64(); }
374 +                                break;
375 +                        }
376 +                        result = new StructResultType<ulong>(Address, Value);
377 +                    }
378 +                }
379 +                //double percent_done = 100.0 * ((double)index / (double)reader.ResultCount);
380 +                //string message = string.Format("-> Reading Result at index: 0x{0}", index.ToString("X"));
381 +                //update_progress((int)percent_done, message);
382 +                return result;
383 +            }
384 +            catch (Exception ex)
385 +            {
386 +                logger.Error.WriteLine("GetResultAtIndex...Failed to read the stream at index: 0x{0}", index.ToString("X"));
387 +                logger.VerboseError.WriteLine(ex.ToString());
388 +                return StructResultType<ulong>.Empty;
389 +            }
390 +        }
391 +        #endregion
392 +  
393      }
394   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines