diff --git a/plugins/builtin/romfs/lang/de_DE.json b/plugins/builtin/romfs/lang/de_DE.json index 151ad0b2e..335fdeef1 100644 --- a/plugins/builtin/romfs/lang/de_DE.json +++ b/plugins/builtin/romfs/lang/de_DE.json @@ -124,7 +124,7 @@ "hex.builtin.menu.file.export.as_language": "Text formatierte Bytes", "hex.builtin.menu.file.export.as_language.popup.export_error": "Exportieren von bytes als Datei fehlgeschlagen!", "hex.builtin.menu.file.export.base64": "Base64", - "hex.builtin.menu.file.export.base64.popup.export_error": "Erstellen der Base64 Datei fehlgeschlagen!", + "hex.builtin.menu.file.export.error.create_file": "Erstellen der Datei fehlgeschlagen!", "hex.builtin.menu.file.export.bookmark": "Lesezeichen", "hex.builtin.menu.file.export.data_processor": "Datenprozessors Arbeitsbereich", "hex.builtin.menu.file.export.ips": "IPS Patch", diff --git a/plugins/builtin/romfs/lang/en_US.json b/plugins/builtin/romfs/lang/en_US.json index e88a20e98..940a3eed3 100644 --- a/plugins/builtin/romfs/lang/en_US.json +++ b/plugins/builtin/romfs/lang/en_US.json @@ -124,7 +124,7 @@ "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.error.create_file": "Failed to create new file!", "hex.builtin.menu.file.export.ips.popup.export_error": "Failed to create new IPS file!", "hex.builtin.menu.file.export.ips.popup.invalid_patch_header_error": "Invalid IPS patch header!", "hex.builtin.menu.file.export.ips.popup.address_out_of_range_error": "A patch tried to patch an address that is out of range!", @@ -139,6 +139,7 @@ "hex.builtin.menu.file.export.popup.create": "Cannot export data. Failed to create file!", "hex.builtin.menu.file.export.report": "Report", "hex.builtin.menu.file.export.report.popup.export_error": "Failed to create new report file!", + "hex.builtin.menu.file.export.selection_to_file": "Selection to File...", "hex.builtin.menu.file.export.title": "Export File", "hex.builtin.menu.file.import": "Import...", "hex.builtin.menu.file.import.ips": "IPS Patch", diff --git a/plugins/builtin/romfs/lang/es_ES.json b/plugins/builtin/romfs/lang/es_ES.json index 55b6c1704..20c53113f 100644 --- a/plugins/builtin/romfs/lang/es_ES.json +++ b/plugins/builtin/romfs/lang/es_ES.json @@ -124,7 +124,6 @@ "hex.builtin.menu.file.export.as_language": "", "hex.builtin.menu.file.export.as_language.popup.export_error": "", "hex.builtin.menu.file.export.base64": "Base64", - "hex.builtin.menu.file.export.base64.popup.export_error": "¡Fallo al crear un nuevo archivo base64!", "hex.builtin.menu.file.export.bookmark": "Marcador", "hex.builtin.menu.file.export.data_processor": "Espacio De Trabajo Del Procesador De Datos", "hex.builtin.menu.file.export.ips": "Parche IPS", diff --git a/plugins/builtin/romfs/lang/it_IT.json b/plugins/builtin/romfs/lang/it_IT.json index 9fcbd1b9e..5f27d4296 100644 --- a/plugins/builtin/romfs/lang/it_IT.json +++ b/plugins/builtin/romfs/lang/it_IT.json @@ -124,7 +124,6 @@ "hex.builtin.menu.file.export.as_language": "", "hex.builtin.menu.file.export.as_language.popup.export_error": "", "hex.builtin.menu.file.export.base64": "", - "hex.builtin.menu.file.export.base64.popup.export_error": "", "hex.builtin.menu.file.export.bookmark": "", "hex.builtin.menu.file.export.data_processor": "", "hex.builtin.menu.file.export.ips": "IPS Patch", diff --git a/plugins/builtin/romfs/lang/ja_JP.json b/plugins/builtin/romfs/lang/ja_JP.json index 011d6fccf..0d2cf27fa 100644 --- a/plugins/builtin/romfs/lang/ja_JP.json +++ b/plugins/builtin/romfs/lang/ja_JP.json @@ -124,7 +124,6 @@ "hex.builtin.menu.file.export.as_language": "", "hex.builtin.menu.file.export.as_language.popup.export_error": "", "hex.builtin.menu.file.export.base64": "", - "hex.builtin.menu.file.export.base64.popup.export_error": "", "hex.builtin.menu.file.export.bookmark": "", "hex.builtin.menu.file.export.data_processor": "", "hex.builtin.menu.file.export.ips": "IPSパッチ", diff --git a/plugins/builtin/romfs/lang/ko_KR.json b/plugins/builtin/romfs/lang/ko_KR.json index fb359f3ab..51977c491 100644 --- a/plugins/builtin/romfs/lang/ko_KR.json +++ b/plugins/builtin/romfs/lang/ko_KR.json @@ -124,7 +124,6 @@ "hex.builtin.menu.file.export.as_language": "텍스트 형식 바이트", "hex.builtin.menu.file.export.as_language.popup.export_error": "파일로 바이트를 내보내지 못했습니다!", "hex.builtin.menu.file.export.base64": "Base64", - "hex.builtin.menu.file.export.base64.popup.export_error": "새 Base64 파일을 만들지 못했습니다!", "hex.builtin.menu.file.export.bookmark": "북마크", "hex.builtin.menu.file.export.data_processor": "데이터 프로세서 작업 공간", "hex.builtin.menu.file.export.ips": "IPS 패치", diff --git a/plugins/builtin/romfs/lang/pt_BR.json b/plugins/builtin/romfs/lang/pt_BR.json index 98d57b9a3..138227c8c 100644 --- a/plugins/builtin/romfs/lang/pt_BR.json +++ b/plugins/builtin/romfs/lang/pt_BR.json @@ -124,7 +124,6 @@ "hex.builtin.menu.file.export.as_language": "", "hex.builtin.menu.file.export.as_language.popup.export_error": "", "hex.builtin.menu.file.export.base64": "", - "hex.builtin.menu.file.export.base64.popup.export_error": "", "hex.builtin.menu.file.export.bookmark": "", "hex.builtin.menu.file.export.data_processor": "", "hex.builtin.menu.file.export.ips": "IPS Patch", diff --git a/plugins/builtin/romfs/lang/zh_CN.json b/plugins/builtin/romfs/lang/zh_CN.json index 8899bea97..17f13c4c2 100644 --- a/plugins/builtin/romfs/lang/zh_CN.json +++ b/plugins/builtin/romfs/lang/zh_CN.json @@ -124,7 +124,6 @@ "hex.builtin.menu.file.export.as_language": "", "hex.builtin.menu.file.export.as_language.popup.export_error": "", "hex.builtin.menu.file.export.base64": "Base64", - "hex.builtin.menu.file.export.base64.popup.export_error": "创建新的Base64文件失败!", "hex.builtin.menu.file.export.bookmark": "书签", "hex.builtin.menu.file.export.data_processor": "数据处理器工作区", "hex.builtin.menu.file.export.ips": "IPS 补丁", diff --git a/plugins/builtin/romfs/lang/zh_TW.json b/plugins/builtin/romfs/lang/zh_TW.json index d58e2fa5b..9238d5374 100644 --- a/plugins/builtin/romfs/lang/zh_TW.json +++ b/plugins/builtin/romfs/lang/zh_TW.json @@ -124,7 +124,6 @@ "hex.builtin.menu.file.export.as_language": "", "hex.builtin.menu.file.export.as_language.popup.export_error": "", "hex.builtin.menu.file.export.base64": "Base64", - "hex.builtin.menu.file.export.base64.popup.export_error": "無法建立新 Base64 檔案!", "hex.builtin.menu.file.export.bookmark": "書籤", "hex.builtin.menu.file.export.data_processor": "資料處理器工作區", "hex.builtin.menu.file.export.ips": "IPS 修補檔案", diff --git a/plugins/builtin/source/content/main_menu_items.cpp b/plugins/builtin/source/content/main_menu_items.cpp index ced55429a..f25066f2f 100644 --- a/plugins/builtin/source/content/main_menu_items.cpp +++ b/plugins/builtin/source/content/main_menu_items.cpp @@ -19,10 +19,12 @@ #include #include +#include #include using namespace std::literals::string_literals; +using namespace wolv::literals; namespace hex::plugin::builtin { @@ -172,15 +174,15 @@ namespace hex::plugin::builtin { wolv::io::File outputFile(path, wolv::io::File::Mode::Create); if (!outputFile.isValid()) { TaskManager::doLater([] { - ui::ToastError::open("hex.builtin.menu.file.export.base64.popup.export_error"_lang); + ui::ToastError::open("hex.builtin.menu.file.export.error.create_file"_lang); }); return; } auto provider = ImHexApi::Provider::get(); - std::vector bytes(3000); - for (u64 address = 0; address < provider->getActualSize(); address += 3000) { - bytes.resize(std::min(3000, provider->getActualSize() - address)); + std::vector bytes(5_MiB); + for (u64 address = 0; address < provider->getActualSize(); address += bytes.size()) { + bytes.resize(std::min(bytes.size(), provider->getActualSize() - address)); provider->read(provider->getBaseAddress() + address, bytes.data(), bytes.size()); outputFile.writeVector(crypt::encode64(bytes)); @@ -189,6 +191,31 @@ namespace hex::plugin::builtin { }); } + void exportSelectionToFile() { + fs::openFileBrowser(fs::DialogMode::Save, {}, [](const auto &path) { + TaskManager::createTask("hex.ui.common.processing", TaskManager::NoProgress, [path](auto &) { + wolv::io::File outputFile(path, wolv::io::File::Mode::Create); + if (!outputFile.isValid()) { + TaskManager::doLater([] { + ui::ToastError::open("hex.builtin.menu.file.export.error.create_file"_lang); + }); + return; + } + + auto provider = ImHexApi::Provider::get(); + std::vector bytes(5_MiB); + + auto selection = ImHexApi::HexEditor::getSelection(); + for (u64 address = selection->getStartAddress(); address <= selection->getEndAddress(); address += bytes.size()) { + bytes.resize(std::min(bytes.size(), selection->getEndAddress() - address)); + provider->read(address, bytes.data(), bytes.size()); + + outputFile.writeVector(bytes); + } + }); + }); + } + void drawExportLanguageMenu() { for (const auto &formatter : ContentRegistry::DataFormatter::impl::getEntries()) { if (ImGui::MenuItem(Lang(formatter.unlocalizedName), nullptr, false, ImHexApi::Provider::get()->getActualSize() > 0)) { @@ -419,19 +446,25 @@ namespace hex::plugin::builtin { { ContentRegistry::Interface::addMenuItemSubMenu({ "hex.builtin.menu.file", "hex.builtin.menu.file.export" }, ICON_VS_SIGN_OUT, 6000, []{}, isProviderDumpable); + /* Selection to File */ + ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.menu.file.export", "hex.builtin.menu.file.export.selection_to_file" }, ICON_VS_FILE_BINARY, 6010, + Shortcut::None, + exportSelectionToFile, + ImHexApi::HexEditor::isSelectionValid); + /* Base 64 */ - ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.menu.file.export", "hex.builtin.menu.file.export.base64" }, 6005, + ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.menu.file.export", "hex.builtin.menu.file.export.base64" }, ICON_VS_NOTE, 6020, Shortcut::None, exportBase64, isProviderDumpable); /* Language */ - ContentRegistry::Interface::addMenuItemSubMenu({ "hex.builtin.menu.file", "hex.builtin.menu.file.export", "hex.builtin.menu.file.export.as_language" }, ICON_VS_CODE, 6010, + ContentRegistry::Interface::addMenuItemSubMenu({ "hex.builtin.menu.file", "hex.builtin.menu.file.export", "hex.builtin.menu.file.export.as_language" }, ICON_VS_CODE, 6030, drawExportLanguageMenu, isProviderDumpable); /* Report */ - ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.menu.file.export", "hex.builtin.menu.file.export.report" }, ICON_VS_MARKDOWN, 6020, + ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.menu.file.export", "hex.builtin.menu.file.export.report" }, ICON_VS_MARKDOWN, 6040, Shortcut::None, exportReport, ImHexApi::Provider::isValid);