diff --git a/GUI/extensions.cpp b/GUI/extensions.cpp index 12b3547..8a3936a 100644 --- a/GUI/extensions.cpp +++ b/GUI/extensions.cpp @@ -3,10 +3,11 @@ #include std::map extensions; +int processing; std::map LoadExtensions() { - extensions = std::map(); + std::map newExtensions; std::map extensionNames; wchar_t path[MAX_PATH] = {}; (QDir::currentPath() + "/*_nexthooker_extension.dll").toWCharArray(path); @@ -17,18 +18,24 @@ std::map LoadExtensions() GetProcAddress(LoadLibraryW(fileData.cFileName), "OnNewSentence") ) { - extensions[std::wcstol(fileData.cFileName, nullptr, 10)] = (ExtensionFunction)GetProcAddress(GetModuleHandleW(fileData.cFileName), "OnNewSentence"); + newExtensions[std::wcstol(fileData.cFileName, nullptr, 10)] = (ExtensionFunction)GetProcAddress(GetModuleHandleW(fileData.cFileName), "OnNewSentence"); QString name = QString::fromWCharArray(fileData.cFileName); name.chop(sizeof("_nexthooker_extension.dll") - 1); name.remove(0, name.split("_")[0].length() + 1); extensionNames[std::wcstol(fileData.cFileName, nullptr, 10)] = name; } while (FindNextFileW(file, &fileData) != 0); + while (processing) Sleep(10); + processing = -1; + extensions = newExtensions; + processing = 0; return extensionNames; } std::wstring DispatchSentenceToExtensions(std::wstring sentence, std::unordered_map miscInfo) { + while (processing < 0) Sleep(10); + processing++; wchar_t* sentenceBuffer = new wchar_t[sentence.size() + 1]; wcscpy(sentenceBuffer, sentence.c_str()); InfoForExtension* miscInfoLinkedList = new InfoForExtension; @@ -56,5 +63,6 @@ std::wstring DispatchSentenceToExtensions(std::wstring sentence, std::unordered_ } std::wstring newSentence = std::wstring(sentenceBuffer); delete[] sentenceBuffer; + processing--; return newSentence; }