Command Line Argument for Filename

This commit is contained in:
Florian Märkl 2017-04-01 13:20:13 +02:00 committed by Sergi Àlvarez i Capilla
parent ec15a46775
commit 8f80007531
6 changed files with 48 additions and 18 deletions

View File

@ -1,12 +1,17 @@
#include "mainwindow.h" #include "mainwindow.h"
#include "newfiledialog.h" #include "newfiledialog.h"
#include "optionsdialog.h"
#include <QApplication> #include <QApplication>
#include <QCommandLineParser>
#include <QTextCodec> #include <QTextCodec>
#include <QMessageBox> #include <QMessageBox>
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setApplicationName("Iaito");
a.setApplicationVersion(APP_VERSION); a.setApplicationVersion(APP_VERSION);
// Set QString codec to UTF-8 // Set QString codec to UTF-8
@ -16,6 +21,16 @@ int main(int argc, char *argv[])
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
#endif #endif
QCommandLineParser cmdParser;
cmdParser.setApplicationDescription("A Qt and C++ GUI for radare2 reverse engineering framework");
cmdParser.addHelpOption();
cmdParser.addVersionOption();
cmdParser.addPositionalArgument("filename", QCoreApplication::translate("main", "Filename to open."));
cmdParser.process(a);
QStringList args = cmdParser.positionalArguments();
// Check r2 version // Check r2 version
QString r2version = r_core_version(); QString r2version = r_core_version();
QString localVersion = "" R2_GITTAP; QString localVersion = "" R2_GITTAP;
@ -31,7 +46,18 @@ int main(int argc, char *argv[])
return 1; return 1;
} }
NewFileDialog n; if(args.empty())
n.show(); {
NewFileDialog *n = new NewFileDialog();
n->setAttribute(Qt::WA_DeleteOnClose);
n->exec();
}
else // filename specified as positional argument
{
OptionsDialog *o = new OptionsDialog(args[0]);
o->setAttribute(Qt::WA_DeleteOnClose);
o->exec();
}
return a.exec(); return a.exec();
} }

View File

@ -100,7 +100,7 @@ MainWindow::MainWindow(QWidget *parent) :
backButton->setIcon(QIcon(":/new/prefix1/img/icons/arrow_left.png")); backButton->setIcon(QIcon(":/new/prefix1/img/icons/arrow_left.png"));
//backButton->setPopupMode(QToolButton::DelayedPopup); //backButton->setPopupMode(QToolButton::DelayedPopup);
ui->mainToolBar->insertWidget(ui->actionForward, backButton); ui->mainToolBar->insertWidget(ui->actionForward, backButton);
connect(backButton, SIGNAL(clicked()), this, SLOT(on_backButton_clicked())); //connect(backButton, SIGNAL(clicked()), this, SLOT(on_backButton_clicked()));
// Sepparator between undo/redo and goto lineEdit // Sepparator between undo/redo and goto lineEdit
QWidget* spacer3 = new QWidget(); QWidget* spacer3 = new QWidget();

View File

@ -8,6 +8,8 @@
#include <QMessageBox> #include <QMessageBox>
#include <QDir> #include <QDir>
const int NewFileDialog::MaxRecentFiles;
static QColor getColorFor(QString str, int pos) { static QColor getColorFor(QString str, int pos) {
QList<QColor> Colors; QList<QColor> Colors;
Colors << QColor(29, 188, 156); // Turquoise Colors << QColor(29, 188, 156); // Turquoise
@ -79,11 +81,6 @@ NewFileDialog::NewFileDialog(QWidget *parent) :
ui->createButton->hide(); ui->createButton->hide();
} }
QString NewFileDialog::strippedName(const QString &fullFileName)
{
return QFileInfo(fullFileName).fileName();
}
NewFileDialog::~NewFileDialog() NewFileDialog::~NewFileDialog()
{ {
delete ui; delete ui;
@ -100,8 +97,7 @@ void NewFileDialog::on_loadFileButton_clicked()
} else { } else {
// Close dialog and open OptionsDialog // Close dialog and open OptionsDialog
close(); close();
OptionsDialog* o = new OptionsDialog(nullptr); OptionsDialog* o = new OptionsDialog(fname);
o->setFilename (fname, this->strippedName(fname));
o->exec(); o->exec();
} }
} }
@ -145,8 +141,7 @@ void NewFileDialog::on_recentsList_itemDoubleClicked(QListWidgetItem *item)
QString sitem = data.toString(); QString sitem = data.toString();
// Close dialog and open OptionsDialog // Close dialog and open OptionsDialog
close(); close();
OptionsDialog* o = new OptionsDialog(nullptr); OptionsDialog* o = new OptionsDialog(sitem);
o->setFilename (sitem, this->strippedName(sitem));
o->exec(); o->exec();
} }

View File

@ -36,8 +36,8 @@ private slots:
private: private:
Ui::NewFileDialog *ui; Ui::NewFileDialog *ui;
QString strippedName(const QString &fullFileName);
enum { MaxRecentFiles = 5 }; static const int MaxRecentFiles = 5;
}; };
#endif // NEWFILEDIALOG_H #endif // NEWFILEDIALOG_H

View File

@ -6,7 +6,7 @@
#include <QSettings> #include <QSettings>
#include <QFileInfo> #include <QFileInfo>
OptionsDialog::OptionsDialog(QWidget *parent): OptionsDialog::OptionsDialog(QString filename, QWidget *parent):
QDialog(parent), QDialog(parent),
ui(new Ui::OptionsDialog), ui(new Ui::OptionsDialog),
analThread(this) analThread(this)
@ -42,6 +42,8 @@ OptionsDialog::OptionsDialog(QWidget *parent):
//this->layout()->setSizeConstraint(QLayout::SetFixedSize); //this->layout()->setSizeConstraint(QLayout::SetFixedSize);
connect(&analThread, SIGNAL(finished()), this, SLOT(anal_finished())); connect(&analThread, SIGNAL(finished()), this, SLOT(anal_finished()));
setFilename(filename);
} }
OptionsDialog::~OptionsDialog() OptionsDialog::~OptionsDialog()
@ -57,6 +59,11 @@ void OptionsDialog::setFilename(QString fn, QString shortfn) {
this->core->tryFile (fn, 1); this->core->tryFile (fn, 1);
} }
void OptionsDialog::setFilename(QString fn)
{
setFilename(fn, QFileInfo(fn).fileName());
}
void OptionsDialog::on_closeButton_clicked() void OptionsDialog::on_closeButton_clicked()
{ {
close(); close();

View File

@ -19,9 +19,8 @@ class OptionsDialog : public QDialog
public: public:
QRCore *core; QRCore *core;
explicit OptionsDialog(QWidget *parent = 0); explicit OptionsDialog(QString filename, QWidget *parent = 0);
~OptionsDialog(); ~OptionsDialog();
void setFilename(QString fn, QString shortfn);
RAnalFunction functionAt(ut64 addr); RAnalFunction functionAt(ut64 addr);
QStringList asm_plugins; QStringList asm_plugins;
@ -45,6 +44,9 @@ private:
Ui::OptionsDialog *ui; Ui::OptionsDialog *ui;
AnalThread analThread; AnalThread analThread;
MainWindow *w; MainWindow *w;
void setFilename(QString fn, QString shortfn);
void setFilename(QString fn);
}; };
#endif // OPTIONSDIALOG_H #endif // OPTIONSDIALOG_H