Пример #1
0
        public void Refresh()
        {
            var file = HostedScriptEngine.ConfigFilePath();

            if (file != null)
            {
                _config = KeyValueConfig.Read(file);
            }
        }
Пример #2
0
        /// <summary>
        ///     Loads data from disk
        /// </summary>
        /// <param name="basePath"></param>
        /// <param name="useKeyring"></param>
        /// <param name="loadMultipleLangs"></param>
        /// <returns></returns>
        public static CASCConfig LoadLocalStorageConfig(string basePath, bool useKeyring, bool loadMultipleLangs)
        {
            CASCConfig config = new CASCConfig {
                OnlineMode = false,
                BasePath   = basePath
            };

            try {
                string productDbPath = Path.Combine(basePath, ".product.db");
                config.InstallData = new ProductDatabase(productDbPath, true).Data.ProductInstalls[0];
            } catch { }

            config.SpeechLanguage = config.InstallData?.Settings?.SelectedSpeechLanguage ?? "enUS";
            config.TextLanguage   = config.InstallData?.Settings?.SelectedTextLanguage ?? "enUS";

            string buildInfoPath = Path.Combine(basePath, ".build.info");

            using (Stream buildInfoStream = new FileStream(buildInfoPath, FileMode.Open)) {
                config._buildInfo = BarSeparatedConfig.Read(buildInfoStream);
            }

            Dictionary <string, string> bi = config.GetActiveBuild();

            if (bi == null)
            {
                throw new Exception("Can't find active BuildInfoEntry");
            }

            string dataFolder = GetDataFolder();

            config.ActiveBuild = 0;

            config.Builds = new List <KeyValueConfig>();

            string buildKey     = bi["BuildKey"];
            string buildCfgPath = Path.Combine(basePath, dataFolder, "config", buildKey.Substring(0, 2), buildKey.Substring(2, 2), buildKey);

            try {
                using (Stream stream = new FileStream(buildCfgPath, FileMode.Open)) {
                    config.Builds.Add(KeyValueConfig.Read(stream));
                }
            } catch {
                using (Stream stream = CDNIndexHandler.OpenConfigFileDirect(config, buildKey)) {
                    config.Builds.Add(KeyValueConfig.Read(stream));
                }
            }

            string cdnKey     = bi["CDNKey"];
            string cdnCfgPath = Path.Combine(basePath, dataFolder, "config", cdnKey.Substring(0, 2), cdnKey.Substring(2, 2), cdnKey);

            try {
                using (Stream stream = new FileStream(cdnCfgPath, FileMode.Open)) {
                    config._cdnConfig = KeyValueConfig.Read(stream);
                }
            } catch {
                using (Stream stream = CDNIndexHandler.OpenConfigFileDirect(config, cdnKey)) {
                    config._cdnConfig = KeyValueConfig.Read(stream);
                }
            }

            if (bi.ContainsKey("Keyring") && bi["Keyring"].Length > 0)
            {
                string keyringKey     = bi["Keyring"];
                string keyringCfgPath = Path.Combine(basePath, dataFolder, "config", keyringKey.Substring(0, 2), keyringKey.Substring(2, 2), keyringKey);
                try {
                    using (Stream stream = new FileStream(keyringCfgPath, FileMode.Open)) {
                        config.KeyRing = KeyValueConfig.Read(stream);
                    }
                } catch {
                    using (Stream stream = CDNIndexHandler.OpenConfigFileDirect(config, keyringKey)) {
                        config.KeyRing = KeyValueConfig.Read(stream);
                    }
                }
                if (useKeyring)
                {
                    config.LoadKeyringKeys(TACTKeyService.Keys, true);
                }
            }

            config.InstalledLanguages        = new HashSet <string>();
            config.LoadAllInstalledLanguages = loadMultipleLangs;
            if (bi.ContainsKey("Tags") && bi["Tags"].Trim().Length > 0)
            {
                string[] tags = bi["Tags"].Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                foreach (string tag in tags)
                {
                    try {
                        Enum.Parse(typeof(LocaleFlags), tag.Substring(0, 4));
                        config.InstalledLanguages.Add(tag);
                    } catch { }
                }
            }

            // for debugging:
            //var buildInfo = config.Builds[config.ActiveBuild];

            return(config);
        }