From b95620907aeb77ec672ae5cd7d4edd19becb7b27 Mon Sep 17 00:00:00 2001 From: a1ext Date: Fri, 2 Nov 2018 09:48:17 +0300 Subject: [PATCH] Related to #865 issue (#900) Wrong path separators have been used. The fix makes them consistent and correspond the Operating System. --- src/Cutter.cpp | 5 +++-- src/Cutter.h | 2 +- src/MainWindow.cpp | 16 ++++++++------ src/MainWindow.h | 2 +- src/common/Configuration.cpp | 5 +++-- src/dialogs/InitialOptionsDialog.cpp | 4 ++-- src/dialogs/NewFileDialog.cpp | 33 ++++++++++++---------------- src/dialogs/OpenFileDialog.cpp | 4 ++-- src/dialogs/SaveProjectDialog.cpp | 13 +++-------- 9 files changed, 38 insertions(+), 46 deletions(-) diff --git a/src/Cutter.cpp b/src/Cutter.cpp index 1132ee15..905d721d 100644 --- a/src/Cutter.cpp +++ b/src/Cutter.cpp @@ -2045,9 +2045,10 @@ void CutterCore::openProject(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()); - emit projectSaved(name); + emit projectSaved(ok, name); } void CutterCore::deleteProject(const QString &name) diff --git a/src/Cutter.h b/src/Cutter.h index 39f76319..8eb977a9 100644 --- a/src/Cutter.h +++ b/src/Cutter.h @@ -628,7 +628,7 @@ signals: void refreshCodeViews(); void stackChanged(); - void projectSaved(const QString &name); + void projectSaved(bool successfully, const QString &name); /*! * emitted when config regarding disassembly display changes diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 11542015..75f21d5f 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -246,7 +246,7 @@ void MainWindow::initUI() QShortcut *refresh_shortcut = new QShortcut(QKeySequence(QKeySequence::Refresh), this); 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::changeDefinedView, this, &MainWindow::changeDefinedView); @@ -762,9 +762,8 @@ void MainWindow::on_actionRun_Script_triggered() dialog.setViewMode(QFileDialog::Detail); dialog.setDirectory(QDir::home()); - QString fileName; - fileName = dialog.getOpenFileName(this, tr("Select radare2 script")); - if (!fileName.length()) // Cancel was pressed + const QString &fileName = QDir::toNativeSeparators(dialog.getOpenFileName(this, tr("Select radare2 script"))); + if (fileName.isEmpty()) // Cancel was pressed return; core->loadScript(fileName); } @@ -878,7 +877,7 @@ void MainWindow::on_actionImportPDB_triggered() return; } - QString pdbFile = dialog.selectedFiles().first(); + const QString &pdbFile = QDir::toNativeSeparators(dialog.selectedFiles().first()); if (!pdbFile.isEmpty()) { 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() diff --git a/src/MainWindow.h b/src/MainWindow.h index ee0b99f4..fc60634e 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -167,7 +167,7 @@ private slots: void on_actionExport_as_code_triggered(); - void projectSaved(const QString &name); + void projectSaved(bool successfully, const QString &name); void updateTasksIndicator(); diff --git a/src/common/Configuration.cpp b/src/common/Configuration.cpp index dcfb1aee..95d55ccd 100644 --- a/src/common/Configuration.cpp +++ b/src/common/Configuration.cpp @@ -1,6 +1,7 @@ #include "Configuration.h" #include #include +#include #include #include #include @@ -73,12 +74,12 @@ QString Configuration::getDirProjects() setDirProjects(projectsDir); } - return projectsDir; + return QDir::toNativeSeparators(projectsDir); } void Configuration::setDirProjects(const QString &dir) { - s.setValue("dir.projects", dir); + s.setValue("dir.projects", QDir::toNativeSeparators(dir)); } /** diff --git a/src/dialogs/InitialOptionsDialog.cpp b/src/dialogs/InitialOptionsDialog.cpp index a9ff0ee9..94a8e9ff 100644 --- a/src/dialogs/InitialOptionsDialog.cpp +++ b/src/dialogs/InitialOptionsDialog.cpp @@ -386,7 +386,7 @@ void InitialOptionsDialog::on_pdbSelectButton_clicked() return; } - QString fileName = dialog.selectedFiles().first(); + const QString &fileName = QDir::toNativeSeparators(dialog.selectedFiles().first()); if (!fileName.isEmpty()) { ui->pdbLineEdit->setText(fileName); @@ -409,7 +409,7 @@ void InitialOptionsDialog::on_scriptSelectButton_clicked() return; } - QString fileName = dialog.selectedFiles().first(); + const QString &fileName = QDir::toNativeSeparators(dialog.selectedFiles().first()); if (!fileName.isEmpty()) { ui->scriptLineEdit->setText(fileName); diff --git a/src/dialogs/NewFileDialog.cpp b/src/dialogs/NewFileDialog.cpp index b75b7a87..fe97f922 100644 --- a/src/dialogs/NewFileDialog.cpp +++ b/src/dialogs/NewFileDialog.cpp @@ -84,7 +84,7 @@ void NewFileDialog::on_loadFileButton_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()) { ui->newFileEdit->setText(fileName); @@ -94,27 +94,21 @@ void NewFileDialog::on_selectFileButton_clicked() void NewFileDialog::on_selectProjectsDirButton_clicked() { - QFileDialog dialog(this); - dialog.setFileMode(QFileDialog::DirectoryOnly); - auto currentDir = Config()->getDirProjects(); if (currentDir.startsWith("~")) { 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 (!dialog.exec()) { + if (!dir.isEmpty()) { return; } - QString dir = dialog.selectedFiles().first(); - if (!dir.isEmpty()) { - Config()->setDirProjects(dir); - fillProjectsList(); - } + Config()->setDirProjects(dir); + fillProjectsList(); } void NewFileDialog::on_loadProjectButton_clicked() @@ -265,7 +259,7 @@ bool NewFileDialog::fillRecentFilesList() QMutableListIterator it(files); int i = 0; while (it.hasNext()) { - const QString &file = it.next(); + const QString &file = QDir::toNativeSeparators(it.next()); // Get stored files // Remove all but the file name @@ -310,7 +304,7 @@ bool NewFileDialog::fillProjectsList() int i = 0; 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); @@ -342,7 +336,8 @@ void NewFileDialog::fillIOPluginsList() 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()) { QMessageBox msgBox(this); 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 QSettings settings; QStringList files = settings.value("recentFileList").toStringList(); - files.removeAll(filename); - files.prepend(filename); + files.removeAll(nativeFn); + files.prepend(nativeFn); while (files.size() > MaxRecentFiles) files.removeLast(); @@ -366,7 +361,7 @@ void NewFileDialog::loadFile(const QString &filename) if (ui->ioPlugin->currentIndex()) { ioFile = ui->ioPlugin->currentText() + "://"; } - ioFile += filename; + ioFile += nativeFn; InitialOptions options; options.filename = ioFile; main->openNewFile(options, ui->checkBox_FilelessOpen->isChecked()); diff --git a/src/dialogs/OpenFileDialog.cpp b/src/dialogs/OpenFileDialog.cpp index 977d59ce..02eeaa27 100644 --- a/src/dialogs/OpenFileDialog.cpp +++ b/src/dialogs/OpenFileDialog.cpp @@ -23,10 +23,10 @@ void OpenFileDialog::on_selectFileButton_clicked() void OpenFileDialog::on_buttonBox_accepted() { - QString filePath = ui->filenameLineEdit->text(); + const QString &filePath = QDir::toNativeSeparators(ui->filenameLineEdit->text()); RVA mapAddress = RVA_INVALID; QString mapAddressStr = ui->mapAddressLineEdit->text(); - if (mapAddressStr.length()) { + if (!mapAddressStr.isEmpty()) { mapAddress = Core()->math(mapAddressStr); } Core()->openFile(filePath, mapAddress); diff --git a/src/dialogs/SaveProjectDialog.cpp b/src/dialogs/SaveProjectDialog.cpp index 9c64acb6..42cc40f2 100644 --- a/src/dialogs/SaveProjectDialog.cpp +++ b/src/dialogs/SaveProjectDialog.cpp @@ -38,22 +38,15 @@ SaveProjectDialog::~SaveProjectDialog() void SaveProjectDialog::on_selectProjectsDirButton_clicked() { - QFileDialog dialog(this); - dialog.setFileMode(QFileDialog::DirectoryOnly); - QString currentDir = ui->projectsDirEdit->text(); if (currentDir.startsWith("~")) { 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()) { ui->projectsDirEdit->setText(dir); }