1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-22 07:13:07 +01:00

Fix FileWatcher for Windows

This commit is contained in:
Ted John
2018-03-31 10:27:45 +01:00
parent 26eb91016e
commit 5ba96a34ac
3 changed files with 5 additions and 2 deletions

View File

@@ -77,6 +77,7 @@ FileWatcher::WatchDescriptor::~WatchDescriptor()
FileWatcher::FileWatcher(const std::string &directoryPath) FileWatcher::FileWatcher(const std::string &directoryPath)
{ {
#ifdef _WIN32 #ifdef _WIN32
_path = directoryPath;
_directoryHandle = CreateFileA(directoryPath.c_str(), FILE_LIST_DIRECTORY, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, nullptr); _directoryHandle = CreateFileA(directoryPath.c_str(), FILE_LIST_DIRECTORY, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, nullptr);
if (_directoryHandle == INVALID_HANDLE_VALUE) if (_directoryHandle == INVALID_HANDLE_VALUE)
{ {
@@ -127,7 +128,8 @@ void FileWatcher::WatchDirectory()
std::wstring fileNameW(notifyInfo->FileName, notifyInfo->FileNameLength / sizeof(wchar_t)); std::wstring fileNameW(notifyInfo->FileName, notifyInfo->FileNameLength / sizeof(wchar_t));
auto fileName = String::ToUtf8(fileNameW); auto fileName = String::ToUtf8(fileNameW);
onFileChanged(fileName); auto path = fs::path(_path) / fs::path(fileName);
onFileChanged(path.u8string());
} }
while (notifyInfo->NextEntryOffset != 0); while (notifyInfo->NextEntryOffset != 0);
} }

View File

@@ -17,6 +17,7 @@ class FileWatcher
private: private:
std::thread _watchThread; std::thread _watchThread;
#ifdef _WIN32 #ifdef _WIN32
std::string _path;
HANDLE _directoryHandle{}; HANDLE _directoryHandle{};
#else #else
struct FileDescriptor struct FileDescriptor

View File

@@ -114,7 +114,7 @@ void ScriptEngine::AutoReloadPlugins()
auto findResult = std::find_if(_plugins.begin(), _plugins.end(), auto findResult = std::find_if(_plugins.begin(), _plugins.end(),
[&path](const std::shared_ptr<Plugin>& plugin) [&path](const std::shared_ptr<Plugin>& plugin)
{ {
return path == plugin->GetPath(); return Path::Equals(path, plugin->GetPath());
}); });
if (findResult != _plugins.end()) if (findResult != _plugins.end())
{ {