2024-02-08 19:12:20 +08:00
|
|
|
#ifndef LUNA_PLUGINMANAGER_H
|
|
|
|
#define LUNA_PLUGINMANAGER_H
|
2024-07-21 19:28:47 +08:00
|
|
|
#include "Plugin/extension.h"
|
|
|
|
#include "textthread.h"
|
|
|
|
#include <nlohmann/json.hpp>
|
2024-02-08 19:12:20 +08:00
|
|
|
class LunaHost;
|
2024-03-29 18:07:15 +08:00
|
|
|
class confighelper;
|
2024-07-21 19:28:47 +08:00
|
|
|
enum class addpluginresult
|
|
|
|
{
|
2024-03-29 15:57:38 +08:00
|
|
|
success,
|
|
|
|
invaliddll,
|
|
|
|
isnotaplugins,
|
|
|
|
dumplicate
|
|
|
|
};
|
2024-07-21 19:28:47 +08:00
|
|
|
struct pluginitem
|
|
|
|
{
|
2024-03-29 18:07:15 +08:00
|
|
|
std::string path;
|
|
|
|
bool isQt;
|
|
|
|
bool enable;
|
2024-04-24 09:04:02 +08:00
|
|
|
bool vissetting;
|
2024-07-21 19:28:47 +08:00
|
|
|
pluginitem(const nlohmann::json &);
|
|
|
|
pluginitem(const std::wstring &, bool);
|
2024-03-29 18:07:15 +08:00
|
|
|
std::wstring wpath();
|
|
|
|
nlohmann::json dump() const;
|
|
|
|
};
|
2024-04-24 09:04:02 +08:00
|
|
|
class Pluginmanager;
|
2024-07-21 19:28:47 +08:00
|
|
|
struct plugindata
|
|
|
|
{
|
|
|
|
typedef wchar_t *(*OnNewSentence_t)(wchar_t *, const InfoForExtension *);
|
2024-04-24 09:04:02 +08:00
|
|
|
typedef void (*VisSetting_t)(bool);
|
|
|
|
std::wstring refpath;
|
2024-03-30 00:40:49 +08:00
|
|
|
bool isQt;
|
2024-04-23 20:01:57 +08:00
|
|
|
OnNewSentence_t OnNewSentence;
|
2024-04-24 09:04:02 +08:00
|
|
|
VisSetting_t VisSetting;
|
2024-03-30 00:40:49 +08:00
|
|
|
HMODULE hmodule;
|
2024-04-23 20:01:57 +08:00
|
|
|
void clear();
|
2024-10-03 14:53:59 +08:00
|
|
|
plugindata() {};
|
2024-07-21 19:28:47 +08:00
|
|
|
plugindata(const std::wstring &, Pluginmanager *, bool, HMODULE);
|
2024-04-24 09:04:02 +08:00
|
|
|
bool valid();
|
2024-07-21 19:28:47 +08:00
|
|
|
void initstatus(const pluginitem &);
|
2024-03-30 00:40:49 +08:00
|
|
|
};
|
2024-07-21 19:28:47 +08:00
|
|
|
class Pluginmanager
|
|
|
|
{
|
|
|
|
std::unordered_map<std::wstring, plugindata> OnNewSentenceS;
|
2024-02-08 16:18:33 +08:00
|
|
|
concurrency::reader_writer_lock OnNewSentenceSLock;
|
2024-07-21 19:28:47 +08:00
|
|
|
bool checkisdump(const std::wstring &);
|
|
|
|
confighelper *configs;
|
|
|
|
LunaHost *host;
|
|
|
|
std::array<InfoForExtension, 20> GetSentenceInfo(TextThread &thread);
|
|
|
|
void loadqtdlls(std::vector<std::wstring> &collectQtplugs);
|
|
|
|
|
2024-02-08 16:18:33 +08:00
|
|
|
public:
|
2024-07-21 19:28:47 +08:00
|
|
|
Pluginmanager(LunaHost *);
|
|
|
|
bool dispatch(TextThread &, std::wstring &sentence);
|
|
|
|
addpluginresult addplugin(const std::wstring &);
|
|
|
|
std::optional<std::wstring> selectpluginfile();
|
|
|
|
|
2024-03-29 18:07:15 +08:00
|
|
|
pluginitem get(int);
|
2024-07-21 19:28:47 +08:00
|
|
|
std::optional<pluginitem> get(const std::wstring &);
|
2024-03-29 18:07:15 +08:00
|
|
|
std::wstring getname(int);
|
|
|
|
bool getenable(int);
|
2024-07-21 19:28:47 +08:00
|
|
|
void set(int, const pluginitem &);
|
|
|
|
void setenable(int, bool);
|
2024-03-29 18:07:15 +08:00
|
|
|
int count();
|
2024-07-21 19:28:47 +08:00
|
|
|
void add(const pluginitem &);
|
|
|
|
void remove(const std::wstring &);
|
|
|
|
void unload(const std::wstring &);
|
|
|
|
addpluginresult load(const std::wstring &, bool *isqt = 0);
|
|
|
|
void swaprank(int, int);
|
2024-04-24 09:04:02 +08:00
|
|
|
bool getvisible(int);
|
|
|
|
bool getvisible_setable(int);
|
2024-07-21 19:28:47 +08:00
|
|
|
void setvisible(int, bool);
|
2024-02-08 16:18:33 +08:00
|
|
|
};
|
|
|
|
|
2024-02-08 19:12:20 +08:00
|
|
|
#endif
|