Skip to content

Instantly share code, notes, and snippets.

@kibotu
Last active May 3, 2018 07:51
Show Gist options
  • Save kibotu/7de828936daef49f533e to your computer and use it in GitHub Desktop.
Save kibotu/7de828936daef49f533e to your computer and use it in GitHub Desktop.
CSVParser
public static class CSVParser
{
public static string ReadKeyStorePassword (string path)
{
string password = "";
StreamReader theReader = new StreamReader (path, Encoding.Default);
using (theReader) {
password = theReader.ReadLine ().Replace ("\n", "");
}
theReader.Close ();
return password;
}
public static IDictionary<string,SocialPlatformServiceFeature> LoadDictionary (string path)
{
StreamReader theReader = new StreamReader (path, Encoding.Default);
IDictionary<string,SocialPlatformServiceFeature> dict = new Dictionary<string,SocialPlatformServiceFeature> ();
using (theReader) {
try {
while (!theReader.EndOfStream) {
parseGpsLine (dict, theReader.ReadLine ().Trim ().Replace ("\"", ""));
parseAmazonLine (dict, theReader.ReadLine ().Trim ().Replace ("\"", ""));
}
} catch (System.Exception e) {
Debug.Log ("Parsing of achievements failed" + e.ToString ());
}
}
theReader.Close ();
foreach (var entry in dict)
Debug.Log (entry.Key + " " + entry.Value.ToString ());
return dict;
}
public static void parseGpsLine (IDictionary<string,SocialPlatformServiceFeature> dict, string line)
{
string[] parts = line.Split (new string[] { "," }, System.StringSplitOptions.None);
SocialPlatformServiceFeature feature = new SocialPlatformServiceFeature ();
feature.Name = parts [0].Substring (11, parts [0].Length - 11);
feature.Id = parts [1];
if (parts.Length > 2)
feature.IsIncremental = parts [2] == "incremental";
dict [feature.Name] = feature;
}
public static void parseAmazonLine (IDictionary<string,SocialPlatformServiceFeature> dict, string line)
{
string[] parts = line.Split (new string[] { "," }, System.StringSplitOptions.None);
SocialPlatformServiceFeature feature = new SocialPlatformServiceFeature ();
feature.Id = parts [0];
if (parts.Length > 5)
feature.Name = parts [5];
dict [feature.Name] = feature;
}
}
private IDictionary<string,SocialPlatformServiceFeature> _socialPlatformServiceFeature;
public IDictionary<string,SocialPlatformServiceFeature> SocialPlatformFeature {
get { return _socialPlatformServiceFeature ?? CSVParser.LoadDictionary(GetSocialPlatformCSVPath()); }
}
public class SocialPlatformServiceFeature {
public enum FeatureType {
Achievement, Leaderboard
}
public FeatureType Type;
public string Name;
public string Id;
public bool IsIncremental;
public string ToString() {
return "[" + Type.ToString () + ", " + Name + ", " + Id + ", " + IsIncremental + "]";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment