mirror of
https://github.com/HIllya51/LunaHook.git
synced 2024-12-24 20:24:13 +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)
|
||||
|
||||
set(VERSION_MAJOR 3)
|
||||
set(VERSION_MINOR 0)
|
||||
set(VERSION_PATCH 3)
|
||||
set(VERSION_MINOR 1)
|
||||
set(VERSION_PATCH 0)
|
||||
set(VERSION_REVISION 0)
|
||||
|
||||
add_subdirectory(include)
|
||||
|
@ -67,6 +67,7 @@
|
||||
#define MenuPluginRankUp L"Up"
|
||||
#define MenuPluginRankDown L"Down"
|
||||
#define MenuPluginEnable L"Enable"
|
||||
#define MenuPluginVisSetting L"Show Setting"
|
||||
#define DefaultFont L"Arial"
|
||||
#define CantLoadQtLoader L"Can't Load QtLoader.dll"
|
||||
#define InvalidPlugin L"Invalid Plugin!"
|
||||
|
@ -67,6 +67,7 @@
|
||||
#define MenuPluginRankUp L"上移"
|
||||
#define MenuPluginRankDown L"下移"
|
||||
#define MenuPluginEnable L"使用"
|
||||
#define MenuPluginVisSetting L"显示设置"
|
||||
#define DefaultFont L"微软雅黑"
|
||||
#define CantLoadQtLoader L"无法加载QtLoader.dll"
|
||||
#define InvalidPlugin L"插件无效!"
|
||||
|
@ -588,6 +588,10 @@ Pluginwindow::Pluginwindow(mainwindow*p,Pluginmanager* pl):mainwindow(p),pluginm
|
||||
else
|
||||
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;
|
||||
};
|
||||
|
@ -26,7 +26,7 @@ public:
|
||||
connect(ui.saveButton, &QPushButton::clicked, this, &Window::Save);
|
||||
|
||||
setWindowTitle(REGEX_FILTER);
|
||||
QMetaObject::invokeMethod(this, &QWidget::show, Qt::QueuedConnection);
|
||||
//QMetaObject::invokeMethod(this, &QWidget::show, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
setWindowTitle("Styler");
|
||||
QMetaObject::invokeMethod(this, &QWidget::show, Qt::QueuedConnection);
|
||||
//QMetaObject::invokeMethod(this, &QWidget::show, Qt::QueuedConnection);
|
||||
|
||||
LoadScript();
|
||||
}
|
||||
@ -52,3 +52,12 @@ bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
|
||||
{
|
||||
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);
|
||||
|
||||
setWindowTitle(THREAD_LINKER);
|
||||
QMetaObject::invokeMethod(this, &QWidget::show, Qt::QueuedConnection);
|
||||
//QMetaObject::invokeMethod(this, &QWidget::show, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
private:
|
||||
@ -77,3 +77,14 @@ bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
|
||||
((void(*)(int64_t, const wchar_t*))action)(link, sentence.c_str());
|
||||
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);
|
||||
QMetaObject::invokeMethod(this, &QWidget::show, Qt::QueuedConnection);
|
||||
//QMetaObject::invokeMethod(this, &QWidget::show, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
~Window()
|
||||
@ -210,3 +210,12 @@ TEST(
|
||||
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){
|
||||
auto modules=loadqtdllsX(collectQtplugs);
|
||||
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){
|
||||
@ -86,12 +86,12 @@ Pluginmanager::Pluginmanager(LunaHost* _host):host(_host),configs(_host->configs
|
||||
}
|
||||
else{
|
||||
auto base=LoadLibraryW(path.c_str());
|
||||
OnNewSentenceS[path]={false,base};
|
||||
OnNewSentenceS[path]={path,this,false,base};
|
||||
}
|
||||
}
|
||||
loadqtdlls(collectQtplugs);
|
||||
|
||||
OnNewSentenceS[L"InternalClipBoard"]={false,GetModuleHandle(0)};//内部链接的剪贴板插件
|
||||
OnNewSentenceS[L"InternalClipBoard"]={L"",this,false,GetModuleHandle(0)};//内部链接的剪贴板插件
|
||||
|
||||
|
||||
} catch (const std::exception& ex) {
|
||||
@ -142,6 +142,7 @@ pluginitem::pluginitem(const nlohmann::json& js){
|
||||
isQt=safequeryjson(js,"isQt",false);
|
||||
isref=safequeryjson(js,"isref",false);
|
||||
enable=safequeryjson(js,"enable",true);
|
||||
vissetting=safequeryjson(js,"vissetting",true);
|
||||
}
|
||||
std::wstring pluginitem::wpath(){
|
||||
auto wp=StringToWideString(path);
|
||||
@ -162,15 +163,29 @@ pluginitem::pluginitem(const std::wstring& pabs,bool _isQt){
|
||||
isref=_isref;
|
||||
path=WideStringToString(p);
|
||||
enable=true;
|
||||
vissetting=true;
|
||||
}
|
||||
nlohmann::json pluginitem::dump() const{
|
||||
return {
|
||||
{"path",path},
|
||||
{"isQt",isQt},
|
||||
{"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){
|
||||
return get(idx).enable;
|
||||
}
|
||||
@ -182,21 +197,6 @@ void Pluginmanager::setenable(int idx,bool en){
|
||||
std::wstring Pluginmanager::getname(int idx){
|
||||
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){
|
||||
for(auto& p:OnNewSentenceS){
|
||||
if(p.first==dll)return true;
|
||||
@ -216,6 +216,7 @@ void Pluginmanager::unload(const std::wstring& wss){
|
||||
void plugindata::clear(){
|
||||
hmodule=0;
|
||||
OnNewSentence=0;
|
||||
VisSetting=0;
|
||||
}
|
||||
void Pluginmanager::remove(const std::wstring& wss){
|
||||
unload(wss);
|
||||
@ -329,23 +330,48 @@ addpluginresult Pluginmanager::load(const std::wstring& p,bool*isqt){
|
||||
|
||||
std::scoped_lock lock(OnNewSentenceSLock);
|
||||
|
||||
OnNewSentenceS[p]={isQt,base};
|
||||
if(!OnNewSentenceS[p].OnNewSentence)
|
||||
OnNewSentenceS[p]={p,this,isQt,base};
|
||||
if(!OnNewSentenceS[p].valid())
|
||||
return addpluginresult::isnotaplugins;
|
||||
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;
|
||||
isQt=_isQt;
|
||||
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){
|
||||
if(checkisdump(p))return addpluginresult::dumplicate;
|
||||
bool isQt;
|
||||
auto ret=load(p,&isQt);
|
||||
if(ret==addpluginresult::success)
|
||||
if(ret==addpluginresult::success){
|
||||
add({p,isQt});
|
||||
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -16,24 +16,29 @@ struct pluginitem{
|
||||
bool isQt;
|
||||
bool isref;
|
||||
bool enable;
|
||||
bool vissetting;
|
||||
pluginitem(const nlohmann::json&);
|
||||
pluginitem(const std::wstring&,bool);
|
||||
std::wstring wpath();
|
||||
nlohmann::json dump() const;
|
||||
};
|
||||
class Pluginmanager;
|
||||
struct plugindata{
|
||||
typedef wchar_t* (*OnNewSentence_t)(wchar_t*, const InfoForExtension*);
|
||||
|
||||
typedef void (*VisSetting_t)(bool);
|
||||
std::wstring refpath;
|
||||
bool isQt;
|
||||
OnNewSentence_t OnNewSentence;
|
||||
VisSetting_t VisSetting;
|
||||
HMODULE hmodule;
|
||||
void clear();
|
||||
plugindata(){};
|
||||
plugindata(bool,HMODULE);
|
||||
plugindata(const std::wstring&,Pluginmanager*,bool,HMODULE);
|
||||
bool valid();
|
||||
void initstatus(const pluginitem&);
|
||||
};
|
||||
class Pluginmanager{
|
||||
std::unordered_map<std::wstring,plugindata>OnNewSentenceS;
|
||||
std::optional<LPVOID> checkisvalidplugin(const std::wstring&);
|
||||
concurrency::reader_writer_lock OnNewSentenceSLock;
|
||||
bool checkisdump(const std::wstring&);
|
||||
confighelper* configs;
|
||||
@ -47,6 +52,7 @@ public:
|
||||
std::optional<std::wstring>selectpluginfile();
|
||||
|
||||
pluginitem get(int);
|
||||
std::optional<pluginitem> get(const std::wstring&);
|
||||
std::wstring getname(int);
|
||||
bool getenable(int);
|
||||
void set(int,const pluginitem&);
|
||||
@ -57,6 +63,9 @@ public:
|
||||
void unload(const std::wstring&);
|
||||
addpluginresult load(const std::wstring&,bool*isqt=0);
|
||||
void swaprank(int,int);
|
||||
bool getvisible(int);
|
||||
bool getvisible_setable(int);
|
||||
void setvisible(int,bool);
|
||||
};
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user