mirror of
https://github.com/HIllya51/LunaHook.git
synced 2025-01-12 04:49:37 +08:00
ref path
This commit is contained in:
parent
3d05e89edd
commit
a6600ac38a
@ -1,5 +1,5 @@
|
|||||||
#include"confighelper.h"
|
#include"confighelper.h"
|
||||||
|
#include"stringutils.h"
|
||||||
std::string readfile(const wchar_t* fname) {
|
std::string readfile(const wchar_t* fname) {
|
||||||
FILE* f;
|
FILE* f;
|
||||||
_wfopen_s(&f, fname, L"rb");
|
_wfopen_s(&f, fname, L"rb");
|
||||||
@ -52,12 +52,50 @@ void confighelper::pluginrankswap(int a,int b){
|
|||||||
plgs[b]=plgs[a];
|
plgs[b]=plgs[a];
|
||||||
plgs[a]=_b;
|
plgs[a]=_b;
|
||||||
}
|
}
|
||||||
void confighelper::pluginsadd(const std::string& p,bool isQt){
|
void confighelper::pluginsadd(const pluginitem& item){
|
||||||
configs["plugins"].push_back({
|
configs["plugins"].push_back(item.dump());
|
||||||
{"path",p},
|
|
||||||
{"isQt",isQt}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
nlohmann::json confighelper::pluginsget(){
|
int confighelper::pluginsnum(){
|
||||||
return configs["plugins"];
|
return configs["plugins"].size();
|
||||||
|
}
|
||||||
|
pluginitem confighelper::pluginsget(int i){
|
||||||
|
return pluginitem{configs["plugins"][i]};
|
||||||
|
}
|
||||||
|
template<typename T>
|
||||||
|
T safequeryjson(const nlohmann::json& js,const std::string& key,const T &defaultv){
|
||||||
|
if(js.find(key)==js.end()){
|
||||||
|
return defaultv;
|
||||||
|
}
|
||||||
|
return js[key];
|
||||||
|
}
|
||||||
|
pluginitem::pluginitem(const nlohmann::json& js){
|
||||||
|
path=js["path"];
|
||||||
|
isQt=safequeryjson(js,"isQt",false);
|
||||||
|
isref=safequeryjson(js,"isref",false);
|
||||||
|
}
|
||||||
|
std::wstring pluginitem::wpath(){
|
||||||
|
auto wp=StringToWideString(path);
|
||||||
|
if(isref)return std::filesystem::current_path()/wp;
|
||||||
|
else return wp;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::pair<std::wstring,bool> castabs2ref(const std::wstring&p){
|
||||||
|
auto curr=std::filesystem::current_path().wstring();
|
||||||
|
if(startWith(p,curr)){
|
||||||
|
return {p.substr(curr.size()+1),true};
|
||||||
|
}
|
||||||
|
return {p,false};
|
||||||
|
}
|
||||||
|
pluginitem::pluginitem(const std::wstring& pabs,bool _isQt){
|
||||||
|
isQt=_isQt;
|
||||||
|
auto [p,_isref]=castabs2ref(pabs);
|
||||||
|
isref=_isref;
|
||||||
|
path=WideStringToString(p);
|
||||||
|
}
|
||||||
|
nlohmann::json pluginitem::dump() const{
|
||||||
|
return {
|
||||||
|
{"path",path},
|
||||||
|
{"isQt",isQt},
|
||||||
|
{"isref",isref}
|
||||||
|
};
|
||||||
}
|
}
|
@ -1,14 +1,24 @@
|
|||||||
#ifndef LUNA_CONFIG_HELPER
|
#ifndef LUNA_CONFIG_HELPER
|
||||||
#define LUNA_CONFIG_HELPER
|
#define LUNA_CONFIG_HELPER
|
||||||
#include<nlohmann/json.hpp>
|
#include<nlohmann/json.hpp>
|
||||||
|
struct pluginitem{
|
||||||
|
std::string path;
|
||||||
|
bool isQt;
|
||||||
|
bool isref;
|
||||||
|
pluginitem(const nlohmann::json&);
|
||||||
|
pluginitem(const std::wstring&,bool);
|
||||||
|
std::wstring wpath();
|
||||||
|
nlohmann::json dump() const;
|
||||||
|
};
|
||||||
class confighelper{
|
class confighelper{
|
||||||
nlohmann::json configs;
|
nlohmann::json configs;
|
||||||
std::wstring configpath;
|
std::wstring configpath;
|
||||||
public:
|
public:
|
||||||
confighelper();
|
confighelper();
|
||||||
~confighelper();
|
~confighelper();
|
||||||
nlohmann::json pluginsget();
|
pluginitem pluginsget(int);
|
||||||
void pluginsadd(const std::string&,bool);
|
int pluginsnum();
|
||||||
|
void pluginsadd(const pluginitem&);
|
||||||
void pluginsremove(const std::string&);
|
void pluginsremove(const std::string&);
|
||||||
void pluginrankswap(int,int);
|
void pluginrankswap(int,int);
|
||||||
template<class T>
|
template<class T>
|
||||||
|
@ -17,7 +17,7 @@ std::optional<std::wstring>SelectFile(HWND hwnd,LPCWSTR lpstrFilter){
|
|||||||
ofn.lpstrFilter = lpstrFilter;
|
ofn.lpstrFilter = lpstrFilter;
|
||||||
ofn.lpstrFile = szFileName;
|
ofn.lpstrFile = szFileName;
|
||||||
ofn.nMaxFile = sizeof(szFileName);
|
ofn.nMaxFile = sizeof(szFileName);
|
||||||
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
|
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_NOCHANGEDIR;
|
||||||
|
|
||||||
if (GetOpenFileName(&ofn))
|
if (GetOpenFileName(&ofn))
|
||||||
{
|
{
|
||||||
@ -67,11 +67,11 @@ Pluginmanager::Pluginmanager(LunaHost* _host):host(_host){
|
|||||||
std::scoped_lock lock(OnNewSentenceSLock);
|
std::scoped_lock lock(OnNewSentenceSLock);
|
||||||
|
|
||||||
OnNewSentenceS[L"InternalClipBoard"]=GetProcAddress(GetModuleHandle(0),"OnNewSentence");//内部链接的剪贴板插件
|
OnNewSentenceS[L"InternalClipBoard"]=GetProcAddress(GetModuleHandle(0),"OnNewSentence");//内部链接的剪贴板插件
|
||||||
auto plgs=host->configs->pluginsget();
|
|
||||||
std::vector<std::wstring>collectQtplugs;
|
std::vector<std::wstring>collectQtplugs;
|
||||||
for (auto i=0;i<plgs.size();i++) {
|
for (auto i=0;i<host->configs->pluginsnum();i++) {
|
||||||
bool isqt=plgs[i]["isQt"];
|
auto plg=host->configs->pluginsget(i);
|
||||||
auto path=StringToWideString(plgs[i]["path"]);
|
bool isqt=plg.isQt;
|
||||||
|
auto path=plg.wpath();
|
||||||
PluginRank.push_back(path);
|
PluginRank.push_back(path);
|
||||||
OnNewSentenceS[path]=0;
|
OnNewSentenceS[path]=0;
|
||||||
if(isqt){
|
if(isqt){
|
||||||
@ -149,7 +149,7 @@ void Pluginmanager::swaprank(int a,int b){
|
|||||||
}
|
}
|
||||||
bool Pluginmanager::addplugin(const std::wstring& p,bool isQt){
|
bool Pluginmanager::addplugin(const std::wstring& p,bool isQt){
|
||||||
if(isQt){
|
if(isQt){
|
||||||
host->configs->pluginsadd(WideStringToString(p),isQt);
|
host->configs->pluginsadd({p,isQt});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
auto plugin=GetProcAddress(LoadLibraryW(p.c_str()),"OnNewSentence");
|
auto plugin=GetProcAddress(LoadLibraryW(p.c_str()),"OnNewSentence");
|
||||||
@ -159,7 +159,7 @@ bool Pluginmanager::addplugin(const std::wstring& p,bool isQt){
|
|||||||
PluginRank.push_back(p);
|
PluginRank.push_back(p);
|
||||||
//std::swap(PluginRank.end()-2,PluginRank.end()-1);
|
//std::swap(PluginRank.end()-2,PluginRank.end()-1);
|
||||||
OnNewSentenceS[p]=plugin;
|
OnNewSentenceS[p]=plugin;
|
||||||
host->configs->pluginsadd(WideStringToString(p),isQt);
|
host->configs->pluginsadd({p,isQt});
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user