diff options
author | Hugo Locurcio <hugo.locurcio@hugo.pro> | 2021-04-06 01:44:15 +0200 |
---|---|---|
committer | Hugo Locurcio <hugo.locurcio@hugo.pro> | 2021-04-06 14:27:15 +0200 |
commit | 09f38ea2150cbf6aa3915bd2f5734df7ef24c88f (patch) | |
tree | b066b94f4125d82ef80b10815351f7583aa798e4 /editor/editor_node.cpp | |
parent | f4b82814f89d992bc0119245590737ae361a0358 (diff) |
Improve error messages for missing export presets when using `--export`
- Display a specific error message if the project doesn't have an
`export_presets.cfg` file.
- Display a list of detected export presets if an invalid export
preset name is supplied.
Diffstat (limited to 'editor/editor_node.cpp')
-rw-r--r-- | editor/editor_node.cpp | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 6a50976908..9ca46cfcc0 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -794,17 +794,27 @@ void EditorNode::_fs_changed() { } preset.unref(); } + if (preset.is_null()) { - export_error = vformat( - "Invalid export preset name: %s. Make sure `export_presets.cfg` is present in the current directory.", - preset_name); + DirAccessRef da = DirAccess::create(DirAccess::ACCESS_RESOURCES); + if (da->file_exists("res://export_presets.cfg")) { + export_error = vformat( + "Invalid export preset name: %s.\nThe following presets were detected in this project's `export_presets.cfg`:\n\n", + preset_name); + for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); ++i) { + // Write the preset name between double quotes since it needs to be written between quotes on the command line if it contains spaces. + export_error += vformat(" \"%s\"\n", EditorExport::get_singleton()->get_export_preset(i)->get_name()); + } + } else { + export_error = "This project doesn't have an `export_presets.cfg` file at its root.\nCreate an export preset from the \"Project > Export\" dialog and try again."; + } } else { Ref<EditorExportPlatform> platform = preset->get_platform(); const String export_path = export_defer.path.is_empty() ? preset->get_export_path() : export_defer.path; if (export_path.is_empty()) { - export_error = vformat("Export preset '%s' doesn't have a default export path, and none was specified.", preset_name); + export_error = vformat("Export preset \"%s\" doesn't have a default export path, and none was specified.", preset_name); } else if (platform.is_null()) { - export_error = vformat("Export preset '%s' doesn't have a matching platform.", preset_name); + export_error = vformat("Export preset \"%s\" doesn't have a matching platform.", preset_name); } else { Error err = OK; if (export_defer.pack_only) { // Only export .pck or .zip data pack. @@ -817,7 +827,7 @@ void EditorNode::_fs_changed() { String config_error; bool missing_templates; if (!platform->can_export(preset, config_error, missing_templates)) { - ERR_PRINT(vformat("Cannot export project with preset '%s' due to configuration errors:\n%s", preset_name, config_error)); + ERR_PRINT(vformat("Cannot export project with preset \"%s\" due to configuration errors:\n%s", preset_name, config_error)); err = missing_templates ? ERR_FILE_NOT_FOUND : ERR_UNCONFIGURED; } else { err = platform->export_project(preset, export_defer.debug, export_path); @@ -827,13 +837,13 @@ void EditorNode::_fs_changed() { case OK: break; case ERR_FILE_NOT_FOUND: - export_error = vformat("Project export failed for preset '%s', the export template appears to be missing.", preset_name); + export_error = vformat("Project export failed for preset \"%s\". The export template appears to be missing.", preset_name); break; case ERR_FILE_BAD_PATH: - export_error = vformat("Project export failed for preset '%s', the target path '%s' appears to be invalid.", preset_name, export_path); + export_error = vformat("Project export failed for preset \"%s\". The target path \"%s\" appears to be invalid.", preset_name, export_path); break; default: - export_error = vformat("Project export failed with error code %d for preset '%s'.", (int)err, preset_name); + export_error = vformat("Project export failed with error code %d for preset \"%s\".", (int)err, preset_name); break; } } |