Skip to content

Commit

Permalink
changed the way the update message is displayed
Browse files Browse the repository at this point in the history
added display of the current version
  • Loading branch information
DmitriySalnikov committed Jul 20, 2023
1 parent f7ba15f commit 8594a15
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
22 changes: 15 additions & 7 deletions src/asset_library_update_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "version.h"

MSVC_WARNING_DISABLE(4244)
#include <godot_cpp/classes/engine.hpp>
#include <godot_cpp/classes/json.hpp>
#include <godot_cpp/classes/project_settings.hpp>
#include <godot_cpp/classes/scene_tree.hpp>
Expand Down Expand Up @@ -43,12 +44,14 @@ void AssetLibraryUpdateChecker::request_completed(int result, int response_code,
}

if (ver_num > DD3D_VERSION) {
PRINT_WARNING(String("\nAn update for Debug Draw 3D is available. Current: ") + DD3D_VERSION_STR + " -> New: " + ver + "\n" +
"It will not be possible to update the addon through the editor, since its files are currently locked.\n" +
"You need to download the archive from this link (select the URL below, click copy and paste this address into your browser):\n" + download_url + "\n" +
"Then close the editor and replace the files in your project with new ones from the archive\n" +
"(In the archive, first go inside the godot_debug_draw_3d-XXXXX... folder and extract its contents).\n" +
"To disable this alert, go to the Project Settings in the \"debug_draw_3d/settings/\" section");
PRINT(String("=====\n") +
"An update for " + addon_name + " is available. Current: " + DD3D_VERSION_STR + " -> New: " + ver + "\n" +
"It will not be possible to update the addon through the editor, since its files are currently locked.\n" +
"You need to download the archive from this link (select the URL below, click copy and paste this address into your browser):\n" + download_url + "\n" +
"Then close the editor and replace the files in your project with new ones from the archive\n" +
"(In the archive, first go inside the " + repository_name + "-XXXXX... folder and extract its contents).\n" +
"To disable this alert, go to the Project Settings in the \"" + root_settings_section + "\" section\n"+
"=====");
}
}

Expand All @@ -64,7 +67,12 @@ void AssetLibraryUpdateChecker::init() {
}

AssetLibraryUpdateChecker::AssetLibraryUpdateChecker() {
DEFINE_SETTING_AND_GET(bool check_updates, "debug_draw_3d/settings/check_for_updates", true, Variant::BOOL);
addon_name = "Debug Draw 3D";
repository_name = "godot_debug_draw_3d";
root_settings_section = "debug_draw_3d/settings/";

DEFINE_SETTING_READ_ONLY(root_settings_section + "addon_version", DD3D_VERSION_STR, Variant::STRING);
DEFINE_SETTING_AND_GET(bool check_updates, root_settings_section + "check_for_updates", true, Variant::BOOL);

if (check_updates)
call_deferred(TEXT(init));
Expand Down
3 changes: 3 additions & 0 deletions src/asset_library_update_checker.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class AssetLibraryUpdateChecker : public RefCounted {

private:
HTTPRequest *request = nullptr;
String addon_name;
String repository_name;
String root_settings_section;

protected:
static void _bind_methods();
Expand Down
11 changes: 11 additions & 0 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ static String get_file_name_in_repository(const String &name) {
PS()->set_initial_value(path, def); \
} \
var = PS()->get_setting(path)
#define DEFINE_SETTING_READ_ONLY(path, def, type) \
{ \
PS()->set_setting(path, def); \
Dictionary info; \
info["name"] = path; \
info["type"] = type; \
/* Does not work in the ProjectSettings */ \
info["usage"] = PROPERTY_USAGE_READ_ONLY; \
PS()->add_property_info(info); \
PS()->set_initial_value(path, def); \
}

// TODO: temp constants. I didn't find them in gdnative api

Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#define DD3D_MAJOR 1
#define DD3D_MINOR 1
#define DD3D_PATCH 1
#define DD3D_PATCH 2
#define DD3D_VERSION ((DD3D_MAJOR << (8 * 3)) + (DD3D_MINOR << (8 * 2)) + (DD3D_PATCH << (8 * 1)))

#define _DD3D_VERSION_STR_TEXT(text) #text
Expand Down

0 comments on commit 8594a15

Please sign in to comment.