@@ -729,53 +729,18 @@ GDExtensionInterfaceFunctionPtr GDExtension::get_interface_function(const String
729729
730730Error GDExtension::open_library (const String &p_path, const String &p_entry_symbol) {
731731 String abs_path = ProjectSettings::get_singleton ()->globalize_path (p_path);
732- #if defined(WINDOWS_ENABLED) && defined(TOOLS_ENABLED)
733- // If running on the editor on Windows, we copy the library and open the copy.
734- // This is so the original file isn't locked and can be updated by a compiler.
735- bool library_copied = false ;
736- if (Engine::get_singleton ()->is_editor_hint ()) {
737- if (!FileAccess::exists (abs_path)) {
738- ERR_PRINT (" GDExtension library not found: " + abs_path);
739- return ERR_FILE_NOT_FOUND;
740- }
741-
742- // Copy the file to the same directory as the original with a prefix in the name.
743- // This is so relative path to dependencies are satisfied.
744- String copy_path = abs_path.get_base_dir ().path_join (" ~" + abs_path.get_file ());
732+ String actual_lib_path;
733+ Error err = OS::get_singleton ()->open_dynamic_library (abs_path, library, true , &actual_lib_path, Engine::get_singleton ()->is_editor_hint ());
745734
746- // If there's a left-over copy (possibly from a crash) then delete it first.
747- if (FileAccess::exists (copy_path)) {
748- DirAccess::remove_absolute (copy_path);
749- }
750-
751- Error copy_err = DirAccess::copy_absolute (abs_path, copy_path);
752- if (copy_err) {
753- ERR_PRINT (" Error copying GDExtension library: " + abs_path);
754- return ERR_CANT_CREATE;
755- }
756- FileAccess::set_hidden_attribute (copy_path, true );
757- library_copied = true ;
758-
759- // Save the copied path so it can be deleted later.
760- temp_lib_path = copy_path;
761-
762- // Use the copy to open the library.
763- abs_path = copy_path;
735+ if (actual_lib_path.get_file () != abs_path.get_file ()) {
736+ // If temporary files are generated, let's change the library path to point at the original,
737+ // because that's what we want to check to see if it's changed.
738+ library_path = actual_lib_path.get_base_dir ().path_join (p_path.get_file ());
764739 }
765- #endif
766740
767- Error err = OS::get_singleton ()->open_dynamic_library (abs_path, library, true , &library_path);
768741 ERR_FAIL_COND_V_MSG (err == ERR_FILE_NOT_FOUND, err, " GDExtension dynamic library not found: " + abs_path);
769742 ERR_FAIL_COND_V_MSG (err != OK, err, " Can't open GDExtension dynamic library: " + abs_path);
770743
771- #if defined(WINDOWS_ENABLED) && defined(TOOLS_ENABLED)
772- // If we copied the file, let's change the library path to point at the original,
773- // because that's what we want to check to see if it's changed.
774- if (library_copied) {
775- library_path = library_path.get_base_dir () + " \\ " + p_path.get_file ();
776- }
777- #endif
778-
779744 void *entry_funcptr = nullptr ;
780745
781746 err = OS::get_singleton ()->get_dynamic_library_symbol_handle (library, p_entry_symbol, entry_funcptr, false );
@@ -803,13 +768,6 @@ void GDExtension::close_library() {
803768 ERR_FAIL_NULL (library);
804769 OS::get_singleton ()->close_dynamic_library (library);
805770
806- #if defined(TOOLS_ENABLED) && defined(WINDOWS_ENABLED)
807- // Delete temporary copy of library if it exists.
808- if (!temp_lib_path.is_empty () && Engine::get_singleton ()->is_editor_hint ()) {
809- DirAccess::remove_absolute (temp_lib_path);
810- }
811- #endif
812-
813771 library = nullptr ;
814772 class_icon_paths.clear ();
815773
@@ -1014,13 +972,6 @@ Error GDExtensionResourceLoader::load_gdextension_resource(const String &p_path,
1014972
1015973 err = p_extension->open_library (is_static_library ? String () : library_path, entry_symbol);
1016974 if (err != OK) {
1017- #if defined(WINDOWS_ENABLED) && defined(TOOLS_ENABLED)
1018- // If the DLL fails to load, make sure that temporary DLL copies are cleaned up.
1019- if (Engine::get_singleton ()->is_editor_hint ()) {
1020- DirAccess::remove_absolute (p_extension->get_temp_library_path ());
1021- }
1022- #endif
1023-
1024975 // Unreference the extension so that this loading can be considered a failure.
1025976 p_extension.unref ();
1026977
0 commit comments