Ejemplo n.º 1
0
bool FCollection::Load(FText& OutError)
{
	ObjectSet.Empty();
	DiskSnapshot = FCollectionSnapshot();

	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;
	}

	// Normalize line endings and parse into array
	TArray<FString> FileContents;
	FullFileContentsString.ReplaceInline(TEXT("\r"), TEXT(""));
	FullFileContentsString.ParseIntoArray(FileContents, TEXT("\n"), /*bCullEmpty=*/false);

	if ( FileContents.Num() == 0 )
	{
		// Empty file, assume static collection with no items
		return true;
	}

	// Load the header from the contents array
	TMap<FString,FString> HeaderPairs;
	while ( FileContents.Num() )
	{
		// Pop the 0th element from the contents array and read it
		const FString Line = FileContents[0].Trim().TrimTrailing();
		FileContents.RemoveAt(0);

		if (Line.Len() == 0)
		{
			// Empty line. Done reading headers.
			break;
		}

		FString Key;
		FString Value;
		if ( Line.Split(TEXT(":"), &Key, &Value) )
		{
			HeaderPairs.Add(Key, Value);
		}
	}

	// Now process the header pairs to prepare and validate this collection
	if ( !LoadHeaderPairs(HeaderPairs) )
	{
		// Bad header
		OutError = FText::Format(LOCTEXT("LoadError_BadHeader", "The collection file '{0}' contains a bad header and could not be loaded."), FText::FromString(SourceFilename));
		return false;
	}

	// Now load the content if the header load was successful
	if ( IsDynamic() )
	{
		// @todo collection Load dynamic collections
	}
	else
	{
		// Static collection, a flat list of asset paths
		for (FString Line : FileContents)
		{
			Line.Trim();
			Line.TrimTrailing();

			if ( Line.Len() )
			{
				AddObjectToCollection(FName(*Line));
			}
		}
	}

	DiskSnapshot.TakeSnapshot(*this);

	return true;
}
Ejemplo n.º 2
0
bool FCollection::LoadFromFile(const FString& InFilename, bool InUseSCC)
{
	Clear();

	FString FullFileContentsString;
	if ( !FFileHelper::LoadFileToString(FullFileContentsString, *InFilename) )
	{
		return false;
	}

	// Initialize the FCollection and set up the collection name
	bUseSCC = InUseSCC;
	SourceFilename = InFilename;
	CollectionName = FName(*FPaths::GetBaseFilename(InFilename));
		
	// Normalize line endings and parse into array
	TArray<FString> FileContents;
	FullFileContentsString.ReplaceInline(TEXT("\r"), TEXT(""));
	FullFileContentsString.ParseIntoArray(&FileContents, TEXT("\n"), /*bCullEmpty=*/false);

	if ( FileContents.Num() == 0 )
	{
		// Empty file, assume static collection with no items
		return true;
	}

	// Load the header from the contents array
	TMap<FString,FString> HeaderPairs;
	while ( FileContents.Num() )
	{
		// Pop the 0th element from the contents array and read it
		const FString Line = FileContents[0].Trim().TrimTrailing();
		FileContents.RemoveAt(0);

		if (Line.Len() == 0)
		{
			// Empty line. Done reading headers.
			break;
		}

		FString Key;
		FString Value;
		if ( Line.Split(TEXT(":"), &Key, &Value) )
		{
			HeaderPairs.Add(Key, Value);
		}
	}

	// Now process the header pairs to prepare and validate this collection
	if ( !LoadHeaderPairs(HeaderPairs) )
	{
		// Bad header
		return false;
	}

	// Now load the content if the header load was successful
	if ( IsDynamic() )
	{
		// @todo collection Load dynamic collections
	}
	else
	{
		// Static collection, a flat list of asset paths
		for (int32 LineIdx = 0; LineIdx < FileContents.Num(); ++LineIdx)
		{
			const FString Line = FileContents[LineIdx].Trim().TrimTrailing();

			if ( Line.Len() )
			{
				AddAssetToCollection(FName(*Line));
			}
		}

		DiskAssetList = AssetList;
	}

	return true;
}