Fix game deployment if output name contains invalid path characters
#3004
This commit is contained in:
@@ -511,11 +511,12 @@ bool WindowsPlatformTools::OnDeployBinaries(CookingData& data)
|
||||
|
||||
// Rename app
|
||||
const String newName = EditorUtilities::GetOutputName();
|
||||
if (newName != StringUtils::GetFileNameWithoutExtension(files[0]))
|
||||
const StringView oldName = StringUtils::GetFileNameWithoutExtension(files[0]);
|
||||
if (newName != oldName)
|
||||
{
|
||||
if (FileSystem::MoveFile(data.NativeCodeOutputPath / newName + TEXT(".exe"), files[0], true))
|
||||
{
|
||||
data.Error(TEXT("Failed to change output executable name."));
|
||||
data.Error(String::Format(TEXT("Failed to change output executable name from '{}' to '{}'."), oldName, newName));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,11 @@
|
||||
#include "Engine/Platform/File.h"
|
||||
#include "Engine/Platform/FileSystem.h"
|
||||
#include "Engine/Platform/CreateProcessSettings.h"
|
||||
#include "Engine/Core/Log.h"
|
||||
#include "Engine/Graphics/Textures/TextureData.h"
|
||||
#include "Engine/Graphics/PixelFormatExtensions.h"
|
||||
#include "Engine/Tools/TextureTool/TextureTool.h"
|
||||
#include "Engine/Core/Log.h"
|
||||
#include "Engine/Core/Types/StringBuilder.h"
|
||||
#include "Engine/Core/Config/GameSettings.h"
|
||||
#include "Engine/Core/Config/BuildSettings.h"
|
||||
#include "Engine/Content/Content.h"
|
||||
@@ -28,6 +29,7 @@ String EditorUtilities::GetOutputName()
|
||||
outputName.Replace(TEXT("${COMPANY_NAME}"), *gameSettings->CompanyName, StringSearchCase::IgnoreCase);
|
||||
if (outputName.IsEmpty())
|
||||
outputName = TEXT("FlaxGame");
|
||||
ValidatePathChars(outputName, 0);
|
||||
return outputName;
|
||||
}
|
||||
|
||||
@@ -360,6 +362,28 @@ bool EditorUtilities::IsInvalidPathChar(Char c)
|
||||
return false;
|
||||
}
|
||||
|
||||
void EditorUtilities::ValidatePathChars(String& filename, char invalidCharReplacement)
|
||||
{
|
||||
if (invalidCharReplacement == 0)
|
||||
{
|
||||
StringBuilder result;
|
||||
for (int32 i = 0; i < filename.Length(); i++)
|
||||
{
|
||||
if (!IsInvalidPathChar(filename[i]))
|
||||
result.Append(filename[i]);
|
||||
}
|
||||
filename = result.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int32 i = 0; i < filename.Length(); i++)
|
||||
{
|
||||
if (IsInvalidPathChar(filename[i]))
|
||||
filename[i] = invalidCharReplacement;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool EditorUtilities::ReplaceInFiles(const String& folderPath, const Char* searchPattern, DirectorySearchOption searchOption, const String& findWhat, const String& replaceWith)
|
||||
{
|
||||
Array<String> files;
|
||||
@@ -391,7 +415,7 @@ bool EditorUtilities::ReplaceInFile(const StringView& file, const Dictionary<Str
|
||||
|
||||
bool EditorUtilities::CopyFileIfNewer(const StringView& dst, const StringView& src)
|
||||
{
|
||||
if (FileSystem::FileExists(dst) &&
|
||||
if (FileSystem::FileExists(dst) &&
|
||||
FileSystem::GetFileLastEditTime(src) <= FileSystem::GetFileLastEditTime(dst) &&
|
||||
FileSystem::GetFileSize(dst) == FileSystem::GetFileSize(src))
|
||||
return false;
|
||||
|
||||
@@ -57,6 +57,13 @@ public:
|
||||
/// <returns><c>true</c> if the given character cannot be used as a path because it is illegal character; otherwise, <c>false</c>.</returns>
|
||||
static bool IsInvalidPathChar(Char c);
|
||||
|
||||
/// <summary>
|
||||
/// Validates path characters and replaces any incorrect ones.
|
||||
/// </summary>
|
||||
/// <param name="filename">The input and output filename string to process.</param>
|
||||
/// <param name="invalidCharReplacement">The character to use for replacement for any invalid characters in the path. Use '0' to remove them.</param>
|
||||
static void ValidatePathChars(String& filename, char invalidCharReplacement = ' ');
|
||||
|
||||
/// <summary>
|
||||
/// Replaces the given text with other one in the files.
|
||||
/// </summary>
|
||||
|
||||
@@ -1080,11 +1080,7 @@ void TrySetupMaterialParameter(MaterialInstance* instance, Span<const Char*> par
|
||||
String GetAdditionalImportPath(const String& autoImportOutput, Array<String>& importedFileNames, const String& name)
|
||||
{
|
||||
String filename = name;
|
||||
for (int32 j = filename.Length() - 1; j >= 0; j--)
|
||||
{
|
||||
if (EditorUtilities::IsInvalidPathChar(filename[j]))
|
||||
filename[j] = ' ';
|
||||
}
|
||||
EditorUtilities::ValidatePathChars(filename);
|
||||
if (importedFileNames.Contains(filename))
|
||||
{
|
||||
int32 counter = 1;
|
||||
|
||||
Reference in New Issue
Block a user