Пример #1
0
        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);
            }

            config.Build = Convert.ToInt32(config._BuildInfo["Version"][0].Split('.')[3]);

            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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        public static CASCConfig LoadOnlineStorageConfig(string product)
        {
            var config = new CASCConfig {
                OnlineMode = true
            };

            using (var cdnsStream = CDNIndexHandler.OpenFileDirect(String.Format("http://us.patch.battle.net/{0}/cdns", product)))
            {
                config._CDNData = KeyValueConfig.ReadVerBarConfig(cdnsStream);
            }

            using (var versionsStream = CDNIndexHandler.OpenFileDirect(String.Format("http://us.patch.battle.net/{0}/versions", product)))
            {
                config._VersionsData = KeyValueConfig.ReadVerBarConfig(versionsStream);
            }

            int index = 0;
            int build = 0;

            for (int i = 0; i < config._VersionsData["BuildId"].Count; ++i)
            {
                int build2 = Convert.ToInt32(config._VersionsData["BuildId"][i]);
                if (build2 > build)
                {
                    build = build2;
                    index = i;
                }
            }

            config.Build = build;

            string buildKey = config._VersionsData["BuildConfig"][index];

            using (Stream stream = CDNIndexHandler.OpenConfigFileDirect(config.CDNUrl, buildKey))
            {
                config._BuildConfig = KeyValueConfig.ReadKeyValueConfig(stream);
            }

            string cdnKey = config._VersionsData["CDNConfig"][index];

            using (Stream stream = CDNIndexHandler.OpenConfigFileDirect(config.CDNUrl, cdnKey))
            {
                config._CDNConfig = KeyValueConfig.ReadKeyValueConfig(stream);
            }
            return(config);
        }
Пример #4
0
        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 (Data.Count != tokens.Length)
                    //    throw new Exception("VerBarConfig: Data.Count != tokens.Length");
                    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);
        }