From b49226e0850d6dd30801881433bf3fef1f1608b1 Mon Sep 17 00:00:00 2001 From: PouleyKetchoupp Date: Tue, 20 Aug 2019 13:59:46 +0200 Subject: [PATCH] Support for file not found in ConfigFile::Load and handle a few specific cases EditorSettings::set_project_metadata: creates project_metadata.cfg if it doesn't exist EditorPlugin::get_config: removed (not used) Fixes #31444 --- core/io/config_file.cpp | 2 +- drivers/unix/file_access_unix.cpp | 13 +++++++++++-- drivers/windows/file_access_windows.cpp | 13 ++++++++++--- editor/editor_node.cpp | 1 - editor/editor_plugin.cpp | 7 ------- editor/editor_plugin.h | 5 ----- editor/editor_settings.cpp | 2 +- 7 files changed, 23 insertions(+), 20 deletions(-) diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp index 70bb816acd6..9063e028be4 100644 --- a/core/io/config_file.cpp +++ b/core/io/config_file.cpp @@ -201,7 +201,7 @@ Error ConfigFile::load(const String &p_path) { FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); if (!f) - return ERR_CANT_OPEN; + return err; return _internal_load(p_path, f); } diff --git a/drivers/unix/file_access_unix.cpp b/drivers/unix/file_access_unix.cpp index 5820a59019e..071734eb48d 100644 --- a/drivers/unix/file_access_unix.cpp +++ b/drivers/unix/file_access_unix.cpp @@ -38,6 +38,8 @@ #include #include +#include + #if defined(UNIX_ENABLED) #include #endif @@ -112,8 +114,15 @@ Error FileAccessUnix::_open(const String &p_path, int p_mode_flags) { f = fopen(path.utf8().get_data(), mode_string); if (f == NULL) { - last_error = ERR_FILE_CANT_OPEN; - return ERR_FILE_CANT_OPEN; + switch (errno) { + case ENOENT: { + last_error = ERR_FILE_NOT_FOUND; + } break; + default: { + last_error = ERR_FILE_CANT_OPEN; + } break; + } + return last_error; } else { last_error = OK; flags = p_mode_flags; diff --git a/drivers/windows/file_access_windows.cpp b/drivers/windows/file_access_windows.cpp index c12a2d75a83..7db847d6eda 100644 --- a/drivers/windows/file_access_windows.cpp +++ b/drivers/windows/file_access_windows.cpp @@ -114,11 +114,18 @@ Error FileAccessWindows::_open(const String &p_path, int p_mode_flags) { path = path + ".tmp"; } - _wfopen_s(&f, path.c_str(), mode_string); + errno_t errcode = _wfopen_s(&f, path.c_str(), mode_string); if (f == NULL) { - last_error = ERR_FILE_CANT_OPEN; - return ERR_FILE_CANT_OPEN; + switch (errcode) { + case ENOENT: { + last_error = ERR_FILE_NOT_FOUND; + } break; + default: { + last_error = ERR_FILE_CANT_OPEN; + } break; + } + return last_error; } else { last_error = OK; flags = p_mode_flags; diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 311f8b295b8..71e70300e93 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -2954,7 +2954,6 @@ void EditorNode::set_addon_plugin_enabled(const String &p_addon, bool p_enabled, EditorPlugin *ep = memnew(EditorPlugin); ep->set_script(script.get_ref_ptr()); - ep->set_dir_cache(p_addon); plugin_addons[p_addon] = ep; add_editor_plugin(ep, p_config_changed); diff --git a/editor/editor_plugin.cpp b/editor/editor_plugin.cpp index 4b6afcbb866..e27f1ab9ebc 100644 --- a/editor/editor_plugin.cpp +++ b/editor/editor_plugin.cpp @@ -324,13 +324,6 @@ void EditorPlugin::remove_autoload_singleton(const String &p_name) { EditorNode::get_singleton()->get_project_settings()->get_autoload_settings()->autoload_remove(p_name); } -Ref EditorPlugin::get_config() { - Ref cf = memnew(ConfigFile); - Error err = cf->load(_dir_cache.plus_file("plugin.cfg")); - ERR_FAIL_COND_V(err != OK, cf); - return cf; -} - ToolButton *EditorPlugin::add_control_to_bottom_panel(Control *p_control, const String &p_title) { ERR_FAIL_NULL_V(p_control, NULL); return EditorNode::get_singleton()->add_bottom_panel_item(p_title, p_control); diff --git a/editor/editor_plugin.h b/editor/editor_plugin.h index 7b6f55e93d6..8941dfa28cb 100644 --- a/editor/editor_plugin.h +++ b/editor/editor_plugin.h @@ -117,7 +117,6 @@ class EditorPlugin : public Node { bool force_draw_over_forwarding_enabled; String last_main_screen_name; - String _dir_cache; protected: static void _bind_methods(); @@ -236,10 +235,6 @@ public: void add_autoload_singleton(const String &p_name, const String &p_path); void remove_autoload_singleton(const String &p_name); - void set_dir_cache(const String &p_dir) { _dir_cache = p_dir; } - String get_dir_cache() { return _dir_cache; } - Ref get_config(); - void enable_plugin(); void disable_plugin(); diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index cb3bfa3a496..3bd333692fe 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -1216,7 +1216,7 @@ void EditorSettings::set_project_metadata(const String &p_section, const String String path = get_project_settings_dir().plus_file("project_metadata.cfg"); Error err; err = cf->load(path); - ERR_FAIL_COND(err != OK); + ERR_FAIL_COND(err != OK && err != ERR_FILE_NOT_FOUND); cf->set_value(p_section, p_key, p_data); err = cf->save(path); ERR_FAIL_COND(err != OK);