Merge pull request #47268 from reduz/keep-import-mode

Add a "keep" import mode to keep files as-is and export them.
This commit is contained in:
Rémi Verschelde 2021-03-22 21:35:22 +01:00 committed by GitHub
commit a7fb5f8558
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 122 additions and 45 deletions

View File

@ -295,6 +295,9 @@ Error ConfigFile::_parse(const String &p_path, VariantParser::Stream *p_stream)
return OK;
}
void ConfigFile::clear() {
values.clear();
}
void ConfigFile::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_value", "section", "key", "value"), &ConfigFile::set_value);
ClassDB::bind_method(D_METHOD("get_value", "section", "key", "default"), &ConfigFile::get_value, DEFVAL(Variant()));
@ -317,4 +320,6 @@ void ConfigFile::_bind_methods() {
ClassDB::bind_method(D_METHOD("save_encrypted", "path", "key"), &ConfigFile::save_encrypted);
ClassDB::bind_method(D_METHOD("save_encrypted_pass", "path", "password"), &ConfigFile::save_encrypted_pass);
ClassDB::bind_method(D_METHOD("clear"), &ConfigFile::clear);
}

View File

@ -68,6 +68,8 @@ public:
Error load(const String &p_path);
Error parse(const String &p_data);
void clear();
Error load_encrypted(const String &p_path, const Vector<uint8_t> &p_key);
Error load_encrypted_pass(const String &p_path, const String &p_pass);

View File

@ -874,6 +874,20 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
continue;
}
String importer_type = config->get_value("remap", "importer");
if (importer_type == "keep") {
//just keep file as-is
Vector<uint8_t> array = FileAccess::get_file_as_array(path);
err = p_func(p_udata, path, array, idx, total, enc_in_filters, enc_ex_filters, key);
if (err != OK) {
return err;
}
continue;
}
List<String> remaps;
config->get_section_keys("remap", &remaps);

View File

@ -405,6 +405,10 @@ bool EditorFileSystem::_test_for_reimport(const String &p_path, bool p_only_impo
memdelete(f);
if (importer_name == "keep") {
return false; //keep mode, do not reimport
}
Ref<ResourceImporter> importer = ResourceFormatImporter::get_singleton()->get_importer_by_name(importer_name);
if (importer->get_format_version() > version) {
@ -1532,6 +1536,10 @@ Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector
source_file_options[p_files[i]] = Map<StringName, Variant>();
importer_name = file_importer_name;
if (importer_name == "keep") {
continue; //do nothing
}
Ref<ResourceImporter> importer = ResourceFormatImporter::get_singleton()->get_importer_by_name(importer_name);
ERR_FAIL_COND_V(!importer.is_valid(), ERR_FILE_CORRUPT);
List<ResourceImporter::ImportOption> options;
@ -1555,6 +1563,10 @@ Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector
base_paths[p_files[i]] = ResourceFormatImporter::get_singleton()->get_import_base_path(p_files[i]);
}
if (importer_name == "keep") {
return OK; // (do nothing)
}
ERR_FAIL_COND_V(importer_name == String(), ERR_UNCONFIGURED);
Ref<ResourceImporter> importer = ResourceFormatImporter::get_singleton()->get_importer_by_name(importer_name);
@ -1700,7 +1712,7 @@ void EditorFileSystem::_reimport_file(const String &p_file, const Map<StringName
params[E->get()] = cf->get_value("params", E->get());
}
}
if (p_custom_importer != String() && cf->has_section("remap")) {
if (p_custom_importer == String() && cf->has_section("remap")) {
importer_name = cf->get_value("remap", "importer");
}
}
@ -1710,6 +1722,16 @@ void EditorFileSystem::_reimport_file(const String &p_file, const Map<StringName
late_added_files.insert(p_file); //imported files do not call update_file(), but just in case..
}
if (importer_name == "keep") {
//keep files, do nothing.
fs->files[cpos]->modified_time = FileAccess::get_modified_time(p_file);
fs->files[cpos]->import_modified_time = FileAccess::get_modified_time(p_file + ".import");
fs->files[cpos]->deps.clear();
fs->files[cpos]->type = "";
fs->files[cpos]->import_valid = false;
EditorResourcePreview::get_singleton()->check_for_invalidation(p_file);
return;
}
Ref<ResourceImporter> importer;
bool load_default = false;
//find the importer

View File

@ -98,11 +98,9 @@ void ImportDock::set_edit_path(const String &p_path) {
return;
}
params->importer = ResourceFormatImporter::get_singleton()->get_importer_by_name(config->get_value("remap", "importer"));
if (params->importer.is_null()) {
clear();
return;
}
String importer_name = config->get_value("remap", "importer");
params->importer = ResourceFormatImporter::get_singleton()->get_importer_by_name(importer_name);
params->paths.clear();
params->paths.push_back(p_path);
@ -124,11 +122,18 @@ void ImportDock::set_edit_path(const String &p_path) {
for (List<Pair<String, String>>::Element *E = importer_names.front(); E; E = E->next()) {
import_as->add_item(E->get().first);
import_as->set_item_metadata(import_as->get_item_count() - 1, E->get().second);
if (E->get().second == params->importer->get_importer_name()) {
if (E->get().second == importer_name) {
import_as->select(import_as->get_item_count() - 1);
}
}
import_as->add_separator();
import_as->add_item(TTR("Keep File (No Import)"));
import_as->set_item_metadata(import_as->get_item_count() - 1, "keep");
if (importer_name == "keep") {
import_as->select(import_as->get_item_count() - 1);
}
import->set_disabled(false);
import_as->set_disabled(false);
preset->set_disabled(false);
@ -138,7 +143,10 @@ void ImportDock::set_edit_path(const String &p_path) {
void ImportDock::_update_options(const Ref<ConfigFile> &p_config) {
List<ResourceImporter::ImportOption> options;
if (params->importer.is_valid()) {
params->importer->get_import_options(&options);
}
params->properties.clear();
params->values.clear();
@ -157,7 +165,7 @@ void ImportDock::_update_options(const Ref<ConfigFile> &p_config) {
params->update();
_update_preset_menu();
if (params->paths.size() == 1 && params->importer->has_advanced_options()) {
if (params->importer.is_valid() && params->paths.size() == 1 && params->importer->has_advanced_options()) {
advanced->show();
advanced_spacer->show();
} else {
@ -279,6 +287,13 @@ void ImportDock::set_edit_multiple_paths(const Vector<String> &p_paths) {
void ImportDock::_update_preset_menu() {
preset->get_popup()->clear();
if (params->importer.is_null()) {
preset->get_popup()->add_item(TTR("Default"));
preset->hide();
return;
}
preset->show();
if (params->importer->get_preset_count() == 0) {
preset->get_popup()->add_item(TTR("Default"));
} else {
@ -298,6 +313,10 @@ void ImportDock::_update_preset_menu() {
void ImportDock::_importer_selected(int i_idx) {
String name = import_as->get_selected_metadata();
if (name == "keep") {
params->importer.unref();
_update_options(Ref<ConfigFile>());
} else {
Ref<ResourceImporter> importer = ResourceFormatImporter::get_singleton()->get_importer_by_name(name);
ERR_FAIL_COND(importer.is_null());
@ -313,6 +332,7 @@ void ImportDock::_importer_selected(int i_idx) {
}
_update_options(config);
}
}
void ImportDock::_preset_selected(int p_idx) {
int item_id = preset->get_popup()->get_item_id(p_idx);
@ -407,6 +427,13 @@ static bool _find_owners(EditorFileSystemDirectory *efsd, const String &p_path)
void ImportDock::_reimport_attempt() {
bool need_restart = false;
bool used_in_resources = false;
String importer_name;
if (params->importer.is_valid()) {
importer_name = params->importer->get_importer_name();
} else {
importer_name = "keep";
}
for (int i = 0; i < params->paths.size(); i++) {
Ref<ConfigFile> config;
config.instance();
@ -414,7 +441,7 @@ void ImportDock::_reimport_attempt() {
ERR_CONTINUE(err != OK);
String imported_with = config->get_value("remap", "importer");
if (imported_with != params->importer->get_importer_name()) {
if (imported_with != importer_name) {
need_restart = true;
if (_find_owners(EditorFileSystem::get_singleton()->get_filesystem(), params->paths[i])) {
used_in_resources = true;
@ -450,6 +477,7 @@ void ImportDock::_reimport() {
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()) {
@ -484,6 +512,12 @@ void ImportDock::_reimport() {
config->set_value("remap", "group_file", Variant()); //clear group file if unused
}
} else {
//set to no import
config->clear();
config->set_value("remap", "importer", "keep");
}
config->save(params->paths[i] + ".import");
}