Skip to content

Commit

Permalink
(GH-308) AutoUninstaller on by default
Browse files Browse the repository at this point in the history
Switch AutoUninstaller feature to be on by default. Set up feature
flags to allow changing the default value if the feature was not set
explicitly by a user.
  • Loading branch information
ferventcoder committed Jun 4, 2015
1 parent 161c18b commit 55d3f94
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,23 +127,28 @@ private static void set_machine_sources(ChocolateyConfiguration config, ConfigFi

private static void set_feature_flags(ChocolateyConfiguration config, ConfigFileSettings configFileSettings)
{
config.Features.CheckSumFiles = set_feature_flag(ApplicationParameters.Features.CheckSumFiles, configFileSettings);
config.Features.AutoUninstaller = set_feature_flag(ApplicationParameters.Features.AutoUninstaller, configFileSettings);
config.PromptForConfirmation = !set_feature_flag(ApplicationParameters.Features.AllowGlobalConfirmation, configFileSettings);
config.Features.CheckSumFiles = set_feature_flag(ApplicationParameters.Features.CheckSumFiles, configFileSettings, defaultEnabled: true);
config.Features.AutoUninstaller = set_feature_flag(ApplicationParameters.Features.AutoUninstaller, configFileSettings, defaultEnabled: true);
config.PromptForConfirmation = !set_feature_flag(ApplicationParameters.Features.AllowGlobalConfirmation, configFileSettings, defaultEnabled: false);
}

private static bool set_feature_flag(string featureName, ConfigFileSettings configFileSettings)
private static bool set_feature_flag(string featureName, ConfigFileSettings configFileSettings, bool defaultEnabled)
{
var enabled = false;
var feature = configFileSettings.Features.FirstOrDefault(f => f.Name.is_equal_to(featureName));
if (feature != null && feature.Enabled) enabled = true;

if (feature == null)
{
configFileSettings.Features.Add(new ConfigFileFeatureSetting {Name = featureName, Enabled = enabled});
configFileSettings.Features.Add(new ConfigFileFeatureSetting {Name = featureName, Enabled = defaultEnabled});
}
else
{
if (!feature.SetExplicitly && feature.Enabled != defaultEnabled)
{
feature.Enabled = defaultEnabled;
}
}

return enabled;
return feature != null ? feature.Enabled : defaultEnabled;
}

private static void set_global_options(IList<string> args, ChocolateyConfiguration config)
Expand Down

0 comments on commit 55d3f94

Please sign in to comment.