Skip to content

Commit

Permalink
(chocolatey#494) Address review comments
Browse files Browse the repository at this point in the history
Renamed configuration file variable to indicate it's the path to the
configuration file. Made ConfigFileChanged public and added it to the
interface. Also renamed it to OnConfigFileChanged as that seems to be a
better name to indicate it's the action for when the file changes.
  • Loading branch information
corbob committed Sep 6, 2022
1 parent dcb3405 commit f377968
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ConfigFileWatcher : IConfigFileWatcher
private readonly IEventAggregator _eventAggregator;
private readonly FileSystemWatcher _fileSystemWatcher;
private readonly IXmlService _xmlService;
private readonly string _configFile = chocolatey.infrastructure.app.ApplicationParameters.GlobalConfigFileLocation;
private readonly string _configFilePath = chocolatey.infrastructure.app.ApplicationParameters.GlobalConfigFileLocation;
private int _lastKnownConfigFileHash;

public ConfigFileWatcher(IFileSystem fileSystem, IEventAggregator eventAggregator, IXmlService xmlService)
Expand All @@ -31,18 +31,18 @@ public ConfigFileWatcher(IFileSystem fileSystem, IEventAggregator eventAggregato
_xmlService = xmlService;
_fileSystemWatcher = new FileSystemWatcher
{
Path = _fileSystem.get_directory_name(_configFile),
Filter = _fileSystem.get_file_name(_configFile),
Path = _fileSystem.get_directory_name(_configFilePath),
Filter = _fileSystem.get_file_name(_configFilePath),
NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName,
};
_fileSystemWatcher.Changed += ConfigFileChanged;
_fileSystemWatcher.Changed += OnConfigFileChanged;
_fileSystemWatcher.EnableRaisingEvents = true;
_lastKnownConfigFileHash = _xmlService.deserialize<ConfigFileSettings>(_configFile).GetHashCode();
_lastKnownConfigFileHash = _xmlService.deserialize<ConfigFileSettings>(_configFilePath).GetHashCode();
}

private void ConfigFileChanged(object sender, FileSystemEventArgs e)
public void OnConfigFileChanged(object sender, FileSystemEventArgs e)
{
var currentSettingsHash = _xmlService.deserialize<ConfigFileSettings>(_configFile).GetHashCode();
var currentSettingsHash = _xmlService.deserialize<ConfigFileSettings>(_configFilePath).GetHashCode();
if (currentSettingsHash != _lastKnownConfigFileHash)
{
_eventAggregator.PublishOnUIThread(new SourcesUpdatedMessage());
Expand Down
3 changes: 3 additions & 0 deletions Source/ChocolateyGui.Common/Services/IConfigFileWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

using System.IO;

namespace ChocolateyGui.Common.Services
{
public interface IConfigFileWatcher
{
void OnConfigFileChanged(object sender, FileSystemEventArgs e);
}
}

0 comments on commit f377968

Please sign in to comment.