diff options
author | DmitriySalnikov <salnikov.mine@yandex.ru> | 2024-01-11 15:33:35 +0300 |
---|---|---|
committer | DmitriySalnikov <salnikov.mine@yandex.ru> | 2024-04-05 00:14:23 +0300 |
commit | b73e740786302b3e53f66d57f7a798031b1b0d26 (patch) | |
tree | 1475e65278973629ede4683aa2db174a6d87b5ad /core/extension | |
parent | f6a78f83aa4b74aa5cb80ca2e3419448b1998e4f (diff) | |
download | redot-engine-b73e740786302b3e53f66d57f7a798031b1b0d26.tar.gz |
Add renaming of PDB files to avoid blocking them
Diffstat (limited to 'core/extension')
-rw-r--r-- | core/extension/gdextension.cpp | 61 | ||||
-rw-r--r-- | core/extension/gdextension.h | 7 |
2 files changed, 6 insertions, 62 deletions
diff --git a/core/extension/gdextension.cpp b/core/extension/gdextension.cpp index 0ed4c3380c..546c40e9cb 100644 --- a/core/extension/gdextension.cpp +++ b/core/extension/gdextension.cpp @@ -729,53 +729,18 @@ GDExtensionInterfaceFunctionPtr GDExtension::get_interface_function(const String Error GDExtension::open_library(const String &p_path, const String &p_entry_symbol) { String abs_path = ProjectSettings::get_singleton()->globalize_path(p_path); -#if defined(WINDOWS_ENABLED) && defined(TOOLS_ENABLED) - // If running on the editor on Windows, we copy the library and open the copy. - // This is so the original file isn't locked and can be updated by a compiler. - bool library_copied = false; - if (Engine::get_singleton()->is_editor_hint()) { - if (!FileAccess::exists(abs_path)) { - ERR_PRINT("GDExtension library not found: " + abs_path); - return ERR_FILE_NOT_FOUND; - } - - // Copy the file to the same directory as the original with a prefix in the name. - // This is so relative path to dependencies are satisfied. - String copy_path = abs_path.get_base_dir().path_join("~" + abs_path.get_file()); + String actual_lib_path; + Error err = OS::get_singleton()->open_dynamic_library(abs_path, library, true, &actual_lib_path, Engine::get_singleton()->is_editor_hint()); - // If there's a left-over copy (possibly from a crash) then delete it first. - if (FileAccess::exists(copy_path)) { - DirAccess::remove_absolute(copy_path); - } - - Error copy_err = DirAccess::copy_absolute(abs_path, copy_path); - if (copy_err) { - ERR_PRINT("Error copying GDExtension library: " + abs_path); - return ERR_CANT_CREATE; - } - FileAccess::set_hidden_attribute(copy_path, true); - library_copied = true; - - // Save the copied path so it can be deleted later. - temp_lib_path = copy_path; - - // Use the copy to open the library. - abs_path = copy_path; + if (actual_lib_path.get_file() != abs_path.get_file()) { + // If temporary files are generated, let's change the library path to point at the original, + // because that's what we want to check to see if it's changed. + library_path = actual_lib_path.get_base_dir().path_join(p_path.get_file()); } -#endif - Error err = OS::get_singleton()->open_dynamic_library(abs_path, library, true, &library_path); ERR_FAIL_COND_V_MSG(err == ERR_FILE_NOT_FOUND, err, "GDExtension dynamic library not found: " + abs_path); ERR_FAIL_COND_V_MSG(err != OK, err, "Can't open GDExtension dynamic library: " + abs_path); -#if defined(WINDOWS_ENABLED) && defined(TOOLS_ENABLED) - // If we copied the file, let's change the library path to point at the original, - // because that's what we want to check to see if it's changed. - if (library_copied) { - library_path = library_path.get_base_dir() + "\\" + p_path.get_file(); - } -#endif - void *entry_funcptr = nullptr; err = OS::get_singleton()->get_dynamic_library_symbol_handle(library, p_entry_symbol, entry_funcptr, false); @@ -803,13 +768,6 @@ void GDExtension::close_library() { ERR_FAIL_NULL(library); OS::get_singleton()->close_dynamic_library(library); -#if defined(TOOLS_ENABLED) && defined(WINDOWS_ENABLED) - // Delete temporary copy of library if it exists. - if (!temp_lib_path.is_empty() && Engine::get_singleton()->is_editor_hint()) { - DirAccess::remove_absolute(temp_lib_path); - } -#endif - library = nullptr; class_icon_paths.clear(); @@ -1014,13 +972,6 @@ Error GDExtensionResourceLoader::load_gdextension_resource(const String &p_path, err = p_extension->open_library(is_static_library ? String() : library_path, entry_symbol); if (err != OK) { -#if defined(WINDOWS_ENABLED) && defined(TOOLS_ENABLED) - // If the DLL fails to load, make sure that temporary DLL copies are cleaned up. - if (Engine::get_singleton()->is_editor_hint()) { - DirAccess::remove_absolute(p_extension->get_temp_library_path()); - } -#endif - // Unreference the extension so that this loading can be considered a failure. p_extension.unref(); diff --git a/core/extension/gdextension.h b/core/extension/gdextension.h index 2d0cb6a5ba..1f48edecf7 100644 --- a/core/extension/gdextension.h +++ b/core/extension/gdextension.h @@ -47,9 +47,6 @@ class GDExtension : public Resource { void *library = nullptr; // pointer if valid, String library_path; -#if defined(WINDOWS_ENABLED) && defined(TOOLS_ENABLED) - String temp_lib_path; -#endif bool reloadable = false; struct Extension { @@ -130,10 +127,6 @@ public: Error open_library(const String &p_path, const String &p_entry_symbol); void close_library(); -#if defined(WINDOWS_ENABLED) && defined(TOOLS_ENABLED) - String get_temp_library_path() const { return temp_lib_path; } -#endif - enum InitializationLevel { INITIALIZATION_LEVEL_CORE = GDEXTENSION_INITIALIZATION_CORE, INITIALIZATION_LEVEL_SERVERS = GDEXTENSION_INITIALIZATION_SERVERS, |