2019-12-26 15:32:37 -05:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
2014-03-14 14:13:41 -04:00
|
|
|
|
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340)
#lockdown Nick.Penwarden
#rb none
==========================
MAJOR FEATURES + CHANGES
==========================
Change 3209340 on 2016/11/23 by Ben.Marsh
Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h.
Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms.
* Every header now includes everything it needs to compile.
* There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first.
* There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h.
* Every .cpp file includes its matching .h file first.
* This helps validate that each header is including everything it needs to compile.
* No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more.
* You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there.
* There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible.
* No engine code explicitly includes a precompiled header any more.
* We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies.
* PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files.
Tool used to generate this transform is at Engine\Source\Programs\IncludeTool.
[CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
|
|
|
#include "DirectoryWatcherWindows.h"
|
|
|
|
|
#include "DirectoryWatcherPrivate.h"
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
FDirectoryWatcherWindows::FDirectoryWatcherWindows()
|
|
|
|
|
{
|
|
|
|
|
NumRequests = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FDirectoryWatcherWindows::~FDirectoryWatcherWindows()
|
|
|
|
|
{
|
|
|
|
|
if ( RequestMap.Num() != 0 )
|
|
|
|
|
{
|
|
|
|
|
// Delete any remaining requests here. These requests are likely from modules which are still loaded at the time that this module unloads.
|
2019-01-08 09:58:31 -05:00
|
|
|
for (TMap<FDirectoryWithFlags, FDirectoryWatchRequestWindows*>::TConstIterator RequestIt(RequestMap); RequestIt; ++RequestIt)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
if ( ensure(RequestIt.Value()) )
|
|
|
|
|
{
|
|
|
|
|
// make sure we end the watch request, as we may get a callback if a request is in flight
|
|
|
|
|
RequestIt.Value()->EndWatchRequest();
|
|
|
|
|
delete RequestIt.Value();
|
|
|
|
|
NumRequests--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RequestMap.Empty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( RequestsPendingDelete.Num() != 0 )
|
|
|
|
|
{
|
|
|
|
|
for ( int32 RequestIdx = 0; RequestIdx < RequestsPendingDelete.Num(); ++RequestIdx )
|
|
|
|
|
{
|
|
|
|
|
delete RequestsPendingDelete[RequestIdx];
|
|
|
|
|
NumRequests--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Make sure every request that was created is destroyed
|
|
|
|
|
ensure(NumRequests == 0);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-25 20:17:42 -04:00
|
|
|
bool FDirectoryWatcherWindows::RegisterDirectoryChangedCallback_Handle( const FString& Directory, const FDirectoryChanged& InDelegate, FDelegateHandle& Handle, uint32 Flags )
|
2015-01-08 09:29:27 -05:00
|
|
|
{
|
2019-01-08 09:58:31 -05:00
|
|
|
const FDirectoryWithFlags DirectoryKey(Directory, Flags);
|
|
|
|
|
FDirectoryWatchRequestWindows** RequestPtr = RequestMap.Find(DirectoryKey);
|
2015-01-08 09:29:27 -05:00
|
|
|
FDirectoryWatchRequestWindows* Request = NULL;
|
|
|
|
|
|
|
|
|
|
if ( RequestPtr )
|
|
|
|
|
{
|
|
|
|
|
// There should be no NULL entries in the map
|
|
|
|
|
check (*RequestPtr);
|
|
|
|
|
|
|
|
|
|
Request = *RequestPtr;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-06-25 20:17:42 -04:00
|
|
|
Request = new FDirectoryWatchRequestWindows(Flags);
|
2015-01-08 09:29:27 -05:00
|
|
|
NumRequests++;
|
|
|
|
|
|
|
|
|
|
// Begin reading directory changes
|
|
|
|
|
if ( !Request->Init(Directory) )
|
|
|
|
|
{
|
|
|
|
|
uint32 Error = GetLastError();
|
2015-10-28 19:18:20 -04:00
|
|
|
TCHAR ErrorMsg[1024];
|
|
|
|
|
FPlatformMisc::GetSystemErrorMessage(ErrorMsg, 1024, Error);
|
2015-10-29 11:01:37 -04:00
|
|
|
UE_LOG(LogDirectoryWatcher, Warning, TEXT("Failed to begin reading directory changes for %s. Error: %s (0x%08x)"), *Directory, ErrorMsg, Error);
|
2015-10-28 19:18:20 -04:00
|
|
|
|
2015-01-08 09:29:27 -05:00
|
|
|
delete Request;
|
|
|
|
|
NumRequests--;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-08 09:58:31 -05:00
|
|
|
RequestMap.Add(DirectoryKey, Request);
|
2015-01-08 09:29:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Handle = Request->AddDelegate(InDelegate);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FDirectoryWatcherWindows::UnregisterDirectoryChangedCallback_Handle( const FString& Directory, FDelegateHandle InHandle )
|
|
|
|
|
{
|
2019-01-08 09:58:31 -05:00
|
|
|
for (const auto& RequestPair : RequestMap)
|
2015-01-08 09:29:27 -05:00
|
|
|
{
|
2019-01-08 09:58:31 -05:00
|
|
|
if (RequestPair.Key.Key == Directory)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2019-01-08 09:58:31 -05:00
|
|
|
// There should be no NULL entries in the map
|
|
|
|
|
check(RequestPair.Value);
|
|
|
|
|
|
|
|
|
|
if (RequestPair.Value->RemoveDelegate(InHandle))
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2019-01-08 09:58:31 -05:00
|
|
|
if (!RequestPair.Value->HasDelegates())
|
|
|
|
|
{
|
|
|
|
|
// Remove from the active map and add to the pending delete list
|
|
|
|
|
RequestMap.Remove(RequestPair.Key);
|
|
|
|
|
RequestsPendingDelete.AddUnique(RequestPair.Value);
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2019-01-08 09:58:31 -05:00
|
|
|
// Signal to end the watch which will mark this request for deletion
|
|
|
|
|
RequestPair.Value->EndWatchRequest();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FDirectoryWatcherWindows::Tick( float DeltaSeconds )
|
|
|
|
|
{
|
|
|
|
|
TArray<HANDLE> DirectoryHandles;
|
2019-01-08 09:58:31 -05:00
|
|
|
TMap<FDirectoryWithFlags, FDirectoryWatchRequestWindows*> InvalidRequestsToDelete;
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
// Find all handles to listen to and invalid requests to delete
|
2019-01-08 09:58:31 -05:00
|
|
|
for (TMap<FDirectoryWithFlags, FDirectoryWatchRequestWindows*>::TConstIterator RequestIt(RequestMap); RequestIt; ++RequestIt)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
if ( RequestIt.Value()->IsPendingDelete() )
|
|
|
|
|
{
|
|
|
|
|
InvalidRequestsToDelete.Add(RequestIt.Key(), RequestIt.Value());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
DirectoryHandles.Add(RequestIt.Value()->GetDirectoryHandle());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Remove all invalid requests from the request map and add them to the pending delete list so they will be deleted below
|
2019-01-08 09:58:31 -05:00
|
|
|
for (TMap<FDirectoryWithFlags, FDirectoryWatchRequestWindows*>::TConstIterator RequestIt(InvalidRequestsToDelete); RequestIt; ++RequestIt)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
RequestMap.Remove(RequestIt.Key());
|
|
|
|
|
RequestsPendingDelete.AddUnique(RequestIt.Value());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Trigger any file changed delegates that are queued up
|
2019-06-07 11:22:52 -04:00
|
|
|
// We need to do this in batches of MAXIMUM_WAIT_OBJECTS-1 as described by the documentation for MsgWaitForMultipleObjectsEx
|
2014-03-14 14:13:41 -04:00
|
|
|
if ( DirectoryHandles.Num() > 0 )
|
|
|
|
|
{
|
2019-06-07 11:22:52 -04:00
|
|
|
static const int32 BatchSize = MAXIMUM_WAIT_OBJECTS - 1;
|
|
|
|
|
for (int32 HandleOffset = 0; HandleOffset < DirectoryHandles.Num(); HandleOffset += BatchSize)
|
|
|
|
|
{
|
|
|
|
|
MsgWaitForMultipleObjectsEx(FMath::Min(DirectoryHandles.Num() - HandleOffset, BatchSize), DirectoryHandles.GetData() + HandleOffset, 0, QS_ALLEVENTS, MWMO_ALERTABLE);
|
|
|
|
|
}
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Delete any stale or invalid requests
|
|
|
|
|
for ( int32 RequestIdx = RequestsPendingDelete.Num() - 1; RequestIdx >= 0; --RequestIdx )
|
|
|
|
|
{
|
|
|
|
|
FDirectoryWatchRequestWindows* Request = RequestsPendingDelete[RequestIdx];
|
|
|
|
|
|
|
|
|
|
if ( Request->IsPendingDelete() )
|
|
|
|
|
{
|
|
|
|
|
// This request is safe to delete. Delete and remove it from the list
|
|
|
|
|
delete Request;
|
|
|
|
|
NumRequests--;
|
|
|
|
|
RequestsPendingDelete.RemoveAt(RequestIdx);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Finally, trigger any file change notification delegates
|
2019-01-08 09:58:31 -05:00
|
|
|
for (TMap<FDirectoryWithFlags, FDirectoryWatchRequestWindows*>::TConstIterator RequestIt(RequestMap); RequestIt; ++RequestIt)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
RequestIt.Value()->ProcessPendingNotifications();
|
|
|
|
|
}
|
|
|
|
|
}
|