diff --git a/vnr/extensions/Extensions.cpp b/vnr/extensions/Extensions.cpp new file mode 100644 index 0000000..ae5a9e2 --- /dev/null +++ b/vnr/extensions/Extensions.cpp @@ -0,0 +1,38 @@ +#include +#include + +typedef void(*ExtensionFunction)(LPCWSTR, DWORD64); + +std::map extensionFunctions; + +void LoadExtensions() +{ + wchar_t path[MAX_PATH]; + wchar_t* end = path + GetModuleFileNameW(nullptr, path, MAX_PATH); + while (*(--end) != L'\\'); + *(end + 1) = L'*'; + *(end + 2) = L'\0'; + WIN32_FIND_DATAW fileData; + HANDLE file = FindFirstFileW(path, &fileData); + do + { + if (fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + { + } + else + { + if (wcsstr(fileData.cFileName, L"_nextvnr_extension.dll")) + { + extensionFunctions[wcstoul(fileData.cFileName, nullptr, 10)] = (ExtensionFunction)GetProcAddress(LoadLibraryW(fileData.cFileName), "OnSentence"); + } + } + } while (FindNextFileW(file, &fileData) != 0); +} + +void DispatchSentenceToExtensions(LPCWSTR sentence, DWORD64 info) +{ + for (auto extension : extensionFunctions) + { + extension.second(sentence, info); + } +} \ No newline at end of file diff --git a/vnr/extensions/Extensions.h b/vnr/extensions/Extensions.h new file mode 100644 index 0000000..d85310c --- /dev/null +++ b/vnr/extensions/Extensions.h @@ -0,0 +1,5 @@ +#include + +typedef void(*ExtensionFunction)(LPCWSTR, DWORD64); +void LoadExtensions(); +void DispatchSentenceToExtensions(LPCWSTR sentence, DWORD64 info); \ No newline at end of file diff --git a/vnr/texthook/host/CMakeLists.txt b/vnr/texthook/host/CMakeLists.txt index edf446a..4fa56a7 100644 --- a/vnr/texthook/host/CMakeLists.txt +++ b/vnr/texthook/host/CMakeLists.txt @@ -25,6 +25,8 @@ set(vnrhost_src # ${PROJECT_SOURCE_DIR}/wintimer/wintimerbase.cc # ${PROJECT_SOURCE_DIR}/wintimer/wintimerbase.h ${PROJECT_SOURCE_DIR}/sakurakit/skdebug.h + ${PROJECT_SOURCE_DIR}/extensions/Extensions.cpp + ${PROJECT_SOURCE_DIR}/extensions/Extensions.h ) add_library(vnrhost SHARED ${vnrhost_src}) diff --git a/vnr/texthook/host/host.cc b/vnr/texthook/host/host.cc index 853c3b8..b82240b 100644 --- a/vnr/texthook/host/host.cc +++ b/vnr/texthook/host/host.cc @@ -18,6 +18,7 @@ #include "ithsys/ithsys.h" #include "ccutil/ccmacro.h" #include +#include "extensions/Extensions.h" #define DEBUG "vnrhost/host.cc" #include "sakurakit/skdebug.h" @@ -106,6 +107,7 @@ IHFSERVICE bool IHFAPI OpenHost() } else { + LoadExtensions(); ::running = true; ::settings = new Settings; ::man = new HookManager; diff --git a/vnr/texthook/host/textthread.cc b/vnr/texthook/host/textthread.cc index 53fe518..91af4cc 100644 --- a/vnr/texthook/host/textthread.cc +++ b/vnr/texthook/host/textthread.cc @@ -13,6 +13,7 @@ #include "vnrhook/include/const.h" #include "ithsys/ithsys.h" #include +#include "extensions/Extensions.h" MK_BASIC_TYPE(BYTE) MK_BASIC_TYPE(ThreadParameter) @@ -36,10 +37,9 @@ void CALLBACK NewLineBuff(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) { KillTimer(hwnd,idEvent); TextThread *id=(TextThread*)idEvent; - - if (id->Status()&CURRENT_SELECT) - //texts->SetLine(); - id->CopyLastToClipboard(); + id->DispatchLastSentence(); + + //id->SendLastToExtension(); id->SetNewLineFlag(); } @@ -649,43 +649,32 @@ DWORD TextThread::GetEntryString(LPSTR str, DWORD max) // } //} -static char clipboard_buffer[0x400]; // jichi 8/25/2013: clipboard removed -void CopyToClipboard(void* str,bool unicode, int len) +void DispatchSentence(void* str,DWORD status, int len) { - if (settings->clipboardFlag && str && len > 0) + char sentenceBuffer[0x400]; + if (str && len > 0) { int size=(len*2|0xF)+1; if (len>=1022) return; - memcpy(clipboard_buffer,str,len); - *(WORD*)(clipboard_buffer+len)=0; + memcpy(sentenceBuffer,str,len); + *(WORD*)(sentenceBuffer+len)=0; HGLOBAL hCopy; - LPWSTR copy; - if (OpenClipboard(0)) - { - if (hCopy=GlobalAlloc(GMEM_MOVEABLE,size)) - { - if (copy=(LPWSTR)GlobalLock(hCopy)) - { - if (unicode) - { - memcpy(copy,clipboard_buffer,len+2); - } - else - copy[MB_WC(clipboard_buffer,copy)]=0; - GlobalUnlock(hCopy); - EmptyClipboard(); - SetClipboardData(CF_UNICODETEXT,hCopy); - } - } - CloseClipboard(); - } + wchar_t copy[0x200]; + if (status&USING_UNICODE) + { + memcpy(copy, sentenceBuffer, len + 2); + } + else + copy[MB_WC(sentenceBuffer, copy)] = 0; + DispatchSentenceToExtensions(copy, status); } } -void TextThread::CopyLastToClipboard() +void TextThread::DispatchLastSentence() { // jichi 8/25/2013: clipboard removed - CopyToClipboard(storage+last_sentence,(status&USING_UNICODE)>0,used-last_sentence); + DispatchSentence(storage+last_sentence,status,used-last_sentence); + } //void TextThread::ResetEditText() diff --git a/vnr/texthook/host/textthread.h b/vnr/texthook/host/textthread.h index 4f98838..1f6f5f9 100644 --- a/vnr/texthook/host/textthread.h +++ b/vnr/texthook/host/textthread.h @@ -62,7 +62,7 @@ public: //void ResetEditText(); void ComboSelectCurrent(); void UnLinkAll(); - void CopyLastToClipboard(); + void DispatchLastSentence(); //void AdjustPrevRepeat(DWORD len); //void PrevRepeatLength(DWORD &len);