| 197 | } |
| 198 | |
| 199 | void exportSelectionToFile() { |
| 200 | fs::openFileBrowser(fs::DialogMode::Save, {}, [](const auto &path) { |
| 201 | TaskManager::createTask("hex.ui.common.processing", TaskManager::NoProgress, [path](auto &task) { |
| 202 | wolv::io::File outputFile(path, wolv::io::File::Mode::Create); |
| 203 | if (!outputFile.isValid()) { |
| 204 | TaskManager::doLater([] { |
| 205 | ui::ToastError::open("hex.builtin.menu.file.export.error.create_file"_lang); |
| 206 | }); |
| 207 | return; |
| 208 | } |
| 209 | |
| 210 | auto provider = ImHexApi::Provider::get(); |
| 211 | std::vector<u8> bytes(5_MiB); |
| 212 | |
| 213 | auto selection = ImHexApi::HexEditor::getSelection(); |
| 214 | for (u64 address = selection->getStartAddress(); address <= selection->getEndAddress(); address += bytes.size()) { |
| 215 | bytes.resize(std::min<u64>(bytes.size(), selection->getEndAddress() - address + 1)); |
| 216 | provider->read(address, bytes.data(), bytes.size()); |
| 217 | |
| 218 | outputFile.writeVector(bytes); |
| 219 | task.update(); |
| 220 | } |
| 221 | }); |
| 222 | }); |
| 223 | } |
| 224 | |
| 225 | void drawExportLanguageMenu() { |
| 226 | for (const auto &formatter : ContentRegistry::DataFormatter::impl::getExportMenuEntries()) { |