Related to #865 issue (#900)

Wrong path separators have been used. The fix makes them consistent and correspond the Operating System.
This commit is contained in:
a1ext 2018-11-02 09:48:17 +03:00 committed by Itay Cohen
parent 3f76ee000c
commit b95620907a
9 changed files with 38 additions and 46 deletions

View File

@ -2045,9 +2045,10 @@ void CutterCore::openProject(const QString &name)
void CutterCore::saveProject(const QString &name) void CutterCore::saveProject(const QString &name)
{ {
cmd("Ps " + name); const QString &rv = cmd("Ps " + name.trimmed()).trimmed();
const bool ok = rv == name.trimmed();
cmd("Pnj " + notes.toUtf8().toBase64()); cmd("Pnj " + notes.toUtf8().toBase64());
emit projectSaved(name); emit projectSaved(ok, name);
} }
void CutterCore::deleteProject(const QString &name) void CutterCore::deleteProject(const QString &name)

View File

@ -628,7 +628,7 @@ signals:
void refreshCodeViews(); void refreshCodeViews();
void stackChanged(); void stackChanged();
void projectSaved(const QString &name); void projectSaved(bool successfully, const QString &name);
/*! /*!
* emitted when config regarding disassembly display changes * emitted when config regarding disassembly display changes

View File

@ -246,7 +246,7 @@ void MainWindow::initUI()
QShortcut *refresh_shortcut = new QShortcut(QKeySequence(QKeySequence::Refresh), this); QShortcut *refresh_shortcut = new QShortcut(QKeySequence(QKeySequence::Refresh), this);
connect(refresh_shortcut, SIGNAL(activated()), this, SLOT(refreshAll())); connect(refresh_shortcut, SIGNAL(activated()), this, SLOT(refreshAll()));
connect(core, SIGNAL(projectSaved(const QString &)), this, SLOT(projectSaved(const QString &))); connect(core, SIGNAL(projectSaved(bool, const QString &)), this, SLOT(projectSaved(bool, const QString &)));
connect(core, &CutterCore::changeDebugView, this, &MainWindow::changeDebugView); connect(core, &CutterCore::changeDebugView, this, &MainWindow::changeDebugView);
connect(core, &CutterCore::changeDefinedView, this, &MainWindow::changeDefinedView); connect(core, &CutterCore::changeDefinedView, this, &MainWindow::changeDefinedView);
@ -762,9 +762,8 @@ void MainWindow::on_actionRun_Script_triggered()
dialog.setViewMode(QFileDialog::Detail); dialog.setViewMode(QFileDialog::Detail);
dialog.setDirectory(QDir::home()); dialog.setDirectory(QDir::home());
QString fileName; const QString &fileName = QDir::toNativeSeparators(dialog.getOpenFileName(this, tr("Select radare2 script")));
fileName = dialog.getOpenFileName(this, tr("Select radare2 script")); if (fileName.isEmpty()) // Cancel was pressed
if (!fileName.length()) // Cancel was pressed
return; return;
core->loadScript(fileName); core->loadScript(fileName);
} }
@ -878,7 +877,7 @@ void MainWindow::on_actionImportPDB_triggered()
return; return;
} }
QString pdbFile = dialog.selectedFiles().first(); const QString &pdbFile = QDir::toNativeSeparators(dialog.selectedFiles().first());
if (!pdbFile.isEmpty()) { if (!pdbFile.isEmpty()) {
core->loadPDB(pdbFile); core->loadPDB(pdbFile);
@ -938,9 +937,12 @@ void MainWindow::on_actionExport_as_code_triggered()
} }
void MainWindow::projectSaved(const QString &name) void MainWindow::projectSaved(bool successfully, const QString &name)
{ {
core->message(tr("Project saved:") + " " + name); if (successfully)
core->message(tr("Project saved: %1").arg(name));
else
core->message(tr("Failed to save project: %1").arg(name));
} }
void MainWindow::changeDebugView() void MainWindow::changeDebugView()

View File

@ -167,7 +167,7 @@ private slots:
void on_actionExport_as_code_triggered(); void on_actionExport_as_code_triggered();
void projectSaved(const QString &name); void projectSaved(bool successfully, const QString &name);
void updateTasksIndicator(); void updateTasksIndicator();

View File

@ -1,6 +1,7 @@
#include "Configuration.h" #include "Configuration.h"
#include <QJsonObject> #include <QJsonObject>
#include <QJsonArray> #include <QJsonArray>
#include <QDir>
#include <QFontDatabase> #include <QFontDatabase>
#include <QFile> #include <QFile>
#include <QApplication> #include <QApplication>
@ -73,12 +74,12 @@ QString Configuration::getDirProjects()
setDirProjects(projectsDir); setDirProjects(projectsDir);
} }
return projectsDir; return QDir::toNativeSeparators(projectsDir);
} }
void Configuration::setDirProjects(const QString &dir) void Configuration::setDirProjects(const QString &dir)
{ {
s.setValue("dir.projects", dir); s.setValue("dir.projects", QDir::toNativeSeparators(dir));
} }
/** /**

View File

@ -386,7 +386,7 @@ void InitialOptionsDialog::on_pdbSelectButton_clicked()
return; return;
} }
QString fileName = dialog.selectedFiles().first(); const QString &fileName = QDir::toNativeSeparators(dialog.selectedFiles().first());
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
ui->pdbLineEdit->setText(fileName); ui->pdbLineEdit->setText(fileName);
@ -409,7 +409,7 @@ void InitialOptionsDialog::on_scriptSelectButton_clicked()
return; return;
} }
QString fileName = dialog.selectedFiles().first(); const QString &fileName = QDir::toNativeSeparators(dialog.selectedFiles().first());
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
ui->scriptLineEdit->setText(fileName); ui->scriptLineEdit->setText(fileName);

View File

@ -84,7 +84,7 @@ void NewFileDialog::on_loadFileButton_clicked()
void NewFileDialog::on_selectFileButton_clicked() void NewFileDialog::on_selectFileButton_clicked()
{ {
QString fileName = QFileDialog::getOpenFileName(this, tr("Select file"), QDir::homePath()); const QString &fileName = QDir::toNativeSeparators(QFileDialog::getOpenFileName(this, tr("Select file"), QDir::homePath()));
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
ui->newFileEdit->setText(fileName); ui->newFileEdit->setText(fileName);
@ -94,28 +94,22 @@ void NewFileDialog::on_selectFileButton_clicked()
void NewFileDialog::on_selectProjectsDirButton_clicked() void NewFileDialog::on_selectProjectsDirButton_clicked()
{ {
QFileDialog dialog(this);
dialog.setFileMode(QFileDialog::DirectoryOnly);
auto currentDir = Config()->getDirProjects(); auto currentDir = Config()->getDirProjects();
if (currentDir.startsWith("~")) { if (currentDir.startsWith("~")) {
currentDir = QDir::homePath() + currentDir.mid(1); currentDir = QDir::homePath() + currentDir.mid(1);
} }
dialog.setDirectory(currentDir); const QString &dir = QDir::toNativeSeparators(QFileDialog::getExistingDirectory(this,
tr("Select project path (dir.projects)"),
currentDir));
dialog.setWindowTitle(tr("Select project path (dir.projects)")); if (!dir.isEmpty()) {
if (!dialog.exec()) {
return; return;
} }
QString dir = dialog.selectedFiles().first();
if (!dir.isEmpty()) {
Config()->setDirProjects(dir); Config()->setDirProjects(dir);
fillProjectsList(); fillProjectsList();
} }
}
void NewFileDialog::on_loadProjectButton_clicked() void NewFileDialog::on_loadProjectButton_clicked()
{ {
@ -265,7 +259,7 @@ bool NewFileDialog::fillRecentFilesList()
QMutableListIterator<QString> it(files); QMutableListIterator<QString> it(files);
int i = 0; int i = 0;
while (it.hasNext()) { while (it.hasNext()) {
const QString &file = it.next(); const QString &file = QDir::toNativeSeparators(it.next());
// Get stored files // Get stored files
// Remove all but the file name // Remove all but the file name
@ -310,7 +304,7 @@ bool NewFileDialog::fillProjectsList()
int i = 0; int i = 0;
for (const QString &project : projects) { for (const QString &project : projects) {
QString info = core->cmd("Pi " + project); QString info = QDir::toNativeSeparators(core->cmd("Pi " + project));
QListWidgetItem *item = new QListWidgetItem(getIconFor(project, i++), project + "\n" + info); QListWidgetItem *item = new QListWidgetItem(getIconFor(project, i++), project + "\n" + info);
@ -342,7 +336,8 @@ void NewFileDialog::fillIOPluginsList()
void NewFileDialog::loadFile(const QString &filename) void NewFileDialog::loadFile(const QString &filename)
{ {
if (ui->ioPlugin->currentIndex() == 0 && !Core()->tryFile(filename, false) const QString &nativeFn = QDir::toNativeSeparators(filename);
if (ui->ioPlugin->currentIndex() == 0 && !Core()->tryFile(nativeFn, false)
&& !ui->checkBox_FilelessOpen->isChecked()) { && !ui->checkBox_FilelessOpen->isChecked()) {
QMessageBox msgBox(this); QMessageBox msgBox(this);
msgBox.setText(tr("Select a new program or a previous one before continuing.")); msgBox.setText(tr("Select a new program or a previous one before continuing."));
@ -353,8 +348,8 @@ void NewFileDialog::loadFile(const QString &filename)
// Add file to recent file list // Add file to recent file list
QSettings settings; QSettings settings;
QStringList files = settings.value("recentFileList").toStringList(); QStringList files = settings.value("recentFileList").toStringList();
files.removeAll(filename); files.removeAll(nativeFn);
files.prepend(filename); files.prepend(nativeFn);
while (files.size() > MaxRecentFiles) while (files.size() > MaxRecentFiles)
files.removeLast(); files.removeLast();
@ -366,7 +361,7 @@ void NewFileDialog::loadFile(const QString &filename)
if (ui->ioPlugin->currentIndex()) { if (ui->ioPlugin->currentIndex()) {
ioFile = ui->ioPlugin->currentText() + "://"; ioFile = ui->ioPlugin->currentText() + "://";
} }
ioFile += filename; ioFile += nativeFn;
InitialOptions options; InitialOptions options;
options.filename = ioFile; options.filename = ioFile;
main->openNewFile(options, ui->checkBox_FilelessOpen->isChecked()); main->openNewFile(options, ui->checkBox_FilelessOpen->isChecked());

View File

@ -23,10 +23,10 @@ void OpenFileDialog::on_selectFileButton_clicked()
void OpenFileDialog::on_buttonBox_accepted() void OpenFileDialog::on_buttonBox_accepted()
{ {
QString filePath = ui->filenameLineEdit->text(); const QString &filePath = QDir::toNativeSeparators(ui->filenameLineEdit->text());
RVA mapAddress = RVA_INVALID; RVA mapAddress = RVA_INVALID;
QString mapAddressStr = ui->mapAddressLineEdit->text(); QString mapAddressStr = ui->mapAddressLineEdit->text();
if (mapAddressStr.length()) { if (!mapAddressStr.isEmpty()) {
mapAddress = Core()->math(mapAddressStr); mapAddress = Core()->math(mapAddressStr);
} }
Core()->openFile(filePath, mapAddress); Core()->openFile(filePath, mapAddress);

View File

@ -38,22 +38,15 @@ SaveProjectDialog::~SaveProjectDialog()
void SaveProjectDialog::on_selectProjectsDirButton_clicked() void SaveProjectDialog::on_selectProjectsDirButton_clicked()
{ {
QFileDialog dialog(this);
dialog.setFileMode(QFileDialog::DirectoryOnly);
QString currentDir = ui->projectsDirEdit->text(); QString currentDir = ui->projectsDirEdit->text();
if (currentDir.startsWith("~")) { if (currentDir.startsWith("~")) {
currentDir = QDir::homePath() + currentDir.mid(1); currentDir = QDir::homePath() + currentDir.mid(1);
} }
dialog.setDirectory(currentDir);
dialog.setWindowTitle(tr("Select project path (dir.projects)")); const QString& dir = QDir::toNativeSeparators(QFileDialog::getExistingDirectory(this,
tr("Select project path (dir.projects)"),
currentDir));
if (!dialog.exec()) {
return;
}
QString dir = dialog.selectedFiles().first();
if (!dir.isEmpty()) { if (!dir.isEmpty()) {
ui->projectsDirEdit->setText(dir); ui->projectsDirEdit->setText(dir);
} }