Repository: godotengine/godot
File: editor/import_dock.cpp (C++)

Code before:
	for (int i = 0; i < params->paths.size(); i++) {
		Ref<ConfigFile> config;
		config.instantiate();
		Error err = config->load(params->paths[i] + ".import");
		ERR_CONTINUE(err != OK);

		String imported_with = config->get_value("remap", "importer");
		if (imported_with != importer_name) {
			need_restart = true;
			if (_find_owners(EditorFileSystem::get_singleton()->get_filesystem(), params->paths[i])) {
				used_in_resources = true;
			}
		}
	}

	if (need_restart) {
		label_warning->set_visible(used_in_resources);
		reimport_confirm->popup_centered();
		return;
	}

	_reimport();
}

void ImportDock::_reimport_and_restart() {
	EditorNode::get_singleton()->save_all_scenes();
	EditorResourcePreview::get_singleton()->stop(); //don't try to re-create previews after import
	_reimport();
	EditorNode::get_singleton()->restart_editor();
}

void ImportDock::_advanced_options() {
	if (params->paths.size() == 1 && params->importer.is_valid()) {
		params->importer->show_advanced_options(params->paths[0]);
	}
}
void ImportDock::_reimport() {
	for (int i = 0; i < params->paths.size(); i++) {
		Ref<ConfigFile> config;
		config.instantiate();
		Error err = config->load(params->paths[i] + ".import");
		ERR_CONTINUE(err != OK);

		if (params->importer.is_valid()) {
			String importer_name = params->importer->get_importer_name();

			if (params->checking && config->get_value("remap", "importer") == params->importer->get_importer_name()) {
				//update only what is edited (checkboxes) if the importer is the same
				for (const PropertyInfo &E : params->properties) {
					if (params->checked.has(E.name)) {
						config->set_value("params", E.name, params->values[E.name]);

Review comment (bug):
`int i = 0;` and `i++;` is unused. Causing a werror failure with mingw-llvm.

Code after:
	for (int i = 0; i < params->paths.size(); i++) {
		Ref<ConfigFile> config;
		config.instantiate();
		Error err = config->load(params->paths[i] + ".import");
		ERR_CONTINUE(err != OK);

		String imported_with = config->get_value("remap", "importer");
		if (imported_with != importer_name) {
			need_cleanup.push_back(params->paths[i]);
			if (_find_owners(EditorFileSystem::get_singleton()->get_filesystem(), params->paths[i])) {
				used_in_resources = true;
			}
		}
	}

	if (!need_cleanup.is_empty() || used_in_resources) {
		cleanup_warning->set_visible(!need_cleanup.is_empty());
		label_warning->set_visible(used_in_resources);
		reimport_confirm->popup_centered();
		return;
	}

	_reimport();
}

void ImportDock::_reimport_and_cleanup() {
	HashMap<String, Ref<Resource>> old_resources;

	for (const String &path : need_cleanup) {
		Ref<Resource> res = ResourceLoader::load(path);
		res->set_path("");
		res->set_meta(SNAME("_skip_save_"), true);
		old_resources[path] = res;
	}

	EditorResourcePreview::get_singleton()->stop(); // Don't try to re-create previews after import.
	_reimport();

	if (need_cleanup.is_empty()) {
		return;
	}

	// After changing resource type we need to make sure that all old instances are unloaded or replaced.
	EditorNode::get_singleton()->push_item(nullptr);
	EditorUndoRedoManager::get_singleton()->clear_history();

	List<Ref<Resource>> external_resources;
	ResourceCache::get_cached_resources(&external_resources);

	for (const String &path : need_cleanup) {
		Ref<Resource> old_res = old_resources[path];