Fix companion script loading

This commit is contained in:
Florian Märkl 2018-07-24 18:49:52 +02:00
parent 390f30b124
commit 2987bd833f
4 changed files with 19 additions and 6 deletions

View File

@ -286,18 +286,19 @@ void MainWindow::openNewFile(const QString &fn, int analLevel, QList<QString> ad
/* Prompt to load filename.r2 script */ /* Prompt to load filename.r2 script */
QString script = QString("%1.r2").arg(this->filename); QString script = QString("%1.r2").arg(this->filename);
QString loadScript;
if (r_file_exists(script.toStdString().data())) { if (r_file_exists(script.toStdString().data())) {
QMessageBox mb; QMessageBox mb;
mb.setWindowTitle(tr("Script loading")); mb.setWindowTitle(tr("Script loading"));
mb.setText(tr("Do you want to load the '%1' script?").arg(script)); mb.setText(tr("Do you want to load the '%1' script?").arg(script));
mb.setStandardButtons(QMessageBox::Yes | QMessageBox::No); mb.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
if (mb.exec() == QMessageBox::Yes) { if (mb.exec() == QMessageBox::Yes) {
core->loadScript(script); loadScript = script;
} }
} }
/* Show analysis options dialog */ /* Show analysis options dialog */
displayAnalysisOptionsDialog(analLevel, advancedOptions); displayAnalysisOptionsDialog(analLevel, advancedOptions, loadScript);
} }
void MainWindow::openNewFileFailed() void MainWindow::openNewFileFailed()
@ -327,10 +328,11 @@ void MainWindow::closeNewFileDialog()
newFileDialog = nullptr; newFileDialog = nullptr;
} }
void MainWindow::displayAnalysisOptionsDialog(int analLevel, QList<QString> advancedOptions) void MainWindow::displayAnalysisOptionsDialog(int analLevel, QList<QString> advancedOptions, const QString &script)
{ {
OptionsDialog *o = new OptionsDialog(this); OptionsDialog *o = new OptionsDialog(this);
o->setAttribute(Qt::WA_DeleteOnClose); o->setAttribute(Qt::WA_DeleteOnClose);
o->setInitialScript(script);
o->show(); o->show();
if (analLevel >= 0) { if (analLevel >= 0) {
@ -823,7 +825,7 @@ void MainWindow::on_actionRefresh_Panels_triggered()
void MainWindow::on_actionAnalyze_triggered() void MainWindow::on_actionAnalyze_triggered()
{ {
displayAnalysisOptionsDialog(-1, QList<QString>()); displayAnalysisOptionsDialog(-1, QList<QString>(), nullptr);
} }
void MainWindow::on_actionImportPDB_triggered() void MainWindow::on_actionImportPDB_triggered()

View File

@ -71,7 +71,7 @@ public:
QList<QString> advancedOptions = QList<QString>()); QList<QString> advancedOptions = QList<QString>());
void displayNewFileDialog(); void displayNewFileDialog();
void closeNewFileDialog(); void closeNewFileDialog();
void displayAnalysisOptionsDialog(int analLevel, QList<QString> advancedOptions); void displayAnalysisOptionsDialog(int analLevel, QList<QString> advancedOptions, const QString &script);
void openProject(const QString &project_name); void openProject(const QString &project_name);
void initUI(); void initUI();

View File

@ -82,6 +82,15 @@ void OptionsDialog::updateCPUComboBox()
ui->cpuComboBox->lineEdit()->setText(currentText); ui->cpuComboBox->lineEdit()->setText(currentText);
} }
void OptionsDialog::setInitialScript(const QString &script)
{
ui->scriptCheckBox->setChecked(!script.isEmpty());
ui->scriptLineEdit->setText(script);
if (!script.isEmpty()) {
ui->analSlider->setValue(0);
}
}
QString OptionsDialog::getSelectedArch() QString OptionsDialog::getSelectedArch()
{ {
QVariant archValue = ui->archComboBox->currentData(); QVariant archValue = ui->archComboBox->currentData();

View File

@ -40,6 +40,8 @@ protected:
void closeEvent(QCloseEvent *event) override; void closeEvent(QCloseEvent *event) override;
private: private:
std::unique_ptr<Ui::OptionsDialog> ui;
MainWindow *main; MainWindow *main;
CutterCore *core; CutterCore *core;
int defaultAnalLevel; int defaultAnalLevel;
@ -49,7 +51,7 @@ private:
void updateCPUComboBox(); void updateCPUComboBox();
public: public:
std::unique_ptr<Ui::OptionsDialog> ui; void setInitialScript(const QString &script);
QString getSelectedArch(); QString getSelectedArch();
QString getSelectedCPU(); QString getSelectedCPU();