You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-30 16:26:50 +00:00
Save the changes before duplicating resource files
First synchronize the in-memory data to the file, and then copy the file. This can avoid differences between the copied file and the source file.
This commit is contained in:
@@ -3105,8 +3105,31 @@ Error EditorFileSystem::_copy_file(const String &p_from, const String &p_to) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Load the resource and save it again in the new location (this generates a new UID).
|
// Load the resource and save it again in the new location (this generates a new UID).
|
||||||
Error err;
|
Error err = OK;
|
||||||
Ref<Resource> res = ResourceLoader::load(p_from, "", ResourceFormatLoader::CACHE_MODE_REUSE, &err);
|
Ref<Resource> res = ResourceCache::get_ref(p_from);
|
||||||
|
if (res.is_null()) {
|
||||||
|
res = ResourceLoader::load(p_from, "", ResourceFormatLoader::CACHE_MODE_REUSE, &err);
|
||||||
|
} else {
|
||||||
|
bool edited = false;
|
||||||
|
List<Ref<Resource>> cached;
|
||||||
|
ResourceCache::get_cached_resources(&cached);
|
||||||
|
for (Ref<Resource> &resource : cached) {
|
||||||
|
if (!resource->is_edited()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!resource->get_path().begins_with(p_from)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// The resource or one of its built-in resources is edited.
|
||||||
|
edited = true;
|
||||||
|
resource->set_edited(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (edited) {
|
||||||
|
// Save cached resources to prevent changes from being lost and to prevent discrepancies.
|
||||||
|
EditorNode::get_singleton()->save_resource(res);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (err == OK && res.is_valid()) {
|
if (err == OK && res.is_valid()) {
|
||||||
err = ResourceSaver::save(res, p_to, ResourceSaver::FLAG_COMPRESS);
|
err = ResourceSaver::save(res, p_to, ResourceSaver::FLAG_COMPRESS);
|
||||||
if (err != OK) {
|
if (err != OK) {
|
||||||
|
|||||||
Reference in New Issue
Block a user