2
0
Эх сурвалжийг харах

csv import: generate positve UID for .translation and follow renames

Mask with INT64_MAX to avoid negative UIDs which cause bugs.
If the generated .translation UID is already in use (renamed), overwrite that file instead.
Lyuma 6 сар өмнө
parent
commit
f2ad4303aa

+ 11 - 3
editor/import/resource_importer_csv_translation.cpp

@@ -142,14 +142,22 @@ Error ResourceImporterCSVTranslation::import(ResourceUID::ID p_source_id, const
 		}
 
 		String save_path = p_source_file.get_basename() + "." + translations[i]->get_locale() + ".translation";
+		ResourceUID::ID save_id = hash64_murmur3_64(translations[i]->get_locale().hash64(), p_source_id) & 0x7FFFFFFFFFFFFFFF;
+		bool uid_already_exists = ResourceUID::get_singleton()->has_id(save_id);
+		if (uid_already_exists) {
+			// Avoid creating a new file with a duplicate UID.
+			// Always use this UID, even if the user has moved it to a different path.
+			save_path = ResourceUID::get_singleton()->get_id_path(save_id);
+		}
 
 		ResourceSaver::save(xlt, save_path);
 		if (r_gen_files) {
 			r_gen_files->push_back(save_path);
 		}
-
-		ResourceUID::ID save_id = hash64_murmur3_64(translations[i]->get_locale().hash64(), p_source_id);
-		ResourceSaver::set_uid(save_path, save_id);
+		if (!uid_already_exists) {
+			// No need to call set_uid if save_path already refers to save_id.
+			ResourceSaver::set_uid(save_path, save_id);
+		}
 	}
 
 	return OK;