diff --git a/plugins/builtin/romfs/lang/en_US.json b/plugins/builtin/romfs/lang/en_US.json index 21b582371..bc2d2c71c 100644 --- a/plugins/builtin/romfs/lang/en_US.json +++ b/plugins/builtin/romfs/lang/en_US.json @@ -212,6 +212,8 @@ "hex.builtin.menu.file.close": "Close", "hex.builtin.menu.file.create_file": "New File...", "hex.builtin.menu.file.export": "Export...", + "hex.builtin.menu.file.export.as_language": "Text Formatted Bytes", + "hex.builtin.menu.file.export.as_language.popup.export_error": "Failed to export bytes to the file!", "hex.builtin.menu.file.export.base64": "Base64", "hex.builtin.menu.file.export.base64.popup.export_error": "Failed to create new base64 file!", "hex.builtin.menu.file.export.ips.popup.export_error": "Failed to create new IPS file!", diff --git a/plugins/builtin/source/content/main_menu_items.cpp b/plugins/builtin/source/content/main_menu_items.cpp index ef8557b3a..4c23ea50f 100644 --- a/plugins/builtin/source/content/main_menu_items.cpp +++ b/plugins/builtin/source/content/main_menu_items.cpp @@ -218,6 +218,36 @@ namespace hex::plugin::builtin { }); } + void drawExportLanguageMenu() { + for (const auto &formatter : ContentRegistry::DataFormatter::impl::getEntries()) { + if (ImGui::MenuItem(LangEntry(formatter.unlocalizedName))) { + fs::openFileBrowser(fs::DialogMode::Save, {}, [&formatter](const auto &path) { + TaskManager::createTask("Exporting data", TaskManager::NoProgress, [&formatter, path](auto&){ + auto provider = ImHexApi::Provider::get(); + auto selection = ImHexApi::HexEditor::getSelection() + .value_or( + ImHexApi::HexEditor::ProviderRegion { + { provider->getBaseAddress(), provider->getSize() }, + provider + }); + + auto result = formatter.callback(provider, selection.getStartAddress(), selection.getSize()); + + wolv::io::File file(path, wolv::io::File::Mode::Create); + if (!file.isValid()) { + TaskManager::doLater([] { + PopupError::open("hex.builtin.menu.file.export.as_language.popup.export_error"_lang); + }); + return; + } + + file.writeString(result); + }); + }); + } + } + } + void exportIPSPatch() { auto provider = ImHexApi::Provider::get(); @@ -384,6 +414,10 @@ namespace hex::plugin::builtin { exportBase64, isProviderDumpable); + ContentRegistry::Interface::addMenuItemSubMenu({ "hex.builtin.menu.file", "hex.builtin.menu.file.export", "hex.builtin.menu.file.export.as_language" }, 6010, + drawExportLanguageMenu, + isProviderDumpable); + ContentRegistry::Interface::addMenuItemSeparator({ "hex.builtin.menu.file", "hex.builtin.menu.file.export" }, 6050); /* IPS */