fix extension thread safety
This commit is contained in:
parent
3ad311293f
commit
104f9a7b8c
@ -51,3 +51,16 @@ bool DispatchSentenceToExtensions(std::wstring& sentence, std::unordered_map<std
|
||||
HeapFree(GetProcessHeap(), 0, sentenceBuffer);
|
||||
return success;
|
||||
}
|
||||
|
||||
void UnloadExtension(int extenNumber)
|
||||
{
|
||||
std::unique_lock<std::shared_mutex> 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 }));
|
||||
}
|
||||
|
@ -22,5 +22,6 @@ struct Extension
|
||||
|
||||
std::set<Extension> LoadExtensions();
|
||||
bool DispatchSentenceToExtensions(std::wstring& sentence, std::unordered_map<std::string, int64_t> miscInfo);
|
||||
void UnloadExtension(int extenNumber);
|
||||
|
||||
#endif // EXTENSIONS_H
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user