public static InvokerSettings getFromFile(string file) { InvokerSettings invokerSettings = JsonConvert.DeserializeObject <InvokerSettings>(File.ReadAllText(file)); invokerSettings.Initialize(); return(invokerSettings); }
void LoadProperties(string envName = "default", string envType = "default") { if (!Directory.Exists(InvokerSettingDirectory) || (!Directory.GetFiles(InvokerSettingDirectory, SEARCH_PATTERN_ENV_JSON).Any())) { Directory.CreateDirectory(InvokerSettingDirectory); foreach (string envFile in Directory.GetFiles(assemblyLocation, SEARCH_PATTERN_ENV_JSON)) { FileInfo srcFI = new FileInfo(envFile); srcFI.CopyTo(InvokerSettingDirectory + "\\" + srcFI.Name, false); } } if (!File.Exists(userSettingsFile)) { if (File.Exists(originalSettingsFile)) { File.Copy(originalSettingsFile, userSettingsFile); } else { MessageBox.Show("Settings file missing: " + originalSettingsFile + ". Restore the file or repair application from control panel and try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(-1); } } invokerSettings = File.Exists(userSettingsFile) ? InvokerSettings.getFromFile(userSettingsFile) : (File.Exists(originalSettingsFile) ? InvokerSettings.getFromFile(originalSettingsFile) : new InvokerSettings()); currentEnvSettings = new EnvironmentSettings(invokerSettings.environmentSettings[envType].properties); execProperties.Clear(); execProperties.Add("_invoker_general_properties_file", new FileInfo(userSettingsFile).FullName); execProperties.Add("_invoker_environment_settings_file", InvokerSettingDirectory + envName + ENV_JSON_EXTN); execProperties.Add("_specialChar_newLine", "\n"); execProperties.Add("_specialChar_backspace", "\b"); execProperties.Add("_specialChar_escape", '\x1b'.ToString()); envSettingsMap.Clear(); EnvironmentSelectionComboBox.Items.Clear(); trayEnvSelectorComboBox.Items.Clear(); EnvironmentSelectionComboBox.Items.Clear(); trayEnvSelectorComboBox.Items.Clear(); foreach (string envFile in Directory.GetFiles(InvokerSettingDirectory, SEARCH_PATTERN_ENV_JSON)) { string baseFileName = Path.GetFileName(envFile); string envAlias = baseFileName.Substring(0, baseFileName.IndexOf(ENV_JSON_EXTN)); EnvironmentSelectionComboBox.Items.Add(envAlias); trayEnvSelectorComboBox.Items.Add(envAlias); envSettingsMap.Add(envAlias, EnvironmentSettings.getFromFile(envFile)); } //Selecting the environment will apply the settings if (EnvironmentSelectionComboBox.Items.Contains(envName)) { EnvironmentSelectionComboBox.SelectedIndex = EnvironmentSelectionComboBox.Items.IndexOf(envName); } else { applySettings(); } EnvironmentCollectionChanged(); }