public static CASCConfig LoadSpecificStorageConfig(string product, string buildconfig, string encoding) { var config = new CASCConfig { OnlineMode = true, Region = "us", Product = product }; using (var ribbit = new RibbitClient("us")) using (var cdnsStream = ribbit.GetAsStream($"v1/products/{product}/cdns")) config.CDNData = VerBarConfig.ReadVerBarConfig(cdnsStream); config.GameType = CASCGame.DetectGameByUid(product); using (var stream = CDNIndexHandler.OpenConfigFileDirect(config, encoding)) config.CDNConfig = KeyValueConfig.ReadKeyValueConfig(stream); config.Builds = new List <KeyValueConfig>(); using (var stream = CDNIndexHandler.OpenConfigFileDirect(config, buildconfig)) { var cfg = KeyValueConfig.ReadKeyValueConfig(stream); config.Builds.Add(cfg); } return(config); }
public static CASCConfig LoadLocalStorageConfig(string basePath, string product = null) { var config = new CASCConfig { OnlineMode = false, BasePath = basePath, Product = product }; config.GameType = CASCGame.DetectLocalGame(basePath); if (config.GameType == CASCGameType.Agent || config.GameType == CASCGameType.Hearthstone) { throw new Exception("Local mode not supported for this game!"); } string buildInfoPath = Path.Combine(basePath, ".build.info"); using (Stream buildInfoStream = new FileStream(buildInfoPath, FileMode.Open)) { config._BuildInfo = VerBarConfig.ReadVerBarConfig(buildInfoStream); } Dictionary <string, string> bi = config.GetActiveBuild(product); if (bi == null) { throw new Exception("Can't find active BuildInfoEntry"); } string dataFolder = CASCGame.GetDataFolder(config.GameType); config.ActiveBuild = 0; config._Builds = new List <KeyValueConfig>(); string buildKey = bi["BuildKey"]; //string buildKey = "5a05c58e28d0b2c3245954b6f4e2ae66"; string buildCfgPath = Path.Combine(basePath, dataFolder, "config", 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 = bi["CDNKey"]; //string cdnKey = "23d301e8633baaa063189ca9442b3088"; string cdnCfgPath = Path.Combine(basePath, dataFolder, "config", cdnKey.Substring(0, 2), cdnKey.Substring(2, 2), cdnKey); using (Stream stream = new FileStream(cdnCfgPath, FileMode.Open)) { config._CDNConfig = KeyValueConfig.ReadKeyValueConfig(stream); } CDNCache.Init(config); return(config); }
public static VerBarConfig ReadVerBarConfig(TextReader reader) { var result = new VerBarConfig(); int lineNum = 0; string[] fields = null; 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[] { '|' }); 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); }
private static string GetConfigVariable(VerBarConfig config, string filterParamName, string filterParamValue, string varName) { if (!HasConfigVariable(config, filterParamName)) { if (config[0].TryGetValue(varName, out string varValue)) { return(varValue); } return(null); } for (int i = 0; i < config.Count; i++) { var cfg = config[i]; if (cfg.TryGetValue(filterParamName, out string paramValue) && paramValue == filterParamValue && cfg.TryGetValue(varName, out string varValue)) { return(varValue); } } return(null); }
private static bool HasConfigVariable(VerBarConfig config, string varName) => config[0].ContainsKey(varName);
public static CASCConfig LoadLocalStorageConfig(string basePath, string product, ILoggerOptions loggerOptions = null) { string buildInfoPath = Path.Combine(basePath, ".build.info"); if (!File.Exists(buildInfoPath)) { throw new Exception("Local mode not supported for this game!"); } Logger.Init(loggerOptions); var config = new CASCConfig { OnlineMode = false, BasePath = basePath, Product = product }; using (Stream buildInfoStream = new FileStream(buildInfoPath, FileMode.Open)) { config._BuildInfo = VerBarConfig.ReadVerBarConfig(buildInfoStream); } CASCGameType gameType; if (!HasConfigVariable(config._BuildInfo, "Product")) { var detectedGameType = CASCGame.DetectLocalGame(basePath, product, config.GetBuildInfoVariable("BuildKey")); if (detectedGameType.HasValue) { gameType = detectedGameType.Value; } else { throw new Exception($"No product {product} found at {basePath}"); } } else { string productUid = config.GetBuildInfoVariable("Product"); if (productUid == null) { throw new Exception($"No product {product} found at {basePath}"); } gameType = CASCGame.DetectGameByUid(product); } config.GameType = gameType; string dataFolder = CASCGame.GetDataFolder(config.GameType); config.ActiveBuild = 0; config._Builds = new List <KeyValueConfig>(); if (File.Exists("fakebuildconfig")) { using (Stream stream = new FileStream("fakebuildconfig", FileMode.Open)) { var cfg = KeyValueConfig.ReadKeyValueConfig(stream); config._Builds.Add(cfg); } } else { string buildKey = config.GetBuildInfoVariable("BuildKey"); //string buildKey = "5a05c58e28d0b2c3245954b6f4e2ae66"; string buildCfgPath = Path.Combine(basePath, dataFolder, "config", buildKey.Substring(0, 2), buildKey.Substring(2, 2), buildKey); using (Stream stream = new FileStream(buildCfgPath, FileMode.Open)) { config._Builds.Add(KeyValueConfig.ReadKeyValueConfig(stream)); } } if (File.Exists("fakecdnconfig")) { using (Stream stream = new FileStream("fakecdnconfig", FileMode.Open)) { config._CDNConfig = KeyValueConfig.ReadKeyValueConfig(stream); } } else { string cdnKey = config.GetBuildInfoVariable("CDNKey"); //string cdnKey = "23d301e8633baaa063189ca9442b3088"; string cdnCfgPath = Path.Combine(basePath, dataFolder, "config", cdnKey.Substring(0, 2), cdnKey.Substring(2, 2), cdnKey); using (Stream stream = new FileStream(cdnCfgPath, FileMode.Open)) { config._CDNConfig = KeyValueConfig.ReadKeyValueConfig(stream); } } CDNCache.Init(config); return(config); }
public static CASCConfig LoadOnlineStorageConfig(string product, string region, bool useCurrentBuild = false, ILoggerOptions loggerOptions = null) { Logger.Init(loggerOptions); var config = new CASCConfig { OnlineMode = true, Region = region, Product = product }; using (var ribbit = new RibbitClient("us")) using (var cdnsStream = ribbit.GetAsStream($"v1/products/{product}/cdns")) //using (var cdnsStream = CDNIndexHandler.OpenFileDirect(string.Format("http://us.patch.battle.net:1119/{0}/cdns", product))) { config._CdnsData = VerBarConfig.ReadVerBarConfig(cdnsStream); } using (var ribbit = new RibbitClient("us")) using (var versionsStream = ribbit.GetAsStream($"v1/products/{product}/versions")) //using (var versionsStream = CDNIndexHandler.OpenFileDirect(string.Format("http://us.patch.battle.net:1119/{0}/versions", product))) { config._VersionsData = VerBarConfig.ReadVerBarConfig(versionsStream); } CDNCache.Init(config); config.GameType = CASCGame.DetectGameByUid(product); if (File.Exists("fakecdnconfig")) { using (Stream stream = new FileStream("fakecdnconfig", FileMode.Open)) { config._CDNConfig = KeyValueConfig.ReadKeyValueConfig(stream); } } else { string cdnKey = config.GetVersionsVariable("CDNConfig").ToLower(); //string cdnKey = "da4896ce91922122bc0a2371ee114423"; using (Stream stream = CDNIndexHandler.OpenConfigFileDirect(config, cdnKey)) { config._CDNConfig = KeyValueConfig.ReadKeyValueConfig(stream); } } config.ActiveBuild = 0; config._Builds = new List <KeyValueConfig>(); if (config._CDNConfig["builds"] != null) { for (int i = 0; i < config._CDNConfig["builds"].Count; i++) { try { using (Stream stream = CDNIndexHandler.OpenConfigFileDirect(config, config._CDNConfig["builds"][i])) { var cfg = KeyValueConfig.ReadKeyValueConfig(stream); config._Builds.Add(cfg); } } catch { } } if (useCurrentBuild) { string curBuildKey = config.GetVersionsVariable("BuildConfig"); int buildIndex = config._CDNConfig["builds"].IndexOf(curBuildKey); if (buildIndex != -1) { config.ActiveBuild = buildIndex; } } } if (File.Exists("fakebuildconfig")) { using (Stream stream = new FileStream("fakebuildconfig", FileMode.Open)) { var cfg = KeyValueConfig.ReadKeyValueConfig(stream); config._Builds.Add(cfg); } } else { string buildKey = config.GetVersionsVariable("BuildConfig").ToLower(); //string buildKey = "3b0517b51edbe0b96f6ac5ea7eaaed38"; using (Stream stream = CDNIndexHandler.OpenConfigFileDirect(config, buildKey)) { var cfg = KeyValueConfig.ReadKeyValueConfig(stream); config._Builds.Add(cfg); } } return(config); }
public static CASCConfig LoadOnlineStorageConfig(string product, string region, bool useCurrentBuild = false) { var config = new CASCConfig { OnlineMode = true }; config.Region = region; config.Product = product; using (var ribbit = new RibbitClient("us")) using (var cdnsStream = ribbit.GetAsStream($"v1/products/{product}/cdns")) //using (var cdnsStream = CDNIndexHandler.OpenFileDirect(string.Format("http://us.patch.battle.net:1119/{0}/cdns", product))) { config._CDNData = VerBarConfig.ReadVerBarConfig(cdnsStream); } using (var ribbit = new RibbitClient("us")) using (var versionsStream = ribbit.GetAsStream($"v1/products/{product}/versions")) //using (var versionsStream = CDNIndexHandler.OpenFileDirect(string.Format("http://us.patch.battle.net:1119/{0}/versions", product))) { config._VersionsData = VerBarConfig.ReadVerBarConfig(versionsStream); } for (int i = 0; i < config._VersionsData.Count; ++i) { if (config._VersionsData[i]["Region"] == region) { config._versionsIndex = i; break; } } CDNCache.Init(config); config.GameType = CASCGame.DetectOnlineGame(product); string cdnKey = config._VersionsData[config._versionsIndex]["CDNConfig"].ToLower(); //string cdnKey = "da4896ce91922122bc0a2371ee114423"; using (Stream stream = CDNIndexHandler.OpenConfigFileDirect(config, cdnKey)) { config._CDNConfig = KeyValueConfig.ReadKeyValueConfig(stream); } config.ActiveBuild = 0; config._Builds = new List <KeyValueConfig>(); if (config._CDNConfig["builds"] != null) { for (int i = 0; i < config._CDNConfig["builds"].Count; i++) { try { using (Stream stream = CDNIndexHandler.OpenConfigFileDirect(config, config._CDNConfig["builds"][i])) { var cfg = KeyValueConfig.ReadKeyValueConfig(stream); config._Builds.Add(cfg); } } catch { } } if (useCurrentBuild) { string curBuildKey = config._VersionsData[config._versionsIndex]["BuildConfig"]; int buildIndex = config._CDNConfig["builds"].IndexOf(curBuildKey); if (buildIndex != -1) { config.ActiveBuild = buildIndex; } } } string buildKey = config._VersionsData[config._versionsIndex]["BuildConfig"].ToLower(); //string buildKey = "3b0517b51edbe0b96f6ac5ea7eaaed38"; using (Stream stream = CDNIndexHandler.OpenConfigFileDirect(config, buildKey)) { var cfg = KeyValueConfig.ReadKeyValueConfig(stream); config._Builds.Add(cfg); } return(config); }
public static CASCConfig LoadOnlineStorageConfig(string product, string region, bool useCurrentBuild = false) { var config = new CASCConfig { OnlineMode = true }; config.Region = region; config.Product = product; using (var cdnsStream = CDNIndexHandler.OpenFileDirect(string.Format("http://us.patch.battle.net:1119/{0}/cdns", product))) { config._CDNData = VerBarConfig.ReadVerBarConfig(cdnsStream); } using (var versionsStream = CDNIndexHandler.OpenFileDirect(string.Format("http://us.patch.battle.net:1119/{0}/versions", product))) { config._VersionsData = VerBarConfig.ReadVerBarConfig(versionsStream); } for (int i = 0; i < config._VersionsData.Count; ++i) { if (config._VersionsData[i]["Region"] == region) { config._versionsIndex = i; break; } } config.GameType = CASCGame.DetectOnlineGame(product); string cdnKey = config._VersionsData[config._versionsIndex]["CDNConfig"].ToLower(); //string cdnKey = "a7483232ba17b111f42ffbcd1e7f9eeb"; //string cdnKey = "8c4ac7ab2f96ab75dab58448ffd07842"; //string cdnKey = "47615445690e4dd6b998558e33ed50d2"; using (Stream stream = CDNIndexHandler.OpenConfigFileDirect(config, cdnKey)) { config._CDNConfig = KeyValueConfig.ReadKeyValueConfig(stream); } config.ActiveBuild = 0; config._Builds = new List <KeyValueConfig>(); if (config._CDNConfig["builds"] != null) { for (int i = 0; i < config._CDNConfig["builds"].Count; i++) { try { using (Stream stream = CDNIndexHandler.OpenConfigFileDirect(config, config._CDNConfig["builds"][i])) { var cfg = KeyValueConfig.ReadKeyValueConfig(stream); config._Builds.Add(cfg); } } catch { } } if (useCurrentBuild) { string curBuildKey = config._VersionsData[config._versionsIndex]["BuildConfig"]; int buildIndex = config._CDNConfig["builds"].IndexOf(curBuildKey); if (buildIndex != -1) { config.ActiveBuild = buildIndex; } } } string buildKey = config._VersionsData[config._versionsIndex]["BuildConfig"].ToLower(); //string buildKey = "033c730bed51704e2bac595c9a2794cf"; //string buildKey = "f639eab0a11d5b7a9099bc188badaa2e"; //string buildKey = "38ac0190903e71643e14ef9db0087c1d"; using (Stream stream = CDNIndexHandler.OpenConfigFileDirect(config, buildKey)) { var cfg = KeyValueConfig.ReadKeyValueConfig(stream); config._Builds.Add(cfg); } return(config); }
public static CASCConfig LoadOnlineStorageConfig(string product, string region, bool useCurrentBuild = false) { var config = new CASCConfig { OnlineMode = true }; config.Region = region; config.Product = product; using (var cdnsStream = CDNIndexHandler.OpenFileDirect(string.Format("http://us.patch.battle.net:1119/{0}/cdns", product))) { config._CDNData = VerBarConfig.ReadVerBarConfig(cdnsStream); } using (var versionsStream = CDNIndexHandler.OpenFileDirect(string.Format("http://us.patch.battle.net:1119/{0}/versions", product))) { config._VersionsData = VerBarConfig.ReadVerBarConfig(versionsStream); } for (int i = 0; i < config._VersionsData.Count; ++i) { if (config._VersionsData[i]["Region"] == region) { config._versionsIndex = i; break; } } config.GameType = CASCGame.DetectOnlineGame(product); string cdnKey = config._VersionsData[config._versionsIndex]["CDNConfig"].ToLower(); //string cdnKey = "d583ee15a02b81cc494aeeef8d195059"; //string cdnKey = "8c4ac7ab2f96ab75dab58448ffd07842"; using (Stream stream = CDNIndexHandler.OpenConfigFileDirect(config, cdnKey)) { config._CDNConfig = KeyValueConfig.ReadKeyValueConfig(stream); } config.ActiveBuild = 0; config._Builds = new List <KeyValueConfig>(); if (config._CDNConfig["builds"] != null) { for (int i = 0; i < config._CDNConfig["builds"].Count; i++) { try { using (Stream stream = CDNIndexHandler.OpenConfigFileDirect(config, config._CDNConfig["builds"][i])) { var cfg = KeyValueConfig.ReadKeyValueConfig(stream); config._Builds.Add(cfg); } } catch { } } if (useCurrentBuild) { string curBuildKey = config._VersionsData[config._versionsIndex]["BuildConfig"]; int buildIndex = config._CDNConfig["builds"].IndexOf(curBuildKey); if (buildIndex != -1) { config.ActiveBuild = buildIndex; } } } string buildKey = config._VersionsData[config._versionsIndex]["BuildConfig"].ToLower(); //string buildKey = "2e1db4da3a538cd52521b73040bdb162"; //string buildKey = "f639eab0a11d5b7a9099bc188badaa2e"; using (Stream stream = CDNIndexHandler.OpenConfigFileDirect(config, buildKey)) { var cfg = KeyValueConfig.ReadKeyValueConfig(stream); config._Builds.Add(cfg); } return(config); }
public static CASCConfig LoadOnlineStorageConfig(string product, string region, bool useCurrentBuild = false) { var config = new CASCConfig { OnlineMode = true }; config.Region = region; config.Product = product; using (var cdnsStream = CDNIndexHandler.OpenFileDirect(string.Format("http://us.patch.battle.net:1119/{0}/cdns", product))) { config._CDNData = VerBarConfig.ReadVerBarConfig(cdnsStream); } using (var versionsStream = CDNIndexHandler.OpenFileDirect(string.Format("http://us.patch.battle.net:1119/{0}/versions", product))) { config._VersionsData = VerBarConfig.ReadVerBarConfig(versionsStream); } for (int i = 0; i < config._VersionsData.Count; ++i) { if (config._VersionsData[i]["Region"] == region) { config._versionsIndex = i; break; } } config.GameType = CASCGame.DetectOnlineGame(product); string cdnKey = config._VersionsData[config._versionsIndex]["CDNConfig"].ToLower(); //string cdnKey = "1964f5dfcb945c1b31acabedeaf13d09"; using (Stream stream = CDNIndexHandler.OpenConfigFileDirect(config, cdnKey)) { config._CDNConfig = KeyValueConfig.ReadKeyValueConfig(stream); } config.ActiveBuild = 0; config._Builds = new List <KeyValueConfig>(); if (config._CDNConfig["builds"] != null) { for (int i = 0; i < config._CDNConfig["builds"].Count; i++) { try { using (Stream stream = CDNIndexHandler.OpenConfigFileDirect(config, config._CDNConfig["builds"][i])) { var cfg = KeyValueConfig.ReadKeyValueConfig(stream); config._Builds.Add(cfg); } } catch { } } if (useCurrentBuild) { string curBuildKey = config._VersionsData[config._versionsIndex]["BuildConfig"]; int buildIndex = config._CDNConfig["builds"].IndexOf(curBuildKey); if (buildIndex != -1) { config.ActiveBuild = buildIndex; } } } string buildKey = config._VersionsData[config._versionsIndex]["BuildConfig"].ToLower(); //string buildKey = "e8f3d86ab313c4bdf5cf4f5daea32477"; using (Stream stream = CDNIndexHandler.OpenConfigFileDirect(config, buildKey)) { var cfg = KeyValueConfig.ReadKeyValueConfig(stream); config._Builds.Add(cfg); } return(config); }