diff --git a/WingHexExplorer/WingHexExplorer.pri b/WingHexExplorer/WingHexExplorer.pri index 8a11c76..3f8c45d 100644 --- a/WingHexExplorer/WingHexExplorer.pri +++ b/WingHexExplorer/WingHexExplorer.pri @@ -48,4 +48,4 @@ HEADERS += \ TRANSLATIONS += \ - $$PWD/lang/zh.ts \ No newline at end of file + $$PWD/lang/zh.ts diff --git a/WingHexExplorer/class/appmanager.cpp b/WingHexExplorer/class/appmanager.cpp index 4e06cef..7ad8e53 100644 --- a/WingHexExplorer/class/appmanager.cpp +++ b/WingHexExplorer/class/appmanager.cpp @@ -16,7 +16,8 @@ AppManager *AppManager::instance() { void AppManager::openFiles(QStringList files) { if (mWindow) { for (auto file : files) { - mWindow->openFile(file); + if (mWindow->openWorkSpace(file) != ErrFile::Success) + mWindow->openFile(file); } //通过dbus接口从任务栏激活窗口 if (!Q_LIKELY(Utilities::activeWindowFromDock(mWindow->winId()))) { diff --git a/WingHexExplorer/dialog/mainwindow.cpp b/WingHexExplorer/dialog/mainwindow.cpp index 3da08ad..bf1d078 100644 --- a/WingHexExplorer/dialog/mainwindow.cpp +++ b/WingHexExplorer/dialog/mainwindow.cpp @@ -572,6 +572,8 @@ MainWindow::MainWindow(DMainWindow *parent) { setDockNestingEnabled(true); findresultMenu = new DMenu(this); + AddMenuAction("export", tr("ExportFindResult"), + MainWindow::on_exportfindresult, findresultMenu); AddMenuAction("del", tr("ClearFindResult"), MainWindow::on_clearfindresult, findresultMenu); @@ -2168,6 +2170,38 @@ void MainWindow::on_clearfindresult() { findresitem = nullptr; } +void MainWindow::on_exportfindresult() { + auto c = findresult->rowCount(); + if (c == 0) { + DMessageManager::instance()->sendMessage(this, ICONRES("export"), + tr("EmptyFindResult")); + return; + } + auto filename = QFileDialog::getSaveFileName(this, tr("ChooseSaveFile")); + if (filename.isEmpty()) + return; + QFile f(filename); + if (f.open(QFile::WriteOnly)) { + QJsonArray arr; + for (int i = 0; i < c; i++) { + QJsonObject jobj; + jobj.insert("file", findresitem[i][0].text()); + jobj.insert("offset", findresitem[i][1].text()); + jobj.insert("value", findresitem[i][2].text()); + arr.append(jobj); + } + QJsonDocument doc(arr); + if (f.write(doc.toJson(QJsonDocument::JsonFormat::Indented)) >= 0) { + f.close(); + DMessageManager::instance()->sendMessage(this, ICONRES("export"), + tr("SaveFindResult")); + } + } else { + DMessageManager::instance()->sendMessage(this, ICONRES("export"), + tr("SaveFindResultError")); + } +} + void MainWindow::on_sponsor() { SponsorDialog d; d.exec(); @@ -2178,19 +2212,21 @@ void MainWindow::on_about() { d.exec(); } -bool MainWindow::openWorkSpace(QString filename) { +ErrFile MainWindow::openWorkSpace(QString filename) { QString file; QList bookmarks; QHash metas; + auto res = ErrFile::Error; if (WorkSpaceManager::loadWorkSpace(filename, file, bookmarks, metas)) { - openFile(file, false, filename); + res = openFile(file, false, filename); + if (res != ErrFile::Success) + return res; auto doc = hexeditor->document(); doc->applyBookMarks(bookmarks); on_documentSwitched(); doc->metadata()->applyMetas(metas); - return true; } - return false; + return res; } void MainWindow::on_openworkspace() { @@ -2198,7 +2234,7 @@ void MainWindow::on_openworkspace() { this, tr("ChooseFile"), QString(), tr("ProjectFile (*.wingpro)")); if (filename.isEmpty()) return; - if (!openWorkSpace(filename)) + if (openWorkSpace(filename) != ErrFile::Success) DMessageManager::instance()->sendMessage(this, ICONRES("workspace"), tr("SaveUnSuccessfully")); } diff --git a/WingHexExplorer/dialog/mainwindow.h b/WingHexExplorer/dialog/mainwindow.h index e7f6eca..ee608f6 100644 --- a/WingHexExplorer/dialog/mainwindow.h +++ b/WingHexExplorer/dialog/mainwindow.h @@ -114,6 +114,7 @@ private: public: ErrFile openFile(QString filename, bool readonly = false, QString workspace = ""); + ErrFile openWorkSpace(QString filename); private: void newFile(); @@ -140,7 +141,6 @@ private: void cutCurrentBytes(quint64 pos, qint64 len, QByteArray &arr); void pasteFileBytes(int index, QByteArray arr, qint64 len = -1); void pasteCurrentBytes(quint64 pos, QByteArray arr, qint64 len = -1); - bool openWorkSpace(QString filename); bool saveWorkSpace(); bool saveAsWorkSpace(QString filename); @@ -184,6 +184,7 @@ private: void on_fillnop(); void on_fillzero(); void on_fill(); + void on_exportfindresult(); void on_clearfindresult(); void on_loadplg(); void on_encoding(); diff --git a/WingHexExplorer/lang/zh.qm b/WingHexExplorer/lang/zh.qm index 1f93d36..958e617 100644 Binary files a/WingHexExplorer/lang/zh.qm and b/WingHexExplorer/lang/zh.qm differ diff --git a/WingHexExplorer/lang/zh.ts b/WingHexExplorer/lang/zh.ts index 04e2193..7b86c59 100644 --- a/WingHexExplorer/lang/zh.ts +++ b/WingHexExplorer/lang/zh.ts @@ -260,7 +260,7 @@ - + Fill 填充 @@ -303,9 +303,9 @@ - - - + + + BookMark 书签 @@ -440,72 +440,92 @@ + ExportFindResult + 导出搜索结果 + + + ClearFindResult 清空记录 - + file 文件名 - + addr 地址偏移 - + value 搜索值 - + FindResult 搜索结果 - + Log 日志 - + LoggerInitFinish 日志系统初始化完毕 - + CutToClipBoard 数据已剪切到粘贴板! - + UnCutToClipBoard 由于保持大小限制,数据剪切到粘贴板失败! - + CopyToClipBoard 数据已拷贝到粘贴板 - + TooMuchFindResult 搜索结果数量达到限制,结果可能不完整! - - + + EmptyFindResult + 没有可导出的搜索结果! + + + + SaveFindResult + 导出搜索结果成功! + + + + SaveFindResultError + 导出结果失败! + + + + ProjectFile (*.wingpro) 项目文件 (*.wingpro) - + Warn 警告 - + PleaseSaveNewFile 请保存文件后继续! @@ -514,52 +534,52 @@ 类型 - + Value - + Number 数值 - + SettingLoading 设置加载中…… - + PluginLoading 正在加载插件…… - + UnLoadPluginSetting 因在设置中禁用插件导致无法加载! - + MenuName : 菜单名称: - + DockWidgetName : 停靠组件名: - + Untitled 未命名 - + ChoosePlugin 请选择插件文件 - + PluginFile (*.wingplg) 插件文件 (*.wingplg) @@ -568,113 +588,114 @@ 由于你目前处于 ROOT 状态,故默认锁定文件!请为自己的修改负责! - + DriverOpenErrorTip 打开驱动器失败 - - - + + + Error 错误 - + NoRoot 无 root 权限,无法继续的操作! - - + + ChooseFile 选择文件 - + FileNotExist 文件不存在! - + FilePermission 因文件权限无法继续! - - + + Close 关闭 - - + + ConfirmSave 正在关闭未保存的文件,你确定抛弃继续吗? - + ChooseExportFile 请选择导出文件路径: - - - - + + + + SaveSuccessfully 保存成功! - - - - - + + + + + SaveUnSuccessfully 保存失败 - - - + + + + ChooseSaveFile 请选择保存文件路径: - + FindFininish 查找结果完毕! - + SaveSelError 保存选区字节失败,因文件不具有可写权限! - - + + Addr : 0x%1 地址:0x%1 - + NoSelection 没有选区,无法继续的操作! - - + + InputComment 请输入评语: - + PleaseInputFill 请输入填充字节值 - + FillInputError 填充字节输入错误 diff --git a/WingHexExplorer/main.cpp b/WingHexExplorer/main.cpp index b34e2a3..c087b38 100644 --- a/WingHexExplorer/main.cpp +++ b/WingHexExplorer/main.cpp @@ -77,7 +77,8 @@ int main(int argc, char *argv[]) { MainWindow w; for (auto item : urls) { - w.openFile(item); + if (w.openWorkSpace(item) != ErrFile::Success) + w.openFile(item); } manager->mWindow = &w;