Detect external modification of project.godot

This commit is contained in:
kobewi 2021-01-17 01:09:17 +01:00
parent 412125f191
commit c390c82014
5 changed files with 25 additions and 4 deletions

View File

@ -597,6 +597,7 @@ Error ProjectSettings::_load_settings_text(const String &p_path) {
// If we're loading a project.godot from source code, we can operate some
// ProjectSettings conversions if need be.
_convert_to_last_version(config_version);
last_save_time = FileAccess::get_modified_time(get_resource_path().plus_file("project.godot"));
return OK;
} else if (err != OK) {
ERR_PRINT("Error parsing " + p_path + " at line " + itos(lines) + ": " + error_text + " File might be corrupted.");
@ -676,7 +677,11 @@ void ProjectSettings::clear(const String &p_name) {
}
Error ProjectSettings::save() {
return save_custom(get_resource_path().plus_file("project.godot"));
Error error = save_custom(get_resource_path().plus_file("project.godot"));
if (error == OK) {
last_save_time = FileAccess::get_modified_time(get_resource_path().plus_file("project.godot"));
}
return error;
}
Error ProjectSettings::_save_settings_binary(const String &p_file, const Map<String, List<String>> &props, const CustomMap &p_custom, const String &p_custom_features) {

View File

@ -78,6 +78,8 @@ protected:
int last_order = NO_BUILTIN_ORDER_BASE;
int last_builtin_order = 0;
uint64_t last_save_time = 0;
Map<StringName, VariantContainer> props;
String resource_path;
Map<StringName, PropertyInfo> custom_prop_info;
@ -113,7 +115,6 @@ protected:
Error _setup(const String &p_path, const String &p_main_pack, bool p_upwards = false);
protected:
static void _bind_methods();
public:
@ -150,6 +151,7 @@ public:
Error save();
void set_custom_property_info(const String &p_prop, const PropertyInfo &p_info);
const Map<StringName, PropertyInfo> &get_custom_property_info() const;
uint64_t get_last_saved_time() { return last_save_time; }
Vector<String> get_optimizer_presets() const;

View File

@ -111,7 +111,7 @@ public:
struct EditedScene {
Node *root = nullptr;
String path;
uint64_t file_modified_time;
uint64_t file_modified_time = 0;
Dictionary editor_states;
List<Node *> selection;
Vector<EditorHistory::History> history_stored;

View File

@ -904,6 +904,13 @@ void EditorNode::_scan_external_changes() {
}
}
String project_settings_path = ProjectSettings::get_singleton()->get_resource_path().plus_file("project.godot");
if (FileAccess::get_modified_time(project_settings_path) > ProjectSettings::get_singleton()->get_last_saved_time()) {
TreeItem *ti = disk_changed_list->create_item(r);
ti->set_text(0, "project.godot");
need_reload = true;
}
if (need_reload) {
disk_changed->call_deferred("popup_centered_ratio", 0.5);
}
@ -911,6 +918,7 @@ void EditorNode::_scan_external_changes() {
void EditorNode::_resave_scenes(String p_str) {
save_all_scenes();
ProjectSettings::get_singleton()->save();
disk_changed->hide();
}
@ -932,7 +940,7 @@ void EditorNode::_reload_modified_scenes() {
Error err = load_scene(filename, false, false, true, false, true);
if (err != OK) {
ERR_PRINT("Failed to load scene");
ERR_PRINT(vformat("Failed to load scene: %s", filename));
}
editor_data.move_edited_scene_to_index(i);
}
@ -944,6 +952,10 @@ void EditorNode::_reload_modified_scenes() {
disk_changed->hide();
}
void EditorNode::_reload_project_settings() {
ProjectSettings::get_singleton()->setup(ProjectSettings::get_singleton()->get_resource_path(), String(), true);
}
void EditorNode::_vp_resized() {
}
@ -6681,6 +6693,7 @@ EditorNode::EditorNode() {
disk_changed_list->set_v_size_flags(Control::SIZE_EXPAND_FILL);
disk_changed->connect("confirmed", callable_mp(this, &EditorNode::_reload_modified_scenes));
disk_changed->connect("confirmed", callable_mp(this, &EditorNode::_reload_project_settings));
disk_changed->get_ok_button()->set_text(TTR("Reload"));
disk_changed->add_button(TTR("Resave"), !DisplayServer::get_singleton()->get_swap_cancel_ok(), "resave");

View File

@ -646,6 +646,7 @@ private:
void _resources_changed(const Vector<String> &p_resources);
void _scan_external_changes();
void _reload_modified_scenes();
void _reload_project_settings();
void _resave_scenes(String p_str);
void _feature_profile_changed();