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 "newfiledialog.h"
#include "optionsdialog.h"
#include <QApplication>
#include <QCommandLineParser>
#include <QTextCodec>
#include <QMessageBox>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setApplicationName("Iaito");
a.setApplicationVersion(APP_VERSION);
// Set QString codec to UTF-8
@ -16,6 +21,16 @@ int main(int argc, char *argv[])
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
#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
QString r2version = r_core_version();
QString localVersion = "" R2_GITTAP;
@ -31,7 +46,18 @@ int main(int argc, char *argv[])
return 1;
}
NewFileDialog n;
n.show();
if(args.empty())
{
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();
}

View File

@ -100,7 +100,7 @@ MainWindow::MainWindow(QWidget *parent) :
backButton->setIcon(QIcon(":/new/prefix1/img/icons/arrow_left.png"));
//backButton->setPopupMode(QToolButton::DelayedPopup);
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
QWidget* spacer3 = new QWidget();

View File

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

View File

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

View File

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

View File

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