Skip to content
This repository has been archived by the owner on Mar 29, 2020. It is now read-only.

Commit

Permalink
Refactor the definition reader
Browse files Browse the repository at this point in the history
  • Loading branch information
Idhrendur committed Feb 10, 2018
1 parent 98f89b2 commit 7b78ef1
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions ProvinceMapper/DefinitionReader.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.IO;



namespace ProvinceMapper
{
class DefinitionReader
{
public DefinitionReader(string path, StatusUpdate su)
public DefinitionReader(string path, StatusUpdate progress)
{
StreamReader sr = new StreamReader(path, Encoding.GetEncoding(1252));
sr.ReadLine(); // discard first line
while (!sr.EndOfStream)
StreamReader reader = new StreamReader(path, Encoding.GetEncoding(1252));
reader.ReadLine(); // discard first line

while (!reader.EndOfStream)
{
string province = sr.ReadLine();
string province = reader.ReadLine();
string[] provinceTokens = province.Split(';');
if ((provinceTokens[4] == "RNW") || ((provinceTokens[4].Length > 5) && (provinceTokens[4].Substring(0, 6) == "Unused")))
if (IsRNWProvince(provinceTokens) || IsUnusedProvince(provinceTokens))
{
continue;
}

try
{
Province p = new Province(provinceTokens);
Expand All @@ -28,11 +30,23 @@ public DefinitionReader(string path, StatusUpdate su)
catch
{
}
su(100.0 * sr.BaseStream.Position / sr.BaseStream.Length);

progress(100.0 * reader.BaseStream.Position / reader.BaseStream.Length);
}
sr.Close();

reader.Close();
}

public List<Province> provinces = new List<Province>();

private bool IsRNWProvince(string[] provinceTokens)
{
return (provinceTokens[4] == "RNW");
}

private bool IsUnusedProvince(string[] provinceTokens)
{
return ((provinceTokens[4].Length > 5) && (provinceTokens[4].Substring(0, 6) == "Unused"));
}
}
}

0 comments on commit 7b78ef1

Please sign in to comment.