mirror of
https://github.com/godotengine/godot.git
synced 2024-11-21 19:42:43 +00:00
Rework and simplify update checking logic
This commit is contained in:
parent
705b7a0b0b
commit
44593eecc7
@ -63,7 +63,7 @@ void EngineUpdateLabel::_http_request_completed(int p_result, int p_response_cod
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Array version_data;
|
Array version_array;
|
||||||
{
|
{
|
||||||
String s;
|
String s;
|
||||||
const uint8_t *r = p_body.ptr();
|
const uint8_t *r = p_body.ptr();
|
||||||
@ -80,23 +80,22 @@ void EngineUpdateLabel::_http_request_completed(int p_result, int p_response_cod
|
|||||||
_set_message(TTR("Received JSON data is not a valid version array."), theme_cache.error_color);
|
_set_message(TTR("Received JSON data is not a valid version array."), theme_cache.error_color);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
version_data = result;
|
version_array = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateMode update_mode = UpdateMode(int(EDITOR_GET("network/connection/engine_version_update_mode")));
|
UpdateMode update_mode = UpdateMode(int(EDITOR_GET("network/connection/engine_version_update_mode")));
|
||||||
bool stable_only = update_mode == UpdateMode::NEWEST_STABLE || update_mode == UpdateMode::NEWEST_PATCH;
|
bool stable_only = update_mode == UpdateMode::NEWEST_STABLE || update_mode == UpdateMode::NEWEST_PATCH;
|
||||||
|
|
||||||
const Dictionary version_info = Engine::get_singleton()->get_version_info();
|
const Dictionary current_version_info = Engine::get_singleton()->get_version_info();
|
||||||
int current_major = version_info["major"];
|
int current_major = current_version_info.get("major", 0);
|
||||||
int current_minor = version_info["minor"];
|
int current_minor = current_version_info.get("minor", 0);
|
||||||
int current_patch = version_info["patch"];
|
int current_patch = current_version_info.get("patch", 0);
|
||||||
|
|
||||||
Dictionary found_version_info;
|
for (const Variant &data_bit : version_array) {
|
||||||
for (const Variant &data_bit : version_data) {
|
const Dictionary version_info = data_bit;
|
||||||
const Dictionary info = data_bit;
|
|
||||||
|
|
||||||
const String version_string = info["name"];
|
const String base_version_string = version_info.get("name", "");
|
||||||
const PackedStringArray version_bits = version_string.split(".");
|
const PackedStringArray version_bits = base_version_string.split(".");
|
||||||
|
|
||||||
if (version_bits.size() < 2) {
|
if (version_bits.size() < 2) {
|
||||||
continue;
|
continue;
|
||||||
@ -120,55 +119,45 @@ void EngineUpdateLabel::_http_request_completed(int p_result, int p_response_cod
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minor > current_minor || patch > current_patch) {
|
const Array releases = version_info.get("releases", Array());
|
||||||
String version_type = info["flavor"];
|
if (releases.is_empty()) {
|
||||||
if (stable_only && _get_version_type(version_type, nullptr) != VersionType::STABLE) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
found_version = version_string;
|
const Dictionary newest_release = releases[0];
|
||||||
found_version += "-" + version_type;
|
const String release_string = newest_release.get("name", "unknown");
|
||||||
break;
|
|
||||||
} else if (minor == current_minor && patch == current_patch) {
|
int release_index;
|
||||||
found_version_info = info;
|
VersionType release_type = _get_version_type(release_string, &release_index);
|
||||||
found_version = version_string;
|
|
||||||
break;
|
if (minor > current_minor || patch > current_patch) {
|
||||||
}
|
if (stable_only && release_type != VersionType::STABLE) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found_version_info.is_empty() && !found_version.is_empty()) {
|
available_newer_version = vformat("%s-%s", base_version_string, release_string);
|
||||||
_set_status(UpdateStatus::UPDATE_AVAILABLE);
|
break;
|
||||||
_set_message(vformat(TTR("Update available: %s."), found_version), theme_cache.update_color);
|
|
||||||
return;
|
|
||||||
} else if (found_version_info.is_empty() || stable_only) {
|
|
||||||
_set_status(UpdateStatus::UP_TO_DATE);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int current_version_index;
|
int current_version_index;
|
||||||
VersionType current_version_type = _get_version_type(version_info["status"], ¤t_version_index);
|
VersionType current_version_type = _get_version_type(current_version_info.get("status", "unknown"), ¤t_version_index);
|
||||||
|
|
||||||
const Array releases = found_version_info["releases"];
|
if (int(release_type) > int(current_version_type)) {
|
||||||
for (const Variant &data_bit : version_data) {
|
break;
|
||||||
const Dictionary info = data_bit;
|
}
|
||||||
|
|
||||||
const String version_string = info["name"];
|
if (int(release_type) == int(current_version_type) && release_index < current_version_index) {
|
||||||
int version_index;
|
break;
|
||||||
VersionType version_type = _get_version_type(version_string, &version_index);
|
}
|
||||||
|
|
||||||
if (int(version_type) < int(current_version_type) || version_index > current_version_index) {
|
available_newer_version = vformat("%s-%s", base_version_string, release_string);
|
||||||
found_version += "-" + version_string;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!available_newer_version.is_empty()) {
|
||||||
_set_status(UpdateStatus::UPDATE_AVAILABLE);
|
_set_status(UpdateStatus::UPDATE_AVAILABLE);
|
||||||
_set_message(vformat(TTR("Update available: %s."), found_version), theme_cache.update_color);
|
_set_message(vformat(TTR("Update available: %s."), available_newer_version), theme_cache.update_color);
|
||||||
return;
|
} else if (available_newer_version.is_empty()) {
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (current_version_index == DEV_VERSION) {
|
|
||||||
// Since version index can't be determined and no strictly newer version exists, display a different status.
|
|
||||||
_set_status(UpdateStatus::DEV);
|
|
||||||
} else {
|
|
||||||
_set_status(UpdateStatus::UP_TO_DATE);
|
_set_status(UpdateStatus::UP_TO_DATE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -184,7 +173,7 @@ void EngineUpdateLabel::_set_message(const String &p_message, const Color &p_col
|
|||||||
|
|
||||||
void EngineUpdateLabel::_set_status(UpdateStatus p_status) {
|
void EngineUpdateLabel::_set_status(UpdateStatus p_status) {
|
||||||
status = p_status;
|
status = p_status;
|
||||||
if (status == UpdateStatus::DEV || status == UpdateStatus::BUSY || status == UpdateStatus::UP_TO_DATE) {
|
if (status == UpdateStatus::BUSY || status == UpdateStatus::UP_TO_DATE) {
|
||||||
// Hide the label to prevent unnecessary distraction.
|
// Hide the label to prevent unnecessary distraction.
|
||||||
hide();
|
hide();
|
||||||
return;
|
return;
|
||||||
@ -306,7 +295,7 @@ void EngineUpdateLabel::pressed() {
|
|||||||
} break;
|
} break;
|
||||||
|
|
||||||
case UpdateStatus::UPDATE_AVAILABLE: {
|
case UpdateStatus::UPDATE_AVAILABLE: {
|
||||||
OS::get_singleton()->shell_open("https://godotengine.org/download/archive/" + found_version);
|
OS::get_singleton()->shell_open("https://godotengine.org/download/archive/" + available_newer_version);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
|
@ -60,7 +60,6 @@ private:
|
|||||||
|
|
||||||
enum class UpdateStatus {
|
enum class UpdateStatus {
|
||||||
NONE,
|
NONE,
|
||||||
DEV,
|
|
||||||
OFFLINE,
|
OFFLINE,
|
||||||
BUSY,
|
BUSY,
|
||||||
ERROR,
|
ERROR,
|
||||||
@ -79,7 +78,7 @@ private:
|
|||||||
|
|
||||||
UpdateStatus status = UpdateStatus::NONE;
|
UpdateStatus status = UpdateStatus::NONE;
|
||||||
bool checked_update = false;
|
bool checked_update = false;
|
||||||
String found_version;
|
String available_newer_version;
|
||||||
|
|
||||||
bool _can_check_updates() const;
|
bool _can_check_updates() const;
|
||||||
void _check_update();
|
void _check_update();
|
||||||
|
Loading…
Reference in New Issue
Block a user