public static KeyValueConfig ReadKeyValueConfig(TextReader reader) { var result = new KeyValueConfig(); string line; while ((line = reader.ReadLine()) != null) { if (String.IsNullOrWhiteSpace(line) || line.StartsWith("#")) // skip empty lines and comments { continue; } string[] tokens = line.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries); if (tokens.Length != 2) { throw new Exception("KeyValueConfig: tokens.Length != 2"); } var values = tokens[1].Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var valuesList = values.ToList(); result.Data.Add(tokens[0].Trim(), valuesList); } return(result); }
public static CASCConfig LoadLocalStorageConfig(string basePath) { var config = new CASCConfig { OnlineMode = false, BasePath = basePath }; string buildInfoPath = Path.Combine(basePath, ".build.info"); using (Stream buildInfoStream = new FileStream(buildInfoPath, FileMode.Open)) { config._BuildInfo = KeyValueConfig.ReadVerBarConfig(buildInfoStream); } string buildKey = config._BuildInfo["Build Key"][0]; string buildCfgPath = Path.Combine(basePath, "Data\\config\\", buildKey.Substring(0, 2), buildKey.Substring(2, 2), buildKey); using (Stream stream = new FileStream(buildCfgPath, FileMode.Open)) { config._BuildConfig = KeyValueConfig.ReadKeyValueConfig(stream); } string cdnKey = config._BuildInfo["CDN Key"][0]; string cdnCfgPath = Path.Combine(basePath, "Data\\config\\", cdnKey.Substring(0, 2), cdnKey.Substring(2, 2), cdnKey); using (Stream stream = new FileStream(cdnCfgPath, FileMode.Open)) { config._CDNConfig = KeyValueConfig.ReadKeyValueConfig(stream); } return(config); }
public static KeyValueConfig ReadVerBarConfig(TextReader reader) { var result = new KeyValueConfig(); string line; int lineNum = 0; while ((line = reader.ReadLine()) != null) { if (String.IsNullOrWhiteSpace(line) || line.StartsWith("#")) // skip empty lines and comments { continue; } string[] tokens = line.Split(new char[] { '|' }); if (lineNum == 0) // keys { foreach (var token in tokens) { var tokens2 = token.Split(new char[] { '!' }); result.Data[tokens2[0]] = new List <string>(); } } else // values { if (result.Data.Count != tokens.Length) { continue; } for (int i = 0; i < result.Data.Count; i++) { result.Data.ElementAt(i).Value.Add(tokens[i]); } } lineNum++; } return(result); }