mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
Fix generated .exe not working if the project name contains special characters (#5254)
This commit is contained in:
@@ -69,6 +69,29 @@ static void InsertUnique(std::vector<gd::String> &container, gd::String str) {
|
|||||||
container.push_back(str);
|
container.push_back(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gd::String CleanProjectName(gd::String projectName) {
|
||||||
|
gd::String partiallyCleanedProjectName = projectName;
|
||||||
|
|
||||||
|
static const gd::String forbiddenFileNameCharacters =
|
||||||
|
"\\/:*?\"<>|"; // See
|
||||||
|
// https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file
|
||||||
|
|
||||||
|
for (size_t i = 0; i < partiallyCleanedProjectName.size();) {
|
||||||
|
// Delete all characters that are not allowed in a filename
|
||||||
|
if (forbiddenFileNameCharacters.find(partiallyCleanedProjectName[i]) !=
|
||||||
|
gd::String::npos) {
|
||||||
|
partiallyCleanedProjectName.erase(i, 1);
|
||||||
|
} else {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (partiallyCleanedProjectName.empty())
|
||||||
|
partiallyCleanedProjectName = "Project";
|
||||||
|
|
||||||
|
return partiallyCleanedProjectName;
|
||||||
|
}
|
||||||
|
|
||||||
ExporterHelper::ExporterHelper(gd::AbstractFileSystem &fileSystem,
|
ExporterHelper::ExporterHelper(gd::AbstractFileSystem &fileSystem,
|
||||||
gd::String gdjsRoot_,
|
gd::String gdjsRoot_,
|
||||||
gd::String codeOutputDir_)
|
gd::String codeOutputDir_)
|
||||||
@@ -101,8 +124,9 @@ bool ExporterHelper::ExportProjectForPixiPreview(
|
|||||||
} else {
|
} else {
|
||||||
// Most of the time, we skip the logo and minimum duration so that
|
// Most of the time, we skip the logo and minimum duration so that
|
||||||
// the preview start as soon as possible.
|
// the preview start as soon as possible.
|
||||||
exportedProject.GetLoadingScreen().ShowGDevelopLogoDuringLoadingScreen(false).SetMinDuration(
|
exportedProject.GetLoadingScreen()
|
||||||
0);
|
.ShowGDevelopLogoDuringLoadingScreen(false)
|
||||||
|
.SetMinDuration(0);
|
||||||
exportedProject.GetWatermark().ShowGDevelopWatermark(false);
|
exportedProject.GetWatermark().ShowGDevelopWatermark(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -308,16 +332,22 @@ bool ExporterHelper::ExportCordovaFiles(const gd::Project &project,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Splashscreen icon for Android 12+.
|
// Splashscreen icon for Android 12+.
|
||||||
gd::String splashScreenIconFilename = getIconFilename("android", "windowSplashScreenAnimatedIcon");
|
gd::String splashScreenIconFilename =
|
||||||
|
getIconFilename("android", "windowSplashScreenAnimatedIcon");
|
||||||
if (!splashScreenIconFilename.empty())
|
if (!splashScreenIconFilename.empty())
|
||||||
output += "<preference name=\"AndroidWindowSplashScreenAnimatedIcon\" value=\""
|
output +=
|
||||||
+ splashScreenIconFilename + "\" />\n";
|
"<preference name=\"AndroidWindowSplashScreenAnimatedIcon\" "
|
||||||
|
"value=\"" +
|
||||||
|
splashScreenIconFilename + "\" />\n";
|
||||||
|
|
||||||
// Splashscreen "branding" image for Android 12+.
|
// Splashscreen "branding" image for Android 12+.
|
||||||
gd::String splashScreenBrandingImageFilename = getIconFilename("android", "windowSplashScreenBrandingImage");
|
gd::String splashScreenBrandingImageFilename =
|
||||||
|
getIconFilename("android", "windowSplashScreenBrandingImage");
|
||||||
if (!splashScreenBrandingImageFilename.empty())
|
if (!splashScreenBrandingImageFilename.empty())
|
||||||
output += "<preference name=\"AndroidWindowSplashScreenBrandingImage\" value=\""
|
output +=
|
||||||
+ splashScreenBrandingImageFilename + "\" />\n";
|
"<preference name=\"AndroidWindowSplashScreenBrandingImage\" "
|
||||||
|
"value=\"" +
|
||||||
|
splashScreenBrandingImageFilename + "\" />\n";
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
};
|
};
|
||||||
@@ -458,11 +488,15 @@ bool ExporterHelper::ExportElectronFiles(const gd::Project &project,
|
|||||||
->GetMangledSceneName(project.GetName())
|
->GetMangledSceneName(project.GetName())
|
||||||
.LowerCase()
|
.LowerCase()
|
||||||
.FindAndReplace(" ", "-")));
|
.FindAndReplace(" ", "-")));
|
||||||
|
// It's important to clean the project name from special characters,
|
||||||
|
// otherwise Windows executable may be corrupted when electron builds it.
|
||||||
|
gd::String jsonCleanedName = gd::Serializer::ToJSON(
|
||||||
|
gd::SerializerElement(CleanProjectName(project.GetName())));
|
||||||
|
|
||||||
{
|
{
|
||||||
gd::String str =
|
gd::String str =
|
||||||
fs.ReadFile(gdjsRoot + "/Runtime/Electron/package.json")
|
fs.ReadFile(gdjsRoot + "/Runtime/Electron/package.json")
|
||||||
.FindAndReplace("\"GDJS_GAME_NAME\"", jsonName)
|
.FindAndReplace("\"GDJS_GAME_NAME\"", jsonCleanedName)
|
||||||
.FindAndReplace("\"GDJS_GAME_PACKAGE_NAME\"", jsonPackageName)
|
.FindAndReplace("\"GDJS_GAME_PACKAGE_NAME\"", jsonPackageName)
|
||||||
.FindAndReplace("\"GDJS_GAME_AUTHOR\"", jsonAuthor)
|
.FindAndReplace("\"GDJS_GAME_AUTHOR\"", jsonAuthor)
|
||||||
.FindAndReplace("\"GDJS_GAME_VERSION\"", jsonVersion)
|
.FindAndReplace("\"GDJS_GAME_VERSION\"", jsonVersion)
|
||||||
@@ -651,10 +685,8 @@ void ExporterHelper::AddLibsInclude(bool pixiRenderers,
|
|||||||
InsertUnique(includesFiles, "pixi-renderers/pixi-bitmapfont-manager.js");
|
InsertUnique(includesFiles, "pixi-renderers/pixi-bitmapfont-manager.js");
|
||||||
InsertUnique(includesFiles,
|
InsertUnique(includesFiles,
|
||||||
"pixi-renderers/spriteruntimeobject-pixi-renderer.js");
|
"pixi-renderers/spriteruntimeobject-pixi-renderer.js");
|
||||||
InsertUnique(includesFiles,
|
InsertUnique(includesFiles, "pixi-renderers/CustomObjectPixiRenderer.js");
|
||||||
"pixi-renderers/CustomObjectPixiRenderer.js");
|
InsertUnique(includesFiles, "pixi-renderers/DebuggerPixiRenderer.js");
|
||||||
InsertUnique(includesFiles,
|
|
||||||
"pixi-renderers/DebuggerPixiRenderer.js");
|
|
||||||
InsertUnique(includesFiles,
|
InsertUnique(includesFiles,
|
||||||
"pixi-renderers/loadingscreen-pixi-renderer.js");
|
"pixi-renderers/loadingscreen-pixi-renderer.js");
|
||||||
InsertUnique(includesFiles, "pixi-renderers/pixi-effects-manager.js");
|
InsertUnique(includesFiles, "pixi-renderers/pixi-effects-manager.js");
|
||||||
|
@@ -152,8 +152,8 @@ struct PreviewExportOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the token to use by the game engine when requiring any resource stored on
|
* Set the token to use by the game engine when requiring any resource stored
|
||||||
* GDevelop Cloud buckets. Note that this is only useful during previews.
|
* on GDevelop Cloud buckets. Note that this is only useful during previews.
|
||||||
*/
|
*/
|
||||||
PreviewExportOptions &SetGDevelopResourceToken(
|
PreviewExportOptions &SetGDevelopResourceToken(
|
||||||
const gd::String &gdevelopResourceToken_) {
|
const gd::String &gdevelopResourceToken_) {
|
||||||
|
@@ -263,7 +263,7 @@ export default class ExportLauncher extends Component<Props, State> {
|
|||||||
t`A game with this ID already exists and you are not the owner.`
|
t`A game with this ID already exists and you are not the owner.`
|
||||||
),
|
),
|
||||||
i18n._(
|
i18n._(
|
||||||
t`A test link will be created but the game will not be registered.`
|
t`A link or file will be created but the game will not be registered.`
|
||||||
),
|
),
|
||||||
].join('\n\n'),
|
].join('\n\n'),
|
||||||
rawError: registerError,
|
rawError: registerError,
|
||||||
@@ -279,7 +279,7 @@ export default class ExportLauncher extends Component<Props, State> {
|
|||||||
t`You have reached the maximum number of games you can register! You can unregister games in your Games Dashboard.`
|
t`You have reached the maximum number of games you can register! You can unregister games in your Games Dashboard.`
|
||||||
),
|
),
|
||||||
i18n._(
|
i18n._(
|
||||||
t`A test link will be created but the game will not be registered.`
|
t`A link or file will be created but the game will not be registered.`
|
||||||
),
|
),
|
||||||
].join('\n\n'),
|
].join('\n\n'),
|
||||||
rawError: registerError,
|
rawError: registerError,
|
||||||
|
Reference in New Issue
Block a user