mirror of
https://github.com/HIllya51/LunaHook.git
synced 2024-10-22 23:18:16 +08:00
fix
This commit is contained in:
parent
eebbbe62a6
commit
24ae167d1a
@ -55,7 +55,7 @@ include(generate_product_version)
|
|||||||
|
|
||||||
set(VERSION_MAJOR 3)
|
set(VERSION_MAJOR 3)
|
||||||
set(VERSION_MINOR 0)
|
set(VERSION_MINOR 0)
|
||||||
set(VERSION_PATCH 2)
|
set(VERSION_PATCH 3)
|
||||||
set(VERSION_REVISION 0)
|
set(VERSION_REVISION 0)
|
||||||
|
|
||||||
add_subdirectory(include)
|
add_subdirectory(include)
|
||||||
|
@ -574,7 +574,7 @@ Pluginwindow::Pluginwindow(mainwindow*p,Pluginmanager* pl):mainwindow(p),pluginm
|
|||||||
if(idx!=-1)
|
if(idx!=-1)
|
||||||
{
|
{
|
||||||
menu.add(MenuRemovePlugin,[&,idx](){
|
menu.add(MenuRemovePlugin,[&,idx](){
|
||||||
pluginmanager->remove((LPCWSTR)listplugins->getdata(idx),false);
|
pluginmanager->remove((LPCWSTR)listplugins->getdata(idx));
|
||||||
listplugins->deleteitem(idx);
|
listplugins->deleteitem(idx);
|
||||||
});
|
});
|
||||||
menu.add_sep();
|
menu.add_sep();
|
||||||
@ -584,9 +584,9 @@ Pluginwindow::Pluginwindow(mainwindow*p,Pluginmanager* pl):mainwindow(p),pluginm
|
|||||||
menu.add_checkable(MenuPluginEnable,pluginmanager->getenable(idx),[&,idx](bool check){
|
menu.add_checkable(MenuPluginEnable,pluginmanager->getenable(idx),[&,idx](bool check){
|
||||||
pluginmanager->setenable(idx,check);
|
pluginmanager->setenable(idx,check);
|
||||||
if(check)
|
if(check)
|
||||||
pluginmanager->addplugin((LPCWSTR)listplugins->getdata(idx),true);
|
pluginmanager->load((LPCWSTR)listplugins->getdata(idx));
|
||||||
else
|
else
|
||||||
pluginmanager->remove((LPCWSTR)listplugins->getdata(idx),true);
|
pluginmanager->unload((LPCWSTR)listplugins->getdata(idx));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return menu;
|
return menu;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
bool sendclipboarddata(const std::wstring&text,HWND hwnd);
|
bool sendclipboarddata(const std::wstring&text,HWND hwnd);
|
||||||
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
|
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
|
||||||
{
|
{
|
||||||
if (sentenceInfo["current select"] && sentenceInfo["process id"] != 0 &&sentenceInfo["toclipboard"])
|
if (sentenceInfo["current select"] && sentenceInfo["toclipboard"])
|
||||||
{
|
{
|
||||||
sendclipboarddata(sentence,(HWND)sentenceInfo["HostHWND"]);
|
sendclipboarddata(sentence,(HWND)sentenceInfo["HostHWND"]);
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ struct Localizer { Localizer() { Localize(); } };
|
|||||||
inline std::wstring S(const QString& s) {
|
inline std::wstring S(const QString& s) {
|
||||||
//s.toStdWString will crash. unknown why.
|
//s.toStdWString will crash. unknown why.
|
||||||
std::wstring ws;
|
std::wstring ws;
|
||||||
ws.resize(s.size()+1);
|
ws.resize(s.size());
|
||||||
s.toWCharArray(ws.data());
|
s.toWCharArray(ws.data());
|
||||||
return ws;
|
return ws;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#include"LunaHost.h"
|
#include"LunaHost.h"
|
||||||
#include"Lang/Lang.h"
|
#include"Lang/Lang.h"
|
||||||
#include"host.h"
|
#include"host.h"
|
||||||
typedef wchar_t* (*OnNewSentence_t)(wchar_t*, const InfoForExtension*);
|
|
||||||
|
|
||||||
std::optional<std::wstring>SelectFile(HWND hwnd,LPCWSTR lpstrFilter){
|
std::optional<std::wstring>SelectFile(HWND hwnd,LPCWSTR lpstrFilter){
|
||||||
OPENFILENAME ofn;
|
OPENFILENAME ofn;
|
||||||
@ -68,7 +67,7 @@ HMODULE loadqtdllsX(const std::wstring&collectQtplugs){
|
|||||||
void Pluginmanager::loadqtdlls(std::vector<std::wstring>&collectQtplugs){
|
void Pluginmanager::loadqtdlls(std::vector<std::wstring>&collectQtplugs){
|
||||||
auto modules=loadqtdllsX(collectQtplugs);
|
auto modules=loadqtdllsX(collectQtplugs);
|
||||||
for(int i=0;i<collectQtplugs.size();i++){
|
for(int i=0;i<collectQtplugs.size();i++){
|
||||||
OnNewSentenceS[collectQtplugs[i]]={true,GetProcAddress(modules[i],"OnNewSentence"),modules[i]};
|
OnNewSentenceS[collectQtplugs[i]]={true,modules[i]};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Pluginmanager::Pluginmanager(LunaHost* _host):host(_host),configs(_host->configs){
|
Pluginmanager::Pluginmanager(LunaHost* _host):host(_host),configs(_host->configs){
|
||||||
@ -80,19 +79,19 @@ Pluginmanager::Pluginmanager(LunaHost* _host):host(_host),configs(_host->configs
|
|||||||
auto plg=get(i);
|
auto plg=get(i);
|
||||||
bool isqt=plg.isQt;
|
bool isqt=plg.isQt;
|
||||||
auto path=plg.wpath();
|
auto path=plg.wpath();
|
||||||
OnNewSentenceS[path]={false,0,0};
|
OnNewSentenceS[path]={};
|
||||||
if(isqt){
|
if(isqt){
|
||||||
if(plg.enable==false)continue;
|
if(plg.enable==false)continue;
|
||||||
collectQtplugs.push_back((path));
|
collectQtplugs.push_back((path));
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
auto base=LoadLibraryW(path.c_str());
|
auto base=LoadLibraryW(path.c_str());
|
||||||
OnNewSentenceS[path]={false,GetProcAddress(base,"OnNewSentence"),base};
|
OnNewSentenceS[path]={false,base};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
loadqtdlls(collectQtplugs);
|
loadqtdlls(collectQtplugs);
|
||||||
|
|
||||||
OnNewSentenceS[L"InternalClipBoard"]={false,GetProcAddress(GetModuleHandle(0),"OnNewSentence"),GetModuleHandle(0)};//内部链接的剪贴板插件
|
OnNewSentenceS[L"InternalClipBoard"]={false,GetModuleHandle(0)};//内部链接的剪贴板插件
|
||||||
|
|
||||||
|
|
||||||
} catch (const std::exception& ex) {
|
} catch (const std::exception& ex) {
|
||||||
@ -114,9 +113,9 @@ bool Pluginmanager::dispatch(TextThread& thread, std::wstring& sentence){
|
|||||||
path=getname(i);
|
path=getname(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto funptr=OnNewSentenceS[path].funcptr;
|
auto funptr=OnNewSentenceS[path].OnNewSentence;
|
||||||
if(funptr==0)continue;
|
if(funptr==0)continue;
|
||||||
if (!*(sentenceBuffer = ((OnNewSentence_t)funptr)(sentenceBuffer, sentenceInfo)))
|
if (!*(sentenceBuffer = funptr(sentenceBuffer, sentenceInfo)))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,7 +203,7 @@ bool Pluginmanager::checkisdump(const std::wstring& dll){
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
void Pluginmanager::remove(const std::wstring& wss,bool onlyload){
|
void Pluginmanager::unload(const std::wstring& wss){
|
||||||
auto hm=OnNewSentenceS[wss].hmodule;
|
auto hm=OnNewSentenceS[wss].hmodule;
|
||||||
if(OnNewSentenceS[wss].isQt && hm){
|
if(OnNewSentenceS[wss].isQt && hm){
|
||||||
((QtFreeLibrary_t)GetProcAddress(GetModuleHandle(0),"QtFreeLibrary"))(hm);
|
((QtFreeLibrary_t)GetProcAddress(GetModuleHandle(0),"QtFreeLibrary"))(hm);
|
||||||
@ -212,11 +211,15 @@ void Pluginmanager::remove(const std::wstring& wss,bool onlyload){
|
|||||||
else
|
else
|
||||||
FreeLibrary(hm);
|
FreeLibrary(hm);
|
||||||
|
|
||||||
|
OnNewSentenceS[wss].clear();
|
||||||
if(onlyload){
|
}
|
||||||
OnNewSentenceS[wss].funcptr=OnNewSentenceS[wss].hmodule=0;
|
void plugindata::clear(){
|
||||||
return;
|
hmodule=0;
|
||||||
}
|
OnNewSentence=0;
|
||||||
|
}
|
||||||
|
void Pluginmanager::remove(const std::wstring& wss){
|
||||||
|
unload(wss);
|
||||||
|
|
||||||
auto s=WideStringToString(wss);
|
auto s=WideStringToString(wss);
|
||||||
auto &plgs=configs->configs["plugins"];
|
auto &plgs=configs->configs["plugins"];
|
||||||
auto it=std::remove_if(plgs.begin(),plgs.end(),[&](auto&t){
|
auto it=std::remove_if(plgs.begin(),plgs.end(),[&](auto&t){
|
||||||
@ -309,12 +312,11 @@ bool qtchecker(const std::set<std::string>& dll)
|
|||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
addpluginresult Pluginmanager::addplugin(const std::wstring& p,bool onlyload){
|
addpluginresult Pluginmanager::load(const std::wstring& p,bool*isqt){
|
||||||
if(!onlyload)
|
|
||||||
if(checkisdump(p))return addpluginresult::dumplicate;
|
|
||||||
auto importtable=getimporttable(p);
|
auto importtable=getimporttable(p);
|
||||||
if(importtable.empty())return addpluginresult::invaliddll;
|
if(importtable.empty())return addpluginresult::invaliddll;
|
||||||
auto isQt=qtchecker(importtable);
|
auto isQt=qtchecker(importtable);
|
||||||
|
if(isqt)*isqt=isQt;
|
||||||
HMODULE base;
|
HMODULE base;
|
||||||
if(isQt){
|
if(isQt){
|
||||||
base=loadqtdllsX(p);
|
base=loadqtdllsX(p);
|
||||||
@ -324,15 +326,27 @@ addpluginresult Pluginmanager::addplugin(const std::wstring& p,bool onlyload){
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(base==0)return addpluginresult::invaliddll;
|
if(base==0)return addpluginresult::invaliddll;
|
||||||
auto plugin=GetProcAddress(base,"OnNewSentence");
|
|
||||||
if(!plugin)return addpluginresult::isnotaplugins;
|
|
||||||
std::scoped_lock lock(OnNewSentenceSLock);
|
std::scoped_lock lock(OnNewSentenceSLock);
|
||||||
|
|
||||||
OnNewSentenceS[p]={isQt,plugin,base};
|
OnNewSentenceS[p]={isQt,base};
|
||||||
if(!onlyload)
|
if(!OnNewSentenceS[p].OnNewSentence)
|
||||||
|
return addpluginresult::isnotaplugins;
|
||||||
|
return addpluginresult::success;
|
||||||
|
}
|
||||||
|
plugindata::plugindata(bool _isQt,HMODULE hm){
|
||||||
|
hmodule=hm;
|
||||||
|
isQt=_isQt;
|
||||||
|
OnNewSentence=(OnNewSentence_t)GetProcAddress(hm,"OnNewSentence");
|
||||||
|
}
|
||||||
|
addpluginresult Pluginmanager::addplugin(const std::wstring& p){
|
||||||
|
if(checkisdump(p))return addpluginresult::dumplicate;
|
||||||
|
bool isQt;
|
||||||
|
auto ret=load(p,&isQt);
|
||||||
|
if(ret==addpluginresult::success)
|
||||||
add({p,isQt});
|
add({p,isQt});
|
||||||
|
|
||||||
return addpluginresult::success;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,9 +22,14 @@ struct pluginitem{
|
|||||||
nlohmann::json dump() const;
|
nlohmann::json dump() const;
|
||||||
};
|
};
|
||||||
struct plugindata{
|
struct plugindata{
|
||||||
|
typedef wchar_t* (*OnNewSentence_t)(wchar_t*, const InfoForExtension*);
|
||||||
|
|
||||||
bool isQt;
|
bool isQt;
|
||||||
LPVOID funcptr;
|
OnNewSentence_t OnNewSentence;
|
||||||
HMODULE hmodule;
|
HMODULE hmodule;
|
||||||
|
void clear();
|
||||||
|
plugindata(){};
|
||||||
|
plugindata(bool,HMODULE);
|
||||||
};
|
};
|
||||||
class Pluginmanager{
|
class Pluginmanager{
|
||||||
std::unordered_map<std::wstring,plugindata>OnNewSentenceS;
|
std::unordered_map<std::wstring,plugindata>OnNewSentenceS;
|
||||||
@ -38,7 +43,7 @@ class Pluginmanager{
|
|||||||
public:
|
public:
|
||||||
Pluginmanager(LunaHost*);
|
Pluginmanager(LunaHost*);
|
||||||
bool dispatch(TextThread&, std::wstring& sentence);
|
bool dispatch(TextThread&, std::wstring& sentence);
|
||||||
addpluginresult addplugin(const std::wstring&,bool onlyload=false);
|
addpluginresult addplugin(const std::wstring&);
|
||||||
std::optional<std::wstring>selectpluginfile();
|
std::optional<std::wstring>selectpluginfile();
|
||||||
|
|
||||||
pluginitem get(int);
|
pluginitem get(int);
|
||||||
@ -48,7 +53,9 @@ public:
|
|||||||
void setenable(int ,bool);
|
void setenable(int ,bool);
|
||||||
int count();
|
int count();
|
||||||
void add(const pluginitem&);
|
void add(const pluginitem&);
|
||||||
void remove(const std::wstring&,bool);
|
void remove(const std::wstring&);
|
||||||
|
void unload(const std::wstring&);
|
||||||
|
addpluginresult load(const std::wstring&,bool*isqt=0);
|
||||||
void swaprank(int,int);
|
void swaprank(int,int);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user