You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm testing out this nice library in an UE4 setting and noticing that while it is working quite well for add and remove, modified is firing twice whenever I update a file (save it in a text editor). Is this a known thing, or is there some way I can avoid it?
Also, when I add a new file to my watched directory, I see two events: one add and one modified - perhaps this is a hint to the problem. Here is the code I'm testing with in a C++ Actor. Note I'm also printing the current frame, which is sometimes the same for the redundant modified event, sometimes it is a frame later.
// Fill out your copyright notice in the Description page of Project Settings.
#include"FileMonitorTest.h"
#include"./FileWatch.hpp"
#include<string>
#definePRINT_DISPLAY_TIME3.0f
#defineprintf(format, ...) if (GEngine) GEngine->AddOnScreenDebugMessage(-1, PRINT_DISPLAY_TIME, FColor::White, FString::Printf(TEXT(format), ##__VA_ARGS__), false)
// Sets default valuesAFileMonitorTest::AFileMonitorTest()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
namespace {
constchar* watchEventTypeToString( const filewatch::Event change_type )
{
switch (change_type) {
case filewatch::Event::added: return"added";
case filewatch::Event::removed: return"removed";
case filewatch::Event::modified: return"modified";
case filewatch::Event::renamed_old: return"renamed_old";
case filewatch::Event::renamed_new: return"renamed_new";
default: break;
};
return"(unknown)";
}
}
// Called when the game starts or when spawnedvoidAFileMonitorTest::BeginPlay()
{
Super::BeginPlay();
// we'll add a watcher for file changes in this directory
std::wstring scanDir( L"E:/epic/Unreal Projects/FileMonitoring/data/scans" );
IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
bool dirExists = PlatformFile.DirectoryExists(scanDir.c_str());
printf("scanDir: %s, exists: %d", scanDir.c_str(), dirExists );
if( dirExists ) {
// print out contents of folder using ue4 stuffs
TArray<FString> fileNames;
PlatformFile.FindFiles( fileNames, scanDir.c_str(), NULL );
printf("num files: %d", fileNames.Num() );
for( int i = 0; i < fileNames.Num(); i++ ) {
printf( "%s", *fileNames[i] );
}
// watch for file changes within scanDirstatic filewatch::FileWatch<std::wstring> watch(
scanDir,
[](const std::wstring& path, const filewatch::Event change_type ) {
FString changeTypeStr = watchEventTypeToString( change_type );usingchar* directly prints rubbish
printf("path: %s, event type: %s, frame: %d", path.c_str(), *changeTypeStr, GFrameNumber );
}
);
}
}
// Called every framevoidAFileMonitorTest::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
The text was updated successfully, but these errors were encountered:
Another interesting note: if I hit save one an empty file, then I only get one modified event fired. But if it has contents, then I get two modified events fired.
Hi,
I'm testing out this nice library in an UE4 setting and noticing that while it is working quite well for
add
andremove
,modified
is firing twice whenever I update a file (save it in a text editor). Is this a known thing, or is there some way I can avoid it?Also, when I add a new file to my watched directory, I see two events: one
add
and onemodified
- perhaps this is a hint to the problem. Here is the code I'm testing with in a C++ Actor. Note I'm also printing the current frame, which is sometimes the same for the redundantmodified
event, sometimes it is a frame later.The text was updated successfully, but these errors were encountered: