2019-12-26 14:45:42 -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 "Framework/Docking/LayoutService.h"
2021-05-19 12:01:55 -04:00
# include "HAL/FileManager.h"
2021-05-04 09:54:42 -04:00
# include "Misc/App.h"
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 "Misc/ConfigCacheIni.h"
2021-05-04 09:54:42 -04:00
# include "Misc/FileHelper.h"
# include "Dom/JsonObject.h"
# include "Serialization/JsonReader.h"
# include "Serialization/JsonSerializer.h"
2014-03-14 14:13:41 -04:00
2020-09-24 00:43:27 -04:00
DEFINE_LOG_CATEGORY_STATIC ( LogLayoutService , Log , All ) ;
2014-03-14 14:13:41 -04:00
2021-11-18 14:37:34 -05:00
const TCHAR * DefaultEditorLayoutsSectionName = TEXT ( " EditorLayouts " ) ;
2021-11-07 23:43:01 -05:00
static const TCHAR * GetEditorLayoutsSectionName ( )
{
static FString EditorLayoutsSectionName ;
if ( EditorLayoutsSectionName . IsEmpty ( ) )
{
GConfig - > GetString ( TEXT ( " Slate " ) , TEXT ( " EditorLayoutsSectionName " ) , EditorLayoutsSectionName , GEditorIni ) ;
EditorLayoutsSectionName . TrimStartAndEndInline ( ) ;
if ( EditorLayoutsSectionName . IsEmpty ( ) )
{
2021-11-18 14:37:34 -05:00
EditorLayoutsSectionName = DefaultEditorLayoutsSectionName ;
2021-11-07 23:43:01 -05:00
}
}
return * EditorLayoutsSectionName ;
}
2021-11-18 14:37:34 -05:00
static bool GetConfigString ( const TCHAR * Key , FString & Value , const FString & Filename , bool bAllowFallback = true )
{
if ( ! GConfig - > GetString ( GetEditorLayoutsSectionName ( ) , Key , Value , Filename ) )
{
if ( bAllowFallback & & GetEditorLayoutsSectionName ( ) ! = DefaultEditorLayoutsSectionName )
{
return GConfig - > GetString ( DefaultEditorLayoutsSectionName , Key , Value , Filename ) ;
}
return false ;
}
return true ;
}
static bool GetConfigSection ( TArray < FString > & Result , const FString & Filename , bool bAllowFallback = true )
{
if ( ! GConfig - > GetSection ( GetEditorLayoutsSectionName ( ) , Result , Filename ) )
{
if ( bAllowFallback & & GetEditorLayoutsSectionName ( ) ! = DefaultEditorLayoutsSectionName )
{
return GConfig - > GetSection ( DefaultEditorLayoutsSectionName , Result , Filename ) ;
}
return false ;
}
return true ;
}
static FConfigSection * GetConfigSectionPrivate ( const bool Force , const bool Const , const FString & Filename , bool bAllowFallback = true )
{
FConfigSection * FoundSection = GConfig - > GetSectionPrivate ( GetEditorLayoutsSectionName ( ) , /*Force*/ false , /*Const*/ true , Filename ) ;
if ( FoundSection )
{
if ( bAllowFallback & & GetEditorLayoutsSectionName ( ) ! = DefaultEditorLayoutsSectionName )
{
FoundSection = GConfig - > GetSectionPrivate ( DefaultEditorLayoutsSectionName , /*Force*/ false , /*Const*/ true , Filename ) ;
}
}
return FoundSection ;
}
2014-05-15 17:34:02 -04:00
2021-05-19 12:01:55 -04:00
static FString PrepareLayoutStringForIni ( const FString & LayoutString )
{
// Have to store braces as parentheses due to braces causing ini issues
return LayoutString
. Replace ( TEXT ( " { " ) , TEXT ( " ( " ) )
. Replace ( TEXT ( " } " ) , TEXT ( " ) " ) )
. Replace ( TEXT ( " \r " ) , TEXT ( " " ) )
. Replace ( TEXT ( " \n " ) , TEXT ( " " ) )
. Replace ( TEXT ( " \t " ) , TEXT ( " " ) ) ;
}
2021-10-12 21:21:22 -04:00
static FString GetLayoutStringFromIni ( const FString & LayoutString , bool & bOutIsJson )
2021-05-19 12:01:55 -04:00
{
2021-10-12 21:21:22 -04:00
if ( FTextStringHelper : : IsComplexText ( * LayoutString ) )
{
bOutIsJson = false ;
return LayoutString ;
}
2021-05-19 12:01:55 -04:00
// Revert parenthesis to braces, from ini readable to Json readable
2021-10-12 21:21:22 -04:00
bOutIsJson = true ;
2021-05-19 12:01:55 -04:00
return LayoutString
. Replace ( TEXT ( " ( " ) , TEXT ( " { " ) )
. Replace ( TEXT ( " ) " ) , TEXT ( " } " ) )
. Replace ( TEXT ( " \\ " ) LINE_TERMINATOR , LINE_TERMINATOR ) ;
}
2014-05-15 17:34:02 -04:00
2014-03-14 14:13:41 -04:00
const FString & FLayoutSaveRestore : : GetAdditionalLayoutConfigIni ( )
{
static const FString IniSectionAdditionalConfig = TEXT ( " SlateAdditionalLayoutConfig " ) ;
return IniSectionAdditionalConfig ;
}
2021-05-19 12:01:55 -04:00
static TSharedPtr < FJsonObject > ConvertSectionToJson ( const TArray < FString > & SectionStrings )
{
TSharedPtr < FJsonObject > RootObject = MakeShared < FJsonObject > ( ) ;
for ( const FString & SectionPair : SectionStrings )
{
FString Key , Value ;
if ( SectionPair . Split ( TEXT ( " = " ) , & Key , & Value ) )
{
2021-10-12 21:21:22 -04:00
bool bIsJson = true ;
Value = GetLayoutStringFromIni ( Value , bIsJson ) ;
2021-05-19 12:01:55 -04:00
2021-10-12 21:21:22 -04:00
if ( bIsJson )
2021-05-19 12:01:55 -04:00
{
2021-10-12 21:21:22 -04:00
TSharedPtr < FJsonObject > ChildObject = MakeShared < FJsonObject > ( ) ;
TSharedRef < TJsonReader < > > Reader = TJsonReaderFactory < > : : Create ( Value ) ;
if ( FJsonSerializer : : Deserialize ( Reader , ChildObject ) )
{
RootObject - > SetObjectField ( Key , ChildObject ) ;
}
else
{
bIsJson = false ;
}
2021-05-19 12:01:55 -04:00
}
2021-10-12 21:21:22 -04:00
if ( ! bIsJson )
2021-05-19 12:01:55 -04:00
{
RootObject - > SetStringField ( Key , Value ) ;
}
}
}
return RootObject ;
}
static FString GetLayoutJsonFileName ( const FString & InConfigFileName )
2021-05-04 09:54:42 -04:00
{
const FString JsonFileName = FPaths : : GetBaseFilename ( InConfigFileName ) + TEXT ( " .json " ) ;
2021-11-18 14:37:34 -05:00
# ifdef UE_SAVED_DIR_OVERRIDE
const FString UserSettingsPath = FPaths : : Combine ( FPlatformProcess : : UserSettingsDir ( ) , TEXT ( PREPROCESSOR_TO_STRING ( UE_SAVED_DIR_OVERRIDE ) ) , TEXT ( " Editor " ) , JsonFileName ) ;
# else
2021-05-04 09:54:42 -04:00
const FString UserSettingsPath = FPaths : : Combine ( FPlatformProcess : : UserSettingsDir ( ) , FApp : : GetEpicProductIdentifier ( ) , TEXT ( " Editor " ) , JsonFileName ) ;
2021-11-18 14:37:34 -05:00
# endif
2021-05-19 12:01:55 -04:00
return UserSettingsPath ;
}
2021-05-04 09:54:42 -04:00
2021-05-19 12:01:55 -04:00
static TSharedPtr < FJsonObject > LoadJsonFile ( const FString & InFileName )
{
TSharedPtr < FJsonObject > JsonObject ;
2021-05-04 09:54:42 -04:00
2021-05-19 12:01:55 -04:00
FString JsonContents ;
if ( FFileHelper : : LoadFileToString ( JsonContents , * InFileName ) )
2021-05-04 09:54:42 -04:00
{
2021-05-19 12:01:55 -04:00
TSharedRef < TJsonReader < > > Reader = TJsonReaderFactory < > : : Create ( JsonContents ) ;
FJsonSerializer : : Deserialize ( Reader , JsonObject ) ;
2021-05-04 09:54:42 -04:00
}
2021-05-19 12:01:55 -04:00
return JsonObject ;
}
static bool SaveJsonFile ( const FString & InFileName , TSharedPtr < FJsonObject > JsonObject )
{
FString NewJsonContents ;
TSharedRef < TJsonWriter < > > Writer = TJsonWriterFactory < > : : Create ( & NewJsonContents ) ;
if ( FJsonSerializer : : Serialize ( JsonObject . ToSharedRef ( ) , Writer ) )
{
return FFileHelper : : SaveStringToFile ( NewJsonContents , * InFileName ) ;
}
return false ;
}
static void SaveLayoutToJson ( const FString & InConfigFileName , const TSharedRef < FTabManager : : FLayout > & InLayoutToSave )
{
const FString UserSettingsPath = GetLayoutJsonFileName ( InConfigFileName ) ;
TSharedPtr < FJsonObject > AllLayoutsObject = LoadJsonFile ( UserSettingsPath ) ;
2021-05-04 09:54:42 -04:00
if ( ! AllLayoutsObject . IsValid ( ) )
{
// doesn't exist
AllLayoutsObject = MakeShared < FJsonObject > ( ) ;
}
2021-05-19 12:01:55 -04:00
AllLayoutsObject - > SetObjectField ( InLayoutToSave - > GetLayoutName ( ) . ToString ( ) , InLayoutToSave - > ToJson ( ) ) ;
2021-05-04 09:54:42 -04:00
2021-05-19 12:01:55 -04:00
SaveJsonFile ( UserSettingsPath , AllLayoutsObject ) ;
2021-05-04 09:54:42 -04:00
}
static bool LoadLayoutFromJson ( const FString & InConfigFileName , const FString & InLayoutName , TSharedPtr < FTabManager : : FLayout > & OutLayout )
{
2021-11-24 08:00:17 -05:00
const FString LayoutJsonFile = GetLayoutJsonFileName ( InConfigFileName ) ;
2021-05-04 09:54:42 -04:00
2021-11-24 08:00:17 -05:00
TSharedPtr < FJsonObject > JsonObject = LoadJsonFile ( LayoutJsonFile ) ;
2021-05-19 12:01:55 -04:00
if ( ! JsonObject . IsValid ( ) )
2021-05-04 09:54:42 -04:00
{
2021-05-19 12:01:55 -04:00
return false ;
}
2021-05-04 09:54:42 -04:00
2021-05-19 12:01:55 -04:00
const TSharedPtr < FJsonObject > * LayoutJson = nullptr ;
if ( JsonObject - > TryGetObjectField ( InLayoutName , LayoutJson ) )
{
OutLayout = FTabManager : : FLayout : : NewFromJson ( * LayoutJson ) ;
return true ;
2021-05-04 09:54:42 -04:00
}
return false ;
}
2014-03-14 14:13:41 -04:00
2020-09-24 00:43:27 -04:00
void FLayoutSaveRestore : : SaveToConfig ( const FString & InConfigFileName , const TSharedRef < FTabManager : : FLayout > & InLayoutToSave )
2014-03-14 14:13:41 -04:00
{
2020-09-24 00:43:27 -04:00
// Only save to config if it's not the FTabManager::FLayout::NullLayout
if ( InLayoutToSave - > GetLayoutName ( ) ! = FTabManager : : FLayout : : NullLayout - > GetLayoutName ( ) )
{
2021-05-19 12:01:55 -04:00
const FString LayoutAsString = PrepareLayoutStringForIni ( InLayoutToSave - > ToString ( ) ) ;
2021-11-07 23:43:01 -05:00
GConfig - > SetString ( GetEditorLayoutsSectionName ( ) , * InLayoutToSave - > GetLayoutName ( ) . ToString ( ) , * LayoutAsString , InConfigFileName ) ;
2021-05-04 09:54:42 -04:00
SaveLayoutToJson ( InConfigFileName , InLayoutToSave ) ;
2020-09-24 00:43:27 -04:00
}
2014-03-14 14:13:41 -04:00
}
2020-09-24 00:43:27 -04:00
TSharedRef < FTabManager : : FLayout > FLayoutSaveRestore : : LoadFromConfig ( const FString & InConfigFileName , const TSharedRef < FTabManager : : FLayout > & InDefaultLayout ,
const EOutputCanBeNullptr InPrimaryAreaOutputCanBeNullptr )
2014-03-14 14:13:41 -04:00
{
2020-09-24 00:43:27 -04:00
TArray < FString > DummyArray ;
return FLayoutSaveRestore : : LoadFromConfigPrivate ( InConfigFileName , InDefaultLayout , InPrimaryAreaOutputCanBeNullptr , false , DummyArray ) ;
}
TSharedRef < FTabManager : : FLayout > FLayoutSaveRestore : : LoadFromConfig ( const FString & InConfigFileName ,
const TSharedRef < FTabManager : : FLayout > & InDefaultLayout , const EOutputCanBeNullptr InPrimaryAreaOutputCanBeNullptr , TArray < FString > & OutRemovedOlderLayoutVersions )
{
return FLayoutSaveRestore : : LoadFromConfigPrivate ( InConfigFileName , InDefaultLayout , InPrimaryAreaOutputCanBeNullptr , true , OutRemovedOlderLayoutVersions ) ;
}
TSharedRef < FTabManager : : FLayout > FLayoutSaveRestore : : LoadFromConfigPrivate ( const FString & InConfigFileName , const TSharedRef < FTabManager : : FLayout > & InDefaultLayout ,
const EOutputCanBeNullptr InPrimaryAreaOutputCanBeNullptr , const bool bInRemoveOlderLayoutVersions , TArray < FString > & OutRemovedOlderLayoutVersions )
{
const FString LayoutNameString = InDefaultLayout - > GetLayoutName ( ) . ToString ( ) ;
2021-05-04 09:54:42 -04:00
TSharedPtr < FTabManager : : FLayout > UserLayout ;
// First try to load from JSON, then INI if that does not exist
if ( ! LoadLayoutFromJson ( InConfigFileName , LayoutNameString , UserLayout ) )
2014-03-14 14:13:41 -04:00
{
2021-05-04 09:54:42 -04:00
FString IniLayoutString ;
2021-11-07 23:43:01 -05:00
// If the Key (InDefaultLayout->GetLayoutName()) already exists in the section GetEditorLayoutsSectionName() of the file InConfigFileName, try to load the layout from that file
2021-11-18 14:37:34 -05:00
GetConfigString ( * LayoutNameString , IniLayoutString , InConfigFileName ) ;
2021-10-12 21:21:22 -04:00
bool bIsJson = false ;
UserLayout = FTabManager : : FLayout : : NewFromString ( GetLayoutStringFromIni ( IniLayoutString , bIsJson ) ) ;
2021-05-04 09:54:42 -04:00
}
2021-05-04 10:51:19 -04:00
if ( UserLayout . IsValid ( ) )
2021-05-04 09:54:42 -04:00
{
// Return UserLayout in the following 2 cases:
// - By default (PrimaryAreaOutputCanBeNullptr = Never or IfNoTabValid)
// - For the case of PrimaryAreaOutputCanBeNullptr = IfNoOpenTabValid, only if the primary area has at least a valid open tab
2021-05-04 10:51:19 -04:00
TSharedPtr < FTabManager : : FArea > PrimaryArea = UserLayout - > GetPrimaryArea ( ) . Pin ( ) ;
if ( PrimaryArea . IsValid ( ) & & ( InPrimaryAreaOutputCanBeNullptr ! = EOutputCanBeNullptr : : IfNoOpenTabValid | | FGlobalTabmanager : : Get ( ) - > HasValidOpenTabs ( PrimaryArea . ToSharedRef ( ) ) ) )
2014-03-14 14:13:41 -04:00
{
2021-05-04 09:54:42 -04:00
return UserLayout . ToSharedRef ( ) ;
2014-03-14 14:13:41 -04:00
}
}
2020-09-24 00:43:27 -04:00
// If the file layout could not be loaded and the caller wants to remove old fields
else if ( bInRemoveOlderLayoutVersions )
{
// If File and Section exist
2021-11-18 14:37:34 -05:00
if ( FConfigSection * ConfigSection = GetConfigSectionPrivate ( /*Force*/ false , /*Const*/ true , InConfigFileName ) )
2020-09-24 00:43:27 -04:00
{
// If Key does not exist (i.e., Section does but not contain that Key)
if ( ! ConfigSection - > Find ( * LayoutNameString ) )
{
// Create LayoutKeyToRemove
FString LayoutKeyToRemove ;
for ( int32 Index = LayoutNameString . Len ( ) - 1 ; Index > 0 ; - - Index )
{
if ( LayoutNameString [ Index ] ! = TCHAR ( ' . ' ) & & ( LayoutNameString [ Index ] < TCHAR ( ' 0 ' ) | | LayoutNameString [ Index ] > TCHAR ( ' 9 ' ) ) )
{
LayoutKeyToRemove = LayoutNameString . Left ( Index + 1 ) ;
break ;
}
}
// Look for older versions of this Key
OutRemovedOlderLayoutVersions . Empty ( ) ;
for ( const auto & SectionPair : * ConfigSection /*->ArrayOfStructKeys*/ )
{
FString CurrentKey = SectionPair . Key . ToString ( ) ;
if ( CurrentKey . Len ( ) > LayoutKeyToRemove . Len ( ) & & CurrentKey . Left ( LayoutKeyToRemove . Len ( ) ) = = LayoutKeyToRemove )
{
OutRemovedOlderLayoutVersions . Emplace ( std : : move ( CurrentKey ) ) ;
}
}
// Remove older versions of this Key
for ( const FString & KeyToRemove : OutRemovedOlderLayoutVersions )
{
2021-11-18 14:37:34 -05:00
if ( GConfig - > RemoveKey ( GetEditorLayoutsSectionName ( ) , * KeyToRemove , InConfigFileName ) )
{
UE_LOG ( LogLayoutService , Warning , TEXT ( " While key \" %s \" was not found, and older version exists (key \" %s \" ). This means section \" %s \" was "
" created with a previous version of UE and is no longer compatible. The old key has been removed and updated with the new one. " ) ,
* LayoutNameString , * KeyToRemove , GetEditorLayoutsSectionName ( ) ) ;
}
else
{
UE_LOG ( LogLayoutService , Warning , TEXT ( " Could not remove old layout key %s because it exists in the fallback section %s instead of the current section %s " ) ,
* KeyToRemove , DefaultEditorLayoutsSectionName , GetEditorLayoutsSectionName ( ) ) ;
}
2020-09-24 00:43:27 -04:00
}
}
}
}
2014-03-14 14:13:41 -04:00
2020-09-24 00:43:27 -04:00
return InDefaultLayout ;
2014-03-14 14:13:41 -04:00
}
2019-09-10 11:35:20 -04:00
void FLayoutSaveRestore : : SaveSectionToConfig ( const FString & InConfigFileName , const FString & InSectionName , const FText & InSectionValue )
{
2021-05-19 12:01:55 -04:00
FString StrValue ;
FTextStringHelper : : WriteToBuffer ( StrValue , InSectionValue ) ;
2021-11-07 23:43:01 -05:00
GConfig - > SetString ( GetEditorLayoutsSectionName ( ) , * InSectionName , * StrValue , InConfigFileName ) ;
2021-05-19 12:01:55 -04:00
const FString JsonFileName = GetLayoutJsonFileName ( InConfigFileName ) ;
TSharedPtr < FJsonObject > JsonObject = LoadJsonFile ( JsonFileName ) ;
if ( JsonObject . IsValid ( ) )
{
JsonObject - > SetStringField ( InSectionName , * StrValue ) ;
SaveJsonFile ( JsonFileName , JsonObject ) ;
}
2019-09-10 11:35:20 -04:00
}
FText FLayoutSaveRestore : : LoadSectionFromConfig ( const FString & InConfigFileName , const FString & InSectionName )
{
2021-05-19 12:01:55 -04:00
FString ValueString ;
const FString JsonFileName = GetLayoutJsonFileName ( InConfigFileName ) ;
TSharedPtr < FJsonObject > JsonObject = LoadJsonFile ( JsonFileName ) ;
if ( JsonObject . IsValid ( ) )
{
ValueString = JsonObject - > GetStringField ( InSectionName ) ;
}
if ( ValueString . IsEmpty ( ) )
{
2021-11-18 14:37:34 -05:00
GetConfigString ( * InSectionName , ValueString , InConfigFileName ) ;
2021-05-19 12:01:55 -04:00
}
FText ValueText ;
2021-11-07 23:43:01 -05:00
FTextStringHelper : : ReadFromBuffer ( * ValueString , ValueText , GetEditorLayoutsSectionName ( ) ) ;
2021-05-19 12:01:55 -04:00
return ValueText ;
2019-09-10 11:35:20 -04:00
}
2021-05-19 12:01:55 -04:00
bool FLayoutSaveRestore : : DuplicateConfig ( const FString & SourceConfigFileName , const FString & TargetConfigFileName )
{
const bool bShouldReplace = true ;
const bool bCopyEvenIfReadOnly = true ;
const bool bCopyAttributes = false ; // If true, we could copy the read-only flag of DefaultLayout.ini and cause save/load to stop working
if ( IFileManager : : Get ( ) . Copy ( * TargetConfigFileName , * SourceConfigFileName , bShouldReplace , bCopyEvenIfReadOnly , bCopyAttributes ) = = COPY_Fail )
{
return false ;
}
// convert this layout to a JSON file
TArray < FString > SectionPairs ;
2021-11-18 14:37:34 -05:00
GetConfigSection ( SectionPairs , TargetConfigFileName ) ;
2021-05-19 12:01:55 -04:00
TSharedPtr < FJsonObject > RootObject = ConvertSectionToJson ( SectionPairs ) ;
const FString TargetJsonFilename = GetLayoutJsonFileName ( TargetConfigFileName ) ;
SaveJsonFile ( TargetJsonFilename , RootObject ) ;
return true ;
}
2019-09-10 11:35:20 -04:00
2014-05-15 17:34:02 -04:00
void FLayoutSaveRestore : : MigrateConfig ( const FString & OldConfigFileName , const FString & NewConfigFileName )
{
TArray < FString > OldSectionStrings ;
// check whether any layout configuration needs to be migrated
2021-11-18 14:37:34 -05:00
if ( ! GetConfigSection ( OldSectionStrings , OldConfigFileName ) | | ( OldSectionStrings . Num ( ) = = 0 ) )
2014-05-15 17:34:02 -04:00
{
return ;
}
TArray < FString > NewSectionStrings ;
// migrate old configuration if a new layout configuration does not yet exist
2021-11-07 23:43:01 -05:00
if ( ! GConfig - > GetSection ( GetEditorLayoutsSectionName ( ) , NewSectionStrings , NewConfigFileName ) | | ( NewSectionStrings . Num ( ) = = 0 ) )
2014-05-15 17:34:02 -04:00
{
FString Key , Value ;
2021-05-19 12:01:55 -04:00
for ( const FString & SectionString : OldSectionStrings )
2014-05-15 17:34:02 -04:00
{
if ( SectionString . Split ( TEXT ( " = " ) , & Key , & Value ) )
{
2021-11-07 23:43:01 -05:00
GConfig - > SetString ( GetEditorLayoutsSectionName ( ) , * Key , * Value , NewConfigFileName ) ;
2014-05-15 17:34:02 -04:00
}
}
}
// remove old configuration
2021-11-18 14:37:34 -05:00
if ( ! GConfig - > EmptySection ( GetEditorLayoutsSectionName ( ) , OldConfigFileName ) )
{
UE_LOG ( LogLayoutService , Warning , TEXT ( " Could not remove old layout in %s because it is using the fallback section %s instead of the current section %s. New layout file will still be created. " ) ,
* OldConfigFileName , DefaultEditorLayoutsSectionName , GetEditorLayoutsSectionName ( ) ) ;
}
2015-04-20 10:12:55 -04:00
GConfig - > Flush ( false , OldConfigFileName ) ;
GConfig - > Flush ( false , NewConfigFileName ) ;
2021-05-19 12:01:55 -04:00
// migrate layout to JSON as well
const FString NewLayoutJsonFileName = GetLayoutJsonFileName ( NewConfigFileName ) ;
TSharedPtr < FJsonObject > JsonObject = LoadJsonFile ( NewLayoutJsonFileName ) ;
if ( ! JsonObject . IsValid ( ) | | JsonObject - > Values . Num ( ) = = 0 )
{
TSharedPtr < FJsonObject > RootObject = ConvertSectionToJson ( OldSectionStrings ) ;
SaveJsonFile ( NewLayoutJsonFileName , RootObject ) ;
}
2014-05-15 17:34:02 -04:00
}
2021-11-18 14:37:34 -05:00
bool FLayoutSaveRestore : : IsValidConfig ( const FString & InConfigFileName , bool bAllowFallback )
2019-09-10 11:35:20 -04:00
{
2021-11-07 23:43:01 -05:00
if ( GConfig - > DoesSectionExist ( GetEditorLayoutsSectionName ( ) , * InConfigFileName ) )
2021-05-19 12:01:55 -04:00
{
return true ;
}
2021-11-18 14:37:34 -05:00
else if ( bAllowFallback & & GConfig - > DoesSectionExist ( DefaultEditorLayoutsSectionName , * InConfigFileName ) )
{
return true ;
}
2021-05-19 12:01:55 -04:00
const FString JsonFileName = GetLayoutJsonFileName ( InConfigFileName ) ;
return IFileManager : : Get ( ) . FileExists ( * JsonFileName ) ;
2021-12-10 18:31:37 -05:00
}