diff --git a/src/Cutter.pro b/src/Cutter.pro index 6085c098..723a4402 100644 --- a/src/Cutter.pro +++ b/src/Cutter.pro @@ -225,7 +225,8 @@ SOURCES += \ common/QtResImporter.cpp \ common/CutterSeekable.cpp \ common/RefreshDeferrer.cpp \ - dialogs/WelcomeDialog.cpp + dialogs/WelcomeDialog.cpp \ + RunScriptTask.cpp HEADERS += \ @@ -333,7 +334,8 @@ HEADERS += \ common/QtResImporter.h \ common/CutterSeekable.h \ common/RefreshDeferrer.h \ - dialogs/WelcomeDialog.h + dialogs/WelcomeDialog.h \ + RunScriptTask.h FORMS += \ dialogs/AboutDialog.ui \ diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 14006399..5b16d312 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -51,6 +51,7 @@ #include "dialogs/RenameDialog.h" #include "dialogs/preferences/PreferencesDialog.h" #include "dialogs/OpenFileDialog.h" +#include "dialogs/AsyncTaskDialog.h" // Widgets Headers #include "widgets/DisassemblerGraphView.h" @@ -86,6 +87,8 @@ #include "widgets/BreakpointWidget.h" #include "widgets/RegisterRefsWidget.h" +#include "RunScriptTask.h" + // Graphics #include #include @@ -446,8 +449,8 @@ void MainWindow::setFilename(const QString &fn) void MainWindow::closeEvent(QCloseEvent *event) { QMessageBox::StandardButton ret = QMessageBox::question(this, APPNAME, - tr("Do you really want to exit?\nSave your project before closing!"), - (QMessageBox::StandardButtons)(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel)); + tr("Do you really want to exit?\nSave your project before closing!"), + (QMessageBox::StandardButtons)(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel)); if (ret == QMessageBox::Cancel) { event->ignore(); return; @@ -810,7 +813,18 @@ void MainWindow::on_actionRun_Script_triggered() const QString &fileName = QDir::toNativeSeparators(dialog.getOpenFileName(this, tr("Select radare2 script"))); if (fileName.isEmpty()) // Cancel was pressed return; - core->loadScript(fileName); + + RunScriptTask *runScriptTask = new RunScriptTask(); + runScriptTask->setFileName(fileName); + + AsyncTask::Ptr runScriptTaskPtr(runScriptTask); + + AsyncTaskDialog *taskDialog = new AsyncTaskDialog(runScriptTaskPtr, this); + taskDialog->setInterruptOnClose(true); + taskDialog->setAttribute(Qt::WA_DeleteOnClose); + taskDialog->show(); + + Core()->getAsyncTaskManager()->start(runScriptTaskPtr); } /** @@ -840,8 +854,8 @@ void MainWindow::on_actionReset_settings_triggered() { QMessageBox::StandardButton ret = (QMessageBox::StandardButton)QMessageBox::question(this, APPNAME, - tr("Do you really want to clear all settings?"), - QMessageBox::Ok | QMessageBox::Cancel); + tr("Do you really want to clear all settings?"), + QMessageBox::Ok | QMessageBox::Cancel); if (ret == QMessageBox::Ok) { Config()->resetAll(); } diff --git a/src/RunScriptTask.cpp b/src/RunScriptTask.cpp new file mode 100644 index 00000000..2ad852dd --- /dev/null +++ b/src/RunScriptTask.cpp @@ -0,0 +1,29 @@ +#include "Cutter.h" +#include "RunScriptTask.h" +#include "MainWindow.h" + +RunScriptTask::RunScriptTask() : + AsyncTask() +{ +} + +RunScriptTask::~RunScriptTask() +{ +} + +void RunScriptTask::interrupt() +{ + AsyncTask::interrupt(); + r_cons_singleton()->context->breaked = true; +} + +void RunScriptTask::runTask() +{ + if (!this->fileName.isNull()) { + log(tr("Executing script...")); + Core()->cmdTask(". " + this->fileName); + if (isInterrupted()) { + return; + } + } +} diff --git a/src/RunScriptTask.h b/src/RunScriptTask.h new file mode 100644 index 00000000..ca3dbb07 --- /dev/null +++ b/src/RunScriptTask.h @@ -0,0 +1,32 @@ +#ifndef RUNSCRIPTTHREAD_H +#define RUNSCRIPTTHREAD_H + +#include "common/AsyncTask.h" +#include "Cutter.h" + +class RunScriptTask : public AsyncTask +{ + Q_OBJECT + +public: + explicit RunScriptTask(); + ~RunScriptTask(); + + QString getTitle() override { + return tr("Run Script"); + } + + void setFileName(const QString &fileName) { + this->fileName = fileName; + } + + void interrupt() override; + +protected: + void runTask() override; + +private: + QString fileName; +}; + +#endif // RUNSCRIPTTHREAD_H