mirror of
https://github.com/Artikash/Textractor.git
synced 2024-12-24 01:14:12 +08:00
add basic extension support
This commit is contained in:
parent
0b79811cc3
commit
9715612b83
38
vnr/extensions/Extensions.cpp
Normal file
38
vnr/extensions/Extensions.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#include <Windows.h>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
typedef void(*ExtensionFunction)(LPCWSTR, DWORD64);
|
||||||
|
|
||||||
|
std::map<DWORD, ExtensionFunction> 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);
|
||||||
|
}
|
||||||
|
}
|
5
vnr/extensions/Extensions.h
Normal file
5
vnr/extensions/Extensions.h
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#include <Windows.h>
|
||||||
|
|
||||||
|
typedef void(*ExtensionFunction)(LPCWSTR, DWORD64);
|
||||||
|
void LoadExtensions();
|
||||||
|
void DispatchSentenceToExtensions(LPCWSTR sentence, DWORD64 info);
|
@ -25,6 +25,8 @@ set(vnrhost_src
|
|||||||
# ${PROJECT_SOURCE_DIR}/wintimer/wintimerbase.cc
|
# ${PROJECT_SOURCE_DIR}/wintimer/wintimerbase.cc
|
||||||
# ${PROJECT_SOURCE_DIR}/wintimer/wintimerbase.h
|
# ${PROJECT_SOURCE_DIR}/wintimer/wintimerbase.h
|
||||||
${PROJECT_SOURCE_DIR}/sakurakit/skdebug.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})
|
add_library(vnrhost SHARED ${vnrhost_src})
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include "ithsys/ithsys.h"
|
#include "ithsys/ithsys.h"
|
||||||
#include "ccutil/ccmacro.h"
|
#include "ccutil/ccmacro.h"
|
||||||
#include <commctrl.h>
|
#include <commctrl.h>
|
||||||
|
#include "extensions/Extensions.h"
|
||||||
|
|
||||||
#define DEBUG "vnrhost/host.cc"
|
#define DEBUG "vnrhost/host.cc"
|
||||||
#include "sakurakit/skdebug.h"
|
#include "sakurakit/skdebug.h"
|
||||||
@ -106,6 +107,7 @@ IHFSERVICE bool IHFAPI OpenHost()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
LoadExtensions();
|
||||||
::running = true;
|
::running = true;
|
||||||
::settings = new Settings;
|
::settings = new Settings;
|
||||||
::man = new HookManager;
|
::man = new HookManager;
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include "vnrhook/include/const.h"
|
#include "vnrhook/include/const.h"
|
||||||
#include "ithsys/ithsys.h"
|
#include "ithsys/ithsys.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include "extensions/Extensions.h"
|
||||||
|
|
||||||
MK_BASIC_TYPE(BYTE)
|
MK_BASIC_TYPE(BYTE)
|
||||||
MK_BASIC_TYPE(ThreadParameter)
|
MK_BASIC_TYPE(ThreadParameter)
|
||||||
@ -36,10 +37,9 @@ void CALLBACK NewLineBuff(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
|
|||||||
{
|
{
|
||||||
KillTimer(hwnd,idEvent);
|
KillTimer(hwnd,idEvent);
|
||||||
TextThread *id=(TextThread*)idEvent;
|
TextThread *id=(TextThread*)idEvent;
|
||||||
|
id->DispatchLastSentence();
|
||||||
|
|
||||||
if (id->Status()&CURRENT_SELECT)
|
//id->SendLastToExtension();
|
||||||
//texts->SetLine();
|
|
||||||
id->CopyLastToClipboard();
|
|
||||||
id->SetNewLineFlag();
|
id->SetNewLineFlag();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -649,43 +649,32 @@ DWORD TextThread::GetEntryString(LPSTR str, DWORD max)
|
|||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
static char clipboard_buffer[0x400];
|
|
||||||
// jichi 8/25/2013: clipboard removed
|
// 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;
|
int size=(len*2|0xF)+1;
|
||||||
if (len>=1022) return;
|
if (len>=1022) return;
|
||||||
memcpy(clipboard_buffer,str,len);
|
memcpy(sentenceBuffer,str,len);
|
||||||
*(WORD*)(clipboard_buffer+len)=0;
|
*(WORD*)(sentenceBuffer+len)=0;
|
||||||
HGLOBAL hCopy;
|
HGLOBAL hCopy;
|
||||||
LPWSTR copy;
|
wchar_t copy[0x200];
|
||||||
if (OpenClipboard(0))
|
if (status&USING_UNICODE)
|
||||||
{
|
{
|
||||||
if (hCopy=GlobalAlloc(GMEM_MOVEABLE,size))
|
memcpy(copy, sentenceBuffer, len + 2);
|
||||||
{
|
|
||||||
if (copy=(LPWSTR)GlobalLock(hCopy))
|
|
||||||
{
|
|
||||||
if (unicode)
|
|
||||||
{
|
|
||||||
memcpy(copy,clipboard_buffer,len+2);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
copy[MB_WC(clipboard_buffer,copy)]=0;
|
copy[MB_WC(sentenceBuffer, copy)] = 0;
|
||||||
GlobalUnlock(hCopy);
|
DispatchSentenceToExtensions(copy, status);
|
||||||
EmptyClipboard();
|
|
||||||
SetClipboardData(CF_UNICODETEXT,hCopy);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CloseClipboard();
|
void TextThread::DispatchLastSentence()
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void TextThread::CopyLastToClipboard()
|
|
||||||
{
|
{
|
||||||
// jichi 8/25/2013: clipboard removed
|
// 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()
|
//void TextThread::ResetEditText()
|
||||||
|
@ -62,7 +62,7 @@ public:
|
|||||||
//void ResetEditText();
|
//void ResetEditText();
|
||||||
void ComboSelectCurrent();
|
void ComboSelectCurrent();
|
||||||
void UnLinkAll();
|
void UnLinkAll();
|
||||||
void CopyLastToClipboard();
|
void DispatchLastSentence();
|
||||||
|
|
||||||
//void AdjustPrevRepeat(DWORD len);
|
//void AdjustPrevRepeat(DWORD len);
|
||||||
//void PrevRepeatLength(DWORD &len);
|
//void PrevRepeatLength(DWORD &len);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user