Skip to content

Commit

Permalink
Update PCK version display to match godotengine/godot#34020 changes, …
Browse files Browse the repository at this point in the history
…add version checks for 4.0(vulkan) branch.
  • Loading branch information
bruvzg committed Jan 6, 2020
1 parent 279619b commit 08f112b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 15 deletions.
30 changes: 17 additions & 13 deletions editor/gdre_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@

#include "core/version_generated.gen.h"

#if VERSION_MAJOR != 3
#if VERSION_MAJOR < 3
#error Unsupported Godot version
#endif

#if VERSION_MINOR == 2
#if ((VERSION_MAJOR == 3) && (VERSION_MINOR == 2)) || (VERSION_MAJOR == 4)
#include "core/crypto/crypto_core.h"
#else
#include "thirdparty/misc/md5.h"
Expand Down Expand Up @@ -850,9 +850,13 @@ void GodotREEditor::_pck_select_request(const String &p_path) {
uint32_t ver_minor = pck->get_32();
uint32_t ver_rev = pck->get_32();

pck_dialog->set_version(String(" ") + RTR("PCK version: ") + itos(version) + "; " + RTR("created by Godot engine: ") + itos(ver_major) + "." + itos(ver_minor) + "; " + ((is_emb) ? RTR("self contained exe") : RTR("standalone")));

print_warning(RTR("PCK version: ") + itos(version) + "; " + RTR("created by Godot engine: ") + itos(ver_major) + "." + itos(ver_minor) + RTR(" rev (unused) ") + itos(ver_rev) + "; " + ((is_emb) ? RTR("self contained exe") : RTR("standalone")), RTR("Read PCK"));
if ((ver_major < 3) || ((ver_major == 3) && (ver_minor < 2))) {
pck_dialog->set_version(String(" ") + RTR("PCK version: ") + itos(version) + "; " + RTR("created by Godot engine: ") + itos(ver_major) + "." + itos(ver_minor) + ".x; " + ((is_emb) ? RTR("self contained exe") : RTR("standalone")));
print_warning(RTR("PCK version: ") + itos(version) + "; " + RTR("created by Godot engine: ") + itos(ver_major) + "." + itos(ver_minor) + ".x; " + ((is_emb) ? RTR("self contained exe") : RTR("standalone")), RTR("Read PCK"));
} else {
pck_dialog->set_version(String(" ") + RTR("PCK version: ") + itos(version) + "; " + RTR("created by Godot engine: ") + itos(ver_major) + "." + itos(ver_minor) + "." + itos(ver_rev) + "; " + ((is_emb) ? RTR("self contained exe") : RTR("standalone")));
print_warning(RTR("PCK version: ") + itos(version) + "; " + RTR("created by Godot engine: ") + itos(ver_major) + "." + itos(ver_minor) + "." + itos(ver_rev) + "; " + ((is_emb) ? RTR("self contained exe") : RTR("standalone")), RTR("Read PCK"));
}
for (int i = 0; i < 16; i++) {
pck->get_32();
}
Expand Down Expand Up @@ -974,7 +978,7 @@ void GodotREEditor::_pck_select_request(const String &p_path) {

files_checked++;

#if VERSION_MINOR == 2
#if ((VERSION_MAJOR == 3) && (VERSION_MINOR == 2)) || (VERSION_MAJOR == 4)
CryptoCore::MD5Context ctx;
ctx.start();
#else
Expand All @@ -989,7 +993,7 @@ void GodotREEditor::_pck_select_request(const String &p_path) {

int got = pck->get_buffer(buf, MIN(32768, rq_size));
if (got > 0) {
#if VERSION_MINOR == 2
#if ((VERSION_MAJOR == 3) && (VERSION_MINOR == 2)) || (VERSION_MAJOR == 4)
ctx.update(buf, got);
#else
MD5Update(&md5, buf, got);
Expand All @@ -1000,7 +1004,7 @@ void GodotREEditor::_pck_select_request(const String &p_path) {
rq_size -= 32768;
}

#if VERSION_MINOR == 2
#if ((VERSION_MAJOR == 3) && (VERSION_MINOR == 2)) || (VERSION_MAJOR == 4)
unsigned char hash[16];
ctx.finish(hash);
#else
Expand All @@ -1014,7 +1018,7 @@ void GodotREEditor::_pck_select_request(const String &p_path) {

bool md5_match = true;
for (int j = 0; j < 16; j++) {
#if VERSION_MINOR == 2
#if ((VERSION_MAJOR == 3) && (VERSION_MINOR == 2)) || (VERSION_MAJOR == 4)
md5_match &= (hash[j] == md5_saved[j]);
file_md5 += String::num_uint64(hash[j], 16);
#else
Expand Down Expand Up @@ -1563,7 +1567,7 @@ uint64_t GodotREEditor::_pck_create_process_folder(EditorProgressGDDC *p_pr, con
} else {
FileAccess *file = FileAccess::open(p_path.plus_file(p_rel).plus_file(f), FileAccess::READ);

#if VERSION_MINOR == 2
#if ((VERSION_MAJOR == 3) && (VERSION_MINOR == 2)) || (VERSION_MAJOR == 4)
CryptoCore::MD5Context ctx;
ctx.start();
#else
Expand All @@ -1578,7 +1582,7 @@ uint64_t GodotREEditor::_pck_create_process_folder(EditorProgressGDDC *p_pr, con

int got = file->get_buffer(buf, MIN(32768, rq_size));
if (got > 0) {
#if VERSION_MINOR == 2
#if ((VERSION_MAJOR == 3) && (VERSION_MINOR == 2)) || (VERSION_MAJOR == 4)
ctx.update(buf, got);
#else
MD5Update(&md5, buf, got);
Expand All @@ -1589,7 +1593,7 @@ uint64_t GodotREEditor::_pck_create_process_folder(EditorProgressGDDC *p_pr, con
rq_size -= 32768;
}

#if VERSION_MINOR == 2
#if ((VERSION_MAJOR == 3) && (VERSION_MINOR == 2)) || (VERSION_MAJOR == 4)
unsigned char hash[16];
ctx.finish(hash);
#else
Expand All @@ -1599,7 +1603,7 @@ uint64_t GodotREEditor::_pck_create_process_folder(EditorProgressGDDC *p_pr, con
PackedFile finfo = PackedFile(offset, file->get_len());
finfo.name = p_rel.plus_file(f);
for (int j = 0; j < 16; j++) {
#if VERSION_MINOR == 2
#if ((VERSION_MAJOR == 3) && (VERSION_MINOR == 2)) || (VERSION_MAJOR == 4)
finfo.md5[j] = hash[j];
#else
finfo.md5[j] = md5.digest[j];
Expand Down
32 changes: 30 additions & 2 deletions editor/gdre_npck_dlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ NewPackDialog::NewPackDialog() {
ver_base->set_max(1);
ver_base->set_step(1);
ver_base->set_value(1);
script_vb->add_margin_child(RTR("PCK version (0 - Godot 2.x; 1 - Godot 3.x):"), ver_base);
ver_base->connect("value_changed", this, "_val_change");
script_vb->add_margin_child(RTR("PCK version (\"0\" - Godot 2.x; \"1\" - Godot 3.x+):"), ver_base);

HBoxContainer *dir_hbc = memnew(HBoxContainer);

Expand All @@ -35,22 +36,28 @@ NewPackDialog::NewPackDialog() {
ver_major->set_max(99999);
ver_major->set_step(1);
ver_major->set_value(VERSION_MAJOR);
ver_major->connect("value_changed", this, "_val_change");
dir_hbc->add_child(ver_major);

ver_minor = memnew(SpinBox);
ver_minor->set_min(0);
ver_minor->set_max(99999);
ver_minor->set_step(1);
ver_minor->set_value(VERSION_MINOR);
ver_minor->connect("value_changed", this, "_val_change");
dir_hbc->add_child(ver_minor);

ver_rev = memnew(SpinBox);
ver_rev->set_min(0);
ver_rev->set_max(99999);
ver_rev->set_step(1);
ver_rev->set_value(0);
ver_rev->connect("value_changed", this, "_val_change");
dir_hbc->add_child(ver_rev);

script_vb->add_margin_child(RTR("Target Godot engine version (note: revision number is ignored by the engine):"), dir_hbc);
_val_change();

script_vb->add_margin_child(RTR("Godot engine version (\"Major\".\"Minor\".\"Patch\", \"Patch\" value should be \"0\" for all pre 3.2 versions):"), dir_hbc);

emb_selection = memnew(FileDialog);
emb_selection->set_access(FileDialog::ACCESS_FILESYSTEM);
Expand Down Expand Up @@ -86,6 +93,26 @@ NewPackDialog::NewPackDialog() {
add_cancel(RTR("Cancel"));
}

void NewPackDialog::_val_change(double p_val) {
#ifdef TOOLS_ENABLED
Color error_color = (EditorNode::get_singleton()) ? EditorNode::get_singleton()->get_gui_base()->get_color("error_color", "Editor") : Color(1, 0, 0);
#else
Color error_color = Color(1, 0, 0);
#endif
Color def_color = ver_major->get_line_edit()->get_color("font_color");
if ((ver_major->get_value() <= 2 && ver_base->get_value() != 0) || (ver_major->get_value() > 2 && ver_base->get_value() != 1)) {
ver_base->get_line_edit()->set("custom_colors/font_color", error_color);
} else {
ver_base->get_line_edit()->set("custom_colors/font_color", def_color);
}

if ((ver_major->get_value() < 3 || (ver_major->get_value() == 3 && ver_minor->get_value() < 2)) && (ver_rev->get_value() != 0)) {
ver_rev->get_line_edit()->set("custom_colors/font_color", error_color);
} else {
ver_rev->get_line_edit()->set("custom_colors/font_color", def_color);
}
}

void NewPackDialog::_exe_select_pressed() {
emb_selection->popup_centered(Size2(800, 600));
}
Expand Down Expand Up @@ -137,4 +164,5 @@ void NewPackDialog::_notification(int p_notification) {
void NewPackDialog::_bind_methods() {
ClassDB::bind_method(D_METHOD("_exe_select_pressed"), &NewPackDialog::_exe_select_pressed);
ClassDB::bind_method(D_METHOD("_exe_select_request", "path"), &NewPackDialog::_exe_select_request);
ClassDB::bind_method(D_METHOD("_val_change", "val"), &NewPackDialog::_val_change);
}
1 change: 1 addition & 0 deletions editor/gdre_npck_dlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class NewPackDialog : public AcceptDialog {
FileDialog *emb_selection;

protected:
void _val_change(double p_val = 0.0f);
void _notification(int p_notification);
static void _bind_methods();

Expand Down

0 comments on commit 08f112b

Please sign in to comment.