Skip to content

Commit

Permalink
(GH-584) split get config file from save
Browse files Browse the repository at this point in the history
Split up getting config file settings, setting the configuration from
those and then later saving the config file settings that have been
added.
  • Loading branch information
ferventcoder committed Feb 10, 2016
1 parent 43f2181 commit 0ad1baa
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,36 @@ public static void set_up_configuration(IList<string> args, ChocolateyConfigurat
{
var fileSystem = container.GetInstance<IFileSystem>();
var xmlService = container.GetInstance<IXmlService>();
set_file_configuration(config, fileSystem, xmlService, notifyWarnLoggingAction);
var configFileSettings = get_config_file_settings(fileSystem, xmlService);
set_file_configuration(config, configFileSettings, fileSystem, notifyWarnLoggingAction);
ConfigurationOptions.reset_options();
set_global_options(args, config, container);
set_environment_options(config);
set_license_options(config, license);
set_environment_variables(config);
set_config_file_settings(configFileSettings, xmlService);
}

private static void set_file_configuration(ChocolateyConfiguration config, IFileSystem fileSystem, IXmlService xmlService, Action<string> notifyWarnLoggingAction)
private static ConfigFileSettings get_config_file_settings(IFileSystem fileSystem, IXmlService xmlService)
{
var globalConfigPath = ApplicationParameters.GlobalConfigFileLocation;
AssemblyFileExtractor.extract_text_file_from_assembly(fileSystem, Assembly.GetExecutingAssembly(), ApplicationParameters.ChocolateyConfigFileResource, globalConfigPath);

var configFileSettings = xmlService.deserialize<ConfigFileSettings>(globalConfigPath);
return xmlService.deserialize<ConfigFileSettings>(globalConfigPath);
}

private static void set_config_file_settings(ConfigFileSettings configFileSettings, IXmlService xmlService)
{
var globalConfigPath = ApplicationParameters.GlobalConfigFileLocation;
// save so all updated configuration items get set to existing config
FaultTolerance.try_catch_with_logging_exception(
() => xmlService.serialize(configFileSettings, globalConfigPath),
"Error updating '{0}'. Please ensure you have permissions to do so".format_with(globalConfigPath),
logWarningInsteadOfError: true);
}

private static void set_file_configuration(ChocolateyConfiguration config, ConfigFileSettings configFileSettings, IFileSystem fileSystem, Action<string> notifyWarnLoggingAction)
{
var sources = new StringBuilder();

var defaultSourcesInOrder = configFileSettings.Sources.Where(s => !s.Disabled).or_empty_list_if_null().ToList();
Expand Down Expand Up @@ -108,12 +124,6 @@ private static void set_file_configuration(ChocolateyConfiguration config, IFile
logWarningInsteadOfError: true);

set_feature_flags(config, configFileSettings);

// save so all updated configuration items get set to existing config
FaultTolerance.try_catch_with_logging_exception(
() => xmlService.serialize(configFileSettings, globalConfigPath),
"Error updating '{0}'. Please ensure you have permissions to do so".format_with(globalConfigPath),
logWarningInsteadOfError: true);
}

private static void set_machine_sources(ChocolateyConfiguration config, ConfigFileSettings configFileSettings)
Expand Down

0 comments on commit 0ad1baa

Please sign in to comment.