I just want to make a suggestion: I have added Append to the to the Save String Text to File functions. I am by no means a programmer but these do work and I make sure to add them every I use Victory. You just need to replace the functions in 2 files and recompile. Its just a slightly easier way instead of appending an array and overwriting.
VictoryBPFunctionLibrary.cpp:
bool UVictoryBPFunctionLibrary::FileIO__SaveStringTextToFile(
FString SaveDirectory,
FString JoyfulFileName,
FString SaveText,
bool AllowOverWriting,
bool Append
) {
if (!FPlatformFileManager::Get().GetPlatformFile().CreateDirectoryTree(*SaveDirectory))
{
//Could not make the specified directory
return false;
//~~~~~~~~~~~~~~~~~~~~~~
}
//get complete file path
SaveDirectory += "\\";
SaveDirectory += JoyfulFileName;
//No over-writing?
if (!AllowOverWriting)
{
//Check if file exists already
if (FPlatformFileManager::Get().GetPlatformFile().FileExists(*SaveDirectory))
{
//no overwriting
return false;
}
}
if (!Append)
{
return FFileHelper::SaveStringToFile(SaveText, *SaveDirectory);
}
return FFileHelper::SaveStringToFile(SaveText, *SaveDirectory, FFileHelper::EEncodingOptions::AutoDetect, &IFileManager::Get(), EFileWrite::FILEWRITE_Append);
}
bool UVictoryBPFunctionLibrary::FileIO__SaveStringArrayToFile(FString SaveDirectory, FString JoyfulFileName, TArray<FString> SaveText, bool AllowOverWriting, bool Append)
{
//Dir Exists?
if (!VCreateDirectory(SaveDirectory))
{
//Could not make the specified directory
return false;
//~~~~~~~~~~~~~~~~~~~~~~
}
//get complete file path
SaveDirectory += "\\";
SaveDirectory += JoyfulFileName;
//No over-writing?
if (!AllowOverWriting)
{
//Check if file exists already
if (FPlatformFileManager::Get().GetPlatformFile().FileExists(*SaveDirectory))
{
//no overwriting
return false;
}
}
FString FinalStr = "";
for (FString& Each : SaveText)
{
FinalStr += Each;
FinalStr += LINE_TERMINATOR;
}
if (!Append)
{
return FFileHelper::SaveStringToFile(FinalStr, *SaveDirectory);
}
return FFileHelper::SaveStringToFile(FinalStr, *SaveDirectory, FFileHelper::EEncodingOptions::AutoDetect, &IFileManager::Get(), EFileWrite::FILEWRITE_Append);
}
VictoryBPFunctionLibrary.h:
/** Saves text to filename of your choosing, make sure include whichever file extension you want in the filename, ex: SelfNotes.txt . Make sure to include the entire file path in the save directory, ex: C:\MyGameDir\BPSavedTextFiles */
UFUNCTION(BlueprintCallable, Category = "Victory BP Library|File IO")
static bool FileIO__SaveStringTextToFile(FString SaveDirectory, FString JoyfulFileName, FString SaveText, bool AllowOverWriting = false, bool Append = false);
/** Saves multiple Strings to filename of your choosing, with each string on its own line! Make sure include whichever file extension you want in the filename, ex: SelfNotes.txt . Make sure to include the entire file path in the save directory, ex: C:\MyGameDir\BPSavedTextFiles */
UFUNCTION(BlueprintCallable, Category = "Victory BP Library|File IO")
static bool FileIO__SaveStringArrayToFile(FString SaveDirectory, FString JoyfulFileName, TArray<FString> SaveText, bool AllowOverWriting = false, bool Append = false);