You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#lockdown Nick.Penwarden #rb none ============================ MAJOR FEATURES & CHANGES ============================ Change 3805828 by Gil.Gribb UE4 - Fixed a bug in the lock free stalling task queue and adjusted a comment. The code is not current used, so this is not actually change the way the code works. Change 3806784 by Ben.Marsh UAT: Remove code to compile UBT when using UE4Build. It should already be compiled as a dependency of UAT. Change 3807549 by Graeme.Thornton Add a cook timer around VerifyCanCookPackage. A licensee reports this taking a lot of time so it'll be good to account for it. Change 3807727 by Graeme.Thornton Unhide the text asset format experimental editor option Change 3807746 by Josh.Engebretson Remove WER from iOS platform Change 3807928 by Robert.Manuszewski When async loading, GC Clusters will be created after packages have been processed to avoid situations where some of the objects that are being added to a cluster haven't been fully loaded yet Change 3808221 by Steve.Robb GitHub #4307 - Made GetModulePtr() thread safe by not using GetModule() ^ I'm not convinced by how much thread-safer this is really, but it's tidier anyway. Change 3809233 by Graeme.Thornton TBA: Misc changes to text asset commandlet - Rename mode to "loadsave" - Add -outputFormat option which can be assigned "text" or "binary" - When saving binary, use a differentiated filename so that source assets aren't overwritten Change 3809518 by Ben.Marsh Remove the outdated UnrealSync automation script. Change 3809643 by Steve.Robb GitHub #4277 : fix bug; FMath::FormatIntToHumanReadable 3rd comma and negative value #jira UE-53037 Change 3809862 by Steve.Robb GitHub #3342 : [FRotator.h] Fix to DecompressAxisFromByte to be more efficient and reflect its intent accurately #jira UE-42593 Change 3811190 by Graeme.Thornton Add support for writing specific log channels to their own files Change 3811197 by Graeme.Thornton Minor updates to output formatting and timing for the text asset commandlet Change 3811257 by Robert.Manuszewski Cluster creation will now be time-sliced Change 3811565 by Steve.Robb Define out non-monolithic module functions. Change 3812561 by Steve.Robb GitHub #3886 : Enable Brace-Initialization for Declaring Variables Incorrect semi-colon search removed after discussion with author. Test added. #jira UE-48242 Change 3812864 by Steve.Robb Removal of some unproven code which was supposed to fix hot reloading BP class functions in plugins. See: https://udn.unrealengine.com/questions/376978/aitask-blueprint-nodes-disappear-when-their-module.html #jira UE-53089 Change 3820358 by Ben.Marsh PR #4358: Incredibuild use ShowAgent by default (Contributed by projectgheist) Change 3822594 by Ben.Marsh UAT: Improvements to log file handling. - Always create log files in the final location, rather than writing to a temp directory and copying in later. - Now supports -Verbose and -VeryVerbose for increasing log verbosity, rather than -Verbose=XXX. - Keep a backlog of log output before the log system is initialized, and flush it to the log file once it is. - Allow buildmachines to specify the uebp_FinalLogFolder environment variable, which is used to form paths for display. When build machines copy log files elsewhere after UAT finishes (eg. a network share), this allows error messages to display the right location. Change 3823695 by Ben.Marsh UGS: Fix issue where precompiled binaries would not be shown as available for a change until scrolling the last submitted code change into the buffer (other symptoms, like de-focussing the main window would cause it to go back to an unavailable state, since the changes buffer was shrunk). Now always queries changes up to the last change for which zipped binaries are available. Change 3823845 by Ben.Marsh UBT: Exclude C# projects for unsupported platforms when generating project files. Change 3824180 by Ben.Marsh UGS: Add an option to show changes by build machines, and move the "only show reviewed" option in there too (Options > Show Changes). #jira Change 3825777 by Steve.Robb Fix to return value of StringToBytes. Change 3825810 by Ben.Marsh UBT: Reduce length of include paths for MSVC toolchain. Change 3825822 by Robert.Manuszewski Optimized PIE lazy pointer fixup. Should be up to 8x faster now. Change 3826734 by Ben.Marsh Remove code to disable TextureFormatAndroid on Linux. It seems to be an editor dependency. Change 3827730 by Steve.Robb Try to avoid decltype(auto) if it's not supported. See: https://udn.unrealengine.com/questions/395644/build-417-with-c11-on-linux-ttuple-errors.html Change 3827745 by Steve.Robb Initializer list support for TMap. Change 3827770 by Steve.Robb GitHub #4399 : Added a CONSTEXPR qualifiers to FVariant::GetType() #jira UE-53813 Change 3829189 by Ben.Marsh UBT: Now always writes a minimal log file. By default, just contains the regular console output and any reasons why actions are outdated and needed to be executed. UAT directs child UBT instances to output logs into its own log folder, so that build machines can save them off. Change 3830444 by Steve.Robb BuildVersion and ModuleManifest moved to Core, and parsing of these files reimplemented to avoid a JSON library. This should be revisited when Core has its own JSON library. Change 3830718 by Ben.Marsh Fix incorrect group name being returned by FStatNameAndInfo::GetGroupName() for stat groups. The editor populates the viewport stats list by calling this for every registered stat and stat group (via FLevelViewportCommands::HandleNewStatGroup). The menu entry attempts to show the stat name with STAT_XXX stripped from the start as the menu item label, with the free-form text description as a tooltip. For stat groups, the it would previously just return the stat group name as "Groups" (due to the raw naming convention of "//Groups//STATGROUP_Foo//..."). Since this didn't match the expected naming convention in FLevelViewportCommands::HandleNewStat (ie. STAT_XXX or STATGROUP_XXX), it would fail to add it. When the first actual stat belonging to that group is added, it would add a menu entry for the group based on that, but the stat description no longer makes sense as a tooltip for the group. As a result, all the editor tooltips were junk. #jira UE-53845 Change 3831064 by Ben.Marsh Fix log file contention when spawning UBT recursively. Change 3832654 by Ben.Marsh UGS: Fix error panel not being selected when opened, and weird alignment/color issues on it. Change 3832680 by Ben.Marsh UGS: Fix failing to detect workspace if synced to a different stream. Seems to be a regression caused by recent P4D upgrade. Change 3832695 by Ben.Marsh UGS: Invert the options in the 'Show Changes' submenu for simplicity. Change 3833528 by Ben.Marsh UAT: Script to rewrite source files with public include paths relative to the 'Public' folder. Usage is: RebasePublicIncludePaths -UpdateDir=<Dir> [-Project=<Dir>] [-Write]. Change 3833543 by Ben.Marsh UBT: Allow targets to opt-out of having public include paths added for every dependent module. This reduces the command line length when building a target, which has recently become a problem with larger games (due to Microsoft's compiler embedding the command line into each object file, with a maximum length of 64kb). All engine modules are compiled with this enabled; games may opt into it by setting bLegacyPublicIncludePaths = false; from their .target.cs, as may individual modules. Change 3834354 by Robert.Manuszewski Archetype pointer will now be cached to avoid locking the object tables when acquiring its info. It should also be faster this way regardless of any locks. #jira UE-52035 Change 3834400 by Robert.Manuszewski Fixing crash on exit caused by cached archetypes not being cleaned up before static exit cleanup. #jira UE-52035 Change 3834947 by Steve.Robb USE_FORMAT_STRING_TYPE_CHECKING removed from FMsg::Logf and FMsg::Logf_Internal. Change 3835004 by Ben.Marsh Fix code that relies on dubious behavior of requiring referenced "include path only" modules having their _API macros set to be empty, even if the module is actually implemented in a separate DLL. Change 3835340 by Ben.Marsh Fix errors making installed build from directories with spaces in the name. Change3835972by Ben.Marsh UBT: Improved diagnostic message for targets which don't need a version file. Change 3836019 by Ben.Marsh UBT: Fix warnings caused by defining linkage macros for third party libraries. Change 3836269 by Ben.Marsh Fix message box larger than the screen height being created when a large number of modules are incompatible on startup. Change 3836543 by Ben.Marsh Enable SoundMod plugin on Linux, since it's already supported through the editor. Change 3836546 by Ben.Marsh PR #4412: fix type mismatch (Contributed by nakapon) Change 3836805 by Ben.Marsh Fix commandlet to compile marketplace plugins. Change 3836829 by Ben.Marsh UBT: Fix ability to precompile plugins from installed engine builds. Change 3837036 by Ben.Marsh UBT: Write the previous and new contents of intermediate files to the log if they change. Makes it easier to debug unexpected rebuilds. Change 3837037 by Ben.Marsh UBT: Fix engine modules having inconsistent definitions depending on whether modules are only referenced for their include paths vs being linked into a binary (due to different _API macro). Change3837040by Ben.Marsh UBT: Remove code that initializes members in ModuleRules and TargetRules objects before the constructor is run. This is no longer necessary, now that the backwards-compatible default constructors have been removed. Change 3837247 by Ben.Marsh UBT: Remove UELinkerFixups module, now that plugins and precompiled modules do not require hacks to force initialization (since they're linked in as object files). Encryption and signing keys are now set via macros expanded from the IMPLEMENT_PRIMARY_GAME_MODULE macro, via project-specific macros added in the TargetRules constructor. Change 3837262 by Ben.Marsh UBT: Set whether a module is an engine module or not via a default value for the rules assembly. All non-program engine and enterprise modules are created with this flag set to true; program targets and modules are now created from a different assembly that sets it to false. This removes hacks from UEBuildModule needed to adjust behavior for different module types based on the directory containing the module. Also add a bUseBackwardsCompatibleDefaults flag to the TargetRules class, also initialized to a default value from a setting passed to the RulesAssembly constructor. This controls whether modules created for the target should be configured to allow breaking changes to default settings, and is set to false for all engine targets, and true for all project targets. Change 3837343 by Ben.Marsh UBT: Remove the OverrideExecutableFileExtension target property. Change the only current use for this (the MayaLiveLinkPlugin target) to use a post build step to copy the file instead. Change 3837356 by Ben.Marsh Fix invalid character encodings. Change 3837727 by Graeme.Thornton UnrealPak: KeyGenerator: Only generate prime table when required, not all the time Change 3837823 by Ben.Marsh UBT: Output warnings and errors when compiling module rules assembly in a way that allows them to be double-clicked in the Visual Studio output window. Change 3837831 by Graeme.Thornton UBT: When parsing crypto settings, always load legacy data first, then allow the new system to override it. Provides the same key backwards compatibility that the editor settings class gives Change 3837857 by Robert.Manuszewski PR #4404: Make FGCArrayPool singleton global instead of per-CU (Contributed by mhutch) Change 3837943 by Robert.Manuszewski PR #4405: Fix FGarbageCollectionTracer (Contributed by mhutch) Change 3838451 by Ben.Marsh UBT: Fix exceptions thrown on a background thread while caching C++ includes not being caught and logged correctly. Now captures exceptions and re-throws on the main thread. #jira UE-53996 Change 3839519 by Ben.Marsh UBT: Simplify configuring bPrecompile and bUsePrecompile settings for modules. Each rules assembly can now be configured as installed, which defaults the module rules it creates to use precompiled data. Change 3843790 by Graeme.Thornton UnrealPak: Log the size of all encrypted data Change 3844258 by Ben.Marsh Fix plugin compile failure when created via new plugin wizard. Passing -plugin on the command line is unnecessary, and is now reserved for packaging external plugins for the marketplace. Also extend the length of time that the error toast stays visible, and don't delete the plugin on failure. #jira UE-54157 Change 3845796 by Ben.Marsh Workaround for slow performance of String.EndsWith() on Mono. Change 3845823 by Ben.Marsh Fix case sensitive matching of platform names in -TargetPlatform=X argument to BuildCookRun. #jira UE-54123 Change 3845901 by Arciel.Rekman Linux: fix crash due to lambda lifetime issues (UE-54040). - The lambda goes out of scope in FBufferVisualizationMenuCommands::CreateVisualizationCommands, crashing the editor if compiled with a recent clang (5.0+). (Edigrating 3819174 to Dev-Core) Change 3846439 by Ben.Marsh Revert CL 3822742 to always call Process.WaitForExit(). The Android target platform module in the editor spawns ADB.EXE, which inherits the editor's stdout/stderr handles and forks itself. Process.WaitForExit() waits for EOF on those pipes, which never occurs because the forked process never terminates. Proper fix is probably to have the engine explicitly duplicate stdout/stderr handles for new pipes to output process, but too risky before copying up to Main. Change 3816608 by Ben.Marsh UBT: Use DirectoryReference objects for all include paths. Change 3816954 by Ben.Marsh UBT: Remove bIncludeDependentLibrariesInLibrary option. This is not widely supported by platform toolchains, and is not used anywhere. Change 3816986 by Ben.Marsh UBT: Remove UEBuildBinaryConfig; UEBuildBinary objects are now just created directly. Change 3816991 by Ben.Marsh UBT: Deprecate PlatformSpecificDynamicallyLoadedModules. We no longer have any special behavior for these modules. Change 3823090 by Ben.Marsh UAT: Improve logging for child UAT instances. - Calling RunUAT now requires an identifier for prefixing into the parent log, which is also used to determine the name of the log folder. - Stdout is no longer written to its own output file, since it's written to the parent stdout, the parent log file, and the child log file anyway. - Log folders for child UAT instances are left intact, rather than being copied to the parent folder. The derived names for the copied names were confusing and hard to read. - Output from UAT is no longer returned as a string. It should not be parsed anyway (but may be huge!). ProcessResult now supports running without capturing output. Change 3826082 by Ben.Marsh UBT: Add a check to make sure that all modules that are precompiled are correctly marked to enable it, even if they are part of the build target. Change 3827025 by Ben.Marsh UBT: Move the compile output directory into a property on the module, and explicitly pass it to the toolchain when compiling. Change 3829927 by James.Hopkin Made HTTP interface const correct Change 3833533 by Ben.Marsh Rewrite engine source files to base include paths relative to the "Public" directory. This allows reducing the number of public include paths that have to be added for engine modules. Change 3835826 by Ben.Marsh UBT: Precompiled targets now generate a separate manifest for each precompiled module, rather than adding object files to a library. This fixes issues where object files from static libraries would not be linked into a target if a symbol in them was not referenced. Change 3835969 by Ben.Marsh UBT: Fix cases where text is being written directly to the console rather than via logging functions. Change 3837777 by Steve.Robb Format string type checking added to FOutputDevice::Logf. Fixes for those. Change 3838569 by Steve.Robb Algo moved up a folder. [CL 3847482 by Ben Marsh in Main branch]
1502 lines
47 KiB
C++
1502 lines
47 KiB
C++
// Copyright 1998-2018 Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "NetworkPlatformFile.h"
|
|
#include "Templates/ScopedPointer.h"
|
|
#include "Misc/CommandLine.h"
|
|
#include "Misc/Paths.h"
|
|
#include "Misc/ScopedEvent.h"
|
|
#include "HAL/ThreadSafeCounter.h"
|
|
#include "Misc/ScopeLock.h"
|
|
#include "Stats/StatsMisc.h"
|
|
#include "Stats/Stats.h"
|
|
#include "Async/AsyncWork.h"
|
|
#include "Misc/ConfigCacheIni.h"
|
|
#include "Misc/LocalTimestampDirectoryVisitor.h"
|
|
#include "Misc/App.h"
|
|
#include "Modules/ModuleManager.h"
|
|
#include "DerivedDataCacheInterface.h"
|
|
#include "Misc/PackageName.h"
|
|
|
|
#include "HTTPTransport.h"
|
|
#include "TCPTransport.h"
|
|
|
|
#include "HAL/IPlatformFileModule.h"
|
|
#include "Templates/UniquePtr.h"
|
|
|
|
#include "UObject/Object.h"
|
|
|
|
DEFINE_LOG_CATEGORY(LogNetworkPlatformFile);
|
|
|
|
FString FNetworkPlatformFile::MP4Extension = TEXT(".mp4");
|
|
FString FNetworkPlatformFile::BulkFileExtension = TEXT(".ubulk");
|
|
FString FNetworkPlatformFile::ExpFileExtension = TEXT(".uexp");
|
|
FString FNetworkPlatformFile::FontFileExtension = TEXT(".ufont");
|
|
|
|
FNetworkPlatformFile::FNetworkPlatformFile()
|
|
: bHasLoadedDDCDirectories(false)
|
|
, InnerPlatformFile(NULL)
|
|
, bIsUsable(false)
|
|
, FileServerPort(0)
|
|
, ConnectionFlags(EConnectionFlags::None)
|
|
, HeartbeatFrequency(5.0f)
|
|
, FinishedAsyncNetworkReadUnsolicitedFiles(NULL)
|
|
, FinishedAsyncWriteUnsolicitedFiles(NULL)
|
|
, Transport(NULL)
|
|
{
|
|
|
|
|
|
|
|
TotalWriteTime = 0.0; // total non async time spent writing to disk
|
|
TotalNetworkSyncTime = 0.0; // total non async time spent syncing to network
|
|
TotalTimeSpentInUnsolicitedPackages = 0.0; // total time async processing unsolicited packages
|
|
TotalWaitForAsyncUnsolicitedPackages = 0.0; // total time spent waiting for unsolicited packages
|
|
TotalFilesSynced = 0; // total number files synced from network
|
|
TotalFilesFoundLocally = 0;
|
|
TotalUnsolicitedPackages = 0; // total number unsolicited files synced
|
|
UnsolicitedPackagesHits = 0; // total number of hits from waiting on unsolicited packages
|
|
UnsolicitedPackageWaits = 0; // total number of waits on unsolicited packages
|
|
|
|
|
|
}
|
|
|
|
bool FNetworkPlatformFile::ShouldBeUsed(IPlatformFile* Inner, const TCHAR* CmdLine) const
|
|
{
|
|
FString HostIp;
|
|
return FParse::Value(CmdLine, TEXT("-FileHostIP="), HostIp);
|
|
}
|
|
|
|
ITransport *CreateTransportForHostAddress(const FString &HostIp )
|
|
{
|
|
if ( HostIp.StartsWith(TEXT("tcp://")))
|
|
{
|
|
return new FTCPTransport();
|
|
}
|
|
|
|
if ( HostIp.StartsWith(TEXT("http://")))
|
|
{
|
|
#if ENABLE_HTTP_FOR_NF
|
|
return new FHTTPTransport();
|
|
#endif
|
|
}
|
|
|
|
// no transport specified assuming tcp
|
|
return new FTCPTransport();
|
|
}
|
|
|
|
bool FNetworkPlatformFile::Initialize(IPlatformFile* Inner, const TCHAR* CmdLine)
|
|
{
|
|
bool bResult = false;
|
|
FString HostIpString;
|
|
if (FParse::Value(CmdLine, TEXT("-FileHostIP="), HostIpString))
|
|
{
|
|
TArray<FString> HostIpList;
|
|
if (HostIpString.ParseIntoArray(HostIpList, TEXT("+"), true) > 0)
|
|
{
|
|
for (int32 HostIpIndex = 0; !bResult && HostIpIndex < HostIpList.Num(); ++HostIpIndex)
|
|
{
|
|
// Try to initialize with each of the IP addresses found in the command line until we
|
|
// get a working one.
|
|
|
|
// find the correct transport for this ip address
|
|
Transport = CreateTransportForHostAddress( HostIpList[HostIpIndex] );
|
|
|
|
UE_LOG(LogNetworkPlatformFile, Warning, TEXT("Created transport for %s."), *HostIpList[HostIpIndex]);
|
|
|
|
if ( Transport )
|
|
{
|
|
bResult = Transport->Initialize( *HostIpList[HostIpIndex] ) && InitializeInternal(Inner, *HostIpList[HostIpIndex]);
|
|
if (bResult)
|
|
break;
|
|
|
|
UE_LOG(LogNetworkPlatformFile, Warning, TEXT("Failed to initialize %s."), *HostIpList[HostIpIndex]);
|
|
|
|
// try a different host might be a different protocol
|
|
delete Transport;
|
|
}
|
|
Transport = NULL;
|
|
}
|
|
}
|
|
}
|
|
|
|
return bResult;
|
|
}
|
|
|
|
bool FNetworkPlatformFile::InitializeInternal(IPlatformFile* Inner, const TCHAR* HostIP)
|
|
{
|
|
// This platform file requires an inner.
|
|
check(Inner != NULL);
|
|
InnerPlatformFile = Inner;
|
|
if (HostIP == NULL)
|
|
{
|
|
UE_LOG(LogNetworkPlatformFile, Error, TEXT("No Host IP specified in the commandline."));
|
|
bIsUsable = false;
|
|
return false;
|
|
}
|
|
|
|
// Save and Intermediate directories are always local
|
|
LocalDirectories.Add(FPaths::EngineDir() / TEXT("Binaries"));
|
|
LocalDirectories.Add(FPaths::EngineIntermediateDir());
|
|
LocalDirectories.Add(FPaths::ProjectDir() / TEXT("Binaries"));
|
|
LocalDirectories.Add(FPaths::ProjectIntermediateDir());
|
|
LocalDirectories.Add(FPaths::ProjectSavedDir() / TEXT("Backup"));
|
|
LocalDirectories.Add(FPaths::ProjectSavedDir() / TEXT("Config"));
|
|
LocalDirectories.Add(FPaths::ProjectSavedDir() / TEXT("Logs"));
|
|
LocalDirectories.Add(FPaths::ProjectSavedDir() / TEXT("Sandboxes"));
|
|
|
|
if (InnerPlatformFile->GetLowerLevel())
|
|
{
|
|
InnerPlatformFile->GetLowerLevel()->AddLocalDirectories(LocalDirectories);
|
|
}
|
|
else
|
|
{
|
|
InnerPlatformFile->AddLocalDirectories(LocalDirectories);
|
|
}
|
|
|
|
|
|
FNetworkFileArchive Payload(NFS_Messages::Heartbeat);
|
|
FArrayReader Out;
|
|
if (!SendPayloadAndReceiveResponse(Payload,Out))
|
|
bIsUsable = true;
|
|
|
|
|
|
// lets see we can test whether the server is up.
|
|
if (Out.Num())
|
|
{
|
|
FCommandLine::AddToSubprocessCommandline( *FString::Printf( TEXT("-FileHostIP=%s"), HostIP ) );
|
|
bIsUsable = true;
|
|
}
|
|
return bIsUsable;
|
|
}
|
|
|
|
bool FNetworkPlatformFile::SendPayloadAndReceiveResponse(TArray<uint8>& In, TArray<uint8>& Out)
|
|
{
|
|
{
|
|
FScopeLock ScopeLock(&SynchronizationObject);
|
|
if ( FinishedAsyncNetworkReadUnsolicitedFiles )
|
|
{
|
|
delete FinishedAsyncNetworkReadUnsolicitedFiles;
|
|
FinishedAsyncNetworkReadUnsolicitedFiles = NULL;
|
|
}
|
|
}
|
|
|
|
return Transport->SendPayloadAndReceiveResponse( In, Out );
|
|
}
|
|
|
|
bool FNetworkPlatformFile::ReceiveResponse(TArray<uint8> &Out )
|
|
{
|
|
return Transport->ReceiveResponse( Out );
|
|
}
|
|
|
|
|
|
void FNetworkPlatformFile::InitializeAfterSetActive()
|
|
{
|
|
double NetworkFileStartupTime = 0.0;
|
|
{
|
|
SCOPE_SECONDS_COUNTER(NetworkFileStartupTime);
|
|
|
|
// send the filenames and timestamps to the server
|
|
FNetworkFileArchive Payload(NFS_Messages::GetFileList);
|
|
FillGetFileList(Payload);
|
|
|
|
// send the directories over, and wait for a response
|
|
FArrayReader Response;
|
|
if (!SendPayloadAndReceiveResponse(Payload, Response))
|
|
{
|
|
delete Transport;
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
// receive the cooked version information
|
|
int32 ServerPackageVersion = 0;
|
|
int32 ServerPackageLicenseeVersion = 0;
|
|
ProcessServerInitialResponse(Response, ServerPackageVersion, ServerPackageLicenseeVersion);
|
|
ProcessServerCachedFilesResponse(Response, ServerPackageVersion, ServerPackageLicenseeVersion);
|
|
|
|
// make sure we can sync a file
|
|
FString TestSyncFile = FPaths::Combine(*(FPaths::EngineDir()), TEXT("Config/BaseEngine.ini"));
|
|
|
|
InnerPlatformFile->SetReadOnly(*TestSyncFile, false);
|
|
InnerPlatformFile->DeleteFile(*TestSyncFile);
|
|
if (InnerPlatformFile->FileExists(*TestSyncFile))
|
|
{
|
|
UE_LOG(LogNetworkPlatformFile, Fatal, TEXT("Could not delete file sync test file %s."), *TestSyncFile);
|
|
}
|
|
|
|
EnsureFileIsLocal(TestSyncFile);
|
|
|
|
if (!InnerPlatformFile->FileExists(*TestSyncFile) || InnerPlatformFile->FileSize(*TestSyncFile) < 1)
|
|
{
|
|
UE_LOG(LogNetworkPlatformFile, Fatal, TEXT("Could not sync test file %s."), *TestSyncFile);
|
|
}
|
|
}
|
|
}
|
|
|
|
FPlatformMisc::LowLevelOutputDebugStringf(TEXT("Network file startup time: %5.3f seconds\n"), NetworkFileStartupTime);
|
|
|
|
}
|
|
|
|
void FNetworkPlatformFile::ProcessServerCachedFilesResponse(FArrayReader& Response, const int32 ServerPackageVersion, const int32 ServerPackageLicenseeVersion)
|
|
{
|
|
/* The server root content directories */
|
|
TArray<FString> ServerRootContentDirectories;
|
|
Response << ServerRootContentDirectories;
|
|
|
|
// receive a list of the cache files and their timestamps
|
|
TMap<FString, FDateTime> ServerCachedFiles;
|
|
Response << ServerCachedFiles;
|
|
|
|
bool bDeleteAllFiles = true;
|
|
// Check the stored cooked version
|
|
FString CookedVersionFile = FPaths::GeneratedConfigDir() / TEXT("CookedVersion.txt");
|
|
|
|
if (InnerPlatformFile->FileExists(*CookedVersionFile) == true)
|
|
{
|
|
IFileHandle* FileHandle = InnerPlatformFile->OpenRead(*CookedVersionFile);
|
|
if (FileHandle != NULL)
|
|
{
|
|
int32 StoredPackageCookedVersion;
|
|
int32 StoredPackageCookedLicenseeVersion;
|
|
if (FileHandle->Read((uint8*)&StoredPackageCookedVersion, sizeof(int32)) == true)
|
|
{
|
|
if (FileHandle->Read((uint8*)&StoredPackageCookedLicenseeVersion, sizeof(int32)) == true)
|
|
{
|
|
if ((ServerPackageVersion == StoredPackageCookedVersion) &&
|
|
(ServerPackageLicenseeVersion == StoredPackageCookedLicenseeVersion))
|
|
{
|
|
bDeleteAllFiles = false;
|
|
}
|
|
else
|
|
{
|
|
UE_LOG(LogNetworkPlatformFile, Display,
|
|
TEXT("Engine version mismatch: Server %d.%d, Stored %d.%d\n"),
|
|
ServerPackageVersion, ServerPackageLicenseeVersion,
|
|
StoredPackageCookedVersion, StoredPackageCookedLicenseeVersion);
|
|
}
|
|
}
|
|
}
|
|
|
|
delete FileHandle;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
UE_LOG(LogNetworkPlatformFile, Display, TEXT("Cooked version file missing: %s\n"), *CookedVersionFile);
|
|
}
|
|
|
|
if (bDeleteAllFiles == true)
|
|
{
|
|
// Make sure the config file exists...
|
|
InnerPlatformFile->CreateDirectoryTree(*(FPaths::GeneratedConfigDir()));
|
|
// Update the cooked version file
|
|
IFileHandle* FileHandle = InnerPlatformFile->OpenWrite(*CookedVersionFile);
|
|
if (FileHandle != NULL)
|
|
{
|
|
FileHandle->Write((const uint8*)&ServerPackageVersion, sizeof(int32));
|
|
FileHandle->Write((const uint8*)&ServerPackageLicenseeVersion, sizeof(int32));
|
|
delete FileHandle;
|
|
}
|
|
}
|
|
|
|
// list of directories to skip
|
|
TArray<FString> DirectoriesToSkip;
|
|
TArray<FString> DirectoriesToNotRecurse;
|
|
// use the timestamp grabbing visitor to get all the content times
|
|
FLocalTimestampDirectoryVisitor Visitor(*InnerPlatformFile, DirectoriesToSkip, DirectoriesToNotRecurse, false);
|
|
|
|
/*TArray<FString> RootContentPaths;
|
|
FPackageName::QueryRootContentPaths(RootContentPaths); */
|
|
for (TArray<FString>::TConstIterator RootPathIt(ServerRootContentDirectories); RootPathIt; ++RootPathIt)
|
|
{
|
|
/*const FString& RootPath = *RootPathIt;
|
|
const FString& ContentFolder = FPackageName::LongPackageNameToFilename(RootPath);*/
|
|
const FString& ContentFolder = *RootPathIt;
|
|
InnerPlatformFile->IterateDirectory(*ContentFolder, Visitor);
|
|
}
|
|
|
|
// delete out of date files using the server cached files
|
|
for (TMap<FString, FDateTime>::TIterator It(ServerCachedFiles); It; ++It)
|
|
{
|
|
bool bDeleteFile = bDeleteAllFiles;
|
|
FString ServerFile = It.Key();
|
|
|
|
// Convert the filename to the client version
|
|
ConvertServerFilenameToClientFilename(ServerFile);
|
|
|
|
// Set it in the visitor file times list
|
|
// If there is any pathing difference (relative path, or whatever) between the server's filelist and the results
|
|
// of platform directory iteration then this will Add a new entry rather than override the existing one. This causes local file deletes
|
|
// and longer loads as we will never see the benefits of local device caching.
|
|
Visitor.FileTimes.Add(ServerFile, FDateTime::MinValue());
|
|
|
|
if (bDeleteFile == false)
|
|
{
|
|
// Check the time stamps...
|
|
// get local time
|
|
FDateTime LocalTime = InnerPlatformFile->GetTimeStamp(*ServerFile);
|
|
// If local time == MinValue than the file does not exist in the cache.
|
|
if (LocalTime != FDateTime::MinValue())
|
|
{
|
|
FDateTime ServerTime = It.Value();
|
|
// delete if out of date
|
|
// We will use 1.0 second as the tolerance to cover any platform differences in resolution
|
|
FTimespan TimeDiff = LocalTime - ServerTime;
|
|
double TimeDiffInSeconds = TimeDiff.GetTotalSeconds();
|
|
bDeleteFile = (TimeDiffInSeconds > 1.0) || (TimeDiffInSeconds < -1.0);
|
|
if (bDeleteFile == true)
|
|
{
|
|
if (InnerPlatformFile->FileExists(*ServerFile) == true)
|
|
{
|
|
UE_LOG(LogNetworkPlatformFile, Display, TEXT("Deleting cached file: TimeDiff %5.3f, %s"), TimeDiffInSeconds, *It.Key());
|
|
}
|
|
else
|
|
{
|
|
// It's a directory
|
|
bDeleteFile = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
UE_LOG(LogNetworkPlatformFile, Display, TEXT("Keeping cached file: %s, TimeDiff worked out ok"), *ServerFile);
|
|
}
|
|
}
|
|
}
|
|
if (bDeleteFile == true)
|
|
{
|
|
UE_LOG(LogNetworkPlatformFile, Display, TEXT("Deleting cached file: %s"), *ServerFile);
|
|
InnerPlatformFile->DeleteFile(*ServerFile);
|
|
}
|
|
}
|
|
|
|
// Any content files we have locally that were not cached, delete them
|
|
for (TMap<FString, FDateTime>::TIterator It(Visitor.FileTimes); It; ++It)
|
|
{
|
|
if ( FCString::Stricmp( *FPaths::GetExtension( It.Key() ), TEXT("pak")) == 0 )
|
|
{
|
|
// ignore pak files they won't be mounted anyway
|
|
continue;
|
|
}
|
|
if (It.Value() != FDateTime::MinValue())
|
|
{
|
|
// This was *not* found in the server file list... delete it
|
|
UE_LOG(LogNetworkPlatformFile, Display, TEXT("Deleting cached file: %s"), *It.Key());
|
|
InnerPlatformFile->DeleteFile(*It.Key());
|
|
}
|
|
}
|
|
}
|
|
|
|
FNetworkPlatformFile::~FNetworkPlatformFile()
|
|
{
|
|
if (!GIsRequestingExit) // the socket subsystem is probably already gone, so it will crash if we clean up
|
|
{
|
|
FScopeLock ScopeLock(&SynchronizationObject);
|
|
if ( FinishedAsyncNetworkReadUnsolicitedFiles )
|
|
{
|
|
delete FinishedAsyncNetworkReadUnsolicitedFiles; // wait here for any async unsolicited files to finish reading being read from the network
|
|
FinishedAsyncNetworkReadUnsolicitedFiles = NULL;
|
|
}
|
|
if ( FinishedAsyncWriteUnsolicitedFiles )
|
|
{
|
|
delete FinishedAsyncWriteUnsolicitedFiles; // wait here for any async unsolicited files to finish writing
|
|
FinishedAsyncWriteUnsolicitedFiles = NULL;
|
|
}
|
|
|
|
delete Transport; // close our sockets.
|
|
}
|
|
}
|
|
|
|
bool FNetworkPlatformFile::DeleteFile(const TCHAR* Filename)
|
|
{
|
|
// FScopeLock ScopeLock(&SynchronizationObject);
|
|
|
|
// make and send payload (this is how we would do for sending all commands over the network)
|
|
// FNetworkFileArchive Payload(NFS_Messages::DeleteFile);
|
|
// Payload << Filename;
|
|
// return FNFSMessageHeader::WrapAndSendPayload(Payload, FileSocket);
|
|
|
|
// perform a local operation
|
|
return InnerPlatformFile->DeleteFile(Filename);
|
|
}
|
|
|
|
bool FNetworkPlatformFile::MoveFile(const TCHAR* To, const TCHAR* From)
|
|
{
|
|
// FScopeLock ScopeLock(&SynchronizationObject);
|
|
|
|
// make and send payload (this is how we would do for sending all commands over the network)
|
|
// FNetworkFileArchive Payload(NFS_Messages::MoveFile);
|
|
// Payload << To << From;
|
|
// return FNFSMessageHeader::WrapAndSendPayload(Payload, FileSocket);
|
|
|
|
FString RelativeFrom = From;
|
|
MakeStandardNetworkFilename(RelativeFrom);
|
|
|
|
// don't copy files in local directories
|
|
if (!IsInLocalDirectory(RelativeFrom))
|
|
{
|
|
// make sure the source file exists here
|
|
EnsureFileIsLocal(RelativeFrom);
|
|
}
|
|
|
|
// perform a local operation
|
|
return InnerPlatformFile->MoveFile(To, From);
|
|
}
|
|
|
|
bool FNetworkPlatformFile::SetReadOnly(const TCHAR* Filename, bool bNewReadOnlyValue)
|
|
{
|
|
// FScopeLock ScopeLock(&SynchronizationObject);
|
|
|
|
// perform a local operation
|
|
return InnerPlatformFile->SetReadOnly(Filename, bNewReadOnlyValue);
|
|
}
|
|
|
|
void FNetworkPlatformFile::SetTimeStamp(const TCHAR* Filename, FDateTime DateTime)
|
|
{
|
|
// perform a local operation
|
|
InnerPlatformFile->SetTimeStamp(Filename, DateTime);
|
|
}
|
|
|
|
IFileHandle* FNetworkPlatformFile::OpenRead(const TCHAR* Filename, bool bAllowWrite)
|
|
{
|
|
// FScopeLock ScopeLock(&SynchronizationObject);
|
|
|
|
FString RelativeFilename = Filename;
|
|
MakeStandardNetworkFilename(RelativeFilename);
|
|
// don't copy files in local directories
|
|
if (!IsInLocalDirectory(RelativeFilename))
|
|
{
|
|
EnsureFileIsLocal(RelativeFilename);
|
|
}
|
|
|
|
double StartTime;
|
|
float ThisTime;
|
|
|
|
StartTime = FPlatformTime::Seconds();
|
|
IFileHandle* Result = InnerPlatformFile->OpenRead(Filename, bAllowWrite);
|
|
|
|
ThisTime = 1000.0f * float(FPlatformTime::Seconds() - StartTime);
|
|
//UE_LOG(LogNetworkPlatformFile, Display, TEXT("Open local file %6.2fms"), ThisTime);
|
|
return Result;
|
|
}
|
|
|
|
IFileHandle* FNetworkPlatformFile::OpenWrite(const TCHAR* Filename, bool bAppend, bool bAllowRead)
|
|
{
|
|
// FScopeLock ScopeLock(&SynchronizationObject);
|
|
|
|
// just let the physical file interface write the file (we don't write over the network)
|
|
return InnerPlatformFile->OpenWrite(Filename, bAppend, bAllowRead);
|
|
}
|
|
|
|
bool FNetworkPlatformFile::CreateDirectoryTree(const TCHAR* Directory)
|
|
{
|
|
// FScopeLock ScopeLock(&SynchronizationObject);
|
|
|
|
// perform a local operation
|
|
return InnerPlatformFile->CreateDirectoryTree(Directory);
|
|
}
|
|
|
|
bool FNetworkPlatformFile::CreateDirectory(const TCHAR* Directory)
|
|
{
|
|
// FScopeLock ScopeLock(&SynchronizationObject);
|
|
|
|
// perform a local operation
|
|
return InnerPlatformFile->CreateDirectory(Directory);
|
|
}
|
|
|
|
bool FNetworkPlatformFile::DeleteDirectory(const TCHAR* Directory)
|
|
{
|
|
// FScopeLock ScopeLock(&SynchronizationObject);
|
|
|
|
// perform a local operation
|
|
return InnerPlatformFile->DeleteDirectory(Directory);
|
|
}
|
|
|
|
FFileStatData FNetworkPlatformFile::GetStatData(const TCHAR* FilenameOrDirectory)
|
|
{
|
|
// FScopeLock ScopeLock(&SynchronizationObject);
|
|
|
|
// perform a local operation
|
|
return InnerPlatformFile->GetStatData(FilenameOrDirectory);
|
|
}
|
|
|
|
bool FNetworkPlatformFile::IterateDirectory(const TCHAR* InDirectory, IPlatformFile::FDirectoryVisitor& Visitor)
|
|
{
|
|
// FScopeLock ScopeLock(&SynchronizationObject);
|
|
|
|
// for .dll, etc searches that don't specify a path, we need to strip off the path
|
|
// before we send it to the visitor
|
|
bool bHadNoPath = InDirectory[0] == 0;
|
|
|
|
// local files go right to the source
|
|
FString RelativeDirectory = InDirectory;
|
|
MakeStandardNetworkFilename(RelativeDirectory);
|
|
if (IsInLocalDirectory(RelativeDirectory))
|
|
{
|
|
return InnerPlatformFile->IterateDirectory(InDirectory, Visitor);
|
|
}
|
|
|
|
// we loop until this is false
|
|
bool RetVal = true;
|
|
|
|
FServerTOC::FDirectory* ServerDirectory = ServerFiles.FindDirectory(RelativeDirectory);
|
|
if (ServerDirectory != NULL)
|
|
{
|
|
// loop over the server files and look if they are in this exact directory
|
|
for (FServerTOC::FDirectory::TIterator It(*ServerDirectory); It && RetVal == true; ++It)
|
|
{
|
|
if (FPaths::GetPath(It.Key()) == RelativeDirectory)
|
|
{
|
|
// timestamps of 0 mean directories
|
|
bool bIsDirectory = It.Value() == 0;
|
|
|
|
// visit (stripping off the path if needed)
|
|
RetVal = Visitor.Visit(bHadNoPath ? *FPaths::GetCleanFilename(It.Key()) : *It.Key(), bIsDirectory);
|
|
}
|
|
}
|
|
}
|
|
|
|
return RetVal;
|
|
}
|
|
|
|
bool FNetworkPlatformFile::IterateDirectoryRecursively(const TCHAR* InDirectory, IPlatformFile::FDirectoryVisitor& Visitor)
|
|
{
|
|
// FScopeLock ScopeLock(&SynchronizationObject);
|
|
|
|
// local files go right to the source
|
|
FString RelativeDirectory = InDirectory;
|
|
MakeStandardNetworkFilename(RelativeDirectory);
|
|
|
|
if (IsInLocalDirectory(RelativeDirectory))
|
|
{
|
|
return InnerPlatformFile->IterateDirectoryRecursively(InDirectory, Visitor);
|
|
}
|
|
|
|
// we loop until this is false
|
|
bool RetVal = true;
|
|
|
|
for (TMap<FString, FServerTOC::FDirectory*>::TIterator DirIt(ServerFiles.Directories); DirIt && RetVal == true; ++DirIt)
|
|
{
|
|
if (DirIt.Key().StartsWith(RelativeDirectory))
|
|
{
|
|
FServerTOC::FDirectory& ServerDirectory = *DirIt.Value();
|
|
|
|
// loop over the server files and look if they are in this exact directory
|
|
for (FServerTOC::FDirectory::TIterator It(ServerDirectory); It && RetVal == true; ++It)
|
|
{
|
|
// timestamps of 0 mean directories
|
|
bool bIsDirectory = It.Value() == 0;
|
|
|
|
// visit!
|
|
RetVal = Visitor.Visit(*It.Key(), bIsDirectory);
|
|
}
|
|
}
|
|
}
|
|
|
|
return RetVal;
|
|
}
|
|
|
|
bool FNetworkPlatformFile::IterateDirectoryStat(const TCHAR* InDirectory, IPlatformFile::FDirectoryStatVisitor& Visitor)
|
|
{
|
|
// FScopeLock ScopeLock(&SynchronizationObject);
|
|
|
|
// for .dll, etc searches that don't specify a path, we need to strip off the path
|
|
// before we send it to the visitor
|
|
bool bHadNoPath = InDirectory[0] == 0;
|
|
|
|
// local files go right to the source
|
|
FString RelativeDirectory = InDirectory;
|
|
MakeStandardNetworkFilename(RelativeDirectory);
|
|
if (IsInLocalDirectory(RelativeDirectory))
|
|
{
|
|
return InnerPlatformFile->IterateDirectoryStat(InDirectory, Visitor);
|
|
}
|
|
|
|
// we loop until this is false
|
|
bool RetVal = true;
|
|
|
|
FServerTOC::FDirectory* ServerDirectory = ServerFiles.FindDirectory(RelativeDirectory);
|
|
if (ServerDirectory != NULL)
|
|
{
|
|
// loop over the server files and look if they are in this exact directory
|
|
for (FServerTOC::FDirectory::TIterator It(*ServerDirectory); It && RetVal == true; ++It)
|
|
{
|
|
if (FPaths::GetPath(It.Key()) == RelativeDirectory)
|
|
{
|
|
// timestamps of 0 mean directories
|
|
bool bIsDirectory = It.Value() == 0;
|
|
|
|
// todo: this data is just wrong for most things, but can we afford to get the files from the server to get the correct info? Could the server provide this instead?
|
|
const FFileStatData StatData(
|
|
FDateTime::MinValue(),
|
|
FDateTime::MinValue(),
|
|
(bIsDirectory) ? FDateTime::MinValue() : It.Value(),
|
|
-1, // FileSize
|
|
bIsDirectory,
|
|
true // IsReadOnly
|
|
);
|
|
|
|
// visit (stripping off the path if needed)
|
|
RetVal = Visitor.Visit(bHadNoPath ? *FPaths::GetCleanFilename(It.Key()) : *It.Key(), StatData);
|
|
}
|
|
}
|
|
}
|
|
|
|
return RetVal;
|
|
}
|
|
|
|
bool FNetworkPlatformFile::IterateDirectoryStatRecursively(const TCHAR* InDirectory, IPlatformFile::FDirectoryStatVisitor& Visitor)
|
|
{
|
|
// FScopeLock ScopeLock(&SynchronizationObject);
|
|
|
|
// local files go right to the source
|
|
FString RelativeDirectory = InDirectory;
|
|
MakeStandardNetworkFilename(RelativeDirectory);
|
|
|
|
if (IsInLocalDirectory(RelativeDirectory))
|
|
{
|
|
return InnerPlatformFile->IterateDirectoryStatRecursively(InDirectory, Visitor);
|
|
}
|
|
|
|
// we loop until this is false
|
|
bool RetVal = true;
|
|
|
|
for (TMap<FString, FServerTOC::FDirectory*>::TIterator DirIt(ServerFiles.Directories); DirIt && RetVal == true; ++DirIt)
|
|
{
|
|
if (DirIt.Key().StartsWith(RelativeDirectory))
|
|
{
|
|
FServerTOC::FDirectory& ServerDirectory = *DirIt.Value();
|
|
|
|
// loop over the server files and look if they are in this exact directory
|
|
for (FServerTOC::FDirectory::TIterator It(ServerDirectory); It && RetVal == true; ++It)
|
|
{
|
|
// timestamps of 0 mean directories
|
|
bool bIsDirectory = It.Value() == 0;
|
|
|
|
// todo: this data is just wrong for most things, but can we afford to get the files from the server to get the correct info? Could the server provide this instead?
|
|
const FFileStatData StatData(
|
|
FDateTime::MinValue(),
|
|
FDateTime::MinValue(),
|
|
(bIsDirectory) ? FDateTime::MinValue() : It.Value(),
|
|
0, // FileSize
|
|
bIsDirectory,
|
|
true // IsReadOnly
|
|
);
|
|
|
|
// visit!
|
|
RetVal = Visitor.Visit(*It.Key(), StatData);
|
|
}
|
|
}
|
|
}
|
|
|
|
return RetVal;
|
|
}
|
|
|
|
bool FNetworkPlatformFile::DeleteDirectoryRecursively(const TCHAR* Directory)
|
|
{
|
|
// FScopeLock ScopeLock(&SynchronizationObject);
|
|
|
|
// perform a local operation
|
|
return InnerPlatformFile->DeleteDirectory(Directory);
|
|
}
|
|
|
|
bool FNetworkPlatformFile::CopyFile(const TCHAR* To, const TCHAR* From, EPlatformFileRead ReadFlags, EPlatformFileWrite WriteFlags)
|
|
{
|
|
// FScopeLock ScopeLock(&SynchronizationObject);
|
|
|
|
FString RelativeFrom = From;
|
|
MakeStandardNetworkFilename(RelativeFrom);
|
|
|
|
// don't copy files in local directories
|
|
if (!IsInLocalDirectory(RelativeFrom))
|
|
{
|
|
// make sure the source file exists here
|
|
EnsureFileIsLocal(RelativeFrom);
|
|
}
|
|
|
|
// perform a local operation
|
|
return InnerPlatformFile->CopyFile(To, From, ReadFlags, WriteFlags);
|
|
}
|
|
|
|
FString FNetworkPlatformFile::ConvertToAbsolutePathForExternalAppForRead( const TCHAR* Filename )
|
|
{
|
|
FString RelativeFrom = Filename;
|
|
MakeStandardNetworkFilename(RelativeFrom);
|
|
|
|
if (!IsInLocalDirectory(RelativeFrom))
|
|
{
|
|
EnsureFileIsLocal(RelativeFrom);
|
|
}
|
|
return InnerPlatformFile->ConvertToAbsolutePathForExternalAppForRead(Filename);
|
|
}
|
|
|
|
FString FNetworkPlatformFile::ConvertToAbsolutePathForExternalAppForWrite( const TCHAR* Filename )
|
|
{
|
|
FString RelativeFrom = Filename;
|
|
MakeStandardNetworkFilename(RelativeFrom);
|
|
|
|
if (!IsInLocalDirectory(RelativeFrom))
|
|
{
|
|
EnsureFileIsLocal(RelativeFrom);
|
|
}
|
|
return InnerPlatformFile->ConvertToAbsolutePathForExternalAppForWrite(Filename);
|
|
}
|
|
|
|
bool FNetworkPlatformFile::DirectoryExists(const TCHAR* Directory)
|
|
{
|
|
if (InnerPlatformFile->DirectoryExists(Directory))
|
|
{
|
|
return true;
|
|
}
|
|
// If there are any syncable files in this directory, consider it existing
|
|
FString RelativeDirectory = Directory;
|
|
MakeStandardNetworkFilename(RelativeDirectory);
|
|
|
|
FServerTOC::FDirectory* ServerDirectory = ServerFiles.FindDirectory(RelativeDirectory);
|
|
return ServerDirectory != NULL;
|
|
}
|
|
|
|
void FNetworkPlatformFile::GetFileInfo(const TCHAR* Filename, FFileInfo& Info)
|
|
{
|
|
FString RelativeFilename = Filename;
|
|
MakeStandardNetworkFilename(RelativeFilename);
|
|
|
|
// don't copy files in local directories
|
|
if (!IsInLocalDirectory(RelativeFilename))
|
|
{
|
|
EnsureFileIsLocal(RelativeFilename);
|
|
}
|
|
|
|
const FFileStatData StatData = InnerPlatformFile->GetStatData(Filename);
|
|
Info.FileExists = StatData.bIsValid && !StatData.bIsDirectory;
|
|
Info.ReadOnly = StatData.bIsReadOnly;
|
|
Info.Size = StatData.FileSize;
|
|
Info.TimeStamp = StatData.ModificationTime;
|
|
Info.AccessTimeStamp = StatData.AccessTime;
|
|
}
|
|
|
|
void FNetworkPlatformFile::ConvertServerFilenameToClientFilename(FString& FilenameToConvert)
|
|
{
|
|
FNetworkPlatformFile::ConvertServerFilenameToClientFilename(FilenameToConvert, ServerEngineDir, ServerProjectDir);
|
|
}
|
|
|
|
void FNetworkPlatformFile::FillGetFileList(FNetworkFileArchive& Payload)
|
|
{
|
|
TArray<FString> TargetPlatformNames;
|
|
FPlatformMisc::GetValidTargetPlatforms(TargetPlatformNames);
|
|
FString GameName = FApp::GetProjectName();
|
|
if (FPaths::IsProjectFilePathSet())
|
|
{
|
|
GameName = FPaths::GetProjectFilePath();
|
|
}
|
|
|
|
FString EngineRelPath = FPaths::EngineDir();
|
|
FString EngineRelPluginPath = FPaths::EnginePluginsDir();
|
|
FString GameRelPath = FPaths::ProjectDir();
|
|
FString GameRelPluginPath = FPaths::ProjectPluginsDir();
|
|
|
|
TArray<FString> Directories;
|
|
Directories.Add(EngineRelPath);
|
|
Directories.Add(EngineRelPluginPath);
|
|
Directories.Add(GameRelPath);
|
|
Directories.Add(GameRelPluginPath);
|
|
|
|
Payload << TargetPlatformNames;
|
|
Payload << GameName;
|
|
Payload << EngineRelPath;
|
|
Payload << GameRelPath;
|
|
Payload << Directories;
|
|
Payload << ConnectionFlags;
|
|
|
|
FString VersionInfo = GetVersionInfo();
|
|
Payload << VersionInfo;
|
|
}
|
|
|
|
void FNetworkPlatformFile::ProcessServerInitialResponse(FArrayReader& InResponse, int32& OutServerPackageVersion, int32& OutServerPackageLicenseeVersion)
|
|
{
|
|
// Receive the cooked version information.
|
|
InResponse << OutServerPackageVersion;
|
|
InResponse << OutServerPackageLicenseeVersion;
|
|
|
|
// receive the server engine and game dir
|
|
InResponse << ServerEngineDir;
|
|
InResponse << ServerProjectDir;
|
|
|
|
UE_LOG(LogNetworkPlatformFile, Display, TEXT(" Server EngineDir = %s"), *ServerEngineDir);
|
|
UE_LOG(LogNetworkPlatformFile, Display, TEXT(" Local EngineDir = %s"), *FPaths::EngineDir());
|
|
UE_LOG(LogNetworkPlatformFile, Display, TEXT(" Server ProjectDir = %s"), *ServerProjectDir);
|
|
UE_LOG(LogNetworkPlatformFile, Display, TEXT(" Local ProjectDir = %s"), *FPaths::ProjectDir());
|
|
|
|
// Receive a list of files and their timestamps.
|
|
TMap<FString, FDateTime> ServerFileMap;
|
|
InResponse << ServerFileMap;
|
|
for (TMap<FString, FDateTime>::TIterator It(ServerFileMap); It; ++It)
|
|
{
|
|
FString ServerFile = It.Key();
|
|
ConvertServerFilenameToClientFilename(ServerFile);
|
|
ServerFiles.AddFileOrDirectory(ServerFile, It.Value());
|
|
}
|
|
}
|
|
|
|
|
|
FString FNetworkPlatformFile::GetVersionInfo() const
|
|
{
|
|
return FString("");
|
|
}
|
|
|
|
bool FNetworkPlatformFile::SendReadMessage(uint8* Destination, int64 BytesToRead)
|
|
{
|
|
// FScopeLock ScopeLock(&SynchronizationObject);
|
|
|
|
return true;
|
|
}
|
|
|
|
bool FNetworkPlatformFile::SendWriteMessage(const uint8* Source, int64 BytesToWrite)
|
|
{
|
|
// FScopeLock ScopeLock(&SynchronizationObject);
|
|
|
|
return true;
|
|
}
|
|
|
|
bool FNetworkPlatformFile::SendMessageToServer(const TCHAR* Message, IPlatformFile::IFileServerMessageHandler* Handler)
|
|
{
|
|
// handle the recompile shaders message
|
|
// @todo: Maybe we should just send the string message to the server, but then we'd have to
|
|
// handle the return from the server in a generic way
|
|
if (FCString::Stricmp(Message, TEXT("RecompileShaders")) == 0)
|
|
{
|
|
FNetworkFileArchive Payload(NFS_Messages::RecompileShaders);
|
|
|
|
// let the handler fill out the object
|
|
Handler->FillPayload(Payload);
|
|
|
|
FArrayReader Response;
|
|
{
|
|
FScopeLock ScopeLock(&SynchronizationObject);
|
|
if (!SendPayloadAndReceiveResponse(Payload, Response))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// locally delete any files that were modified on the server, so that any read will recache the file
|
|
// this has to be done in this class, not in the Handler (which can't access these members)
|
|
TArray<FString> ModifiedFiles;
|
|
Response << ModifiedFiles;
|
|
|
|
if( InnerPlatformFile != NULL )
|
|
{
|
|
for (int32 Index = 0; Index < ModifiedFiles.Num(); Index++)
|
|
{
|
|
InnerPlatformFile->DeleteFile(*ModifiedFiles[Index]);
|
|
CachedLocalFiles.Remove(ModifiedFiles[Index]);
|
|
ServerFiles.AddFileOrDirectory(ModifiedFiles[Index], FDateTime::UtcNow());
|
|
}
|
|
}
|
|
|
|
|
|
// let the handler process the response directly
|
|
Handler->ProcessResponse(Response);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
static FThreadSafeCounter OutstandingAsyncWrites;
|
|
|
|
class FAsyncNetworkWriteWorker : public FNonAbandonableTask
|
|
{
|
|
public:
|
|
/** Filename To write to**/
|
|
FString Filename;
|
|
/** An archive to read the file contents from */
|
|
FArchive* FileArchive;
|
|
/** timestamp for the file **/
|
|
FDateTime ServerTimeStamp;
|
|
IPlatformFile& InnerPlatformFile;
|
|
FScopedEvent* Event;
|
|
|
|
uint8 Buffer[128 * 1024];
|
|
|
|
/** Constructor
|
|
*/
|
|
FAsyncNetworkWriteWorker(const TCHAR* InFilename, FArchive* InArchive, FDateTime InServerTimeStamp, IPlatformFile* InInnerPlatformFile, FScopedEvent* InEvent)
|
|
: Filename(InFilename)
|
|
, FileArchive(InArchive)
|
|
, ServerTimeStamp(InServerTimeStamp)
|
|
, InnerPlatformFile(*InInnerPlatformFile)
|
|
, Event(InEvent)
|
|
{
|
|
}
|
|
|
|
/** Write the file */
|
|
void DoWork()
|
|
{
|
|
if (InnerPlatformFile.FileExists(*Filename))
|
|
{
|
|
InnerPlatformFile.SetReadOnly(*Filename, false);
|
|
InnerPlatformFile.DeleteFile(*Filename);
|
|
}
|
|
// Read FileSize first so that the correct amount of data is read from the archive
|
|
// before exiting this worker.
|
|
uint64 FileSize;
|
|
*FileArchive << FileSize;
|
|
if (ServerTimeStamp != FDateTime::MinValue()) // if the file didn't actually exist on the server, don't create a zero byte file
|
|
{
|
|
FString TempFilename = Filename + TEXT(".tmp");
|
|
InnerPlatformFile.CreateDirectoryTree(*FPaths::GetPath(Filename));
|
|
{
|
|
TUniquePtr<IFileHandle> FileHandle;
|
|
FileHandle.Reset(InnerPlatformFile.OpenWrite(*TempFilename));
|
|
|
|
if (!FileHandle)
|
|
{
|
|
UE_LOG(LogNetworkPlatformFile, Fatal, TEXT("Could not open file for writing '%s'."), *TempFilename);
|
|
}
|
|
|
|
// now write the file from bytes pulled from the archive
|
|
// read/write a chunk at a time
|
|
uint64 RemainingData = FileSize;
|
|
while (RemainingData)
|
|
{
|
|
// read next chunk from archive
|
|
uint32 LocalSize = FPlatformMath::Min<uint32>(ARRAY_COUNT(Buffer), RemainingData);
|
|
FileArchive->Serialize(Buffer, LocalSize);
|
|
// write it out
|
|
if (!FileHandle->Write(Buffer, LocalSize))
|
|
{
|
|
UE_LOG(LogNetworkPlatformFile, Fatal, TEXT("Could not write '%s'."), *TempFilename);
|
|
}
|
|
|
|
// decrement how much is left
|
|
RemainingData -= LocalSize;
|
|
}
|
|
|
|
// delete async write archives
|
|
if (Event)
|
|
{
|
|
delete FileArchive;
|
|
}
|
|
|
|
if (InnerPlatformFile.FileSize(*TempFilename) != FileSize)
|
|
{
|
|
UE_LOG(LogNetworkPlatformFile, Fatal, TEXT("Did not write '%s'."), *TempFilename);
|
|
}
|
|
}
|
|
|
|
// rename from temp filename to real filename
|
|
InnerPlatformFile.MoveFile(*Filename, *TempFilename);
|
|
|
|
// now set the server's timestamp on the local file (so we can make valid comparisons)
|
|
InnerPlatformFile.SetTimeStamp(*Filename, ServerTimeStamp);
|
|
|
|
FDateTime CheckTime = InnerPlatformFile.GetTimeStamp(*Filename);
|
|
if (CheckTime < ServerTimeStamp)
|
|
{
|
|
UE_LOG(LogNetworkPlatformFile, Fatal, TEXT("Could Not Set Timestamp '%s' %s < %s."), *Filename, *CheckTime.ToString(), *ServerTimeStamp.ToString());
|
|
}
|
|
}
|
|
if (Event)
|
|
{
|
|
if (OutstandingAsyncWrites.Decrement() == 0)
|
|
{
|
|
Event->Trigger(); // last file, fire trigger
|
|
}
|
|
}
|
|
}
|
|
|
|
FORCEINLINE TStatId GetStatId() const
|
|
{
|
|
return TStatId();
|
|
//RETURN_QUICK_DECLARE_CYCLE_STAT(FAsyncNetworkWriteWorker, STATGROUP_ThreadPoolAsyncTasks);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Write a file async or sync, with the data coming from a TArray or an FArchive/Filesize
|
|
*/
|
|
void SyncWriteFile(FArchive* Archive, const FString& Filename, FDateTime ServerTimeStamp, IPlatformFile& InnerPlatformFile)
|
|
{
|
|
FScopedEvent* NullEvent = NULL;
|
|
(new FAutoDeleteAsyncTask<FAsyncNetworkWriteWorker>(*Filename, Archive, ServerTimeStamp, &InnerPlatformFile, NullEvent))->StartSynchronousTask();
|
|
}
|
|
|
|
void AsyncWriteFile(FArchive* Archive, const FString& Filename, FDateTime ServerTimeStamp, IPlatformFile& InnerPlatformFile, FScopedEvent* Event = NULL)
|
|
{
|
|
(new FAutoDeleteAsyncTask<FAsyncNetworkWriteWorker>(*Filename, Archive, ServerTimeStamp, &InnerPlatformFile, Event))->StartBackgroundTask();
|
|
}
|
|
|
|
void AsyncReadUnsolicitedFiles(int32 InNumUnsolictedFiles, FNetworkPlatformFile& InNetworkFile, IPlatformFile& InInnerPlatformFile, FString& InServerEngineDir, FString& InServerProjectDir, FScopedEvent *InNetworkDoneEvent, FScopedEvent *InWritingDoneEvent)
|
|
{
|
|
class FAsyncReadUnsolicitedFile : public FNonAbandonableTask
|
|
{
|
|
public:
|
|
int32 NumUnsolictedFiles;
|
|
FNetworkPlatformFile& NetworkFile;
|
|
IPlatformFile& InnerPlatformFile;
|
|
FString ServerEngineDir;
|
|
FString ServerProjectDir;
|
|
FScopedEvent* NetworkDoneEvent; // finished using the network
|
|
FScopedEvent* WritingDoneEvent; // finished writing the files to disk
|
|
|
|
FAsyncReadUnsolicitedFile(int32 In_NumUnsolictedFiles, FNetworkPlatformFile* In_NetworkFile, IPlatformFile* In_InnerPlatformFile, FString& In_ServerEngineDir, FString& In_ServerProjectDir, FScopedEvent *In_NetworkDoneEvent, FScopedEvent *In_WritingDoneEvent )
|
|
: NumUnsolictedFiles(In_NumUnsolictedFiles)
|
|
, NetworkFile(*In_NetworkFile)
|
|
, InnerPlatformFile(*In_InnerPlatformFile)
|
|
, ServerEngineDir(In_ServerEngineDir)
|
|
, ServerProjectDir(In_ServerProjectDir)
|
|
, NetworkDoneEvent(In_NetworkDoneEvent)
|
|
, WritingDoneEvent(In_WritingDoneEvent)
|
|
{
|
|
}
|
|
|
|
/** Write the file */
|
|
void DoWork()
|
|
{
|
|
OutstandingAsyncWrites.Add( NumUnsolictedFiles );
|
|
for (int32 Index = 0; Index < NumUnsolictedFiles; Index++)
|
|
{
|
|
FArrayReader* UnsolictedResponse = new FArrayReader;
|
|
if (!NetworkFile.ReceiveResponse(*UnsolictedResponse))
|
|
{
|
|
UE_LOG(LogNetworkPlatformFile, Fatal, TEXT("Receive failure!"));
|
|
return;
|
|
}
|
|
FString UnsolictedReplyFile;
|
|
*UnsolictedResponse << UnsolictedReplyFile;
|
|
|
|
if (!UnsolictedReplyFile.IsEmpty())
|
|
{
|
|
FNetworkPlatformFile::ConvertServerFilenameToClientFilename(UnsolictedReplyFile, ServerEngineDir, ServerProjectDir);
|
|
// get the server file timestamp
|
|
FDateTime UnsolictedServerTimeStamp;
|
|
*UnsolictedResponse << UnsolictedServerTimeStamp;
|
|
|
|
// write the file by pulling out of the FArrayReader
|
|
AsyncWriteFile(UnsolictedResponse, UnsolictedReplyFile, UnsolictedServerTimeStamp, InnerPlatformFile, WritingDoneEvent);
|
|
}
|
|
}
|
|
NetworkDoneEvent->Trigger();
|
|
}
|
|
|
|
FORCEINLINE TStatId GetStatId() const
|
|
{
|
|
RETURN_QUICK_DECLARE_CYCLE_STAT(FAsyncReadUnsolicitedFile, STATGROUP_ThreadPoolAsyncTasks);
|
|
}
|
|
};
|
|
|
|
(new FAutoDeleteAsyncTask<FAsyncReadUnsolicitedFile>(InNumUnsolictedFiles, &InNetworkFile, &InInnerPlatformFile, InServerEngineDir, InServerProjectDir, InNetworkDoneEvent, InWritingDoneEvent))->StartSynchronousTask();
|
|
}
|
|
|
|
bool FNetworkPlatformFile::IsMediaExtension(const TCHAR* Ext)
|
|
{
|
|
if (*Ext != TEXT('.'))
|
|
{
|
|
return MP4Extension.EndsWith(Ext);
|
|
}
|
|
else
|
|
{
|
|
return MP4Extension == Ext;
|
|
}
|
|
}
|
|
|
|
bool FNetworkPlatformFile::IsAdditionalCookedFileExtension(const TCHAR* Ext)
|
|
{
|
|
if (*Ext != TEXT('.'))
|
|
{
|
|
return BulkFileExtension.EndsWith(Ext) || FontFileExtension.EndsWith(Ext) || ExpFileExtension.EndsWith(Ext);
|
|
}
|
|
else
|
|
{
|
|
return BulkFileExtension == Ext || FontFileExtension == Ext || ExpFileExtension == Ext;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Given a filename, make sure the file exists on the local filesystem
|
|
*/
|
|
|
|
void FNetworkPlatformFile::EnsureFileIsLocal(const FString& Filename)
|
|
{
|
|
double StartTime;
|
|
float ThisTime;
|
|
StartTime = FPlatformTime::Seconds();
|
|
|
|
UE_LOG(LogNetworkPlatformFile, Verbose, TEXT("Searching for %s locally "), *Filename);
|
|
|
|
{
|
|
FScopeLock ScopeLock(&SynchronizationObject);
|
|
// have we already cached this file?
|
|
if (CachedLocalFiles.Find(Filename) != NULL)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
bool bIncrimentedPackageWaits = false;
|
|
if (FinishedAsyncNetworkReadUnsolicitedFiles)
|
|
{
|
|
if (FinishedAsyncNetworkReadUnsolicitedFiles->Get() == 0)
|
|
{
|
|
++UnsolicitedPackageWaits;
|
|
bIncrimentedPackageWaits = true;
|
|
}
|
|
delete FinishedAsyncNetworkReadUnsolicitedFiles; // wait here for any async unsolicited files to finish reading being read from the network
|
|
FinishedAsyncNetworkReadUnsolicitedFiles = NULL;
|
|
}
|
|
if (FinishedAsyncWriteUnsolicitedFiles)
|
|
{
|
|
if (bIncrimentedPackageWaits == false && FinishedAsyncNetworkReadUnsolicitedFiles->Get() == 0)
|
|
{
|
|
++UnsolicitedPackageWaits;
|
|
}
|
|
delete FinishedAsyncWriteUnsolicitedFiles; // wait here for any async unsolicited files to finish writing to disk
|
|
FinishedAsyncWriteUnsolicitedFiles = NULL;
|
|
}
|
|
|
|
FScopeLock ScopeLock(&SynchronizationObject);
|
|
ThisTime = 1000.0f * float(FPlatformTime::Seconds() - StartTime);
|
|
TotalWaitForAsyncUnsolicitedPackages += ThisTime;
|
|
//UE_LOG(LogNetworkPlatformFile, Display, TEXT("Lock and wait for old async writes %6.2fms"), ThisTime);
|
|
|
|
if (CachedLocalFiles.Find(Filename) != NULL)
|
|
{
|
|
++UnsolicitedPackagesHits;
|
|
return;
|
|
}
|
|
|
|
UE_LOG(LogNetworkPlatformFile, Verbose, TEXT("Attempting to get %s from server"), *Filename);
|
|
|
|
// even if an error occurs later, we still want to remember not to try again
|
|
CachedLocalFiles.Add(Filename);
|
|
StartTime = FPlatformTime::Seconds();
|
|
|
|
// no need to read it if it already exists
|
|
// @todo: Handshake with server to delete files that are out of date
|
|
if (InnerPlatformFile->FileExists(*Filename))
|
|
{
|
|
++TotalFilesFoundLocally;
|
|
UE_LOG(LogNetworkPlatformFile, Verbose, TEXT("File %s exists locally but wasn't in cache"), *Filename);
|
|
return;
|
|
}
|
|
|
|
++TotalFilesSynced;
|
|
|
|
|
|
|
|
ThisTime = 1000.0f * float(FPlatformTime::Seconds() - StartTime);
|
|
//UE_LOG(LogNetworkPlatformFile, Display, TEXT("Check for local file %6.2fms - %s"), ThisTime, *Filename);
|
|
|
|
// this is a bit of a waste if we aren't doing cook on the fly, but we assume missing asset files are relatively rare
|
|
FString Extension = FPaths::GetExtension(Filename, true);
|
|
bool bIsCookable = GConfig && GConfig->IsReadyForUse() && (FPackageName::IsPackageExtension(*Extension) || IsMediaExtension(*Extension) || IsAdditionalCookedFileExtension(*Extension));
|
|
|
|
// we only copy files that actually exist on the server, can greatly reduce network traffic for, say,
|
|
// the INT file each package tries to load
|
|
if (!bIsCookable && (ServerFiles.FindFile(Filename) == NULL))
|
|
{
|
|
// Uncomment this to have the server file list dumped
|
|
// the first time a file requested is not found.
|
|
|
|
UE_LOG(LogNetworkPlatformFile, Verbose, TEXT("Didn't find %s in server files list"), *Filename);
|
|
|
|
#if 0
|
|
static bool sb_DumpedServer = false;
|
|
if (sb_DumpedServer == false)
|
|
{
|
|
FPlatformMisc::LowLevelOutputDebugStringf(TEXT("Dumping server files... %s not found\n"), *Filename);
|
|
for (TMap<FString, FServerTOC::FDirectory*>::TIterator ServerDumpIt(ServerFiles.Directories); ServerDumpIt; ++ServerDumpIt)
|
|
{
|
|
FServerTOC::FDirectory& Directory = *ServerDumpIt.Value();
|
|
for (FServerTOC::FDirectory::TIterator DirDumpIt(Directory); DirDumpIt; ++DirDumpIt)
|
|
{
|
|
FPlatformMisc::LowLevelOutputDebugStringf(TEXT("%10s - %s\n"), *(DirDumpIt.Value().ToString()), *(DirDumpIt.Key()));
|
|
}
|
|
}
|
|
sb_DumpedServer = true;
|
|
}
|
|
#endif
|
|
return;
|
|
}
|
|
|
|
// send the filename over (cast away const here because we know this << will not modify the string)
|
|
FNetworkFileArchive Payload(NFS_Messages::SyncFile);
|
|
Payload << (FString&)Filename;
|
|
|
|
UE_LOG(LogNetworkPlatformFile, Log, TEXT("Requesting file %s"), *Filename);
|
|
|
|
StartTime = FPlatformTime::Seconds();
|
|
|
|
// allocate array reader on the heap, because the SyncWriteFile function will delete it
|
|
FArrayReader Response;
|
|
if (!SendPayloadAndReceiveResponse(Payload, Response))
|
|
{
|
|
UE_LOG(LogNetworkPlatformFile, Fatal, TEXT("Receive failure!"));
|
|
return;
|
|
}
|
|
ThisTime = 1000.0f * float(FPlatformTime::Seconds() - StartTime);
|
|
TotalNetworkSyncTime += ThisTime;
|
|
//UE_LOG(LogNetworkPlatformFile, Display, TEXT("Send and receive %6.2fms"), ThisTime);
|
|
|
|
StartTime = FPlatformTime::Seconds();
|
|
|
|
FString ReplyFile;
|
|
Response << ReplyFile;
|
|
ConvertServerFilenameToClientFilename(ReplyFile);
|
|
check(ReplyFile == Filename);
|
|
|
|
// get the server file timestamp
|
|
FDateTime ServerTimeStamp;
|
|
Response << ServerTimeStamp;
|
|
|
|
if (ServerTimeStamp != FDateTime::MinValue()) // if the file didn't actually exist on the server, don't create a zero byte file
|
|
{
|
|
UE_LOG(LogNetworkPlatformFile, Verbose, TEXT("Succeeded in getting %s from server"), *Filename);
|
|
}
|
|
else
|
|
{
|
|
UE_LOG(LogNetworkPlatformFile, Verbose, TEXT("File not found %s from server"), *Filename);
|
|
}
|
|
|
|
// write the file in chunks, synchronously
|
|
SyncWriteFile(&Response, ReplyFile, ServerTimeStamp, *InnerPlatformFile);
|
|
|
|
int32 NumUnsolictedFiles;
|
|
Response << NumUnsolictedFiles;
|
|
|
|
if (NumUnsolictedFiles)
|
|
{
|
|
TotalUnsolicitedPackages += NumUnsolictedFiles;
|
|
check( FinishedAsyncNetworkReadUnsolicitedFiles == NULL );
|
|
check( FinishedAsyncWriteUnsolicitedFiles == NULL );
|
|
FinishedAsyncNetworkReadUnsolicitedFiles = new FScopedEvent;
|
|
FinishedAsyncWriteUnsolicitedFiles = new FScopedEvent;
|
|
AsyncReadUnsolicitedFiles(NumUnsolictedFiles, *this, *InnerPlatformFile, ServerEngineDir, ServerProjectDir, FinishedAsyncNetworkReadUnsolicitedFiles, FinishedAsyncWriteUnsolicitedFiles);
|
|
}
|
|
|
|
ThisTime = 1000.0f * float(FPlatformTime::Seconds() - StartTime);
|
|
TotalWriteTime += ThisTime;
|
|
//UE_LOG(LogNetworkPlatformFile, Display, TEXT("Write file to local %6.2fms"), ThisTime);
|
|
}
|
|
|
|
static FString NetworkPlatformFileEndChop(TEXT("/"));
|
|
void FNetworkPlatformFile::MakeStandardNetworkFilename(FString& Filename)
|
|
{
|
|
FPaths::MakeStandardFilename(Filename);
|
|
Filename.RemoveFromEnd(NetworkPlatformFileEndChop, ESearchCase::CaseSensitive);
|
|
}
|
|
|
|
bool FNetworkPlatformFile::IsInLocalDirectoryUnGuarded(const FString& Filename)
|
|
{
|
|
// cache the directory of the input file
|
|
FString Directory = FPaths::GetPath(Filename);
|
|
|
|
// look if the file is in a local directory
|
|
for (int32 DirIndex = 0; DirIndex < LocalDirectories.Num(); DirIndex++)
|
|
{
|
|
if (Directory.StartsWith(LocalDirectories[DirIndex]))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
// if not local, talk to the server
|
|
return false;
|
|
}
|
|
|
|
bool FNetworkPlatformFile::IsInLocalDirectory(const FString& Filename)
|
|
{
|
|
if (!bHasLoadedDDCDirectories)
|
|
{
|
|
// need to be careful here to avoid initializing the DDC from the wrong thread or using LocalDirectories while it is being initialized
|
|
FScopeLock ScopeLock(&LocalDirectoriesCriticalSection);
|
|
|
|
if (IsInGameThread() && GConfig && GConfig->IsReadyForUse())
|
|
{
|
|
// one time DDC directory initialization
|
|
// add any DDC directories to our list of local directories (local = inner platform file, it may
|
|
// actually live on a server, but it will use the platform's file system)
|
|
if (GetDerivedDataCache())
|
|
{
|
|
TArray<FString> DdcDirectories;
|
|
|
|
GetDerivedDataCacheRef().GetDirectories(DdcDirectories);
|
|
|
|
LocalDirectories.Append(DdcDirectories);
|
|
}
|
|
|
|
FPlatformMisc::MemoryBarrier();
|
|
bHasLoadedDDCDirectories = true;
|
|
}
|
|
|
|
return IsInLocalDirectoryUnGuarded(Filename);
|
|
}
|
|
|
|
// once the DDC is initialized, we don't need to lock a critical section anymore
|
|
return IsInLocalDirectoryUnGuarded(Filename);
|
|
}
|
|
|
|
void FNetworkPlatformFile::PerformHeartbeat()
|
|
{
|
|
// send the filename over (cast away const here because we know this << will not modify the string)
|
|
FNetworkFileArchive Payload(NFS_Messages::Heartbeat);
|
|
|
|
|
|
|
|
// send the filename over
|
|
FArrayReader Response;
|
|
{
|
|
FScopeLock ScopeLock(&SynchronizationObject);
|
|
if (!SendPayloadAndReceiveResponse(Payload, Response))
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
// get any files that have been modified on the server -
|
|
TArray<FString> UpdatedFiles;
|
|
Response << UpdatedFiles;
|
|
|
|
// delete any outdated files from the client
|
|
// @todo: This may need a critical section around all calls to LowLevel in the other functions
|
|
// because we don't want to delete files while other threads are using them!
|
|
|
|
TArray<FString> PackageNames;
|
|
for (int32 FileIndex = 0; FileIndex < UpdatedFiles.Num(); FileIndex++)
|
|
{
|
|
// clean up the linkers for this package
|
|
FString LocalFileName = UpdatedFiles[FileIndex];
|
|
ConvertServerFilenameToClientFilename( LocalFileName );
|
|
|
|
UE_LOG(LogNetworkPlatformFile, Log, TEXT("Server updated file '%s', deleting local copy %s"), *UpdatedFiles[FileIndex], *LocalFileName);
|
|
|
|
FString PackageName;
|
|
if (FPackageName::TryConvertFilenameToLongPackageName(LocalFileName, PackageName))
|
|
{
|
|
PackageNames.Add(PackageName);
|
|
}
|
|
else
|
|
{
|
|
UE_LOG(LogNetworkPlatformFile, Log, TEXT("Unable to convert filename to package name %s"), *LocalFileName);
|
|
}
|
|
|
|
OnFileUpdated(LocalFileName);
|
|
}
|
|
|
|
if ( PackageNames.Num() > 0 )
|
|
{
|
|
FCoreUObjectDelegates::NetworkFileRequestPackageReload.ExecuteIfBound(PackageNames);
|
|
}
|
|
}
|
|
|
|
void FNetworkPlatformFile::OnFileUpdated(const FString& LocalFileName)
|
|
{
|
|
if (InnerPlatformFile->FileExists(*LocalFileName) && InnerPlatformFile->DeleteFile(*LocalFileName) == false)
|
|
{
|
|
UE_LOG(LogNetworkPlatformFile, Error, TEXT("Failed to delete %s, someone is probably accessing without FNetworkPlatformFile, or we need better thread protection"), *LocalFileName);
|
|
}
|
|
CachedLocalFiles.Remove(LocalFileName);
|
|
ServerFiles.AddFileOrDirectory(LocalFileName, FDateTime::UtcNow());
|
|
}
|
|
|
|
void FNetworkPlatformFile::ConvertServerFilenameToClientFilename(FString& FilenameToConvert, const FString& InServerEngineDir, const FString& InServerProjectDir)
|
|
{
|
|
if (FilenameToConvert.StartsWith(InServerEngineDir))
|
|
{
|
|
FilenameToConvert = FilenameToConvert.Replace(*InServerEngineDir, *(FPaths::EngineDir()));
|
|
}
|
|
else if (FilenameToConvert.StartsWith(InServerProjectDir))
|
|
{
|
|
FilenameToConvert = FilenameToConvert.Replace(*InServerProjectDir, *(FPaths::ProjectDir()));
|
|
}
|
|
}
|
|
|
|
void FNetworkPlatformFile::Tick()
|
|
{
|
|
// try send a heart beat every 5 seconds as long as we are not async loading
|
|
static double StartTime = FPlatformTime::Seconds();
|
|
|
|
bool bShouldPerformHeartbeat = true;
|
|
if ((FPlatformTime::Seconds() - StartTime) > HeartbeatFrequency && HeartbeatFrequency >= 0 )
|
|
{
|
|
|
|
|
|
if (IsAsyncLoading() && bShouldPerformHeartbeat)
|
|
{
|
|
bShouldPerformHeartbeat = false;
|
|
}
|
|
|
|
{
|
|
FScopeLock S(&SynchronizationObject);
|
|
if (FinishedAsyncNetworkReadUnsolicitedFiles && bShouldPerformHeartbeat)
|
|
{
|
|
if ( FinishedAsyncNetworkReadUnsolicitedFiles->IsReady() )
|
|
{
|
|
delete FinishedAsyncNetworkReadUnsolicitedFiles;
|
|
FinishedAsyncNetworkReadUnsolicitedFiles = nullptr;
|
|
}
|
|
else
|
|
{
|
|
bShouldPerformHeartbeat = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if ( bShouldPerformHeartbeat )
|
|
{
|
|
StartTime = FPlatformTime::Seconds();
|
|
|
|
//DeleteLoaders();
|
|
PerformHeartbeat();
|
|
}
|
|
}
|
|
}
|
|
|
|
bool FNetworkPlatformFile::Exec(class UWorld* InWorld, const TCHAR* Cmd, FOutputDevice& Ar )
|
|
{
|
|
if (FParse::Command(&Cmd, TEXT("networkfile")))
|
|
{
|
|
if ( FParse::Command(&Cmd, TEXT("stats")))
|
|
{
|
|
|
|
Ar.Logf(TEXT("Network platform file %s stats\n"
|
|
"TotalWriteTime \t%fms \n"
|
|
"TotalNetworkSyncTime \t%fms \n"
|
|
"TotalTimeSpentInUnsolicitedPackages \t%fms \n"
|
|
"TotalWaitForAsyncUnsolicitedPackages \t%fms \n"
|
|
"TotalFilesSynced \t%d \n"
|
|
"TotalFilesFoundLocally \t%d\n"
|
|
"TotalUnsolicitedPackages \t%d \n"
|
|
"UnsolicitedPackagesHits \t%d \n"
|
|
"UnsolicitedPackageWaits \t%d \n"),
|
|
GetTypeName(),
|
|
TotalWriteTime,
|
|
TotalNetworkSyncTime,
|
|
TotalTimeSpentInUnsolicitedPackages,
|
|
TotalWaitForAsyncUnsolicitedPackages,
|
|
TotalFilesSynced,
|
|
TotalFilesFoundLocally,
|
|
TotalUnsolicitedPackages,
|
|
UnsolicitedPackagesHits,
|
|
UnsolicitedPackageWaits);
|
|
|
|
// there could be multiple network platform files so let them all report their stats
|
|
return false;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Module for the network file
|
|
*/
|
|
class FNetworkFileModule : public IPlatformFileModule
|
|
{
|
|
public:
|
|
virtual IPlatformFile* GetPlatformFile() override
|
|
{
|
|
static TUniquePtr<IPlatformFile> AutoDestroySingleton = MakeUnique<FNetworkPlatformFile>();
|
|
return AutoDestroySingleton.Get();
|
|
}
|
|
};
|
|
IMPLEMENT_MODULE(FNetworkFileModule, NetworkFile);
|