From 104f9a7b8c63efa27c21aa790685ebbaf0fefe2b Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Wed, 17 Oct 2018 01:08:31 -0400 Subject: [PATCH] fix extension thread safety --- GUI/extensions.cpp | 13 +++++++++++++ GUI/extensions.h | 1 + GUI/mainwindow.cpp | 7 +------ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/GUI/extensions.cpp b/GUI/extensions.cpp index 01e6586..1db6791 100644 --- a/GUI/extensions.cpp +++ b/GUI/extensions.cpp @@ -51,3 +51,16 @@ bool DispatchSentenceToExtensions(std::wstring& sentence, std::unordered_map extenLock(extenMutex); + if (extensions.find({ extenNumber }) == extensions.end()) return; + QString extenFileName = QString::number(extenNumber) + "_" + extensions.find({ extenNumber })->name + ".dll"; + FreeLibrary(GetModuleHandleW(extenFileName.toStdWString().c_str())); + QString removedFileName = extenFileName; + removedFileName.remove(0, removedFileName.indexOf("_")); + QFile::remove(removedFileName); + if (!QFile::rename(extenFileName, removedFileName)) QFile::remove(extenFileName); + extensions.erase(extensions.find({ extenNumber })); +} diff --git a/GUI/extensions.h b/GUI/extensions.h index de2d642..9741ccf 100644 --- a/GUI/extensions.h +++ b/GUI/extensions.h @@ -22,5 +22,6 @@ struct Extension std::set LoadExtensions(); bool DispatchSentenceToExtensions(std::wstring& sentence, std::unordered_map miscInfo); +void UnloadExtension(int extenNumber); #endif // EXTENSIONS_H diff --git a/GUI/mainwindow.cpp b/GUI/mainwindow.cpp index b4af203..5dbe505 100644 --- a/GUI/mainwindow.cpp +++ b/GUI/mainwindow.cpp @@ -248,11 +248,6 @@ void MainWindow::on_addExtenButton_clicked() void MainWindow::on_rmvExtenButton_clicked() { if (extenCombo->currentText().size() == 0) return; - QString extenFileName = extenCombo->currentText().split(":")[0] + "_" + extenCombo->currentText().split(": ")[1] + ".dll"; - FreeLibrary(GetModuleHandleW(extenFileName.toStdWString().c_str())); - QString removedFileName = extenFileName; - removedFileName.remove(0, removedFileName.indexOf("_")); - QFile::remove(removedFileName); - QFile::rename(extenFileName, removedFileName); + UnloadExtension(extenCombo->currentText().split(":")[0].toInt()); ReloadExtensions(); }