1
0
mirror of synced 2025-01-18 00:56:49 +01:00

feat: Allow exporting bytes as text to a file

This commit is contained in:
WerWolv 2023-11-09 14:57:58 +01:00
parent 0f5d659ce2
commit f1e0960a26
2 changed files with 36 additions and 0 deletions

View File

@ -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!",

View File

@ -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 */