public static CASCConfig LoadLocalStorageConfig() { var config = new CASCConfig(); string buildInfoPath = Path.Combine(Program.Settings.WoWDirectory, Constants.WOW_BUILD_FILE); using (Stream buildInfoStream = new FileStream(buildInfoPath, FileMode.Open)) config.BuildInfo = VerBarConfig.ReadVerBarConfig(buildInfoStream); Dictionary <string, string> buildInfo = config.GetActiveBuild(); if (buildInfo == null) { throw new Exception("BuildInfo missing!"); } string configFolder = Path.Combine(Program.Settings.WoWDirectory, @"Data\config"); config.ActiveBuild = 0; config.Builds = new List <KeyValueConfig>(); string buildKey = buildInfo["BuildKey"]; string buildCfgPath = Path.Combine(configFolder, buildKey.Substring(0, 2), buildKey.Substring(2, 2), buildKey); using (Stream stream = new FileStream(buildCfgPath, FileMode.Open)) config.Builds.Add(KeyValueConfig.ReadKeyValueConfig(stream)); string cdnKey = buildInfo["CDNKey"]; string cdnCfgPath = Path.Combine(configFolder, 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 CASCConfig LoadOnlineStorageConfig() { var config = new CASCConfig(); string usingRegion = null; try { usingRegion = Constants.CDN_REGIONS[0]; using (var stream = CDNIndexHandler.OpenFileDirect(string.Format(Constants.CDN_CONFIG_URL, usingRegion))) config.CDNData = VerBarConfig.ReadVerBarConfig(stream); using (Stream stream = CDNIndexHandler.OpenFileDirect(string.Format(Constants.CDN_VERSION_URL, usingRegion))) config.VersionsData = VerBarConfig.ReadVerBarConfig(stream); } catch { usingRegion = Constants.CDN_REGIONS[1]; using (var stream = CDNIndexHandler.OpenFileDirect(string.Format(Constants.CDN_CONFIG_URL, usingRegion))) config.CDNData = VerBarConfig.ReadVerBarConfig(stream); using (Stream stream = CDNIndexHandler.OpenFileDirect(string.Format(Constants.CDN_VERSION_URL, usingRegion))) config.VersionsData = VerBarConfig.ReadVerBarConfig(stream); } if (usingRegion == null) { throw new Exception("Unable to access default CDN servers for config/versioning."); } for (int i = 0; i < config.VersionsData.Count; i++) { if (config.VersionsData[i]["Region"] == usingRegion) { config.versionIndex = i; break; } } string cdnKey = config.VersionsData[config.versionIndex]["CDNConfig"].ToLower(); using (Stream stream = CDNIndexHandler.OpenConfigFileDirect(config, cdnKey)) config.CDNConfig = KeyValueConfig.ReadKeyValueConfig(stream); config.ActiveBuild = 0; config.Builds = new List <KeyValueConfig>(); string buildKey = config.VersionsData[config.versionIndex]["BuildConfig"].ToLower(); using (Stream stream = CDNIndexHandler.OpenConfigFileDirect(config, buildKey)) { KeyValueConfig buildConfig = KeyValueConfig.ReadKeyValueConfig(stream); config.Builds.Add(buildConfig); } return(config); }
public static VerBarConfig ReadVerBarConfig(TextReader reader) { var result = new VerBarConfig(); string line; int lineNum = 0; string[] fields = null; 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 { fields = new string[tokens.Length]; for (int i = 0; i < tokens.Length; ++i) { fields[i] = tokens[i].Split(new char[] { '!' })[0].Replace(" ", ""); } } else // values { result.Data.Add(new Dictionary <string, string>()); for (int i = 0; i < tokens.Length; ++i) { result.Data[lineNum - 1].Add(fields[i], tokens[i]); } } lineNum++; } return(result); }
public static VerBarConfig ReadVerBarConfig(TextReader reader) { var result = new VerBarConfig(); string line; int lineNum = 0; string[] fields = null; 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 { fields = new string[tokens.Length]; for (int i = 0; i < tokens.Length; ++i) { fields[i] = tokens[i].Split(new char[] { '!' })[0].Replace(" ", ""); } } else // values { result.Data.Add(new Dictionary<string, string>()); for (int i = 0; i < tokens.Length; ++i) { result.Data[lineNum - 1].Add(fields[i], tokens[i]); } } lineNum++; } return result; }