diff --git a/Content/Blueprints/WidgetSongInfos.uasset b/Content/Blueprints/WidgetSongInfos.uasset index 2768447..786d554 100644 Binary files a/Content/Blueprints/WidgetSongInfos.uasset and b/Content/Blueprints/WidgetSongInfos.uasset differ diff --git a/Source/MediocreMapAssistant2/BPFileIO.cpp b/Source/MediocreMapAssistant2/BPFileIO.cpp index 0c049de..1a1e3cf 100644 --- a/Source/MediocreMapAssistant2/BPFileIO.cpp +++ b/Source/MediocreMapAssistant2/BPFileIO.cpp @@ -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(FName("ImageWrapper")); + + TArray 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 UBPFileIO::FindAllDirectories(const FString & TestDir) { TArray result; diff --git a/Source/MediocreMapAssistant2/BPFileIO.h b/Source/MediocreMapAssistant2/BPFileIO.h index ce0e6b6..6b5bc45 100644 --- a/Source/MediocreMapAssistant2/BPFileIO.h +++ b/Source/MediocreMapAssistant2/BPFileIO.h @@ -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 FindAllDirectories(const FString& TestDir);