mirror of
https://github.com/HIllya51/LunaHook.git
synced 2025-01-12 12:59:31 +08:00
update
This commit is contained in:
parent
d6aff9849d
commit
2f93a2bf4d
@ -54,8 +54,8 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/version)
|
|||||||
include(generate_product_version)
|
include(generate_product_version)
|
||||||
|
|
||||||
set(VERSION_MAJOR 3)
|
set(VERSION_MAJOR 3)
|
||||||
set(VERSION_MINOR 0)
|
set(VERSION_MINOR 1)
|
||||||
set(VERSION_PATCH 3)
|
set(VERSION_PATCH 0)
|
||||||
set(VERSION_REVISION 0)
|
set(VERSION_REVISION 0)
|
||||||
|
|
||||||
add_subdirectory(include)
|
add_subdirectory(include)
|
||||||
|
@ -67,6 +67,7 @@
|
|||||||
#define MenuPluginRankUp L"Up"
|
#define MenuPluginRankUp L"Up"
|
||||||
#define MenuPluginRankDown L"Down"
|
#define MenuPluginRankDown L"Down"
|
||||||
#define MenuPluginEnable L"Enable"
|
#define MenuPluginEnable L"Enable"
|
||||||
|
#define MenuPluginVisSetting L"Show Setting"
|
||||||
#define DefaultFont L"Arial"
|
#define DefaultFont L"Arial"
|
||||||
#define CantLoadQtLoader L"Can't Load QtLoader.dll"
|
#define CantLoadQtLoader L"Can't Load QtLoader.dll"
|
||||||
#define InvalidPlugin L"Invalid Plugin!"
|
#define InvalidPlugin L"Invalid Plugin!"
|
||||||
|
@ -67,6 +67,7 @@
|
|||||||
#define MenuPluginRankUp L"上移"
|
#define MenuPluginRankUp L"上移"
|
||||||
#define MenuPluginRankDown L"下移"
|
#define MenuPluginRankDown L"下移"
|
||||||
#define MenuPluginEnable L"使用"
|
#define MenuPluginEnable L"使用"
|
||||||
|
#define MenuPluginVisSetting L"显示设置"
|
||||||
#define DefaultFont L"微软雅黑"
|
#define DefaultFont L"微软雅黑"
|
||||||
#define CantLoadQtLoader L"无法加载QtLoader.dll"
|
#define CantLoadQtLoader L"无法加载QtLoader.dll"
|
||||||
#define InvalidPlugin L"插件无效!"
|
#define InvalidPlugin L"插件无效!"
|
||||||
|
@ -588,6 +588,10 @@ Pluginwindow::Pluginwindow(mainwindow*p,Pluginmanager* pl):mainwindow(p),pluginm
|
|||||||
else
|
else
|
||||||
pluginmanager->unload((LPCWSTR)listplugins->getdata(idx));
|
pluginmanager->unload((LPCWSTR)listplugins->getdata(idx));
|
||||||
});
|
});
|
||||||
|
if(pluginmanager->getvisible_setable(idx))
|
||||||
|
menu.add_checkable(MenuPluginVisSetting,pluginmanager->getvisible(idx),[&,idx](bool check){
|
||||||
|
pluginmanager->setvisible(idx,check);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return menu;
|
return menu;
|
||||||
};
|
};
|
||||||
|
@ -26,7 +26,7 @@ public:
|
|||||||
connect(ui.saveButton, &QPushButton::clicked, this, &Window::Save);
|
connect(ui.saveButton, &QPushButton::clicked, this, &Window::Save);
|
||||||
|
|
||||||
setWindowTitle(REGEX_FILTER);
|
setWindowTitle(REGEX_FILTER);
|
||||||
QMetaObject::invokeMethod(this, &QWidget::show, Qt::QueuedConnection);
|
//QMetaObject::invokeMethod(this, &QWidget::show, Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetRegex(QString regex)
|
void SetRegex(QString regex)
|
||||||
@ -69,3 +69,12 @@ bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
|
|||||||
if (regex) sentence = std::regex_replace(sentence, regex.value(), replace);
|
if (regex) sentence = std::regex_replace(sentence, regex.value(), replace);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" __declspec(dllexport) void VisSetting(bool vis)
|
||||||
|
{
|
||||||
|
if(vis)
|
||||||
|
QMetaObject::invokeMethod(&window, &QWidget::show, Qt::QueuedConnection);
|
||||||
|
else
|
||||||
|
QMetaObject::invokeMethod(&window, &QWidget::hide, Qt::QueuedConnection);
|
||||||
|
}
|
||||||
|
@ -20,7 +20,7 @@ public:
|
|||||||
|
|
||||||
resize(800, 600);
|
resize(800, 600);
|
||||||
setWindowTitle("Styler");
|
setWindowTitle("Styler");
|
||||||
QMetaObject::invokeMethod(this, &QWidget::show, Qt::QueuedConnection);
|
//QMetaObject::invokeMethod(this, &QWidget::show, Qt::QueuedConnection);
|
||||||
|
|
||||||
LoadScript();
|
LoadScript();
|
||||||
}
|
}
|
||||||
@ -52,3 +52,12 @@ bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" __declspec(dllexport) void VisSetting(bool vis)
|
||||||
|
{
|
||||||
|
if(vis)
|
||||||
|
QMetaObject::invokeMethod(&window, &QWidget::show, Qt::QueuedConnection);
|
||||||
|
else
|
||||||
|
QMetaObject::invokeMethod(&window, &QWidget::hide, Qt::QueuedConnection);
|
||||||
|
}
|
||||||
|
@ -27,7 +27,7 @@ public:
|
|||||||
connect(ui.unlinkButton, &QPushButton::clicked, this, &Window::Unlink);
|
connect(ui.unlinkButton, &QPushButton::clicked, this, &Window::Unlink);
|
||||||
|
|
||||||
setWindowTitle(THREAD_LINKER);
|
setWindowTitle(THREAD_LINKER);
|
||||||
QMetaObject::invokeMethod(this, &QWidget::show, Qt::QueuedConnection);
|
//QMetaObject::invokeMethod(this, &QWidget::show, Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -77,3 +77,14 @@ bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
|
|||||||
((void(*)(int64_t, const wchar_t*))action)(link, sentence.c_str());
|
((void(*)(int64_t, const wchar_t*))action)(link, sentence.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" __declspec(dllexport) void VisSetting(bool vis)
|
||||||
|
{
|
||||||
|
if(vis)
|
||||||
|
QMetaObject::invokeMethod(&window, &QWidget::show, Qt::QueuedConnection);
|
||||||
|
else
|
||||||
|
QMetaObject::invokeMethod(&window, &QWidget::hide, Qt::QueuedConnection);
|
||||||
|
}
|
||||||
|
@ -129,7 +129,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
setWindowTitle(TRANSLATION_PROVIDER);
|
setWindowTitle(TRANSLATION_PROVIDER);
|
||||||
QMetaObject::invokeMethod(this, &QWidget::show, Qt::QueuedConnection);
|
//QMetaObject::invokeMethod(this, &QWidget::show, Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
~Window()
|
~Window()
|
||||||
@ -210,3 +210,12 @@ TEST(
|
|||||||
assert(codes.count(L"?"));
|
assert(codes.count(L"?"));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" __declspec(dllexport) void VisSetting(bool vis)
|
||||||
|
{
|
||||||
|
if(vis)
|
||||||
|
QMetaObject::invokeMethod(&window, &QWidget::show, Qt::QueuedConnection);
|
||||||
|
else
|
||||||
|
QMetaObject::invokeMethod(&window, &QWidget::hide, Qt::QueuedConnection);
|
||||||
|
}
|
||||||
|
@ -67,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,modules[i]};
|
OnNewSentenceS[collectQtplugs[i]]={collectQtplugs[i],this,true,modules[i]};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Pluginmanager::Pluginmanager(LunaHost* _host):host(_host),configs(_host->configs){
|
Pluginmanager::Pluginmanager(LunaHost* _host):host(_host),configs(_host->configs){
|
||||||
@ -86,12 +86,12 @@ Pluginmanager::Pluginmanager(LunaHost* _host):host(_host),configs(_host->configs
|
|||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
auto base=LoadLibraryW(path.c_str());
|
auto base=LoadLibraryW(path.c_str());
|
||||||
OnNewSentenceS[path]={false,base};
|
OnNewSentenceS[path]={path,this,false,base};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
loadqtdlls(collectQtplugs);
|
loadqtdlls(collectQtplugs);
|
||||||
|
|
||||||
OnNewSentenceS[L"InternalClipBoard"]={false,GetModuleHandle(0)};//内部链接的剪贴板插件
|
OnNewSentenceS[L"InternalClipBoard"]={L"",this,false,GetModuleHandle(0)};//内部链接的剪贴板插件
|
||||||
|
|
||||||
|
|
||||||
} catch (const std::exception& ex) {
|
} catch (const std::exception& ex) {
|
||||||
@ -142,6 +142,7 @@ pluginitem::pluginitem(const nlohmann::json& js){
|
|||||||
isQt=safequeryjson(js,"isQt",false);
|
isQt=safequeryjson(js,"isQt",false);
|
||||||
isref=safequeryjson(js,"isref",false);
|
isref=safequeryjson(js,"isref",false);
|
||||||
enable=safequeryjson(js,"enable",true);
|
enable=safequeryjson(js,"enable",true);
|
||||||
|
vissetting=safequeryjson(js,"vissetting",true);
|
||||||
}
|
}
|
||||||
std::wstring pluginitem::wpath(){
|
std::wstring pluginitem::wpath(){
|
||||||
auto wp=StringToWideString(path);
|
auto wp=StringToWideString(path);
|
||||||
@ -162,15 +163,29 @@ pluginitem::pluginitem(const std::wstring& pabs,bool _isQt){
|
|||||||
isref=_isref;
|
isref=_isref;
|
||||||
path=WideStringToString(p);
|
path=WideStringToString(p);
|
||||||
enable=true;
|
enable=true;
|
||||||
|
vissetting=true;
|
||||||
}
|
}
|
||||||
nlohmann::json pluginitem::dump() const{
|
nlohmann::json pluginitem::dump() const{
|
||||||
return {
|
return {
|
||||||
{"path",path},
|
{"path",path},
|
||||||
{"isQt",isQt},
|
{"isQt",isQt},
|
||||||
{"isref",isref},
|
{"isref",isref},
|
||||||
{"enable",enable}
|
{"enable",enable},
|
||||||
|
{"vissetting",vissetting}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
bool Pluginmanager::getvisible_setable(int idx){
|
||||||
|
return OnNewSentenceS[getname(idx)].VisSetting;
|
||||||
|
}
|
||||||
|
bool Pluginmanager::getvisible(int idx){
|
||||||
|
return get(idx).vissetting;
|
||||||
|
}
|
||||||
|
void Pluginmanager::setvisible(int idx,bool vis){
|
||||||
|
auto item=get(idx);
|
||||||
|
item.vissetting=vis;
|
||||||
|
set(idx,item);
|
||||||
|
OnNewSentenceS[getname(idx)].VisSetting(vis);
|
||||||
|
}
|
||||||
bool Pluginmanager::getenable(int idx){
|
bool Pluginmanager::getenable(int idx){
|
||||||
return get(idx).enable;
|
return get(idx).enable;
|
||||||
}
|
}
|
||||||
@ -182,21 +197,6 @@ void Pluginmanager::setenable(int idx,bool en){
|
|||||||
std::wstring Pluginmanager::getname(int idx){
|
std::wstring Pluginmanager::getname(int idx){
|
||||||
return get(idx).wpath();
|
return get(idx).wpath();
|
||||||
}
|
}
|
||||||
std::optional<LPVOID> Pluginmanager::checkisvalidplugin(const std::wstring& pl){
|
|
||||||
auto path=std::filesystem::path(pl);
|
|
||||||
if (!std::filesystem::exists(path))return{};
|
|
||||||
if (!std::filesystem::is_regular_file(path))return{};
|
|
||||||
auto appendix=stolower(path.extension().wstring());
|
|
||||||
if((appendix!=std::wstring(L".dll"))&&(appendix!=std::wstring(L".xdll")))return {};
|
|
||||||
auto dll=LoadLibraryW(pl.c_str());
|
|
||||||
if(!dll)return {};
|
|
||||||
auto OnNewSentence=GetProcAddress(LoadLibraryW(pl.c_str()),"OnNewSentence");
|
|
||||||
if(!OnNewSentence){
|
|
||||||
FreeLibrary(dll);
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
return OnNewSentence ;
|
|
||||||
}
|
|
||||||
bool Pluginmanager::checkisdump(const std::wstring& dll){
|
bool Pluginmanager::checkisdump(const std::wstring& dll){
|
||||||
for(auto& p:OnNewSentenceS){
|
for(auto& p:OnNewSentenceS){
|
||||||
if(p.first==dll)return true;
|
if(p.first==dll)return true;
|
||||||
@ -216,6 +216,7 @@ void Pluginmanager::unload(const std::wstring& wss){
|
|||||||
void plugindata::clear(){
|
void plugindata::clear(){
|
||||||
hmodule=0;
|
hmodule=0;
|
||||||
OnNewSentence=0;
|
OnNewSentence=0;
|
||||||
|
VisSetting=0;
|
||||||
}
|
}
|
||||||
void Pluginmanager::remove(const std::wstring& wss){
|
void Pluginmanager::remove(const std::wstring& wss){
|
||||||
unload(wss);
|
unload(wss);
|
||||||
@ -329,23 +330,48 @@ addpluginresult Pluginmanager::load(const std::wstring& p,bool*isqt){
|
|||||||
|
|
||||||
std::scoped_lock lock(OnNewSentenceSLock);
|
std::scoped_lock lock(OnNewSentenceSLock);
|
||||||
|
|
||||||
OnNewSentenceS[p]={isQt,base};
|
OnNewSentenceS[p]={p,this,isQt,base};
|
||||||
if(!OnNewSentenceS[p].OnNewSentence)
|
if(!OnNewSentenceS[p].valid())
|
||||||
return addpluginresult::isnotaplugins;
|
return addpluginresult::isnotaplugins;
|
||||||
return addpluginresult::success;
|
return addpluginresult::success;
|
||||||
}
|
}
|
||||||
plugindata::plugindata(bool _isQt,HMODULE hm){
|
bool plugindata::valid(){
|
||||||
|
return OnNewSentence;
|
||||||
|
}
|
||||||
|
plugindata::plugindata(const std::wstring& p,Pluginmanager* manager,bool _isQt,HMODULE hm){
|
||||||
hmodule=hm;
|
hmodule=hm;
|
||||||
isQt=_isQt;
|
isQt=_isQt;
|
||||||
OnNewSentence=(OnNewSentence_t)GetProcAddress(hm,"OnNewSentence");
|
OnNewSentence=(OnNewSentence_t)GetProcAddress(hm,"OnNewSentence");
|
||||||
|
VisSetting=(VisSetting_t)GetProcAddress(hm,"VisSetting");
|
||||||
|
refpath=p;
|
||||||
|
if(VisSetting)
|
||||||
|
{
|
||||||
|
auto vis=true;
|
||||||
|
if(auto plg=manager->get(p))
|
||||||
|
vis=plg.value().vissetting;
|
||||||
|
VisSetting(vis);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void plugindata::initstatus(const pluginitem& plg){
|
||||||
|
if(plg.vissetting && VisSetting)
|
||||||
|
VisSetting(true);
|
||||||
|
}
|
||||||
|
std::optional<pluginitem> Pluginmanager::get(const std::wstring&p){
|
||||||
|
for(int i=0;i<count();i++)
|
||||||
|
{
|
||||||
|
if(getname(i)==p){
|
||||||
|
return get(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
addpluginresult Pluginmanager::addplugin(const std::wstring& p){
|
addpluginresult Pluginmanager::addplugin(const std::wstring& p){
|
||||||
if(checkisdump(p))return addpluginresult::dumplicate;
|
if(checkisdump(p))return addpluginresult::dumplicate;
|
||||||
bool isQt;
|
bool isQt;
|
||||||
auto ret=load(p,&isQt);
|
auto ret=load(p,&isQt);
|
||||||
if(ret==addpluginresult::success)
|
if(ret==addpluginresult::success){
|
||||||
add({p,isQt});
|
add({p,isQt});
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,24 +16,29 @@ struct pluginitem{
|
|||||||
bool isQt;
|
bool isQt;
|
||||||
bool isref;
|
bool isref;
|
||||||
bool enable;
|
bool enable;
|
||||||
|
bool vissetting;
|
||||||
pluginitem(const nlohmann::json&);
|
pluginitem(const nlohmann::json&);
|
||||||
pluginitem(const std::wstring&,bool);
|
pluginitem(const std::wstring&,bool);
|
||||||
std::wstring wpath();
|
std::wstring wpath();
|
||||||
nlohmann::json dump() const;
|
nlohmann::json dump() const;
|
||||||
};
|
};
|
||||||
|
class Pluginmanager;
|
||||||
struct plugindata{
|
struct plugindata{
|
||||||
typedef wchar_t* (*OnNewSentence_t)(wchar_t*, const InfoForExtension*);
|
typedef wchar_t* (*OnNewSentence_t)(wchar_t*, const InfoForExtension*);
|
||||||
|
typedef void (*VisSetting_t)(bool);
|
||||||
|
std::wstring refpath;
|
||||||
bool isQt;
|
bool isQt;
|
||||||
OnNewSentence_t OnNewSentence;
|
OnNewSentence_t OnNewSentence;
|
||||||
|
VisSetting_t VisSetting;
|
||||||
HMODULE hmodule;
|
HMODULE hmodule;
|
||||||
void clear();
|
void clear();
|
||||||
plugindata(){};
|
plugindata(){};
|
||||||
plugindata(bool,HMODULE);
|
plugindata(const std::wstring&,Pluginmanager*,bool,HMODULE);
|
||||||
|
bool valid();
|
||||||
|
void initstatus(const pluginitem&);
|
||||||
};
|
};
|
||||||
class Pluginmanager{
|
class Pluginmanager{
|
||||||
std::unordered_map<std::wstring,plugindata>OnNewSentenceS;
|
std::unordered_map<std::wstring,plugindata>OnNewSentenceS;
|
||||||
std::optional<LPVOID> checkisvalidplugin(const std::wstring&);
|
|
||||||
concurrency::reader_writer_lock OnNewSentenceSLock;
|
concurrency::reader_writer_lock OnNewSentenceSLock;
|
||||||
bool checkisdump(const std::wstring&);
|
bool checkisdump(const std::wstring&);
|
||||||
confighelper* configs;
|
confighelper* configs;
|
||||||
@ -47,6 +52,7 @@ public:
|
|||||||
std::optional<std::wstring>selectpluginfile();
|
std::optional<std::wstring>selectpluginfile();
|
||||||
|
|
||||||
pluginitem get(int);
|
pluginitem get(int);
|
||||||
|
std::optional<pluginitem> get(const std::wstring&);
|
||||||
std::wstring getname(int);
|
std::wstring getname(int);
|
||||||
bool getenable(int);
|
bool getenable(int);
|
||||||
void set(int,const pluginitem&);
|
void set(int,const pluginitem&);
|
||||||
@ -57,6 +63,9 @@ public:
|
|||||||
void unload(const std::wstring&);
|
void unload(const std::wstring&);
|
||||||
addpluginresult load(const std::wstring&,bool*isqt=0);
|
addpluginresult load(const std::wstring&,bool*isqt=0);
|
||||||
void swaprank(int,int);
|
void swaprank(int,int);
|
||||||
|
bool getvisible(int);
|
||||||
|
bool getvisible_setable(int);
|
||||||
|
void setvisible(int,bool);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
x
Reference in New Issue
Block a user