2019-12-26 15:32:37 -05:00
// Copyright Epic Games, Inc. All Rights Reserved.
2014-03-14 14:13:41 -04:00
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340)
#lockdown Nick.Penwarden
#rb none
==========================
MAJOR FEATURES + CHANGES
==========================
Change 3209340 on 2016/11/23 by Ben.Marsh
Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h.
Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms.
* Every header now includes everything it needs to compile.
* There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first.
* There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h.
* Every .cpp file includes its matching .h file first.
* This helps validate that each header is including everything it needs to compile.
* No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more.
* You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there.
* There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible.
* No engine code explicitly includes a precompiled header any more.
* We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies.
* PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files.
Tool used to generate this transform is at Engine\Source\Programs\IncludeTool.
[CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
# include "Collection.h"
2023-06-05 23:47:24 -04:00
# include "CollectionSettings.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 "HAL/PlatformTime.h"
# include "HAL/FileManager.h"
2023-05-09 15:39:47 -04:00
# include "HAL/IConsoleManager.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/FileHelper.h"
# include "Misc/Paths.h"
# include "Misc/FeedbackContext.h"
# include "Misc/ScopedSlowTask.h"
# include "CollectionManagerLog.h"
# include "ISourceControlOperation.h"
# include "SourceControlOperations.h"
# include "ISourceControlProvider.h"
2014-03-14 14:13:41 -04:00
# include "ISourceControlModule.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/TextFilterExpressionEvaluator.h"
2018-02-22 11:25:06 -05:00
# include "Misc/EngineBuildSettings.h"
2020-04-28 06:20:33 -04:00
# include "Misc/ScopeRWLock.h"
# include "Async/ParallelFor.h"
# include "String/ParseLines.h"
2022-10-13 11:24:42 -04:00
# include "ProfilingDebugging/CpuProfilerTrace.h"
2014-03-14 14:13:41 -04:00
# define LOCTEXT_NAMESPACE "CollectionManager"
2023-05-09 15:39:47 -04:00
static TAutoConsoleVariable < int32 > CVarCollectionsMaxCLDescriptionPathCount (
TEXT ( " Collections.MaxCLDescriptionPathCount " ) ,
1000 ,
TEXT ( " Sets the maximum number of paths reported in a changelist when checking in a collection that adds or removes entries. " ) ,
ECVF_Default ) ;
2015-05-21 07:43:16 -04:00
struct FCollectionUtils
{
2022-09-16 20:57:34 -04:00
static void AppendCollectionToArray ( const TSet < FSoftObjectPath > & InObjectSet , TArray < FSoftObjectPath > & OutObjectArray )
2015-05-21 07:43:16 -04:00
{
2015-06-19 07:33:02 -04:00
OutObjectArray . Reserve ( OutObjectArray . Num ( ) + InObjectSet . Num ( ) ) ;
2022-09-16 20:57:34 -04:00
for ( const FSoftObjectPath & ObjectName : InObjectSet )
2015-05-21 07:43:16 -04:00
{
2015-06-19 07:33:02 -04:00
OutObjectArray . Add ( ObjectName ) ;
2015-05-21 07:43:16 -04:00
}
}
} ;
2015-07-09 09:59:51 -04:00
FCollection : : FCollection ( const FString & InFilename , bool InUseSCC , ECollectionStorageMode : : Type InStorageMode )
2014-03-14 14:13:41 -04:00
{
2015-06-19 07:33:02 -04:00
ensure ( InFilename . Len ( ) > 0 ) ;
2014-03-14 14:13:41 -04:00
bUseSCC = InUseSCC ;
SourceFilename = InFilename ;
CollectionName = FName ( * FPaths : : GetBaseFilename ( InFilename ) ) ;
2015-06-19 07:33:02 -04:00
2015-07-09 09:59:51 -04:00
StorageMode = InStorageMode ;
2015-06-19 07:33:02 -04:00
CollectionGuid = FGuid : : NewGuid ( ) ;
// Initialize the file version to the most recent
FileVersion = ECollectionVersion : : CurrentVersion ;
}
TSharedRef < FCollection > FCollection : : Clone ( const FString & InFilename , bool InUseSCC , ECollectionCloneMode InCloneMode ) const
{
TSharedRef < FCollection > NewCollection = MakeShareable ( new FCollection ( * this ) ) ;
// Set the new collection name and path
NewCollection - > bUseSCC = InUseSCC ;
NewCollection - > SourceFilename = InFilename ;
NewCollection - > CollectionName = FName ( * FPaths : : GetBaseFilename ( InFilename ) ) ;
2015-07-09 09:59:51 -04:00
NewCollection - > StorageMode = StorageMode ;
2015-06-19 07:33:02 -04:00
// Create a new GUID?
if ( InCloneMode = = ECollectionCloneMode : : Unique )
{
NewCollection - > CollectionGuid = FGuid : : NewGuid ( ) ;
}
return NewCollection ;
}
bool FCollection : : Load ( FText & OutError )
{
2020-04-28 06:20:33 -04:00
TRACE_CPUPROFILER_EVENT_SCOPE ( FCollection : : Load )
2015-07-09 14:24:02 -04:00
Empty ( ) ;
2015-06-19 07:33:02 -04:00
FString FullFileContentsString ;
if ( ! FFileHelper : : LoadFileToString ( FullFileContentsString , * SourceFilename ) )
{
OutError = FText : : Format ( LOCTEXT ( " LoadError_FailedToLoadFile " , " Failed to load the collection '{0}' from disk. " ) , FText : : FromString ( SourceFilename ) ) ;
return false ;
}
2020-04-28 06:20:33 -04:00
TArray < FStringView > FileContents ;
UE : : String : : ParseLines ( FullFileContentsString , [ & FileContents ] ( const FStringView & Line ) { FileContents . Add ( Line ) ; } ) ;
2014-03-14 14:13:41 -04:00
2020-04-28 06:20:33 -04:00
if ( FileContents . Num ( ) = = 0 )
2014-03-14 14:13:41 -04:00
{
// Empty file, assume static collection with no items
return true ;
}
// Load the header from the contents array
2020-04-28 06:20:33 -04:00
TMap < FString , FString > HeaderPairs ;
int32 LineIndex = 0 ;
for ( int32 Num = FileContents . Num ( ) ; LineIndex < Num ; + + LineIndex )
2014-03-14 14:13:41 -04:00
{
2020-04-28 06:20:33 -04:00
FStringView Line ( FileContents [ LineIndex ] ) ;
Line . TrimStartAndEndInline ( ) ;
2014-03-14 14:13:41 -04:00
if ( Line . Len ( ) = = 0 )
{
// Empty line. Done reading headers.
2021-01-21 16:22:06 -04:00
+ + LineIndex ;
2014-03-14 14:13:41 -04:00
break ;
}
2021-12-14 14:07:35 -05:00
int32 Offset ;
2020-04-28 06:20:33 -04:00
if ( Line . FindChar ( TEXT ( ' : ' ) , Offset ) )
2014-03-14 14:13:41 -04:00
{
2020-04-28 06:20:33 -04:00
FString Key ( Line . Left ( Offset ) ) ;
FString Value ( Line . Right ( Line . Len ( ) - Offset - 1 ) ) ;
HeaderPairs . Emplace ( MoveTemp ( Key ) , MoveTemp ( Value ) ) ;
2014-03-14 14:13:41 -04:00
}
}
// Now process the header pairs to prepare and validate this collection
if ( ! LoadHeaderPairs ( HeaderPairs ) )
{
// Bad header
2015-06-19 07:33:02 -04:00
OutError = FText : : Format ( LOCTEXT ( " LoadError_BadHeader " , " The collection file '{0}' contains a bad header and could not be loaded. " ) , FText : : FromString ( SourceFilename ) ) ;
2014-03-14 14:13:41 -04:00
return false ;
}
// Now load the content if the header load was successful
2015-07-09 09:59:51 -04:00
if ( StorageMode = = ECollectionStorageMode : : Static )
2014-03-14 14:13:41 -04:00
{
2020-04-28 06:20:33 -04:00
const int32 NamesNum = FileContents . Num ( ) - LineIndex ;
2014-03-14 14:13:41 -04:00
2022-09-16 20:57:34 -04:00
TArray < FSoftObjectPath > Paths ;
Paths . SetNum ( NamesNum ) ;
2020-04-28 06:20:33 -04:00
// Name hashing to register new FName takes time
// Process as much as possible in multiple threads
ParallelFor (
NamesNum ,
2022-09-16 20:57:34 -04:00
[ this , & FileContents , & LineIndex , & Paths ] ( int32 LocalLineIndex )
2014-03-14 14:13:41 -04:00
{
2020-04-28 06:20:33 -04:00
FStringView Line ( FileContents [ LineIndex + LocalLineIndex ] ) ;
2022-09-16 20:57:34 -04:00
Paths [ LocalLineIndex ] = FSoftObjectPath ( Line . TrimStartAndEnd ( ) ) ;
2020-04-28 06:20:33 -04:00
} ,
// Do not pay for scheduling cost if number of items is too low
NamesNum < 1000 ? EParallelForFlags : : ForceSingleThread : EParallelForFlags : : None
) ;
// Static collection, a flat list of asset paths
2022-09-16 20:57:34 -04:00
for ( FSoftObjectPath & Path : Paths )
2020-04-28 06:20:33 -04:00
{
2022-09-16 20:57:34 -04:00
AddObjectToCollection ( Path ) ;
2014-03-14 14:13:41 -04:00
}
}
2015-07-09 09:59:51 -04:00
else
{
// Dynamic collection, a single query line
2020-04-28 06:20:33 -04:00
DynamicQueryText = ( FileContents . Num ( ) > LineIndex ) ? FString ( FileContents [ LineIndex ] . TrimStartAndEnd ( ) ) : FString ( ) ;
2015-07-09 09:59:51 -04:00
}
2014-03-14 14:13:41 -04:00
2015-06-19 07:33:02 -04:00
DiskSnapshot . TakeSnapshot ( * this ) ;
2022-10-13 11:24:42 -04:00
bChangedSinceLastDiskSnapshot = false ;
2015-06-19 07:33:02 -04:00
2014-03-14 14:13:41 -04:00
return true ;
}
2024-02-28 18:50:54 -05:00
bool FCollection : : Save ( const TArray < FText > & AdditionalChangelistText , FText & OutError , bool bForceCommitToRevisionControl )
2014-03-14 14:13:41 -04:00
{
if ( ! ensure ( SourceFilename . Len ( ) ) )
{
OutError = LOCTEXT ( " Error_Internal " , " There was an internal error. " ) ;
return false ;
}
// Store the start time for profiling reasons
double SaveStartTime = FPlatformTime : : Seconds ( ) ;
// Keep track of save progress to update the slow task dialog
const int32 SaveProgressDenominator = 3 ;
int32 SaveProgressNumerator = 0 ;
GWarn - > BeginSlowTask ( FText : : Format ( LOCTEXT ( " SavingCollection " , " Saving Collection {0} " ) , FText : : FromName ( CollectionName ) ) , true ) ;
GWarn - > UpdateProgress ( SaveProgressNumerator + + , SaveProgressDenominator ) ;
if ( bUseSCC )
{
// Checkout the file
if ( ! CheckoutCollection ( OutError ) )
{
UE_LOG ( LogCollectionManager , Error , TEXT ( " Failed to check out a collection file: %s " ) , * CollectionName . ToString ( ) ) ;
GWarn - > EndSlowTask ( ) ;
return false ;
}
}
GWarn - > UpdateProgress ( SaveProgressNumerator + + , SaveProgressDenominator ) ;
// Generate a string with the file contents
FString FileOutput ;
// Start with the header
TMap < FString , FString > HeaderPairs ;
2015-06-19 07:33:02 -04:00
SaveHeaderPairs ( HeaderPairs ) ;
2015-05-21 07:43:16 -04:00
for ( const auto & HeaderPair : HeaderPairs )
2014-03-14 14:13:41 -04:00
{
2015-05-21 07:43:16 -04:00
FileOutput + = HeaderPair . Key + TEXT ( " : " ) + HeaderPair . Value + LINE_TERMINATOR ;
2014-03-14 14:13:41 -04:00
}
FileOutput + = LINE_TERMINATOR ;
// Now for the content
2015-07-09 09:59:51 -04:00
if ( StorageMode = = ECollectionStorageMode : : Static )
2014-03-14 14:13:41 -04:00
{
2015-05-21 07:43:16 -04:00
// Write out the set as a sorted array to keep things in a known order for diffing
2022-09-16 20:57:34 -04:00
TArray < FSoftObjectPath > ObjectList = ObjectSet . Array ( ) ;
ObjectList . Sort ( [ ] ( FSoftObjectPath A , FSoftObjectPath B ) { return A . LexicalLess ( B ) ; } ) ;
2015-05-21 07:43:16 -04:00
2015-06-19 07:33:02 -04:00
// Static collection. Save a flat list of all objects in the collection.
2022-09-16 20:57:34 -04:00
for ( const FSoftObjectPath & ObjectName : ObjectList )
2014-03-14 14:13:41 -04:00
{
2015-06-19 07:33:02 -04:00
FileOutput + = ObjectName . ToString ( ) + LINE_TERMINATOR ;
2014-03-14 14:13:41 -04:00
}
}
2015-07-09 09:59:51 -04:00
else
{
// Dynamic collection, a single query line
FileOutput + = DynamicQueryText + LINE_TERMINATOR ;
}
2014-03-14 14:13:41 -04:00
// Attempt to save the file
bool bSaveSuccessful = false ;
if ( ensure ( FileOutput . Len ( ) ) )
{
// We have some output, write it to file
if ( FFileHelper : : SaveStringToFile ( FileOutput , * SourceFilename ) )
{
bSaveSuccessful = true ;
}
else
{
2015-06-26 13:13:02 -04:00
OutError = FText : : Format ( LOCTEXT ( " Error_WriteFailed " , " Failed to write to collection file: {0} " ) , FText : : FromString ( SourceFilename ) ) ;
UE_LOG ( LogCollectionManager , Error , TEXT ( " %s " ) , * OutError . ToString ( ) ) ;
2014-03-14 14:13:41 -04:00
}
}
else
{
OutError = LOCTEXT ( " Error_Internal " , " There was an internal error. " ) ;
}
GWarn - > UpdateProgress ( SaveProgressNumerator + + , SaveProgressDenominator ) ;
if ( bSaveSuccessful )
{
2024-02-28 18:50:54 -05:00
if ( bUseSCC & & ( bForceCommitToRevisionControl | | GetDefault < UCollectionSettings > ( ) - > bAutoCommitOnSave ) )
2014-03-14 14:13:41 -04:00
{
// Check in the file if the save was successful
if ( bSaveSuccessful )
{
2018-09-26 08:22:54 -04:00
if ( ! CheckinCollection ( AdditionalChangelistText , OutError ) )
2014-03-14 14:13:41 -04:00
{
UE_LOG ( LogCollectionManager , Error , TEXT ( " Failed to check in a collection successfully saving: %s " ) , * CollectionName . ToString ( ) ) ;
bSaveSuccessful = false ;
}
}
// If the save was not successful or the checkin failed, revert
if ( ! bSaveSuccessful )
{
FText Unused ;
if ( ! RevertCollection ( Unused ) )
{
// The revert failed... file will be left on disk as it was saved.
// DiskAssetList will still hold the version of the file when this collection was last loaded or saved successfully so nothing will be out of sync.
// If the user closes the editor before successfully saving, this file may not be exactly what was seen at the time the editor closed.
UE_LOG ( LogCollectionManager , Warning , TEXT ( " Failed to revert a checked out collection after failing to save or checkin: %s " ) , * CollectionName . ToString ( ) ) ;
}
}
}
}
GWarn - > UpdateProgress ( SaveProgressNumerator + + , SaveProgressDenominator ) ;
if ( bSaveSuccessful )
{
2015-06-19 07:33:02 -04:00
// Files are always saved at the latest version as loading should take care of data upgrades
FileVersion = ECollectionVersion : : CurrentVersion ;
DiskSnapshot . TakeSnapshot ( * this ) ;
2022-10-13 11:24:42 -04:00
bChangedSinceLastDiskSnapshot = false ;
2014-03-14 14:13:41 -04:00
}
GWarn - > EndSlowTask ( ) ;
UE_LOG ( LogCollectionManager , Verbose , TEXT ( " Saved collection %s in %0.6f seconds " ) , * CollectionName . ToString ( ) , FPlatformTime : : Seconds ( ) - SaveStartTime ) ;
return bSaveSuccessful ;
}
2015-07-03 13:54:34 -04:00
bool FCollection : : Update ( FText & OutError )
{
if ( ! ensure ( SourceFilename . Len ( ) ) )
{
OutError = LOCTEXT ( " Error_Internal " , " There was an internal error. " ) ;
return false ;
}
if ( ! bUseSCC )
{
// Not under SCC control, so already up-to-date
return true ;
}
FScopedSlowTask SlowTask ( 1.0f , FText : : Format ( LOCTEXT ( " UpdatingCollection " , " Updating Collection {0} " ) , FText : : FromName ( CollectionName ) ) ) ;
ISourceControlProvider & SourceControlProvider = ISourceControlModule : : Get ( ) . GetProvider ( ) ;
if ( ! ISourceControlModule : : Get ( ) . IsEnabled ( ) )
{
2022-11-23 11:57:50 -05:00
OutError = LOCTEXT ( " Error_SCCDisabled " , " Revision control is not enabled. Enable revision control in the preferences menu. " ) ;
2015-07-03 13:54:34 -04:00
return false ;
}
if ( ! SourceControlProvider . IsAvailable ( ) )
{
2022-11-23 11:57:50 -05:00
OutError = LOCTEXT ( " Error_SCCNotAvailable " , " Revision control is currently not available. Check your connection and try again. " ) ;
2015-07-03 13:54:34 -04:00
return false ;
}
const FString AbsoluteFilename = FPaths : : ConvertRelativePathToFull ( SourceFilename ) ;
FSourceControlStatePtr SourceControlState = SourceControlProvider . GetState ( AbsoluteFilename , EStateCacheUsage : : ForceUpdate ) ;
// If not at the head revision, sync up
if ( SourceControlState . IsValid ( ) & & ! SourceControlState - > IsCurrent ( ) )
{
if ( SourceControlProvider . Execute ( ISourceControlOperation : : Create < FSync > ( ) , AbsoluteFilename ) = = ECommandResult : : Failed )
{
// Could not sync up with the head revision
OutError = FText : : Format ( LOCTEXT ( " Error_SCCSync " , " Failed to sync collection '{0}' to the head revision. " ) , FText : : FromName ( CollectionName ) ) ;
return false ;
}
// Check to see if the file exists at the head revision
if ( IFileManager : : Get ( ) . FileExists ( * SourceFilename ) )
{
// File found! Load it and merge with our local changes
FText LoadErrorText ;
2015-07-09 09:59:51 -04:00
FCollection NewCollection ( SourceFilename , false , ECollectionStorageMode : : Static ) ;
2015-07-03 13:54:34 -04:00
if ( ! NewCollection . Load ( LoadErrorText ) )
{
// Failed to load the head revision file so it isn't safe to delete it
OutError = FText : : Format ( LOCTEXT ( " Error_SCCBadHead " , " Failed to load the collection '{0}' at the head revision. {1} " ) , FText : : FromName ( CollectionName ) , LoadErrorText ) ;
return false ;
}
// Loaded the head revision, now merge up so the files are in a consistent state
MergeWithCollection ( NewCollection ) ;
}
// Make sure we get a fresh state from the server
SourceControlState = SourceControlProvider . GetState ( AbsoluteFilename , EStateCacheUsage : : ForceUpdate ) ;
// Got an updated version?
if ( SourceControlState . IsValid ( ) & & ! SourceControlState - > IsCurrent ( ) )
{
OutError = FText : : Format ( LOCTEXT ( " Error_SCCNotCurrent " , " Collection '{0}' is not at head revision after sync. " ) , FText : : FromName ( CollectionName ) ) ;
return false ;
}
}
return true ;
}
2015-07-07 10:31:39 -04:00
bool FCollection : : Merge ( const FCollection & NewCollection )
{
return MergeWithCollection ( NewCollection ) ;
}
2014-03-14 14:13:41 -04:00
bool FCollection : : DeleteSourceFile ( FText & OutError )
{
bool bSuccessfullyDeleted = false ;
if ( SourceFilename . Len ( ) )
{
if ( bUseSCC )
{
bSuccessfullyDeleted = DeleteFromSourceControl ( OutError ) ;
}
else
{
bSuccessfullyDeleted = IFileManager : : Get ( ) . Delete ( * SourceFilename ) ;
if ( ! bSuccessfullyDeleted )
{
2015-06-26 13:13:02 -04:00
OutError = FText : : Format ( LOCTEXT ( " Error_DiskDeleteFailed " , " Failed to delete the collection file: {0} " ) , FText : : FromString ( SourceFilename ) ) ;
2014-03-14 14:13:41 -04:00
}
}
}
else
{
// No source file. Since it doesn't exist we will say it is deleted.
bSuccessfullyDeleted = true ;
}
if ( bSuccessfullyDeleted )
{
2015-06-19 07:33:02 -04:00
DiskSnapshot = FCollectionSnapshot ( ) ;
2022-10-13 11:24:42 -04:00
bChangedSinceLastDiskSnapshot = ( ObjectSet . Num ( ) = = 0 ) ;
2014-03-14 14:13:41 -04:00
}
return bSuccessfullyDeleted ;
}
2015-07-09 14:24:02 -04:00
void FCollection : : Empty ( )
{
ObjectSet . Reset ( ) ;
DynamicQueryText . Reset ( ) ;
DynamicQueryExpressionEvaluatorPtr . Reset ( ) ;
DiskSnapshot . TakeSnapshot ( * this ) ;
2022-10-13 11:24:42 -04:00
bChangedSinceLastDiskSnapshot = false ;
2015-07-09 14:24:02 -04:00
}
2022-09-16 20:57:34 -04:00
bool FCollection : : AddObjectToCollection ( const FSoftObjectPath & ObjectPath )
2014-03-14 14:13:41 -04:00
{
2022-09-16 20:57:34 -04:00
if ( ObjectPath . IsNull ( ) )
2019-10-01 20:41:42 -04:00
{
return false ;
}
2019-04-08 11:29:35 -04:00
if ( StorageMode = = ECollectionStorageMode : : Static )
2014-03-14 14:13:41 -04:00
{
2019-04-08 11:29:35 -04:00
bool bAlreadyInSet = false ;
ObjectSet . Add ( ObjectPath , & bAlreadyInSet ) ;
2022-10-13 11:24:42 -04:00
bChangedSinceLastDiskSnapshot | = ! bAlreadyInSet ;
2019-04-08 11:29:35 -04:00
return ! bAlreadyInSet ;
2014-03-14 14:13:41 -04:00
}
return false ;
}
2022-09-16 20:57:34 -04:00
bool FCollection : : RemoveObjectFromCollection ( const FSoftObjectPath & ObjectPath )
2014-03-14 14:13:41 -04:00
{
2022-09-16 20:57:34 -04:00
if ( ObjectPath . IsNull ( ) )
2019-10-01 20:41:42 -04:00
{
return false ;
}
2022-10-13 11:24:42 -04:00
if ( StorageMode = = ECollectionStorageMode : : Static & & ObjectSet . Remove ( ObjectPath ) > 0 )
2015-07-09 09:59:51 -04:00
{
2022-10-13 11:24:42 -04:00
bChangedSinceLastDiskSnapshot = true ;
return true ;
2015-07-09 09:59:51 -04:00
}
return false ;
2014-03-14 14:13:41 -04:00
}
2022-09-16 20:57:34 -04:00
void FCollection : : GetAssetsInCollection ( TArray < FSoftObjectPath > & Assets ) const
2014-03-14 14:13:41 -04:00
{
2015-07-09 09:59:51 -04:00
if ( StorageMode = = ECollectionStorageMode : : Static )
2014-03-14 14:13:41 -04:00
{
2022-09-16 20:57:34 -04:00
for ( const FSoftObjectPath & ObjectName : ObjectSet )
2014-03-14 14:13:41 -04:00
{
2022-09-16 20:57:34 -04:00
if ( ! ObjectName . GetLongPackageName ( ) . StartsWith ( TEXT ( " /Script/ " ) ) )
2015-07-09 09:59:51 -04:00
{
Assets . Add ( ObjectName ) ;
}
2014-03-14 14:13:41 -04:00
}
}
}
2022-09-16 20:57:34 -04:00
void FCollection : : GetClassesInCollection ( TArray < FTopLevelAssetPath > & Classes ) const
2014-03-14 14:13:41 -04:00
{
2015-07-09 09:59:51 -04:00
if ( StorageMode = = ECollectionStorageMode : : Static )
2014-03-14 14:13:41 -04:00
{
2022-09-16 20:57:34 -04:00
for ( const FSoftObjectPath & ObjectName : ObjectSet )
2014-03-14 14:13:41 -04:00
{
2022-09-16 20:57:34 -04:00
if ( ObjectName . GetLongPackageName ( ) . StartsWith ( TEXT ( " /Script/ " ) ) )
2015-07-09 09:59:51 -04:00
{
2022-09-16 20:57:34 -04:00
Classes . Add ( ObjectName . GetAssetPath ( ) ) ;
2015-07-09 09:59:51 -04:00
}
2014-03-14 14:13:41 -04:00
}
}
}
2022-09-16 20:57:34 -04:00
void FCollection : : GetObjectsInCollection ( TArray < FSoftObjectPath > & Objects ) const
2014-03-14 14:13:41 -04:00
{
2015-07-09 09:59:51 -04:00
if ( StorageMode = = ECollectionStorageMode : : Static )
{
FCollectionUtils : : AppendCollectionToArray ( ObjectSet , Objects ) ;
}
2014-03-14 14:13:41 -04:00
}
2022-09-16 20:57:34 -04:00
bool FCollection : : IsObjectInCollection ( const FSoftObjectPath & ObjectPath ) const
2014-03-14 14:13:41 -04:00
{
2015-07-09 09:59:51 -04:00
if ( StorageMode = = ECollectionStorageMode : : Static )
{
return ObjectSet . Contains ( ObjectPath ) ;
}
return false ;
2014-03-14 14:13:41 -04:00
}
2022-09-16 20:57:34 -04:00
bool FCollection : : IsRedirectorInCollection ( const FSoftObjectPath & ObjectPath ) const
2015-06-26 13:13:02 -04:00
{
2015-07-09 09:59:51 -04:00
if ( StorageMode = = ECollectionStorageMode : : Static )
{
// Redirectors are fixed up in-memory once the asset registry has finished loading,
// so we need to test our on-disk set of objects rather than our in-memory set of objects
return DiskSnapshot . ObjectSet . Contains ( ObjectPath ) ;
}
return false ;
}
bool FCollection : : SetDynamicQueryText ( const FString & InQueryText )
{
if ( StorageMode = = ECollectionStorageMode : : Dynamic )
{
DynamicQueryText = InQueryText ;
return true ;
}
return false ;
}
FString FCollection : : GetDynamicQueryText ( ) const
{
return ( StorageMode = = ECollectionStorageMode : : Dynamic ) ? DynamicQueryText : FString ( ) ;
2015-06-26 13:13:02 -04:00
}
2024-04-19 18:17:59 -04:00
void FCollection : : PrepareDynamicQuery ( )
2015-07-09 14:24:02 -04:00
{
if ( StorageMode = = ECollectionStorageMode : : Dynamic )
{
2024-04-19 18:17:59 -04:00
UE : : TUniqueLock Lock ( * DynamicQueryExpressionEvaluatorLock ) ;
2015-07-09 14:24:02 -04:00
if ( ! DynamicQueryExpressionEvaluatorPtr . IsValid ( ) )
{
DynamicQueryExpressionEvaluatorPtr = MakeShareable ( new FTextFilterExpressionEvaluator ( ETextFilterExpressionEvaluatorMode : : Complex ) ) ;
}
if ( ! DynamicQueryExpressionEvaluatorPtr - > GetFilterText ( ) . ToString ( ) . Equals ( DynamicQueryText , ESearchCase : : CaseSensitive ) )
{
DynamicQueryExpressionEvaluatorPtr - > SetFilterText ( FText : : FromString ( DynamicQueryText ) ) ;
}
2024-04-19 18:17:59 -04:00
}
}
2015-07-09 14:24:02 -04:00
2024-04-19 18:17:59 -04:00
bool FCollection : : TestDynamicQuery ( const ITextFilterExpressionContext & InContext ) const
{
if ( StorageMode = = ECollectionStorageMode : : Dynamic )
{
2015-07-09 14:24:02 -04:00
return DynamicQueryExpressionEvaluatorPtr - > TestTextFilter ( InContext ) ;
}
return false ;
}
2015-07-03 13:54:34 -04:00
FCollectionStatusInfo FCollection : : GetStatusInfo ( ) const
{
2022-10-13 11:24:42 -04:00
TRACE_CPUPROFILER_EVENT_SCOPE ( FCollection : : GetStatusInfo ) ;
2015-07-03 13:54:34 -04:00
FCollectionStatusInfo StatusInfo ;
StatusInfo . bIsDirty = IsDirty ( ) ;
2015-07-09 09:59:51 -04:00
StatusInfo . bIsEmpty = IsEmpty ( ) ;
2015-07-03 13:54:34 -04:00
StatusInfo . bUseSCC = bUseSCC ;
StatusInfo . NumObjects = ObjectSet . Num ( ) ;
if ( bUseSCC & & ISourceControlModule : : Get ( ) . IsEnabled ( ) )
{
ISourceControlProvider & SourceControlProvider = ISourceControlModule : : Get ( ) . GetProvider ( ) ;
if ( SourceControlProvider . IsAvailable ( ) )
{
const FString AbsoluteFilename = FPaths : : ConvertRelativePathToFull ( SourceFilename ) ;
StatusInfo . SCCState = SourceControlProvider . GetState ( AbsoluteFilename , EStateCacheUsage : : Use ) ;
}
}
return StatusInfo ;
}
bool FCollection : : IsDirty ( ) const
{
2022-10-13 11:24:42 -04:00
TRACE_CPUPROFILER_EVENT_SCOPE ( FCollection : : IsDirty ) ;
2015-07-03 13:54:34 -04:00
if ( ParentCollectionGuid ! = DiskSnapshot . ParentCollectionGuid )
{
return true ;
}
2019-10-01 20:41:42 -04:00
if ( CollectionColor ! = DiskSnapshot . CollectionColor )
{
return true ;
}
2015-07-09 09:59:51 -04:00
if ( StorageMode = = ECollectionStorageMode : : Static )
{
2022-10-13 11:24:42 -04:00
return bChangedSinceLastDiskSnapshot ;
2015-07-09 09:59:51 -04:00
}
else
{
2022-10-13 11:24:42 -04:00
return DynamicQueryText ! = DiskSnapshot . DynamicQueryText ;
2015-07-09 09:59:51 -04:00
}
2014-03-14 14:13:41 -04:00
}
2015-06-19 07:33:02 -04:00
2014-03-14 14:13:41 -04:00
bool FCollection : : IsEmpty ( ) const
{
2015-07-09 09:59:51 -04:00
if ( StorageMode = = ECollectionStorageMode : : Static )
{
return ObjectSet . Num ( ) = = 0 ;
}
else
{
return DynamicQueryText . IsEmpty ( ) ;
}
2014-03-14 14:13:41 -04:00
}
void FCollection : : PrintCollection ( ) const
{
2015-07-09 09:59:51 -04:00
if ( StorageMode = = ECollectionStorageMode : : Static )
2014-03-14 14:13:41 -04:00
{
UE_LOG ( LogCollectionManager , Log , TEXT ( " Printing static elements of collection %s " ) , * CollectionName . ToString ( ) ) ;
UE_LOG ( LogCollectionManager , Log , TEXT ( " ============================= " ) ) ;
2015-05-21 07:43:16 -04:00
// Print the set as a sorted array to keep things in a sane order
2022-09-16 20:57:34 -04:00
TArray < FSoftObjectPath > ObjectList = ObjectSet . Array ( ) ;
ObjectList . Sort ( [ ] ( const FSoftObjectPath & A , const FSoftObjectPath & B ) { return A . LexicalLess ( B ) ; } ) ;
2015-05-21 07:43:16 -04:00
2022-09-16 20:57:34 -04:00
for ( const FSoftObjectPath & ObjectName : ObjectList )
2014-03-14 14:13:41 -04:00
{
2015-06-19 07:33:02 -04:00
UE_LOG ( LogCollectionManager , Log , TEXT ( " %s " ) , * ObjectName . ToString ( ) ) ;
2014-03-14 14:13:41 -04:00
}
}
2015-07-09 09:59:51 -04:00
else
{
UE_LOG ( LogCollectionManager , Log , TEXT ( " Printing dynamic query of collection %s " ) , * CollectionName . ToString ( ) ) ;
UE_LOG ( LogCollectionManager , Log , TEXT ( " ============================= " ) ) ;
UE_LOG ( LogCollectionManager , Log , TEXT ( " %s " ) , * DynamicQueryText ) ;
}
2014-03-14 14:13:41 -04:00
}
2015-06-19 07:33:02 -04:00
void FCollection : : SaveHeaderPairs ( TMap < FString , FString > & OutHeaderPairs ) const
2014-03-14 14:13:41 -04:00
{
// These pairs will appear at the top of the file followed by a newline
2015-06-19 07:33:02 -04:00
OutHeaderPairs . Add ( TEXT ( " FileVersion " ) , FString : : FromInt ( ECollectionVersion : : CurrentVersion ) ) ; // Files are always saved at the latest version as loading should take care of data upgrades
2015-07-09 09:59:51 -04:00
OutHeaderPairs . Add ( TEXT ( " Type " ) , ECollectionStorageMode : : ToString ( StorageMode ) ) ;
2015-06-19 07:33:02 -04:00
OutHeaderPairs . Add ( TEXT ( " Guid " ) , CollectionGuid . ToString ( EGuidFormats : : DigitsWithHyphens ) ) ;
OutHeaderPairs . Add ( TEXT ( " ParentGuid " ) , ParentCollectionGuid . ToString ( EGuidFormats : : DigitsWithHyphens ) ) ;
2019-10-01 20:41:42 -04:00
if ( CollectionColor )
{
OutHeaderPairs . Add ( TEXT ( " Color " ) , CollectionColor - > ToString ( ) ) ;
}
2014-03-14 14:13:41 -04:00
}
bool FCollection : : LoadHeaderPairs ( const TMap < FString , FString > & InHeaderPairs )
{
// These pairs will appeared at the top of the file being loaded
// First find all the known pairs
const FString * Version = InHeaderPairs . Find ( TEXT ( " FileVersion " ) ) ;
if ( ! Version )
{
// FileVersion is required
return false ;
}
const FString * Type = InHeaderPairs . Find ( TEXT ( " Type " ) ) ;
if ( ! Type )
{
// Type is required
return false ;
}
2015-07-09 09:59:51 -04:00
StorageMode = ECollectionStorageMode : : FromString ( * * Type ) ;
2015-06-19 07:33:02 -04:00
FileVersion = ( ECollectionVersion : : Type ) FCString : : Atoi ( * * Version ) ;
if ( FileVersion > = ECollectionVersion : : AddedCollectionGuid )
{
const FString * GuidStr = InHeaderPairs . Find ( TEXT ( " Guid " ) ) ;
if ( ! GuidStr | | ! FGuid : : Parse ( * GuidStr , CollectionGuid ) )
{
// Guid is required
return false ;
}
const FString * ParentGuidStr = InHeaderPairs . Find ( TEXT ( " ParentGuid " ) ) ;
if ( ! ParentGuidStr | | ! FGuid : : Parse ( * ParentGuidStr , ParentCollectionGuid ) )
{
ParentCollectionGuid = FGuid ( ) ;
}
}
2014-03-14 14:13:41 -04:00
2019-10-01 20:41:42 -04:00
// Load the optional color
CollectionColor . Reset ( ) ;
if ( const FString * ColorStr = InHeaderPairs . Find ( TEXT ( " Color " ) ) )
{
FLinearColor NewColor ;
if ( NewColor . InitFromString ( * ColorStr ) )
{
CollectionColor = MoveTemp ( NewColor ) ;
}
}
2015-06-19 07:33:02 -04:00
return FileVersion > 0 & & FileVersion < = ECollectionVersion : : CurrentVersion ;
2014-03-14 14:13:41 -04:00
}
2015-07-07 10:31:39 -04:00
bool FCollection : : MergeWithCollection ( const FCollection & Other )
2014-03-14 14:13:41 -04:00
{
2015-07-09 09:59:51 -04:00
bool bHasChanges = ParentCollectionGuid ! = Other . ParentCollectionGuid ;
2015-07-07 10:31:39 -04:00
2015-07-09 09:59:51 -04:00
ParentCollectionGuid = Other . ParentCollectionGuid ;
if ( StorageMode ! = Other . StorageMode )
2014-03-14 14:13:41 -04:00
{
2015-07-09 09:59:51 -04:00
bHasChanges = true ;
StorageMode = Other . StorageMode ;
2015-07-09 14:24:02 -04:00
// Storage mode has changed! Empty the collection so we just copy over the new data verbatim
Empty ( ) ;
2014-03-14 14:13:41 -04:00
}
2015-07-09 09:59:51 -04:00
if ( StorageMode = = ECollectionStorageMode : : Static )
2014-03-14 14:13:41 -04:00
{
2015-07-07 10:31:39 -04:00
// Work out whether we have any changes compared to the other collection
2022-09-16 20:57:34 -04:00
TArray < FSoftObjectPath > ObjectsAdded ;
TArray < FSoftObjectPath > ObjectsRemoved ;
2015-07-07 10:31:39 -04:00
GetObjectDifferences ( ObjectSet , Other . ObjectSet , ObjectsAdded , ObjectsRemoved ) ;
2014-03-14 14:13:41 -04:00
2015-07-09 09:59:51 -04:00
bHasChanges = bHasChanges | | ObjectsAdded . Num ( ) > 0 | | ObjectsRemoved . Num ( ) > 0 ;
2014-03-14 14:13:41 -04:00
2015-07-07 10:31:39 -04:00
if ( bHasChanges )
2014-03-14 14:13:41 -04:00
{
2015-07-07 10:31:39 -04:00
// Gather the differences from the file on disk
ObjectsAdded . Reset ( ) ;
ObjectsRemoved . Reset ( ) ;
GetObjectDifferencesFromDisk ( ObjectsAdded , ObjectsRemoved ) ;
// Copy asset list from other collection
2015-07-09 09:59:51 -04:00
ObjectSet = Other . ObjectSet ;
2015-07-07 10:31:39 -04:00
// Add the objects that were added before the merge
2022-09-16 20:57:34 -04:00
for ( const FSoftObjectPath & AddedObjectName : ObjectsAdded )
2015-07-07 10:31:39 -04:00
{
ObjectSet . Add ( AddedObjectName ) ;
}
// Remove the objects that were removed before the merge
2022-09-16 20:57:34 -04:00
for ( const FSoftObjectPath & RemovedObjectName : ObjectsRemoved )
2015-07-07 10:31:39 -04:00
{
ObjectSet . Remove ( RemovedObjectName ) ;
}
2022-10-13 11:24:42 -04:00
bChangedSinceLastDiskSnapshot = true ;
2014-03-14 14:13:41 -04:00
}
2015-07-07 10:31:39 -04:00
}
2015-07-09 09:59:51 -04:00
else
{
bHasChanges = bHasChanges | | DynamicQueryText ! = Other . DynamicQueryText ;
DynamicQueryText = Other . DynamicQueryText ;
}
DiskSnapshot = Other . DiskSnapshot ;
2015-07-07 10:31:39 -04:00
return bHasChanges ;
}
2022-09-16 20:57:34 -04:00
void FCollection : : GetObjectDifferences ( const TSet < FSoftObjectPath > & BaseSet , const TSet < FSoftObjectPath > & NewSet , TArray < FSoftObjectPath > & ObjectsAdded , TArray < FSoftObjectPath > & ObjectsRemoved )
2015-07-07 10:31:39 -04:00
{
// Find the objects that were removed compared to the base set
2022-09-16 20:57:34 -04:00
for ( const FSoftObjectPath & BaseObjectName : BaseSet )
2015-07-07 10:31:39 -04:00
{
if ( ! NewSet . Contains ( BaseObjectName ) )
{
ObjectsRemoved . Add ( BaseObjectName ) ;
}
}
2020-04-28 06:20:33 -04:00
// If both sets have the same number of items and nothing has been removed
// we can safely infer that both collections are equals without going
// over them a second time.
if ( ObjectsRemoved . Num ( ) = = 0 & & BaseSet . Num ( ) = = NewSet . Num ( ) )
{
return ;
}
2015-07-07 10:31:39 -04:00
// Find the objects that were added compare to the base set
2022-09-16 20:57:34 -04:00
for ( const FSoftObjectPath & NewObjectName : NewSet )
2015-07-07 10:31:39 -04:00
{
if ( ! BaseSet . Contains ( NewObjectName ) )
{
ObjectsAdded . Add ( NewObjectName ) ;
2014-03-14 14:13:41 -04:00
}
}
}
2022-09-16 20:57:34 -04:00
void FCollection : : GetObjectDifferencesFromDisk ( TArray < FSoftObjectPath > & ObjectsAdded , TArray < FSoftObjectPath > & ObjectsRemoved ) const
2014-03-14 14:13:41 -04:00
{
2015-07-09 09:59:51 -04:00
if ( StorageMode = = ECollectionStorageMode : : Static )
{
GetObjectDifferences ( DiskSnapshot . ObjectSet , ObjectSet , ObjectsAdded , ObjectsRemoved ) ;
}
2014-03-14 14:13:41 -04:00
}
bool FCollection : : CheckoutCollection ( FText & OutError )
{
if ( ! ensure ( SourceFilename . Len ( ) ) )
{
OutError = LOCTEXT ( " Error_Internal " , " There was an internal error. " ) ;
return false ;
}
ISourceControlProvider & SourceControlProvider = ISourceControlModule : : Get ( ) . GetProvider ( ) ;
if ( ! ISourceControlModule : : Get ( ) . IsEnabled ( ) )
{
2022-11-23 11:57:50 -05:00
OutError = LOCTEXT ( " Error_SCCDisabled " , " Revision control is not enabled. Enable revision control in the preferences menu. " ) ;
2014-03-14 14:13:41 -04:00
return false ;
}
if ( ! SourceControlProvider . IsAvailable ( ) )
{
2022-11-23 11:57:50 -05:00
OutError = LOCTEXT ( " Error_SCCNotAvailable " , " Revision control is currently not available. Check your connection and try again. " ) ;
2014-03-14 14:13:41 -04:00
return false ;
}
2015-06-16 09:25:36 -04:00
const FString AbsoluteFilename = FPaths : : ConvertRelativePathToFull ( SourceFilename ) ;
2014-03-14 14:13:41 -04:00
FSourceControlStatePtr SourceControlState = SourceControlProvider . GetState ( AbsoluteFilename , EStateCacheUsage : : ForceUpdate ) ;
bool bSuccessfullyCheckedOut = false ;
if ( SourceControlState . IsValid ( ) & & SourceControlState - > IsDeleted ( ) )
{
// Revert our delete
if ( ! RevertCollection ( OutError ) )
{
return false ;
}
// Make sure we get a fresh state from the server
SourceControlState = SourceControlProvider . GetState ( AbsoluteFilename , EStateCacheUsage : : ForceUpdate ) ;
}
// If not at the head revision, sync up
if ( SourceControlState . IsValid ( ) & & ! SourceControlState - > IsCurrent ( ) )
{
2015-06-16 09:25:36 -04:00
if ( SourceControlProvider . Execute ( ISourceControlOperation : : Create < FSync > ( ) , AbsoluteFilename ) = = ECommandResult : : Failed )
2014-03-14 14:13:41 -04:00
{
// Could not sync up with the head revision
2015-06-26 13:13:02 -04:00
OutError = FText : : Format ( LOCTEXT ( " Error_SCCSync " , " Failed to sync collection '{0}' to the head revision. " ) , FText : : FromName ( CollectionName ) ) ;
2014-03-14 14:13:41 -04:00
return false ;
}
// Check to see if the file exists at the head revision
2015-06-19 07:33:02 -04:00
if ( IFileManager : : Get ( ) . FileExists ( * SourceFilename ) )
2014-03-14 14:13:41 -04:00
{
// File found! Load it and merge with our local changes
2015-06-19 07:33:02 -04:00
FText LoadErrorText ;
2015-07-09 09:59:51 -04:00
FCollection NewCollection ( SourceFilename , false , ECollectionStorageMode : : Static ) ;
2015-06-19 07:33:02 -04:00
if ( ! NewCollection . Load ( LoadErrorText ) )
2014-03-14 14:13:41 -04:00
{
// Failed to load the head revision file so it isn't safe to delete it
2015-06-26 13:13:02 -04:00
OutError = FText : : Format ( LOCTEXT ( " Error_SCCBadHead " , " Failed to load the collection '{0}' at the head revision. {1} " ) , FText : : FromName ( CollectionName ) , LoadErrorText ) ;
2014-03-14 14:13:41 -04:00
return false ;
}
// Loaded the head revision, now merge up so the files are in a consistent state
MergeWithCollection ( NewCollection ) ;
}
// Make sure we get a fresh state from the server
SourceControlState = SourceControlProvider . GetState ( AbsoluteFilename , EStateCacheUsage : : ForceUpdate ) ;
}
if ( SourceControlState . IsValid ( ) )
{
2015-06-16 09:25:36 -04:00
if ( ! SourceControlState - > IsSourceControlled ( ) )
{
// Not yet in the depot. We'll add it when we call CheckinCollection
bSuccessfullyCheckedOut = true ;
}
else if ( SourceControlState - > IsAdded ( ) | | SourceControlState - > IsCheckedOut ( ) )
2014-03-14 14:13:41 -04:00
{
// Already checked out or opened for add
bSuccessfullyCheckedOut = true ;
}
else if ( SourceControlState - > CanCheckout ( ) )
{
// In depot and needs to be checked out
2015-06-16 09:25:36 -04:00
bSuccessfullyCheckedOut = ( SourceControlProvider . Execute ( ISourceControlOperation : : Create < FCheckOut > ( ) , AbsoluteFilename ) = = ECommandResult : : Succeeded ) ;
2014-03-14 14:13:41 -04:00
if ( ! bSuccessfullyCheckedOut )
{
2015-06-26 13:13:02 -04:00
OutError = FText : : Format ( LOCTEXT ( " Error_SCCCheckout " , " Failed to check out collection '{0}' " ) , FText : : FromName ( CollectionName ) ) ;
2014-03-14 14:13:41 -04:00
}
}
else if ( ! SourceControlState - > IsCurrent ( ) )
{
2015-06-26 13:13:02 -04:00
OutError = FText : : Format ( LOCTEXT ( " Error_SCCNotCurrent " , " Collection '{0}' is not at head revision after sync. " ) , FText : : FromName ( CollectionName ) ) ;
2014-03-14 14:13:41 -04:00
}
else if ( SourceControlState - > IsCheckedOutOther ( ) )
{
2015-06-26 13:13:02 -04:00
OutError = FText : : Format ( LOCTEXT ( " Error_SCCCheckedOutOther " , " Collection '{0}' is checked out by another user. " ) , FText : : FromName ( CollectionName ) ) ;
2014-03-14 14:13:41 -04:00
}
else
{
2022-11-23 11:57:50 -05:00
OutError = FText : : Format ( LOCTEXT ( " Error_SCCUnknown " , " Could not determine revision control state for collection '{0}' " ) , FText : : FromName ( CollectionName ) ) ;
2014-03-14 14:13:41 -04:00
}
}
else
{
2022-11-23 11:57:50 -05:00
OutError = LOCTEXT ( " Error_SCCInvalid " , " Revision control state is invalid. " ) ;
2014-03-14 14:13:41 -04:00
}
return bSuccessfullyCheckedOut ;
}
2018-09-26 08:22:54 -04:00
bool FCollection : : CheckinCollection ( const TArray < FText > & AdditionalChangelistText , FText & OutError )
2014-03-14 14:13:41 -04:00
{
if ( ! ensure ( SourceFilename . Len ( ) ) )
{
OutError = LOCTEXT ( " Error_Internal " , " There was an internal error. " ) ;
return false ;
}
ISourceControlProvider & SourceControlProvider = ISourceControlModule : : Get ( ) . GetProvider ( ) ;
if ( ! ISourceControlModule : : Get ( ) . IsEnabled ( ) )
{
2022-11-23 11:57:50 -05:00
OutError = LOCTEXT ( " Error_SCCDisabled " , " Revision control is not enabled. Enable revision control in the preferences menu. " ) ;
2014-03-14 14:13:41 -04:00
return false ;
}
if ( ! SourceControlProvider . IsAvailable ( ) )
{
2022-11-23 11:57:50 -05:00
OutError = LOCTEXT ( " Error_SCCNotAvailable " , " Revision control is currently not available. Check your connection and try again. " ) ;
2014-03-14 14:13:41 -04:00
return false ;
}
2015-06-16 09:25:36 -04:00
const FString AbsoluteFilename = FPaths : : ConvertRelativePathToFull ( SourceFilename ) ;
2014-03-14 14:13:41 -04:00
FSourceControlStatePtr SourceControlState = SourceControlProvider . GetState ( AbsoluteFilename , EStateCacheUsage : : ForceUpdate ) ;
2015-06-16 09:25:36 -04:00
if ( SourceControlState . IsValid ( ) & & ! SourceControlState - > IsSourceControlled ( ) )
{
// Not yet in the depot. Add it.
const bool bWasAdded = ( SourceControlProvider . Execute ( ISourceControlOperation : : Create < FMarkForAdd > ( ) , AbsoluteFilename ) = = ECommandResult : : Succeeded ) ;
if ( ! bWasAdded )
{
2022-11-23 11:57:50 -05:00
OutError = FText : : Format ( LOCTEXT ( " Error_SCCAdd " , " Failed to add collection '{0}' to revision control. " ) , FText : : FromName ( CollectionName ) ) ;
2015-06-16 09:25:36 -04:00
return false ;
}
SourceControlState = SourceControlProvider . GetState ( AbsoluteFilename , EStateCacheUsage : : ForceUpdate ) ;
}
2014-03-14 14:13:41 -04:00
if ( SourceControlState . IsValid ( ) & & ! ( SourceControlState - > IsCheckedOut ( ) | | SourceControlState - > IsAdded ( ) ) )
{
2015-06-26 13:13:02 -04:00
OutError = FText : : Format ( LOCTEXT ( " Error_SCCNotCheckedOut " , " Collection '{0}' not checked out or open for add. " ) , FText : : FromName ( CollectionName ) ) ;
2014-03-14 14:13:41 -04:00
return false ;
}
// Form an appropriate summary for the changelist
const FText CollectionNameText = FText : : FromName ( CollectionName ) ;
2015-06-19 07:33:02 -04:00
FTextBuilder ChangelistDescBuilder ;
if ( SourceControlState . IsValid ( ) & & SourceControlState - > IsAdded ( ) )
2014-03-14 14:13:41 -04:00
{
2015-06-19 07:33:02 -04:00
ChangelistDescBuilder . AppendLineFormat ( LOCTEXT ( " CollectionAddedNewDesc " , " Added collection '{0}' " ) , CollectionNameText ) ;
2014-03-14 14:13:41 -04:00
}
else
{
2015-07-09 09:59:51 -04:00
if ( StorageMode = = ECollectionStorageMode : : Static )
2014-03-14 14:13:41 -04:00
{
2023-05-09 15:39:47 -04:00
auto AddFileListToDescription = [ & ChangelistDescBuilder ] ( const TArray < FSoftObjectPath > & Paths )
{
const int32 MaxPaths = CVarCollectionsMaxCLDescriptionPathCount . GetValueOnAnyThread ( ) ;
const int32 ReportedPaths = FMath : : Min ( Paths . Num ( ) , MaxPaths ) ;
const int32 UnreportedPaths = FMath : : Max ( 0 , Paths . Num ( ) - MaxPaths ) ;
for ( int32 PathIdx = 0 ; PathIdx < ReportedPaths ; + + PathIdx )
{
const FSoftObjectPath & AddedObjectName = Paths [ PathIdx ] ;
ChangelistDescBuilder . AppendLine ( FText : : FromString ( AddedObjectName . ToString ( ) ) ) ;
}
if ( UnreportedPaths > 0 )
{
ChangelistDescBuilder . AppendLineFormat ( LOCTEXT ( " CollectionUnreportedPathsDesc " , " ... {0} more path(s) " ) , UnreportedPaths ) ;
}
} ;
2015-06-19 07:33:02 -04:00
// Gather differences from disk
2022-09-16 20:57:34 -04:00
TArray < FSoftObjectPath > ObjectsAdded ;
TArray < FSoftObjectPath > ObjectsRemoved ;
2015-06-19 07:33:02 -04:00
GetObjectDifferencesFromDisk ( ObjectsAdded , ObjectsRemoved ) ;
2014-03-14 14:13:41 -04:00
2022-09-16 20:57:34 -04:00
ObjectsAdded . Sort ( [ ] ( FSoftObjectPath A , FSoftObjectPath B ) { return A . LexicalLess ( B ) ; } ) ;
ObjectsRemoved . Sort ( [ ] ( FSoftObjectPath A , FSoftObjectPath B ) { return A . LexicalLess ( B ) ; } ) ;
2015-06-19 07:33:02 -04:00
// Report added files
FFormatNamedArguments Args ;
2022-09-16 20:57:34 -04:00
Args . Add ( TEXT ( " FirstObjectAdded " ) , ObjectsAdded . Num ( ) > 0 ? FText : : FromString ( ObjectsAdded [ 0 ] . ToString ( ) ) : NSLOCTEXT ( " Core " , " None " , " None " ) ) ;
2015-06-19 07:33:02 -04:00
Args . Add ( TEXT ( " NumberAdded " ) , FText : : AsNumber ( ObjectsAdded . Num ( ) ) ) ;
2022-09-16 20:57:34 -04:00
Args . Add ( TEXT ( " FirstObjectRemoved " ) , ObjectsRemoved . Num ( ) > 0 ? FText : : FromString ( ObjectsRemoved [ 0 ] . ToString ( ) ) : NSLOCTEXT ( " Core " , " None " , " None " ) ) ;
2015-06-19 07:33:02 -04:00
Args . Add ( TEXT ( " NumberRemoved " ) , FText : : AsNumber ( ObjectsRemoved . Num ( ) ) ) ;
Args . Add ( TEXT ( " CollectionName " ) , CollectionNameText ) ;
if ( ObjectsAdded . Num ( ) = = 1 )
2014-03-14 14:13:41 -04:00
{
2015-06-19 07:33:02 -04:00
ChangelistDescBuilder . AppendLineFormat ( LOCTEXT ( " CollectionAddedSingleDesc " , " Added '{FirstObjectAdded}' to collection '{CollectionName}' " ) , Args ) ;
2014-03-14 14:13:41 -04:00
}
2015-06-19 07:33:02 -04:00
else if ( ObjectsAdded . Num ( ) > 1 )
2014-03-14 14:13:41 -04:00
{
2015-06-19 07:33:02 -04:00
ChangelistDescBuilder . AppendLineFormat ( LOCTEXT ( " CollectionAddedMultipleDesc " , " Added {NumberAdded} objects to collection '{CollectionName}': " ) , Args ) ;
ChangelistDescBuilder . Indent ( ) ;
2023-05-09 15:39:47 -04:00
AddFileListToDescription ( ObjectsAdded ) ;
2015-06-19 07:33:02 -04:00
ChangelistDescBuilder . Unindent ( ) ;
2014-03-14 14:13:41 -04:00
}
2015-06-19 07:33:02 -04:00
if ( ObjectsRemoved . Num ( ) = = 1 )
2014-03-14 14:13:41 -04:00
{
2015-06-19 07:33:02 -04:00
ChangelistDescBuilder . AppendLineFormat ( LOCTEXT ( " CollectionRemovedSingleDesc " , " Removed '{FirstObjectRemoved}' from collection '{CollectionName}' " ) , Args ) ;
2014-03-14 14:13:41 -04:00
}
2015-06-19 07:33:02 -04:00
else if ( ObjectsRemoved . Num ( ) > 1 )
{
ChangelistDescBuilder . AppendLineFormat ( LOCTEXT ( " CollectionRemovedMultipleDesc " , " Removed {NumberRemoved} objects from collection '{CollectionName}' " ) , Args ) ;
ChangelistDescBuilder . Indent ( ) ;
2023-05-09 15:39:47 -04:00
AddFileListToDescription ( ObjectsRemoved ) ;
2015-06-19 07:33:02 -04:00
ChangelistDescBuilder . Unindent ( ) ;
}
}
2015-07-09 09:59:51 -04:00
else
{
if ( DiskSnapshot . DynamicQueryText ! = DynamicQueryText )
{
2015-12-10 16:56:55 -05:00
ChangelistDescBuilder . AppendLineFormat ( LOCTEXT ( " CollectionChangedDynamicQueryDesc " , " Changed the dynamic query of collection '{0}' to '{1}' " ) , CollectionNameText , FText : : FromString ( DynamicQueryText ) ) ;
2015-07-09 09:59:51 -04:00
}
}
2015-06-19 07:33:02 -04:00
// Parent change?
if ( DiskSnapshot . ParentCollectionGuid ! = ParentCollectionGuid )
{
ChangelistDescBuilder . AppendLineFormat ( LOCTEXT ( " CollectionChangedParentDesc " , " Changed the parent of collection '{0}' " ) , CollectionNameText ) ;
}
2019-10-01 20:41:42 -04:00
// Color change?
if ( DiskSnapshot . CollectionColor ! = CollectionColor )
{
ChangelistDescBuilder . AppendLineFormat ( LOCTEXT ( " CollectionChangedColorDesc " , " Changed the color of collection '{0}' " ) , CollectionNameText ) ;
}
2015-06-19 07:33:02 -04:00
// Version bump?
if ( FileVersion < ECollectionVersion : : CurrentVersion )
{
ChangelistDescBuilder . AppendLineFormat ( LOCTEXT ( " CollectionUpgradedDesc " , " Upgraded collection '{0}' (was version {1}, now version {2}) " ) , CollectionNameText , FText : : AsNumber ( FileVersion ) , FText : : AsNumber ( ECollectionVersion : : CurrentVersion ) ) ;
2014-03-14 14:13:41 -04:00
}
}
2018-05-23 21:04:31 -04:00
if ( ChangelistDescBuilder . IsEmpty ( ) )
{
// No changes could be detected
ChangelistDescBuilder . AppendLineFormat ( LOCTEXT ( " CollectionNotModifiedDesc " , " Collection '{0}' not modified " ) , CollectionNameText ) ;
}
2018-09-26 08:22:54 -04:00
for ( const FText & AdditionalText : AdditionalChangelistText )
2018-02-22 11:25:06 -05:00
{
2018-09-26 08:22:54 -04:00
ChangelistDescBuilder . AppendLine ( AdditionalText ) ;
2018-02-22 11:25:06 -05:00
}
2015-06-19 07:33:02 -04:00
FText ChangelistDesc = ChangelistDescBuilder . ToText ( ) ;
2014-03-14 14:13:41 -04:00
// Finally check in the file
TSharedRef < FCheckIn , ESPMode : : ThreadSafe > CheckInOperation = ISourceControlOperation : : Create < FCheckIn > ( ) ;
CheckInOperation - > SetDescription ( ChangelistDesc ) ;
if ( SourceControlProvider . Execute ( CheckInOperation , AbsoluteFilename ) )
{
return true ;
}
else
{
2015-06-26 13:13:02 -04:00
OutError = FText : : Format ( LOCTEXT ( " Error_SCCCheckIn " , " Failed to check in collection '{0}'. " ) , FText : : FromName ( CollectionName ) ) ;
2014-03-14 14:13:41 -04:00
return false ;
}
}
bool FCollection : : RevertCollection ( FText & OutError )
{
if ( ! ensure ( SourceFilename . Len ( ) ) )
{
OutError = LOCTEXT ( " Error_Internal " , " There was an internal error. " ) ;
return false ;
}
ISourceControlProvider & SourceControlProvider = ISourceControlModule : : Get ( ) . GetProvider ( ) ;
if ( ! ISourceControlModule : : Get ( ) . IsEnabled ( ) )
{
2022-11-23 11:57:50 -05:00
OutError = LOCTEXT ( " Error_SCCDisabled " , " Revision control is not enabled. Enable revision control in the preferences menu. " ) ;
2014-03-14 14:13:41 -04:00
return false ;
}
if ( ! SourceControlProvider . IsAvailable ( ) )
{
2022-11-23 11:57:50 -05:00
OutError = LOCTEXT ( " Error_SCCNotAvailable " , " Revision control is currently not available. Check your connection and try again. " ) ;
2014-03-14 14:13:41 -04:00
return false ;
}
FString AbsoluteFilename = FPaths : : ConvertRelativePathToFull ( SourceFilename ) ;
FSourceControlStatePtr SourceControlState = SourceControlProvider . GetState ( AbsoluteFilename , EStateCacheUsage : : ForceUpdate ) ;
if ( SourceControlState . IsValid ( ) & & ! ( SourceControlState - > IsCheckedOut ( ) | | SourceControlState - > IsAdded ( ) ) )
{
2015-06-26 13:13:02 -04:00
OutError = FText : : Format ( LOCTEXT ( " Error_SCCNotCheckedOut " , " Collection '{0}' not checked out or open for add. " ) , FText : : FromName ( CollectionName ) ) ;
2014-03-14 14:13:41 -04:00
return false ;
}
2014-04-23 19:31:56 -04:00
if ( SourceControlProvider . Execute ( ISourceControlOperation : : Create < FRevert > ( ) , AbsoluteFilename ) = = ECommandResult : : Succeeded )
2014-03-14 14:13:41 -04:00
{
return true ;
}
else
{
2015-06-26 13:13:02 -04:00
OutError = FText : : Format ( LOCTEXT ( " Error_SCCRevert " , " Could not revert collection '{0}' " ) , FText : : FromName ( CollectionName ) ) ;
2014-03-14 14:13:41 -04:00
return false ;
}
}
bool FCollection : : DeleteFromSourceControl ( FText & OutError )
{
ISourceControlProvider & SourceControlProvider = ISourceControlModule : : Get ( ) . GetProvider ( ) ;
if ( ! ISourceControlModule : : Get ( ) . IsEnabled ( ) )
{
2022-11-23 11:57:50 -05:00
OutError = LOCTEXT ( " Error_SCCDisabled " , " Revision control is not enabled. Enable revision control in the preferences menu. " ) ;
2014-03-14 14:13:41 -04:00
return false ;
}
if ( ! SourceControlProvider . IsAvailable ( ) )
{
2022-11-23 11:57:50 -05:00
OutError = LOCTEXT ( " Error_SCCNotAvailable " , " Revision control is currently not available. Check your connection and try again. " ) ;
2014-03-14 14:13:41 -04:00
return false ;
}
bool bDeletedSuccessfully = false ;
const int32 DeleteProgressDenominator = 2 ;
int32 DeleteProgressNumerator = 0 ;
const FText CollectionNameText = FText : : FromName ( CollectionName ) ;
FFormatNamedArguments Args ;
Args . Add ( TEXT ( " CollectionName " ) , CollectionNameText ) ;
const FText StatusUpdate = FText : : Format ( LOCTEXT ( " DeletingCollection " , " Deleting Collection {CollectionName} " ) , Args ) ;
GWarn - > BeginSlowTask ( StatusUpdate , true ) ;
GWarn - > UpdateProgress ( DeleteProgressNumerator + + , DeleteProgressDenominator ) ;
FString AbsoluteFilename = FPaths : : ConvertRelativePathToFull ( SourceFilename ) ;
FSourceControlStatePtr SourceControlState = SourceControlProvider . GetState ( AbsoluteFilename , EStateCacheUsage : : ForceUpdate ) ;
GWarn - > UpdateProgress ( DeleteProgressNumerator + + , DeleteProgressDenominator ) ;
// If checked out locally for some reason, revert
if ( SourceControlState . IsValid ( ) & & ( SourceControlState - > IsAdded ( ) | | SourceControlState - > IsCheckedOut ( ) | | SourceControlState - > IsDeleted ( ) ) )
{
if ( ! RevertCollection ( OutError ) )
{
// Failed to revert, just bail out
GWarn - > EndSlowTask ( ) ;
return false ;
}
// Make sure we get a fresh state from the server
SourceControlState = SourceControlProvider . GetState ( AbsoluteFilename , EStateCacheUsage : : ForceUpdate ) ;
}
// If not at the head revision, sync up
if ( SourceControlState . IsValid ( ) & & ! SourceControlState - > IsCurrent ( ) )
{
2014-04-23 19:31:56 -04:00
if ( SourceControlProvider . Execute ( ISourceControlOperation : : Create < FSync > ( ) , AbsoluteFilename ) = = ECommandResult : : Failed )
2014-03-14 14:13:41 -04:00
{
// Could not sync up with the head revision
GWarn - > EndSlowTask ( ) ;
2015-06-26 13:13:02 -04:00
OutError = FText : : Format ( LOCTEXT ( " Error_SCCSync " , " Failed to sync collection '{0}' to the head revision. " ) , FText : : FromName ( CollectionName ) ) ;
2014-03-14 14:13:41 -04:00
return false ;
}
// Check to see if the file exists at the head revision
2015-06-19 07:33:02 -04:00
if ( ! IFileManager : : Get ( ) . FileExists ( * SourceFilename ) )
2014-03-14 14:13:41 -04:00
{
// File was already deleted, consider this a success
GWarn - > EndSlowTask ( ) ;
return true ;
}
2015-07-09 09:59:51 -04:00
FCollection NewCollection ( SourceFilename , false , ECollectionStorageMode : : Static ) ;
2015-06-19 07:33:02 -04:00
FText LoadErrorText ;
if ( ! NewCollection . Load ( LoadErrorText ) )
2014-03-14 14:13:41 -04:00
{
// Failed to load the head revision file so it isn't safe to delete it
GWarn - > EndSlowTask ( ) ;
2015-06-26 13:13:02 -04:00
OutError = FText : : Format ( LOCTEXT ( " Error_SCCBadHead " , " Failed to load the collection '{0}' at the head revision. {1} " ) , FText : : FromName ( CollectionName ) , LoadErrorText ) ;
2014-03-14 14:13:41 -04:00
return false ;
}
// Loaded the head revision, now merge up so the files are in a consistent state
MergeWithCollection ( NewCollection ) ;
// Make sure we get a fresh state from the server
SourceControlState = SourceControlProvider . GetState ( AbsoluteFilename , EStateCacheUsage : : ForceUpdate ) ;
}
GWarn - > UpdateProgress ( DeleteProgressNumerator + + , DeleteProgressDenominator ) ;
if ( SourceControlState . IsValid ( ) )
{
if ( SourceControlState - > IsAdded ( ) | | SourceControlState - > IsCheckedOut ( ) )
{
2022-11-23 11:57:50 -05:00
OutError = FText : : Format ( LOCTEXT ( " Error_SCCDeleteWhileCheckedOut " , " Failed to delete collection '{0}' in revision control because it is checked out or open for add. " ) , FText : : FromName ( CollectionName ) ) ;
2014-03-14 14:13:41 -04:00
}
else if ( SourceControlState - > CanCheckout ( ) )
{
2014-04-23 19:31:56 -04:00
if ( SourceControlProvider . Execute ( ISourceControlOperation : : Create < FDelete > ( ) , AbsoluteFilename ) = = ECommandResult : : Succeeded )
2014-03-14 14:13:41 -04:00
{
// Now check in the delete
2020-08-11 01:36:57 -04:00
const FText ChangelistDesc = FText : : Format ( LOCTEXT ( " CollectionDeletedDesc " , " Deleted collection: {CollectionName} " ) , Args ) ;
2014-03-14 14:13:41 -04:00
TSharedRef < FCheckIn , ESPMode : : ThreadSafe > CheckInOperation = ISourceControlOperation : : Create < FCheckIn > ( ) ;
CheckInOperation - > SetDescription ( ChangelistDesc ) ;
if ( SourceControlProvider . Execute ( CheckInOperation , AbsoluteFilename ) )
{
// Deleted successfully!
bDeletedSuccessfully = true ;
}
else
{
FText Unused ;
if ( ! RevertCollection ( Unused ) )
{
UE_LOG ( LogCollectionManager , Warning , TEXT ( " Failed to revert collection '%s' after failing to check in the file that was marked for delete. " ) , * CollectionName . ToString ( ) ) ;
}
2015-06-26 13:13:02 -04:00
OutError = FText : : Format ( LOCTEXT ( " Error_SCCCheckIn " , " Failed to check in collection '{0}'. " ) , FText : : FromName ( CollectionName ) ) ;
2014-03-14 14:13:41 -04:00
}
}
else
{
2022-11-23 11:57:50 -05:00
OutError = FText : : Format ( LOCTEXT ( " Error_SCCDeleteFailed " , " Failed to delete collection '{0}' in revision control. " ) , FText : : FromName ( CollectionName ) ) ;
2014-03-14 14:13:41 -04:00
}
}
else if ( ! SourceControlState - > IsSourceControlled ( ) )
{
// Not yet in the depot or deleted. We can just delete it from disk.
bDeletedSuccessfully = IFileManager : : Get ( ) . Delete ( * AbsoluteFilename ) ;
if ( ! bDeletedSuccessfully )
{
2015-06-26 13:13:02 -04:00
OutError = FText : : Format ( LOCTEXT ( " Error_DiskDeleteFailed " , " Failed to delete the collection file: {0} " ) , FText : : FromString ( AbsoluteFilename ) ) ;
2014-03-14 14:13:41 -04:00
}
}
else if ( ! SourceControlState - > IsCurrent ( ) )
{
2015-06-26 13:13:02 -04:00
OutError = FText : : Format ( LOCTEXT ( " Error_SCCNotCurrent " , " Collection '{0}' is not at head revision after sync. " ) , FText : : FromName ( CollectionName ) ) ;
2014-03-14 14:13:41 -04:00
}
else if ( SourceControlState - > IsCheckedOutOther ( ) )
{
2015-06-26 13:13:02 -04:00
OutError = FText : : Format ( LOCTEXT ( " Error_SCCCheckedOutOther " , " Collection '{0}' is checked out by another user. " ) , FText : : FromName ( CollectionName ) ) ;
2014-03-14 14:13:41 -04:00
}
else
{
2022-11-23 11:57:50 -05:00
OutError = FText : : Format ( LOCTEXT ( " Error_SCCUnknown " , " Could not determine revision control state for collection '{0}' " ) , FText : : FromName ( CollectionName ) ) ;
2014-03-14 14:13:41 -04:00
}
}
else
{
2022-11-23 11:57:50 -05:00
OutError = LOCTEXT ( " Error_SCCInvalid " , " Revision control state is invalid. " ) ;
2014-03-14 14:13:41 -04:00
}
GWarn - > UpdateProgress ( DeleteProgressNumerator + + , DeleteProgressDenominator ) ;
GWarn - > EndSlowTask ( ) ;
return bDeletedSuccessfully ;
}
# undef LOCTEXT_NAMESPACE