mirror of
https://github.com/godotengine/godot.git
synced 2026-01-06 10:11:57 +03:00
Add a "version" project setting and use it in new export presets
This makes it easy to retrieve the project version at runtime for display purposes, while simplifying the export preset configuration. You can now leave the version empty unless you need to override it on a per-preset basis. Since export presets save the values of default values to the `export_presets.cfg` file, this change only affects export presets created after this commit was merged.
This commit is contained in:
@@ -30,6 +30,8 @@
|
||||
|
||||
#include "editor_export.h"
|
||||
|
||||
#include "core/config/project_settings.h"
|
||||
|
||||
bool EditorExportPreset::_set(const StringName &p_name, const Variant &p_value) {
|
||||
values[p_name] = p_value;
|
||||
EditorExport::singleton->save_presets();
|
||||
@@ -332,4 +334,35 @@ Variant EditorExportPreset::get_or_env(const StringName &p_name, const String &p
|
||||
return get(p_name, r_valid);
|
||||
}
|
||||
|
||||
String EditorExportPreset::get_version(const StringName &p_preset_string, bool p_windows_version) const {
|
||||
String result = get(p_preset_string);
|
||||
if (result.is_empty()) {
|
||||
result = GLOBAL_GET("application/config/version");
|
||||
|
||||
if (p_windows_version) {
|
||||
// Modify version number to match Windows constraints (version numbers must have 4 components).
|
||||
const PackedStringArray result_split = result.split(".");
|
||||
String windows_version;
|
||||
if (result_split.is_empty()) {
|
||||
// Use a valid fallback if the version string is empty, as a version number must be specified.
|
||||
result = "1.0.0.0";
|
||||
} else if (result_split.size() == 1) {
|
||||
result = result + ".0.0.0";
|
||||
} else if (result_split.size() == 2) {
|
||||
result = result + ".0.0";
|
||||
} else if (result_split.size() == 3) {
|
||||
result = result + ".0";
|
||||
} else {
|
||||
// 4 components or more in the version string. Trim to contain only the first 4 components.
|
||||
result = vformat("%s.%s.%s.%s", result_split[0] + result_split[1] + result_split[2] + result_split[3]);
|
||||
}
|
||||
} else if (result.is_empty()) {
|
||||
// Use a valid fallback if the version string is empty, as a version number must be specified.
|
||||
result = "1.0.0";
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
EditorExportPreset::EditorExportPreset() {}
|
||||
|
||||
@@ -154,6 +154,13 @@ public:
|
||||
|
||||
Variant get_or_env(const StringName &p_name, const String &p_env_var, bool *r_valid = nullptr) const;
|
||||
|
||||
// Return the preset's version number, or fall back to the
|
||||
// `application/config/version` project setting if set to an empty string.
|
||||
// If `p_windows_version` is `true`, formats the returned version number to
|
||||
// be compatible with Windows executable metadata (which requires a
|
||||
// 4-component format).
|
||||
String get_version(const StringName &p_name, bool p_windows_version = false) const;
|
||||
|
||||
const HashMap<StringName, PropertyInfo> &get_properties() const { return properties; }
|
||||
const HashMap<StringName, Variant> &get_values() const { return values; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user