Skip to content

Commit

Permalink
Added: Monitor for File Changes as well as Creation/Deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
Sewer56 committed Mar 31, 2022
1 parent b895068 commit 3392fc4
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions source/Reloaded.Mod.Loader.IO/Services/ConfigServiceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace Reloaded.Mod.Loader.IO.Services;

/* Mod Monitoring */
private FileSystemWatcher _renameWatcher;
private FileSystemWatcher _changedWatcher;
private FileSystemWatcher _createFolderWatcher;
private FileSystemWatcher _createFileWatcher;
private FileSystemWatcher _deleteFileWatcher;
Expand All @@ -67,6 +68,7 @@ public void Initialize(string configDirectory, string itemFileName, Func<List<Pa
_renameWatcher = Create(ConfigDirectory, null, OnRename, FileSystemWatcherEvents.Renamed, true, "*.json");
_createFolderWatcher = Create(ConfigDirectory, OnCreateFolder, null, FileSystemWatcherEvents.Created, false, "*.*");
_createFileWatcher = Create(ConfigDirectory, OnCreateFile, null, FileSystemWatcherEvents.Created, true, "*.json");
_changedWatcher = Create(ConfigDirectory, OnUpdateFile, null, FileSystemWatcherEvents.Changed, true, "*.json");
_deleteFileWatcher = Create(ConfigDirectory, OnDeleteFile, null, FileSystemWatcherEvents.Deleted);
_deleteDirectoryWatcher = Create(ConfigDirectory, OnDeleteDirectory, null, FileSystemWatcherEvents.Deleted, false, "*.*");
GetItems(executeImmediately);
Expand Down Expand Up @@ -173,6 +175,16 @@ private void CreateFileHandler(string fullPath)
}
}

private void OnUpdateFile(object sender, FileSystemEventArgs e)
{
var fullPath = e.FullPath;
if (IsFileInItemFolder(fullPath) && IsFileConfigFile(fullPath))
{
var config = IConfig<TConfigType>.FromPath(fullPath);
_context.Post(() => AddItem(new PathTuple<TConfigType>(fullPath, config)));
}
}

private void AddItem(PathTuple<TConfigType> itemTuple)
{
// Check for existing item.
Expand Down

0 comments on commit 3392fc4

Please sign in to comment.