| 25 | } |
| 26 | |
| 27 | void FEditorHotReloadWatcher::Watch(const TArray<FString>& Directories) |
| 28 | { |
| 29 | auto& DirectoryWatcherModule = FModuleManager::LoadModuleChecked<FDirectoryWatcherModule>("DirectoryWatcher"); |
| 30 | const auto DirectoryWatcher = DirectoryWatcherModule.Get(); |
| 31 | if (!DirectoryWatcher) |
| 32 | return; |
| 33 | |
| 34 | for (const auto& Watcher : Watchers) |
| 35 | DirectoryWatcher->UnregisterDirectoryChangedCallback_Handle(Watcher.Directory, Watcher.Handle); |
| 36 | Watchers.Reset(); |
| 37 | |
| 38 | for (const auto& Directory : Directories) |
| 39 | { |
| 40 | if (!FPaths::DirectoryExists(Directory)) |
| 41 | continue; |
| 42 | FDirectoryWatcherPayload Watcher; |
| 43 | Watcher.Directory = Directory; |
| 44 | const auto& Delegate = IDirectoryWatcher::FDirectoryChanged::CreateRaw(this, &FEditorHotReloadWatcher::OnFileChanged); |
| 45 | DirectoryWatcher->RegisterDirectoryChangedCallback_Handle(Watcher.Directory, Delegate, Watcher.Handle); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | void FEditorHotReloadWatcher::OnModuleLoaded(const FString& ModuleName, const FString& FullPath) |
| 50 | { |