Browse Source

Add special character and weird image type validation

master
Thomas Cheyney 3 years ago
parent
commit
3489c1228f
3 changed files with 61 additions and 0 deletions
  1. BIN
      Content/Blueprints/WidgetSongInfos.uasset
  2. +58
    -0
      Source/MediocreMapAssistant2/BPFileIO.cpp
  3. +3
    -0
      Source/MediocreMapAssistant2/BPFileIO.h

BIN
Content/Blueprints/WidgetSongInfos.uasset View File


+ 58
- 0
Source/MediocreMapAssistant2/BPFileIO.cpp View File

@ -2,6 +2,13 @@
#include "BPFileIO.h"
#include "ModuleManager.h"
#include "FileHelper.h"
#include "ImageUtils.h"
#include "IImageWrapper.h"
#include "IImageWrapperModule.h"
bool UBPFileIO::VerifyOrCreateDirectory(const FString & TestDir)
{
IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
@ -31,6 +38,57 @@ bool UBPFileIO::VerifyDirectory(const FString & TestDir)
return true;
}
FString UBPFileIO::CheckImageFormatMatches(const FString & TestPath)
{
FString unknownProblem = "Something's weird with your cover image, and i don't know what it is.";
IImageWrapperModule& ImageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName("ImageWrapper"));
TArray<uint8> FileData;
if (!FFileHelper::LoadFileToArray(FileData, *TestPath))
{
UE_LOG(LogTemp, Error, TEXT("Failed to load file"));
return unknownProblem;
}
EImageFormat fileFormat = ImageWrapperModule.DetectImageFormat(FileData.GetData(), FileData.Num());
if ((TestPath.EndsWith(".png") && fileFormat == EImageFormat::PNG) ||
((TestPath.EndsWith(".jpg") || TestPath.EndsWith(".jpeg")) && (fileFormat == EImageFormat::JPEG || fileFormat == EImageFormat::GrayscaleJPEG)))
{
return unknownProblem;
} else if (!TestPath.EndsWith(".png") && !TestPath.EndsWith(".jpg") && !TestPath.EndsWith(".jpeg")) {
return "Your cover image needs to be a jpg or png and end with .jpg, .jpeg or .png";
}
FString fileFormatStr;
switch (fileFormat) {
case EImageFormat::BMP:
fileFormatStr = "BMP";
break;
case EImageFormat::PNG:
fileFormatStr = "PNG";
break;
case EImageFormat::JPEG:
case EImageFormat::GrayscaleJPEG:
fileFormatStr = "JPG";
break;
case EImageFormat::ICO:
fileFormatStr = "ICO";
break;
case EImageFormat::EXR:
fileFormatStr = "EXR";
break;
case EImageFormat::ICNS:
fileFormatStr = "ICNS";
break;
case EImageFormat::Invalid:
default:
fileFormatStr = "Unknown";
}
return "Your cover image appears to be a " + fileFormatStr + " file, but the extension does not match";
}
TArray<FString> UBPFileIO::FindAllDirectories(const FString & TestDir)
{
TArray<FString> result;


+ 3
- 0
Source/MediocreMapAssistant2/BPFileIO.h View File

@ -23,6 +23,9 @@ class MEDIOCREMAPASSISTANT2_API UBPFileIO : public UBlueprintFunctionLibrary
UFUNCTION(BlueprintCallable, Category = "File IO")
static bool VerifyDirectory(const FString& TestDir);
UFUNCTION(BlueprintCallable, Category = "File IO")
static FString CheckImageFormatMatches(const FString& TestPath);
UFUNCTION(BlueprintCallable, Category = "File IO")
static TArray<FString> FindAllDirectories(const FString& TestDir);


Loading…
Cancel
Save