feat: Allow exporting bytes as text to a file
This commit is contained in:
parent
0f5d659ce2
commit
f1e0960a26
@ -212,6 +212,8 @@
|
|||||||
"hex.builtin.menu.file.close": "Close",
|
"hex.builtin.menu.file.close": "Close",
|
||||||
"hex.builtin.menu.file.create_file": "New File...",
|
"hex.builtin.menu.file.create_file": "New File...",
|
||||||
"hex.builtin.menu.file.export": "Export...",
|
"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": "Base64",
|
||||||
"hex.builtin.menu.file.export.base64.popup.export_error": "Failed to create new base64 file!",
|
"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!",
|
"hex.builtin.menu.file.export.ips.popup.export_error": "Failed to create new IPS 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() {
|
void exportIPSPatch() {
|
||||||
auto provider = ImHexApi::Provider::get();
|
auto provider = ImHexApi::Provider::get();
|
||||||
|
|
||||||
@ -384,6 +414,10 @@ namespace hex::plugin::builtin {
|
|||||||
exportBase64,
|
exportBase64,
|
||||||
isProviderDumpable);
|
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);
|
ContentRegistry::Interface::addMenuItemSeparator({ "hex.builtin.menu.file", "hex.builtin.menu.file.export" }, 6050);
|
||||||
|
|
||||||
/* IPS */
|
/* IPS */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user