Guest User

Untitled

a guest
Apr 25th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.IO;
  5. using System.Text.RegularExpressions;
  6. using System.Globalization;
  7.  
  8. namespace ReScene
  9. {
  10.     public class SfvEntry
  11.     {
  12.         public string FileName { get; set; }
  13.         public uint Crc32 { get; set; }
  14.     }
  15.  
  16.     /// <summary>
  17.     /// Implements a simple Reader class that reads through SFV files one line (entry) at a time.
  18.     /// </summary>
  19.     public class SfvReader : IDisposable
  20.     {
  21.         protected StreamReader reader;
  22.  
  23.         public SfvReader(string sfvPath)
  24.         {
  25.             reader = new StreamReader(sfvPath, Encoding.ASCII);
  26.         }
  27.  
  28.         public SfvReader(Stream sfvStream)
  29.         {
  30.             reader = new StreamReader(sfvStream, Encoding.ASCII);
  31.         }
  32.  
  33.         public SfvEntry Read()
  34.         {
  35.             // comment lines in sfv start with ';', so skip those.  also skip any lines that are too short to have both a file name and CRC
  36.             string line;
  37.             do
  38.                 line = reader.ReadLine();
  39.             while (line != null && (line.Trim().Length < 10 || line.StartsWith(";")));
  40.  
  41.             if (line == null)
  42.                 return null;
  43.  
  44.             uint i;
  45.             if (uint.TryParse(line.Substring(line.Length - 8), NumberStyles.HexNumber, null, out i))
  46.                 return new SfvEntry()
  47.                 {
  48.                     FileName = line.Substring(0, line.Length - 9).Trim(),
  49.                     Crc32 = i
  50.                 };
  51.             else
  52.                 return null;
  53.         }
  54.  
  55.         public void Dispose()
  56.         {
  57.             reader.Close();
  58.         }
  59.     }
  60. }
Add Comment
Please, Sign In to add comment