// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
#pragma once
#include "Engine/Core/Common.h"
#include "Engine/Scripting/SoftObjectReference.h"
enum class PixelFormat : unsigned;
enum class DirectorySearchOption;
struct TextureData;
///
/// Helper functions for the editor.
///
class EditorUtilities
{
public:
enum class ApplicationImageType
{
Icon,
SplashScreen,
};
static String GetOutputName();
static bool FormatAppPackageName(String& packageName);
static bool GetApplicationImage(const Guid& imageId, TextureData& imageData, ApplicationImageType type = ApplicationImageType::Icon);
static bool GetTexture(const Guid& textureId, TextureData& textureData);
static bool ExportApplicationImage(const Guid& iconId, int32 width, int32 height, PixelFormat format, const String& path, ApplicationImageType type = ApplicationImageType::Icon);
static bool ExportApplicationImage(const TextureData& icon, int32 width, int32 height, PixelFormat format, const String& path);
template
static bool GetApplicationImage(const SoftObjectReference& image, TextureData& imageData, ApplicationImageType type = ApplicationImageType::Icon)
{
const Guid imageId = image.GetID();
return GetApplicationImage(imageId, imageData, type);
}
template
static bool ExportApplicationImage(const SoftObjectReference& icon, int32 width, int32 height, PixelFormat format, const String& path, ApplicationImageType type = ApplicationImageType::Icon)
{
const Guid iconId = icon.GetID();
return ExportApplicationImage(iconId, width, height, format, path, type);
}
public:
static bool FindWDKBin(String& outputWdkBinPath);
static bool GenerateCertificate(const String& name, const String& outputPfxFilePath);
static bool GenerateCertificate(const String& name, const String& outputPfxFilePath, const String& outputCerFilePath, const String& outputPvkFilePath);
public:
///
/// Determines whether the specified path character is invalid.
///
/// The path character.
/// true if the given character cannot be used as a path because it is illegal character; otherwise, false.
static bool IsInvalidPathChar(Char c);
///
/// Replaces the given text with other one in the files.
///
/// The relative or absolute path to the directory to search.
/// The search string to match against the names of files in . This parameter can contain a combination of valid literal path and wildcard (* and ?) characters (see Remarks), but doesn't support regular expressions.
/// One of the enumeration values that specifies whether the search operation should include all subdirectories or only the current directory.
/// The text to replace.
/// The value to replace to.
/// True if failed, otherwise false.
static bool ReplaceInFiles(const String& folderPath, const Char* searchPattern, DirectorySearchOption searchOption, const String& findWhat, const String& replaceWith);
///
/// Replaces the given text with other one in the file.
///
/// The file to process.
/// The text to replace.
/// The value to replace to.
/// True if failed, otherwise false.
static bool ReplaceInFile(const StringView& file, const StringView& findWhat, const StringView& replaceWith);
static bool ReplaceInFile(const StringView& file, const Dictionary& replaceMap);
static bool CopyFileIfNewer(const StringView& dst, const StringView& src);
static bool CopyDirectoryIfNewer(const StringView& dst, const StringView& src, bool withSubDirectories);
};