示例#1
0
        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);
        }
示例#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("#"))
                {
                    continue;
                }

                string[] tokens = line.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries);

                if (tokens.Length != 2)
                {
                    throw new Exception("KeyValueConfig: Invalid length, expected 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()
        {
            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);
        }
示例#4
0
        public static KeyValueConfig ReadKeyValueConfig(TextReader reader)
        {
            var result = new KeyValueConfig();
            string line;

            while ((line = reader.ReadLine()) != null)
            {
                if (string.IsNullOrWhiteSpace(line) || line.StartsWith("#"))
                    continue;

                string[] tokens = line.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries);

                if (tokens.Length != 2)
                    throw new Exception("KeyValueConfig: Invalid length, expected 2.");

                var values = tokens[1].Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                var valuesList = values.ToList();
                result.Data.Add(tokens[0].Trim(), valuesList);
            }
            return result;
        }