75 lines
2.2 KiB
C++
75 lines
2.2 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "manageTextFileBPLibrary.h"
|
|
#include "manageTextFile.h"
|
|
|
|
UmanageTextFileBPLibrary::UmanageTextFileBPLibrary(const FObjectInitializer& ObjectInitializer)
|
|
: Super(ObjectInitializer)
|
|
{
|
|
|
|
}
|
|
|
|
bool UmanageTextFileBPLibrary::CreateTextFile(FString Path, FString FileName, FString Text)
|
|
{
|
|
if (Path == "" || FileName == "") {
|
|
UE_LOG(LogTemp, Warning, TEXT("Empty Path or FileName, aborting"));
|
|
return false;
|
|
}
|
|
Path.ReplaceInline(TEXT("/"), TEXT("\\"));
|
|
FString fullpath(Path + "\\" + FileName);
|
|
return FFileHelper::SaveStringToFile(Text, *fullpath, FFileHelper::EEncodingOptions::ForceUTF8);
|
|
}
|
|
|
|
bool UmanageTextFileBPLibrary::AppendStringToFile(FString Path, FString FileName, FString Text)
|
|
{
|
|
if (Path == "" || FileName == "") {
|
|
UE_LOG(LogTemp, Warning, TEXT("Empty Path or FileName, aborting"));
|
|
return false;
|
|
}
|
|
Path.ReplaceInline(TEXT("/"), TEXT("\\"));
|
|
FString fullpath(Path + "\\" + FileName);
|
|
|
|
FString OldText;
|
|
if (FPaths::FileExists(fullpath))
|
|
{
|
|
FFileHelper::LoadFileToString(OldText, *fullpath);
|
|
OldText += Text;
|
|
return FFileHelper::SaveStringToFile(Text, *fullpath, FFileHelper::EEncodingOptions::ForceUTF8, &IFileManager::Get(), FILEWRITE_Append);
|
|
}
|
|
else
|
|
{
|
|
return CreateTextFile(Path, FileName, Text);
|
|
}
|
|
}
|
|
|
|
bool UmanageTextFileBPLibrary::FileExists(FString Path, FString FileName)
|
|
{
|
|
if (Path == "" || FileName == "") {
|
|
UE_LOG(LogTemp, Warning, TEXT("Empty Path or FileName, aborting"));
|
|
return false;
|
|
}
|
|
Path.ReplaceInline(TEXT("/"), TEXT("\\"));
|
|
return FPaths::FileExists(Path + "\\" + FileName);
|
|
}
|
|
|
|
bool UmanageTextFileBPLibrary::DeleteFile(FString Path, FString FileName)
|
|
{
|
|
if (Path == "" || FileName == "") {
|
|
UE_LOG(LogTemp, Warning, TEXT("Empty Path or FileName, aborting"));
|
|
return false;
|
|
}
|
|
Path.ReplaceInline(TEXT("/"), TEXT("\\"));
|
|
FString fullpath = Path + "\\" + FileName;
|
|
return FPlatformFileManager::Get().GetPlatformFile().DeleteFile(*fullpath);
|
|
}
|
|
|
|
bool UmanageTextFileBPLibrary::readFile(FString Path, FString FileName,FString &Str) {
|
|
if (Path == "" || FileName == "") {
|
|
UE_LOG(LogTemp, Warning, TEXT("Empty Path or FileName, aborting"));
|
|
return false;
|
|
}
|
|
|
|
FString fullpath = Path + "\\" + FileName;
|
|
return FFileHelper::LoadFileToString(Str, *fullpath);
|
|
|
|
}
|