From 6f85a45167e94f8ecc9d217b8559a8024dc36053 Mon Sep 17 00:00:00 2001 From: Sergey Khrykov Date: Tue, 28 Mar 2023 21:29:05 +0400 Subject: [PATCH 1/5] log flash --- resource_importer_flash.cpp | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/resource_importer_flash.cpp b/resource_importer_flash.cpp index 61904fe..12ccf02 100644 --- a/resource_importer_flash.cpp +++ b/resource_importer_flash.cpp @@ -136,20 +136,35 @@ Error ResourceImporterFlash::import(const String &p_source_file, const String &p if (srgb == 1) tex_flags |= Texture::FLAG_CONVERT_TO_LINEAR; + WARN_PRINT(String("Importing ") + p_source_file); + + WARN_PRINT(itos(__LINE__)); + // read zip and extract it to tmp dir //const Vector2 PADDING(1, 1); FileAccess *zip_source_file; zlib_filefunc_def io = zipio_create_io_from_file(&zip_source_file); + WARN_PRINT(itos(__LINE__)); + zipFile zip_source = unzOpen2(p_source_file.utf8().get_data(), &io); + WARN_PRINT(itos(__LINE__)); + if (zip_source == NULL) return FAILED; + WARN_PRINT(itos(__LINE__)); + + DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES); String tmp_dir = p_save_path + ".tmp/"; da->make_dir_recursive(tmp_dir); + WARN_PRINT(itos(__LINE__)); if (unzGoToFirstFile(zip_source) != UNZ_OK) { + WARN_PRINT(itos(__LINE__)); + return FAILED; } + WARN_PRINT(itos(__LINE__)); String document_path = ""; do { @@ -163,6 +178,8 @@ Error ResourceImporterFlash::import(const String &p_source_file, const String &p if (unzOpenCurrentFile(zip_source) != UNZ_OK) { ERR_FAIL_V_MSG(FAILED, "Could not open file within zip archive."); } + WARN_PRINT(itos(__LINE__)); + unzReadCurrentFile(zip_source, data.write().ptr(), info.uncompressed_size); String file_path = tmp_dir + file_name; da->make_dir_recursive(file_path.get_base_dir()); @@ -177,14 +194,19 @@ Error ResourceImporterFlash::import(const String &p_source_file, const String &p } while (unzGoToNextFile(zip_source) == UNZ_OK); if (document_path == "") { da->remove(tmp_dir); + WARN_PRINT(itos(__LINE__)); + return FAILED; } + WARN_PRINT(itos(__LINE__)); // parse document Ref doc = FlashDocument::from_file(document_path); if (!doc.is_valid()) { da->remove(tmp_dir); + WARN_PRINT(itos(__LINE__)); + return FAILED; } @@ -230,12 +252,14 @@ Error ResourceImporterFlash::import(const String &p_source_file, const String &p // da->remove(tmp_dir); // return imported; // } + WARN_PRINT(itos(__LINE__)); String spritesheet_files_path = doc->get_document_path() + "/spritesheets.list"; Vector spritesheet_files = FileAccess::get_file_as_string(spritesheet_files_path).split("\n"); while (spritesheet_files.size() > 0 && spritesheet_files[spritesheet_files.size()-1] == String()) { spritesheet_files.remove(spritesheet_files.size()-1); } + WARN_PRINT(itos(__LINE__)); Vector> spritesheet_images; Dictionary spritesheets_layout; @@ -272,6 +296,7 @@ Error ResourceImporterFlash::import(const String &p_source_file, const String &p //img->optimize_channels(); spritesheet_images.push_back(img); } + WARN_PRINT(itos(__LINE__)); Array items = doc->get_bitmaps().values(); for (int i=0; iset_texture(frame); } + WARN_PRINT(itos(__LINE__)); String extension = get_save_extension(); Array formats_imported; @@ -310,6 +336,8 @@ Error ResourceImporterFlash::import(const String &p_source_file, const String &p if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_s3tc")) { + WARN_PRINT(itos(__LINE__)); + _save_tex(p_save_path + ".s3tc.ftex", spritesheet_images, compress_mode, Image::COMPRESS_S3TC, mipmaps, tex_flags); doc->set_atlas(ResourceLoader::load(p_save_path + ".s3tc.ftex")); @@ -320,6 +348,8 @@ Error ResourceImporterFlash::import(const String &p_source_file, const String &p } if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_etc2")) { + WARN_PRINT(itos(__LINE__)); + _save_tex(p_save_path + ".etc2.ftex", spritesheet_images, compress_mode, Image::COMPRESS_ETC2, mipmaps, tex_flags); doc->set_atlas(ResourceLoader::load(p_save_path + ".etc2.ftex")); @@ -329,6 +359,8 @@ Error ResourceImporterFlash::import(const String &p_source_file, const String &p } if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_etc")) { + WARN_PRINT(itos(__LINE__)); + _save_tex(p_save_path + ".etc.ftex", spritesheet_images, compress_mode, Image::COMPRESS_ETC, mipmaps, tex_flags); doc->set_atlas(ResourceLoader::load(p_save_path + ".etc.ftex")); @@ -338,6 +370,8 @@ Error ResourceImporterFlash::import(const String &p_source_file, const String &p } if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_pvrtc")) { + WARN_PRINT(itos(__LINE__)); + _save_tex(p_save_path + ".pvrtc.ftex", spritesheet_images, compress_mode, Image::COMPRESS_PVRTC4, mipmaps, tex_flags); doc->set_atlas(ResourceLoader::load(p_save_path + ".pvrtc.ftex")); @@ -347,9 +381,13 @@ Error ResourceImporterFlash::import(const String &p_source_file, const String &p } if (!ok_on_pc) { + WARN_PRINT(itos(__LINE__)); + //EditorNode::add_io_error("Warning, no suitable PC VRAM compression enabled in Project Settings. This texture will not display correctly on PC."); } } else { + WARN_PRINT(itos(__LINE__)); + //import normally _save_tex(p_save_path + ".ftex", spritesheet_images, compress_mode, Image::COMPRESS_S3TC /*this is ignored */, mipmaps, tex_flags); @@ -365,9 +403,12 @@ Error ResourceImporterFlash::import(const String &p_source_file, const String &p metadata["vram_texture"] = compress_mode == COMPRESS_VIDEO_RAM; if (formats_imported.size()) { metadata["imported_formats"] = formats_imported; + WARN_PRINT(itos(__LINE__)); + } *r_metadata = metadata; } + WARN_PRINT(itos(__LINE__)); return OK; From 35601dedec2a609b555032c20367eaf818c34cde Mon Sep 17 00:00:00 2001 From: Sergey Khrykov Date: Wed, 29 Mar 2023 20:13:24 +0400 Subject: [PATCH 2/5] log flash 2 --- resource_importer_flash.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/resource_importer_flash.cpp b/resource_importer_flash.cpp index 12ccf02..59ef593 100644 --- a/resource_importer_flash.cpp +++ b/resource_importer_flash.cpp @@ -149,6 +149,23 @@ Error ResourceImporterFlash::import(const String &p_source_file, const String &p zipFile zip_source = unzOpen2(p_source_file.utf8().get_data(), &io); WARN_PRINT(itos(__LINE__)); + Error err; + FileAccess *f = FileAccess::open(p_source_file, FileAccess::READ, &err); + + if (!f) + { + WARN_PRINT(itos(__LINE__)); + // file not found + } + else + { + WARN_PRINT(itos(f->get_len())); + + } + + + + if (zip_source == NULL) return FAILED; WARN_PRINT(itos(__LINE__)); From e9ad5398fdd8cc0f5ca4a08e2826b2c998e251d4 Mon Sep 17 00:00:00 2001 From: Sergey Khrykov Date: Thu, 30 Mar 2023 00:46:40 +0400 Subject: [PATCH 3/5] more info --- resource_importer_flash.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/resource_importer_flash.cpp b/resource_importer_flash.cpp index 59ef593..3422ddf 100644 --- a/resource_importer_flash.cpp +++ b/resource_importer_flash.cpp @@ -138,28 +138,34 @@ Error ResourceImporterFlash::import(const String &p_source_file, const String &p WARN_PRINT(String("Importing ") + p_source_file); - WARN_PRINT(itos(__LINE__)); // read zip and extract it to tmp dir //const Vector2 PADDING(1, 1); FileAccess *zip_source_file; zlib_filefunc_def io = zipio_create_io_from_file(&zip_source_file); - WARN_PRINT(itos(__LINE__)); zipFile zip_source = unzOpen2(p_source_file.utf8().get_data(), &io); - WARN_PRINT(itos(__LINE__)); + + WARN_PRINT(String("zip_source = ") + itos((int64_t) zip_source)); + Error err; FileAccess *f = FileAccess::open(p_source_file, FileAccess::READ, &err); + //if (!file_exists(p_source_file)) { + // WARN_PRINT( "File doesn't exist."); + //} + + if (!f) { - WARN_PRINT(itos(__LINE__)); + WARN_PRINT(String("File not found")); // file not found } else { - WARN_PRINT(itos(f->get_len())); + WARN_PRINT(String("File size: ") + itos(f->get_len())); + //WARN_PRINT(String("File size: ") + itos(io->get_len())); } From 075c0f55a7bc94b49c29830a00ba82b503f04276 Mon Sep 17 00:00:00 2001 From: Sergey Khrykov Date: Wed, 5 Apr 2023 20:49:50 +0400 Subject: [PATCH 4/5] clean up --- resource_importer_flash.cpp | 45 ++++--------------------------------- 1 file changed, 4 insertions(+), 41 deletions(-) diff --git a/resource_importer_flash.cpp b/resource_importer_flash.cpp index 3422ddf..ba17ca8 100644 --- a/resource_importer_flash.cpp +++ b/resource_importer_flash.cpp @@ -136,58 +136,40 @@ Error ResourceImporterFlash::import(const String &p_source_file, const String &p if (srgb == 1) tex_flags |= Texture::FLAG_CONVERT_TO_LINEAR; - WARN_PRINT(String("Importing ") + p_source_file); - - // read zip and extract it to tmp dir //const Vector2 PADDING(1, 1); FileAccess *zip_source_file; zlib_filefunc_def io = zipio_create_io_from_file(&zip_source_file); - zipFile zip_source = unzOpen2(p_source_file.utf8().get_data(), &io); - WARN_PRINT(String("zip_source = ") + itos((int64_t) zip_source)); - - Error err; - FileAccess *f = FileAccess::open(p_source_file, FileAccess::READ, &err); + FileAccess *f = FileAccess::open(p_source_file, FileAccess::READ, &err); - //if (!file_exists(p_source_file)) { - // WARN_PRINT( "File doesn't exist."); - //} - - if (!f) { - WARN_PRINT(String("File not found")); + WARN_PRINT(String("File not found: " + p_source_file)); // file not found } else { - WARN_PRINT(String("File size: ") + itos(f->get_len())); - //WARN_PRINT(String("File size: ") + itos(io->get_len())); - + print_verbose(String("File size: ") + itos(f->get_len())); } if (zip_source == NULL) return FAILED; - WARN_PRINT(itos(__LINE__)); DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES); String tmp_dir = p_save_path + ".tmp/"; da->make_dir_recursive(tmp_dir); - WARN_PRINT(itos(__LINE__)); if (unzGoToFirstFile(zip_source) != UNZ_OK) { - WARN_PRINT(itos(__LINE__)); - + WARN_PRINT(String("Could not open archive: " + p_source_file)); return FAILED; } - WARN_PRINT(itos(__LINE__)); String document_path = ""; do { @@ -201,7 +183,6 @@ Error ResourceImporterFlash::import(const String &p_source_file, const String &p if (unzOpenCurrentFile(zip_source) != UNZ_OK) { ERR_FAIL_V_MSG(FAILED, "Could not open file within zip archive."); } - WARN_PRINT(itos(__LINE__)); unzReadCurrentFile(zip_source, data.write().ptr(), info.uncompressed_size); String file_path = tmp_dir + file_name; @@ -217,19 +198,13 @@ Error ResourceImporterFlash::import(const String &p_source_file, const String &p } while (unzGoToNextFile(zip_source) == UNZ_OK); if (document_path == "") { da->remove(tmp_dir); - WARN_PRINT(itos(__LINE__)); - return FAILED; } - WARN_PRINT(itos(__LINE__)); - // parse document Ref doc = FlashDocument::from_file(document_path); if (!doc.is_valid()) { da->remove(tmp_dir); - WARN_PRINT(itos(__LINE__)); - return FAILED; } @@ -275,14 +250,12 @@ Error ResourceImporterFlash::import(const String &p_source_file, const String &p // da->remove(tmp_dir); // return imported; // } - WARN_PRINT(itos(__LINE__)); String spritesheet_files_path = doc->get_document_path() + "/spritesheets.list"; Vector spritesheet_files = FileAccess::get_file_as_string(spritesheet_files_path).split("\n"); while (spritesheet_files.size() > 0 && spritesheet_files[spritesheet_files.size()-1] == String()) { spritesheet_files.remove(spritesheet_files.size()-1); } - WARN_PRINT(itos(__LINE__)); Vector> spritesheet_images; Dictionary spritesheets_layout; @@ -319,7 +292,6 @@ Error ResourceImporterFlash::import(const String &p_source_file, const String &p //img->optimize_channels(); spritesheet_images.push_back(img); } - WARN_PRINT(itos(__LINE__)); Array items = doc->get_bitmaps().values(); for (int i=0; iset_texture(frame); } - WARN_PRINT(itos(__LINE__)); String extension = get_save_extension(); Array formats_imported; @@ -359,7 +330,6 @@ Error ResourceImporterFlash::import(const String &p_source_file, const String &p if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_s3tc")) { - WARN_PRINT(itos(__LINE__)); _save_tex(p_save_path + ".s3tc.ftex", spritesheet_images, compress_mode, Image::COMPRESS_S3TC, mipmaps, tex_flags); @@ -371,7 +341,6 @@ Error ResourceImporterFlash::import(const String &p_source_file, const String &p } if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_etc2")) { - WARN_PRINT(itos(__LINE__)); _save_tex(p_save_path + ".etc2.ftex", spritesheet_images, compress_mode, Image::COMPRESS_ETC2, mipmaps, tex_flags); @@ -382,7 +351,6 @@ Error ResourceImporterFlash::import(const String &p_source_file, const String &p } if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_etc")) { - WARN_PRINT(itos(__LINE__)); _save_tex(p_save_path + ".etc.ftex", spritesheet_images, compress_mode, Image::COMPRESS_ETC, mipmaps, tex_flags); @@ -393,7 +361,6 @@ Error ResourceImporterFlash::import(const String &p_source_file, const String &p } if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_pvrtc")) { - WARN_PRINT(itos(__LINE__)); _save_tex(p_save_path + ".pvrtc.ftex", spritesheet_images, compress_mode, Image::COMPRESS_PVRTC4, mipmaps, tex_flags); @@ -404,12 +371,10 @@ Error ResourceImporterFlash::import(const String &p_source_file, const String &p } if (!ok_on_pc) { - WARN_PRINT(itos(__LINE__)); //EditorNode::add_io_error("Warning, no suitable PC VRAM compression enabled in Project Settings. This texture will not display correctly on PC."); } } else { - WARN_PRINT(itos(__LINE__)); //import normally _save_tex(p_save_path + ".ftex", spritesheet_images, @@ -426,12 +391,10 @@ Error ResourceImporterFlash::import(const String &p_source_file, const String &p metadata["vram_texture"] = compress_mode == COMPRESS_VIDEO_RAM; if (formats_imported.size()) { metadata["imported_formats"] = formats_imported; - WARN_PRINT(itos(__LINE__)); } *r_metadata = metadata; } - WARN_PRINT(itos(__LINE__)); return OK; From 8def940608b6563fe63621787b3e1411f396cbfe Mon Sep 17 00:00:00 2001 From: Sergey Khrykov Date: Wed, 5 Apr 2023 20:52:31 +0400 Subject: [PATCH 5/5] clean up --- resource_importer_flash.cpp | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/resource_importer_flash.cpp b/resource_importer_flash.cpp index ba17ca8..66958c9 100644 --- a/resource_importer_flash.cpp +++ b/resource_importer_flash.cpp @@ -145,23 +145,15 @@ Error ResourceImporterFlash::import(const String &p_source_file, const String &p Error err; FileAccess *f = FileAccess::open(p_source_file, FileAccess::READ, &err); - if (!f) - { + if (!f) { WARN_PRINT(String("File not found: " + p_source_file)); - // file not found } - else - { + else { print_verbose(String("File size: ") + itos(f->get_len())); } - - - if (zip_source == NULL) return FAILED; - - DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES); String tmp_dir = p_save_path + ".tmp/"; da->make_dir_recursive(tmp_dir); @@ -183,7 +175,6 @@ Error ResourceImporterFlash::import(const String &p_source_file, const String &p if (unzOpenCurrentFile(zip_source) != UNZ_OK) { ERR_FAIL_V_MSG(FAILED, "Could not open file within zip archive."); } - unzReadCurrentFile(zip_source, data.write().ptr(), info.uncompressed_size); String file_path = tmp_dir + file_name; da->make_dir_recursive(file_path.get_base_dir()); @@ -330,7 +321,6 @@ Error ResourceImporterFlash::import(const String &p_source_file, const String &p if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_s3tc")) { - _save_tex(p_save_path + ".s3tc.ftex", spritesheet_images, compress_mode, Image::COMPRESS_S3TC, mipmaps, tex_flags); doc->set_atlas(ResourceLoader::load(p_save_path + ".s3tc.ftex")); @@ -341,7 +331,6 @@ Error ResourceImporterFlash::import(const String &p_source_file, const String &p } if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_etc2")) { - _save_tex(p_save_path + ".etc2.ftex", spritesheet_images, compress_mode, Image::COMPRESS_ETC2, mipmaps, tex_flags); doc->set_atlas(ResourceLoader::load(p_save_path + ".etc2.ftex")); @@ -351,7 +340,6 @@ Error ResourceImporterFlash::import(const String &p_source_file, const String &p } if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_etc")) { - _save_tex(p_save_path + ".etc.ftex", spritesheet_images, compress_mode, Image::COMPRESS_ETC, mipmaps, tex_flags); doc->set_atlas(ResourceLoader::load(p_save_path + ".etc.ftex")); @@ -361,7 +349,6 @@ Error ResourceImporterFlash::import(const String &p_source_file, const String &p } if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_pvrtc")) { - _save_tex(p_save_path + ".pvrtc.ftex", spritesheet_images, compress_mode, Image::COMPRESS_PVRTC4, mipmaps, tex_flags); doc->set_atlas(ResourceLoader::load(p_save_path + ".pvrtc.ftex")); @@ -371,11 +358,9 @@ Error ResourceImporterFlash::import(const String &p_source_file, const String &p } if (!ok_on_pc) { - //EditorNode::add_io_error("Warning, no suitable PC VRAM compression enabled in Project Settings. This texture will not display correctly on PC."); } } else { - //import normally _save_tex(p_save_path + ".ftex", spritesheet_images, compress_mode, Image::COMPRESS_S3TC /*this is ignored */, mipmaps, tex_flags); @@ -391,7 +376,6 @@ Error ResourceImporterFlash::import(const String &p_source_file, const String &p metadata["vram_texture"] = compress_mode == COMPRESS_VIDEO_RAM; if (formats_imported.size()) { metadata["imported_formats"] = formats_imported; - } *r_metadata = metadata; }