mirror of https://github.com/WerWolv/ImHex.git
feat: Add export selection to file option
This commit is contained in:
parent
7a6ee756b8
commit
f0a44e54d0
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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パッチ",
|
||||
|
|
|
@ -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 패치",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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 补丁",
|
||||
|
|
|
@ -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 修補檔案",
|
||||
|
|
|
@ -19,10 +19,12 @@
|
|||
#include <hex/api/workspace_manager.hpp>
|
||||
|
||||
#include <wolv/io/file.hpp>
|
||||
#include <wolv/literals.hpp>
|
||||
|
||||
#include <romfs/romfs.hpp>
|
||||
|
||||
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<u8> bytes(3000);
|
||||
for (u64 address = 0; address < provider->getActualSize(); address += 3000) {
|
||||
bytes.resize(std::min<u64>(3000, provider->getActualSize() - address));
|
||||
std::vector<u8> bytes(5_MiB);
|
||||
for (u64 address = 0; address < provider->getActualSize(); address += bytes.size()) {
|
||||
bytes.resize(std::min<u64>(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<u8> bytes(5_MiB);
|
||||
|
||||
auto selection = ImHexApi::HexEditor::getSelection();
|
||||
for (u64 address = selection->getStartAddress(); address <= selection->getEndAddress(); address += bytes.size()) {
|
||||
bytes.resize(std::min<u64>(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);
|
||||
|
|
Loading…
Reference in New Issue