Hey everyone,
I have a packaged HTML 5 project sitting on my server.
I’m trying to pull a text file from the server and parse it into a string array using code from Rama’s BP library.
I have the same project packaged and working on Windows, but when I attempt to pull the file from the server it returns a null path. I’m assuming that has to do with the way FFileHelper is reading the file path, but I can’t seem to find another way around this.
I’ve tried out LE’s plugin series to properly request the files or read a JSON object rather than a text file. Unfortunately, all of the plugins cause build errors in blank projects all the way back to 4.13. All related to symbol definitions.
I’m still kinda sketchy when working in Unreal C++ so I was hoping to get some help pulling the file down. Everything I’ve done causes errors. Here’s the code I’m using to parse the text file for reference.
.h
#pragma once
#include "CoreMisc.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "StandardBlueprintFunctions.generated.h"
/**
*
*/
UCLASS()
class PROGEN_API UStandardBlueprintFunctions : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
/*Save String Array*/
public:
/** 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 = "BPStandardFunctions")
static bool FileIO__SaveStringArrayToFile(FString SaveDirectory, FString JoyfulFileName, TArray<FString> SaveText, bool AllowOverWriting = false);
/*Load String Array*/
public:
/** Loads a text file from hard disk and parses it into a String array, where each entry in the string array is 1 line from the text file. Option to exclude lines that are only whitespace characters or '\n'. Returns the size of the final String Array that was created. Returns false if the file could be loaded from hard disk. */
UFUNCTION(BlueprintPure, Category = "BPStandardFunctions")
static bool LoadStringArrayFromFile(TArray<FString>& StringArray, int32& ArraySize, FString FullFilePath = "Enter Full File Path", bool ExcludeEmptyLines = false);
.cpp
#include "Progen.h"
#include "StandardBlueprintFunctions.h"
bool UStandardBlueprintFunctions::FileIO__SaveStringArrayToFile(FString SaveDirectory, FString JoyfulFileName, TArray<FString> SaveText, bool AllowOverWriting)
{
//Dir Exists?
if (!FPlatformFileManager::Get().GetPlatformFile().DirectoryExists(*SaveDirectory))
{
//create directory if it not exist
FPlatformFileManager::Get().GetPlatformFile().CreateDirectory(*SaveDirectory);
//still could not make directory?
if (!FPlatformFileManager::Get().GetPlatformFile().DirectoryExists(*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;
}
return FFileHelper::SaveStringToFile(FinalStr, *SaveDirectory);
}
/** Load string array from file*/
bool UStandardBlueprintFunctions::LoadStringArrayFromFile(TArray<FString>& StringArray, int32& ArraySize, FString FullFilePath, bool ExcludeEmptyLines)
{
ArraySize = 0;
if (FullFilePath == "" || FullFilePath == " ") return false;
//Empty any previous contents!
StringArray.Empty();
TArray<FString> FileArray;
if (!FFileHelper::LoadANSITextFileToStrings(*FullFilePath, NULL, FileArray))
{
return false;
}
if (ExcludeEmptyLines)
{
for (const FString& Each : FileArray)
{
if (Each == "") continue;
//~~~~~~~~~~~~~
//check for any non whitespace
bool FoundNonWhiteSpace = false;
for (int32 v = 0; v < Each.Len(); v++)
{
if (Each[v] != ' ' && Each[v] != '\n')
{
FoundNonWhiteSpace = true;
break;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}
if (FoundNonWhiteSpace)
{
StringArray.Add(Each);
}
}
}
else
{
StringArray.Append(FileArray);
}
ArraySize = StringArray.Num();
return true;
}
Thanks for any help! Let me know if you need anything else.
Entro