diff options
| author | LostDragonist <lost.dragonist@gmail.com> | 2018-08-16 22:40:05 -0500 |
|---|---|---|
| committer | LostDragonist <lost.dragonist@gmail.com> | 2018-08-16 22:40:17 -0500 |
| commit | d65031c814769079a72d79b0edb84a20266b2b3c (patch) | |
| tree | 45031716de5c9653851126a5763a7c3db2fdca92 | |
| parent | c27e718fbdb3355bb75a92e8773afebb7d9c69a5 (diff) | |
Allow user to cancel VFS mapping
| -rw-r--r-- | src/mainwindow.cpp | 3 | ||||
| -rw-r--r-- | src/organizercore.cpp | 3 | ||||
| -rw-r--r-- | src/usvfsconnector.cpp | 4 | ||||
| -rw-r--r-- | src/usvfsconnector.h | 16 |
4 files changed, 25 insertions, 1 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index e6b454c5..3c749bf5 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -5012,6 +5012,9 @@ void MainWindow::on_bossButton_clicked() createStdoutPipe(&stdOutRead, &stdOutWrite);
try {
m_OrganizerCore.prepareVFS();
+ } catch (const UsvfsConnectorException &e) {
+ qDebug(e.what());
+ return;
} catch (const std::exception &e) {
QMessageBox::warning(qApp->activeWindow(), tr("Error"), e.what());
return;
diff --git a/src/organizercore.cpp b/src/organizercore.cpp index 74ec752e..5c85e323 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -1311,6 +1311,9 @@ HANDLE OrganizerCore::spawnBinaryProcess(const QFileInfo &binary, if (m_AboutToRun(binary.absoluteFilePath())) {
try {
m_USVFS.updateMapping(fileMapping(profileName, customOverwrite));
+ } catch (const UsvfsConnectorException &e) {
+ qDebug(e.what());
+ return INVALID_HANDLE_VALUE;
} catch (const std::exception &e) {
QMessageBox::warning(window, tr("Error"), e.what());
return INVALID_HANDLE_VALUE;
diff --git a/src/usvfsconnector.cpp b/src/usvfsconnector.cpp index ffbdf3aa..4ffc81c0 100644 --- a/src/usvfsconnector.cpp +++ b/src/usvfsconnector.cpp @@ -166,6 +166,10 @@ void UsvfsConnector::updateMapping(const MappingType &mapping) ClearVirtualMappings(); for (auto map : mapping) { + if (progress.wasCanceled()) { + ClearVirtualMappings(); + throw UsvfsConnectorException("VFS mapping canceled by user"); + } progress.setValue(value++); if (value % 10 == 0) { QCoreApplication::processEvents(); diff --git a/src/usvfsconnector.h b/src/usvfsconnector.h index 0935bac1..40f8857b 100644 --- a/src/usvfsconnector.h +++ b/src/usvfsconnector.h @@ -21,7 +21,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #ifndef USVFSCONNECTOR_H #define USVFSCONNECTOR_H - +#include <exception> #include <filemapping.h> #include <QString> #include <QThread> @@ -58,6 +58,20 @@ private: }; +class UsvfsConnectorException : public std::exception { + +public: + UsvfsConnectorException(const QString &text) + : std::exception(), m_Message(text.toLocal8Bit()) {} + + virtual const char* what() const throw() + { return m_Message.constData(); } +private: + QByteArray m_Message; + +}; + + class UsvfsConnector : public QObject { Q_OBJECT |
