[Export] Improve app / file version validation.
This commit is contained in:
parent
6afd320984
commit
a0bd5f8568
|
@ -334,31 +334,55 @@ Variant EditorExportPreset::get_or_env(const StringName &p_name, const String &p
|
||||||
return get(p_name, r_valid);
|
return get(p_name, r_valid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ bool _check_digits(const String &p_str) {
|
||||||
|
for (int i = 0; i < p_str.length(); i++) {
|
||||||
|
char32_t c = p_str.operator[](i);
|
||||||
|
if (!is_digit(c)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
String EditorExportPreset::get_version(const StringName &p_preset_string, bool p_windows_version) const {
|
String EditorExportPreset::get_version(const StringName &p_preset_string, bool p_windows_version) const {
|
||||||
String result = get(p_preset_string);
|
String result = get(p_preset_string);
|
||||||
if (result.is_empty()) {
|
if (result.is_empty()) {
|
||||||
result = GLOBAL_GET("application/config/version");
|
result = GLOBAL_GET("application/config/version");
|
||||||
|
|
||||||
if (p_windows_version) {
|
// Split and validate version number components.
|
||||||
// Modify version number to match Windows constraints (version numbers must have 4 components).
|
const PackedStringArray result_split = result.split(".", false);
|
||||||
const PackedStringArray result_split = result.split(".");
|
bool valid_version = !result_split.is_empty();
|
||||||
String windows_version;
|
for (const String &E : result_split) {
|
||||||
if (result_split.is_empty()) {
|
if (!_check_digits(E)) {
|
||||||
// Use a valid fallback if the version string is empty, as a version number must be specified.
|
valid_version = false;
|
||||||
result = "1.0.0.0";
|
break;
|
||||||
} else if (result_split.size() == 1) {
|
}
|
||||||
result = result + ".0.0.0";
|
}
|
||||||
} else if (result_split.size() == 2) {
|
|
||||||
result = result + ".0.0";
|
if (valid_version) {
|
||||||
} else if (result_split.size() == 3) {
|
if (p_windows_version) {
|
||||||
result = result + ".0";
|
// Modify version number to match Windows constraints (version numbers must have 4 components).
|
||||||
} else {
|
if (result_split.size() == 1) {
|
||||||
// 4 components or more in the version string. Trim to contain only the first 4 components.
|
result = result + ".0.0.0";
|
||||||
result = vformat("%s.%s.%s.%s", result_split[0] + result_split[1] + result_split[2] + result_split[3]);
|
} else if (result_split.size() == 2) {
|
||||||
|
result = result + ".0.0";
|
||||||
|
} else if (result_split.size() == 3) {
|
||||||
|
result = result + ".0";
|
||||||
|
} else {
|
||||||
|
result = vformat("%s.%s.%s.%s", result_split[0], result_split[1], result_split[2], result_split[3]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result = String(".").join(result_split);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!result.is_empty()) {
|
||||||
|
WARN_PRINT(vformat("Invalid version number \"%s\". The version number can only contain numeric characters (0-9) and non-consecutive periods (.).", result));
|
||||||
|
}
|
||||||
|
if (p_windows_version) {
|
||||||
|
result = "1.0.0.0";
|
||||||
|
} else {
|
||||||
|
result = "1.0.0";
|
||||||
}
|
}
|
||||||
} 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";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue