diff options
| author | LostDragonist <lost.dragonist@gmail.com> | 2019-04-15 04:11:06 -0500 |
|---|---|---|
| committer | LostDragonist <lost.dragonist@gmail.com> | 2019-04-15 05:25:22 -0500 |
| commit | 149c38d54d2a841af929b432b83804fafdc1e588 (patch) | |
| tree | 5fa69b73a3ec54df39444ce9bcd0e06a4a4a950b /src | |
| parent | 0f13d9a4c00db48402dd70fcd55084d102582f22 (diff) | |
Add protection against non-existent working directory for executables
Diffstat (limited to 'src')
| -rw-r--r-- | src/editexecutablesdialog.cpp | 30 | ||||
| -rw-r--r-- | src/editexecutablesdialog.h | 4 | ||||
| -rw-r--r-- | src/executableslist.cpp | 10 |
3 files changed, 38 insertions, 6 deletions
diff --git a/src/editexecutablesdialog.cpp b/src/editexecutablesdialog.cpp index d1371a76..177661ff 100644 --- a/src/editexecutablesdialog.cpp +++ b/src/editexecutablesdialog.cpp @@ -83,8 +83,33 @@ void EditExecutablesDialog::refreshExecutablesWidget() void EditExecutablesDialog::on_binaryEdit_textChanged(const QString &name) { - QFileInfo fileInfo(name); - ui->addButton->setEnabled(fileInfo.exists() && fileInfo.isFile()); + updateButtonStates(); +} + +void EditExecutablesDialog::on_workingDirEdit_textChanged(const QString &dir) +{ + updateButtonStates(); +} + +void EditExecutablesDialog::updateButtonStates() +{ + bool enabled = true; + + QString filePath(ui->binaryEdit->text()); + QFileInfo fileInfo(filePath); + if (!fileInfo.exists()) + enabled = false; + if (!fileInfo.isFile()) + enabled = false; + + QString dirPath(ui->workingDirEdit->text()); + if (!dirPath.isEmpty()) { + QDir dirInfo(dirPath); + if (!dirInfo.exists()) + enabled = false; + } + + ui->addButton->setEnabled(enabled); } void EditExecutablesDialog::resetInput() @@ -293,7 +318,6 @@ bool EditExecutablesDialog::executableChanged() && fileInfo.isFile(); } } - void EditExecutablesDialog::on_executablesListBox_itemSelectionChanged() { if (ui->executablesListBox->selectedItems().size() == 0) { diff --git a/src/editexecutablesdialog.h b/src/editexecutablesdialog.h index 0169b8ca..bee3cba6 100644 --- a/src/editexecutablesdialog.h +++ b/src/editexecutablesdialog.h @@ -74,6 +74,8 @@ private slots: void on_binaryEdit_textChanged(const QString &arg1);
+ void on_workingDirEdit_textChanged(const QString &arg1);
+
void on_addButton_clicked();
void on_browseButton_clicked();
@@ -106,6 +108,8 @@ private: bool executableChanged();
+ void updateButtonStates();
+
private:
Ui::EditExecutablesDialog *ui;
diff --git a/src/executableslist.cpp b/src/executableslist.cpp index c7786c20..4b2e380b 100644 --- a/src/executableslist.cpp +++ b/src/executableslist.cpp @@ -57,7 +57,7 @@ void ExecutablesList::init(IPluginGame const *game) }
ExecutableInfo explorerpp = ExecutableInfo("Explore Virtual Folder", QFileInfo(QCoreApplication::applicationDirPath() + "/explorer++/Explorer++.exe" ))
.withArgument(QString("\"%1\"").arg(QDir::toNativeSeparators(game->dataDirectory().absolutePath())));
-
+
if (explorerpp.isValid()) {
addExecutableInternal(explorerpp.title(),
explorerpp.binary().absoluteFilePath(),
@@ -65,7 +65,7 @@ void ExecutablesList::init(IPluginGame const *game) explorerpp.workingDirectory().absolutePath(),
explorerpp.steamAppID());
}
-
+
}
void ExecutablesList::getExecutables(std::vector<Executable>::iterator &begin, std::vector<Executable>::iterator &end)
@@ -152,6 +152,7 @@ void ExecutablesList::updateExecutable(const QString &title, Executable::Flags flags)
{
QFileInfo file(executableName);
+ QDir dir(workingDirectory);
auto existingExe = findExe(title);
flags &= mask;
@@ -165,8 +166,11 @@ void ExecutablesList::updateExecutable(const QString &title, // don't overwrite a valid binary with an invalid one
existingExe->m_BinaryInfo = file;
}
+ if (dir.exists()) {
+ // don't overwrite a valid working directory with an invalid one
+ existingExe->m_WorkingDirectory = workingDirectory;
+ }
existingExe->m_Arguments = arguments;
- existingExe->m_WorkingDirectory = workingDirectory;
existingExe->m_SteamAppID = steamAppID;
}
} else {
|
