PackageName.RegisterMountPoint

PackageName.RegisterMountPoint

#Overview

name: PackageName.RegisterMountPoint

This variable is created as a Console Variable (cvar).

It is referenced in 1 C++ source file.

#Summary

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Source/Runtime/CoreUObject/Private/Misc/PackageName.cpp:435

Scope: file

Source code excerpt:

		FConsoleCommandWithArgsDelegate::CreateRaw( this, &FLongPackagePathsSingleton::ExecDumpMountPoints ) )
	, RegisterMountPointCommand(
	TEXT( "PackageName.RegisterMountPoint" ),
	*LOCTEXT("CommandText_RegisterMountPoint", "<RootPath> <ContentPath> // Register a LongPackagePath mount point").ToString(),
		FConsoleCommandWithArgsDelegate::CreateRaw( this, &FLongPackagePathsSingleton::ExecInsertMountPoint ) )
	, UnregisterMountPointCommand(
	TEXT( "PackageName.UnregisterMountPoint" ),
	*LOCTEXT("CommandText_UnregisterMountPoint", "<RootPath> <ContentPath> // Remove a LongPackagePath mount point").ToString(),
		FConsoleCommandWithArgsDelegate::CreateRaw( this, &FLongPackagePathsSingleton::ExecRemoveMountPoint ) )
#endif
	{
		SCOPED_BOOT_TIMING("FPackageName::FLongPackagePathsSingleton");

		ConfigRootPath = TEXT("/Config/");
		EngineRootPath = TEXT("/Engine/");
		GameRootPath   = TEXT("/Game/");
		ScriptRootPath = TEXT("/Script/");
		MemoryRootPath = TEXT("/Memory/");
		TempRootPath   = TEXT("/Temp/");

		VerseSubPath = TEXT("/_Verse/");

		EngineContentPath      = FPaths::EngineContentDir();
		ContentPathShort       = TEXT("../../Content/");
		EngineShadersPath      = FPaths::EngineDir() / TEXT("Shaders/");
		EngineShadersPathShort = TEXT("../../Shaders/");
		GameContentPath        = FPaths::ProjectContentDir();
		GameConfigPath         = FPaths::ProjectConfigDir();
		GameScriptPath         = FPaths::ProjectDir() / TEXT("Script/");
		GameSavedPath          = FPaths::ProjectSavedDir();

		FString RebasedGameDir = FString::Printf(TEXT("../../../%s/"), FApp::GetProjectName());

		GameContentPathRebased = RebasedGameDir / TEXT("Content/");
		GameConfigPathRebased  = RebasedGameDir / TEXT("Config/");
		GameScriptPathRebased  = RebasedGameDir / TEXT("Script/");
		GameSavedPathRebased   = RebasedGameDir / TEXT("Saved/");
		using EMountFlags = FMountPoint::EMountFlags;

		auto LocalInsertMountPoint = [this](const FString& RootPath, const FString& ContentPathRelative, EMountFlags InFlags)
		{
			// Don't call ConstructMountPoint, because that calls FPaths::ConvertRelativePathToFull followed by
			// IFileManager::Get().ConvertToRelativePath, and that combination will convert ../../../Engine/Content
			// into ../../Content, which we don't want here; we want to enter in the full ../../.. path for some entries.
			TStringBuilder<256> AbsolutePathBuilder;
			FPathViews::ToAbsolutePath(ContentPathRelative, AbsolutePathBuilder);
			FMountPoint& MountPoint = *MountPoints.Add_GetRef(MakeUnique<FMountPoint>(
				FString(RootPath), FString(ContentPathRelative), AbsolutePathBuilder.ToString(), 
				InFlags));

			// We are appending to the MountPoint list, and will have only a few duplicates. If any duplicates do occur,
			// keep the MountPoint that was appended earlier as the registered mountpoint.
			FMountPoint*& ExistingRootPath = RootPathTree.FindOrAdd(MountPoint.RootPath);
			if (!ExistingRootPath)
			{
				ExistingRootPath = &MountPoint;
			}
			FMountPoint*& ExistingContentPathRelative = ContentPathTree.FindOrAdd(MountPoint.ContentPathRelative);
			if (!ExistingContentPathRelative)
			{
				ExistingContentPathRelative = &MountPoint;
			}
			FMountPoint*& ExistingContentPathAbsolute = ContentPathTree.FindOrAdd(MountPoint.ContentPathAbsolute);
			if (!ExistingContentPathAbsolute)
			{
				ExistingContentPathAbsolute = &MountPoint;
			}
		};
		
		LocalInsertMountPoint(EngineRootPath, EngineContentPath, EMountFlags::NotReadOnly);
		LocalInsertMountPoint(EngineRootPath, EngineShadersPath, EMountFlags::NotReadOnly | EMountFlags::Alias);
		LocalInsertMountPoint(GameRootPath,   GameContentPath, EMountFlags::NotReadOnly);
		LocalInsertMountPoint(ScriptRootPath, GameScriptPath, EMountFlags::ReadOnly);
		LocalInsertMountPoint(TempRootPath,   GameSavedPath, EMountFlags::ReadOnly);
		LocalInsertMountPoint(ConfigRootPath, GameConfigPath, EMountFlags::ReadOnly);

		// Add other LocalPaths that have different sets of .. but are the same location on disk
		LocalInsertMountPoint(EngineRootPath, EngineShadersPathShort, EMountFlags::NotReadOnly | EMountFlags::Alias);
		if (FPaths::IsSamePath(GameContentPath, ContentPathShort))
		{
			// ../../Content points to the the Engine directory, the same as ../../../Engine/Content
			// But if the /Game is pointing to ../../../Engine/Content as well, then map ../../Content to
			// /Game instead of /Engine
			LocalInsertMountPoint(GameRootPath, ContentPathShort, EMountFlags::NotReadOnly | EMountFlags::Alias);
		}
		else
		{
			LocalInsertMountPoint(EngineRootPath, ContentPathShort, EMountFlags::NotReadOnly | EMountFlags::Alias);
		}
		LocalInsertMountPoint(GameRootPath,   GameContentPathRebased, EMountFlags::NotReadOnly | EMountFlags::Alias);
		LocalInsertMountPoint(ScriptRootPath, GameScriptPathRebased, EMountFlags::ReadOnly | EMountFlags::Alias);
		LocalInsertMountPoint(TempRootPath,   GameSavedPathRebased, EMountFlags::ReadOnly | EMountFlags::Alias);
		LocalInsertMountPoint(ConfigRootPath, GameConfigPathRebased, EMountFlags::ReadOnly | EMountFlags::Alias);
	}

#if !UE_BUILD_SHIPPING
	void ExecDumpMountPoints(const TArray<FString>& Args)
	{
		UE_LOG(LogPackageName, Log, TEXT("Valid mount points:"));

		FReadScopeLock ScopeLock(MountLock);
		for (const TUniquePtr<FMountPoint>& MountPoint : MountPoints)
		{
			UE_LOG(LogPackageName, Log, TEXT("	'%s' -> '%s'"), *MountPoint->RootPath, *MountPoint->ContentPathRelative);
		}