You've already forked LuckyWorld
fixed build issues, added binaries, and updated the AsyncLoadingScreen plugin directory
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
// Copyright 2023 RLoris
|
||||
// Copyright 2025 RLoris
|
||||
|
||||
#include "FileHelperBPLibrary.h"
|
||||
|
||||
#include "HAL/PlatformFileManager.h"
|
||||
#include "HAL/FileManager.h"
|
||||
#include "Misc/FileHelper.h"
|
||||
@ -9,22 +10,26 @@
|
||||
#include "Misc/ConfigCacheIni.h"
|
||||
#include "Engine/DataTable.h"
|
||||
#include "Internationalization/Regex.h"
|
||||
#include "Runtime/Launch/Resources/Version.h"
|
||||
#include "Serialization/Csv/CsvParser.h"
|
||||
#include "UObject/TextProperty.h"
|
||||
|
||||
class FCustomFileVisitor : public IPlatformFile::FDirectoryVisitor
|
||||
{
|
||||
public:
|
||||
FCustomFileVisitor(const FString& Path, TArray<FString>& Paths, const FString& Pattern, bool File, bool Directory) : BasePath(Path), Nodes(Paths), Filter(Pattern), CustomPattern(Pattern), bFile(File), bDirectory(Directory) {};
|
||||
|
||||
//~ Begin FDirectoryVisitor
|
||||
virtual bool Visit(const TCHAR* FilenameOrDirectory, bool bIsDirectory) override;
|
||||
//~ End FDirectoryVisitor
|
||||
|
||||
private:
|
||||
FString BasePath;
|
||||
TArray<FString>& Nodes;
|
||||
FString Filter;
|
||||
FRegexPattern CustomPattern;
|
||||
bool bFile = true;
|
||||
bool bDirectory = true;
|
||||
|
||||
FCustomFileVisitor(FString& Path, TArray<FString>& Paths, const FString& Pattern, bool File, bool Directory) : BasePath(Path), Nodes(Paths), Filter(Pattern), CustomPattern(Pattern), bFile(File), bDirectory(Directory) {};
|
||||
|
||||
virtual bool Visit(const TCHAR* FilenameOrDirectory, bool bIsDirectory);
|
||||
};
|
||||
|
||||
FEnginePath UFileHelperBPLibrary::GetEngineDirectories()
|
||||
@ -38,7 +43,11 @@ FEnginePath UFileHelperBPLibrary::GetEngineDirectories()
|
||||
P.Saved =FPaths::ConvertRelativePathToFull( FPaths::EngineSavedDir());
|
||||
P.User = FPaths::ConvertRelativePathToFull(FPaths::EngineUserDir());
|
||||
P.DefaultLayout = FPaths::ConvertRelativePathToFull(FPaths::EngineDefaultLayoutDir());
|
||||
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 4
|
||||
P.PlatformExtensions = FPaths::ConvertRelativePathToFull(FPaths::EnginePlatformExtensionDir(TEXT("")).TrimChar('/'));
|
||||
#else
|
||||
P.PlatformExtensions = FPaths::ConvertRelativePathToFull(FPaths::EnginePlatformExtensionsDir());
|
||||
#endif
|
||||
P.UserLayout = FPaths::ConvertRelativePathToFull(FPaths::EngineUserLayoutDir());
|
||||
return P;
|
||||
}
|
||||
@ -56,14 +65,18 @@ FProjectPath UFileHelperBPLibrary::GetProjectDirectories()
|
||||
P.Saved = FPaths::ConvertRelativePathToFull(FPaths::ProjectSavedDir());
|
||||
P.User = FPaths::ConvertRelativePathToFull(FPaths::ProjectUserDir());
|
||||
P.PersistentDownload = FPaths::ConvertRelativePathToFull(FPaths::ProjectPersistentDownloadDir());
|
||||
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 4
|
||||
P.PlatformExtensions = FPaths::ConvertRelativePathToFull(FPaths::ProjectPlatformExtensionDir(TEXT("")).TrimChar('/'));
|
||||
#else
|
||||
P.PlatformExtensions = FPaths::ConvertRelativePathToFull(FPaths::ProjectPlatformExtensionsDir());
|
||||
#endif
|
||||
return P;
|
||||
}
|
||||
|
||||
bool UFileHelperBPLibrary::ReadText(FString Path, FString& Output)
|
||||
{
|
||||
IPlatformFile& FileManager = FPlatformFileManager::Get().GetPlatformFile();
|
||||
if (FileManager.FileExists(*Path))
|
||||
if (FileManager.FileExists(*Path))
|
||||
{
|
||||
return FFileHelper::LoadFileToString(Output, *Path);
|
||||
}
|
||||
@ -369,10 +382,10 @@ bool FCustomFileVisitor::Visit(const TCHAR* FilenameOrDirectory, bool bIsDirecto
|
||||
{
|
||||
FString RelativePath = FString(FilenameOrDirectory);
|
||||
FPaths::MakePathRelativeTo(RelativePath, *BasePath);
|
||||
if (!Filter.IsEmpty())
|
||||
if (!Filter.IsEmpty())
|
||||
{
|
||||
FRegexMatcher CustomMatcher(CustomPattern, RelativePath);
|
||||
if (CustomMatcher.FindNext())
|
||||
if (CustomMatcher.FindNext())
|
||||
{
|
||||
Nodes.Add(RelativePath);
|
||||
}
|
||||
@ -388,21 +401,21 @@ bool FCustomFileVisitor::Visit(const TCHAR* FilenameOrDirectory, bool bIsDirecto
|
||||
bool UFileHelperBPLibrary::ListDirectory(FString Path, FString Pattern, TArray<FString>& Nodes, bool ShowFile, bool ShowDirectory, bool Recursive)
|
||||
{
|
||||
IPlatformFile& FileManager = FPlatformFileManager::Get().GetPlatformFile();
|
||||
if (!FileManager.DirectoryExists(*Path))
|
||||
if (!FileManager.DirectoryExists(*Path))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!ShowDirectory && !ShowFile)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
FString BasePath = FPaths::Combine(Path, TEXT("/"));
|
||||
FCustomFileVisitor CustomFileVisitor(BasePath, Nodes, Pattern, ShowFile, ShowDirectory);
|
||||
if (Recursive)
|
||||
{
|
||||
return FileManager.IterateDirectoryRecursively(*Path, CustomFileVisitor);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
return FileManager.IterateDirectory(*Path, CustomFileVisitor);
|
||||
}
|
||||
@ -614,14 +627,14 @@ bool UFileHelperBPLibrary::DataTableToJSON(UDataTable* Table, FString& Output)
|
||||
UDataTable* UFileHelperBPLibrary::CSVToDataTable(FString CSV, UScriptStruct* Struct, bool& Success)
|
||||
{
|
||||
Success = false;
|
||||
if (Struct == nullptr)
|
||||
if (Struct == nullptr)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
UDataTable* DataTable = NewObject<UDataTable>();
|
||||
DataTable->RowStruct = Struct;
|
||||
auto Result = DataTable->CreateTableFromCSVString(CSV);
|
||||
if (Result.Num() == 0)
|
||||
if (Result.Num() == 0)
|
||||
{
|
||||
Success = true;
|
||||
}
|
||||
@ -645,7 +658,7 @@ UDataTable* UFileHelperBPLibrary::JSONToDataTable(FString JSON, UScriptStruct* S
|
||||
return DataTable;
|
||||
}
|
||||
|
||||
void UFileHelperBPLibrary::ReadConfig(FString FilePath, FString Section, FString Key, bool& Success, bool SingleLineArrayRead, UStruct*& OutValue, bool bLoadFromDisk)
|
||||
void UFileHelperBPLibrary::ReadConfig(FString FilePath, FString Section, FString Key, bool& Success, bool SingleLineArrayRead, UStruct*& OutValue)
|
||||
{
|
||||
checkNoEntry();
|
||||
}
|
||||
@ -673,13 +686,17 @@ TArray<FString> UFileHelperBPLibrary::SplitString(FString String, FString Separa
|
||||
return Array;
|
||||
}
|
||||
|
||||
bool UFileHelperBPLibrary::WriteConfigFile(FString Filename, FString Section, FString Key, FProperty* Type, void* Value, bool SingleLineArray, bool bWriteToDisk)
|
||||
bool UFileHelperBPLibrary::WriteConfigFile(FString Filename, FString Section, FString Key, FProperty* Type, void* Value, bool SingleLineArray)
|
||||
{
|
||||
if (!GConfig)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (FBoolProperty* BoolProperty = CastField<FBoolProperty>(Type))
|
||||
|
||||
FConfigFile ConfigFile;
|
||||
FindOrCreateConfigFile(Filename, ConfigFile);
|
||||
|
||||
if (FBoolProperty* BoolProperty = CastField<FBoolProperty>(Type))
|
||||
{
|
||||
GConfig->SetBool(*Section, *Key, *(static_cast<bool*>(Value)), Filename);
|
||||
}
|
||||
@ -768,33 +785,19 @@ bool UFileHelperBPLibrary::WriteConfigFile(FString Filename, FString Section, FS
|
||||
return false;
|
||||
}
|
||||
|
||||
if (bWriteToDisk)
|
||||
{
|
||||
GConfig->Flush(false, Filename);
|
||||
}
|
||||
|
||||
return true;
|
||||
return SaveConfigFile(Filename);
|
||||
}
|
||||
|
||||
bool UFileHelperBPLibrary::ReadConfigFile(FString Filename, FString Section, FString Key, FProperty* Type, void* Value, bool SingleLineArray, bool bLoadFromDisk)
|
||||
bool UFileHelperBPLibrary::ReadConfigFile(FString Filename, FString Section, FString Key, FProperty* Type, void* Value, bool SingleLineArray)
|
||||
{
|
||||
if (!GConfig)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (bLoadFromDisk)
|
||||
{
|
||||
FConfigFile* ConfigFile = GConfig->FindConfigFile(Filename);
|
||||
|
||||
if (!ConfigFile)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ConfigFile->Read(Filename);
|
||||
}
|
||||
|
||||
FConfigFile ConfigFile;
|
||||
FindOrCreateConfigFile(Filename, ConfigFile);
|
||||
|
||||
bool Success = false;
|
||||
if (FBoolProperty* BoolProperty = CastField<FBoolProperty>(Type))
|
||||
{
|
||||
@ -868,32 +871,83 @@ bool UFileHelperBPLibrary::ReadConfigFile(FString Filename, FString Section, FSt
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Success;
|
||||
}
|
||||
|
||||
void UFileHelperBPLibrary::WriteConfig(FString FilePath, FString Section, FString Key, bool& Success, bool SingleLineArrayWrite, const UStruct* Value, bool bWriteToDisk)
|
||||
void UFileHelperBPLibrary::FindOrCreateConfigFile(const FString& InFilePath, FConfigFile& OutConfigFile)
|
||||
{
|
||||
const bool bDisabled = GConfig->AreFileOperationsDisabled();
|
||||
|
||||
if (bDisabled)
|
||||
{
|
||||
GConfig->EnableFileOperations();
|
||||
}
|
||||
|
||||
FConfigFile* ConfigFile = GConfig->Find(InFilePath);
|
||||
|
||||
if (!ConfigFile)
|
||||
{
|
||||
FConfigFile NewConfigFile;
|
||||
NewConfigFile.Read(InFilePath);
|
||||
OutConfigFile = GConfig->Add(InFilePath, NewConfigFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
OutConfigFile = *ConfigFile;
|
||||
}
|
||||
|
||||
if (bDisabled)
|
||||
{
|
||||
GConfig->DisableFileOperations();
|
||||
}
|
||||
}
|
||||
|
||||
bool UFileHelperBPLibrary::SaveConfigFile(const FString& InFilePath)
|
||||
{
|
||||
if (FConfigFile* ConfigFile = GConfig->Find(InFilePath))
|
||||
{
|
||||
const bool bDisabled = GConfig->AreFileOperationsDisabled();
|
||||
|
||||
if (bDisabled)
|
||||
{
|
||||
GConfig->EnableFileOperations();
|
||||
}
|
||||
|
||||
GConfig->Flush(false, InFilePath);
|
||||
|
||||
if (bDisabled)
|
||||
{
|
||||
GConfig->DisableFileOperations();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void UFileHelperBPLibrary::WriteConfig(FString FilePath, FString Section, FString Key, bool& Success, bool SingleLineArrayWrite, const UStruct* Value)
|
||||
{
|
||||
checkNoEntry();
|
||||
}
|
||||
|
||||
bool UFileHelperBPLibrary::RemoveConfig(FString FilePath, FString Section, FString Key, bool bWriteToDisk)
|
||||
bool UFileHelperBPLibrary::RemoveConfig(FString FilePath, FString Section, FString Key)
|
||||
{
|
||||
if (!GConfig)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
FConfigFile ConfigFile;
|
||||
FindOrCreateConfigFile(FilePath, ConfigFile);
|
||||
|
||||
if (!GConfig->RemoveKey(*Section, *Key, *FilePath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (bWriteToDisk)
|
||||
{
|
||||
GConfig->Flush(false, FilePath);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
return SaveConfigFile(FilePath);
|
||||
}
|
||||
|
||||
// equivalent GetTableAsCSV()
|
||||
|
Reference in New Issue
Block a user