This commit is contained in:
恍兮惚兮 2024-11-01 23:34:22 +08:00
parent 4eb6ad29a2
commit 245259e0cc
5 changed files with 20 additions and 25 deletions

View File

@ -60,9 +60,9 @@ include_directories(include)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/version) 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 5)
set(VERSION_MINOR 16) set(VERSION_MINOR 0)
set(VERSION_PATCH 3) set(VERSION_PATCH 0)
set(VERSION_REVISION 0) set(VERSION_REVISION 0)
if(BUILD_CORE) if(BUILD_CORE)

View File

@ -25,7 +25,7 @@ void writefile(const wchar_t *fname, const std::string &s)
confighelper::confighelper() confighelper::confighelper()
{ {
configpath = std::filesystem::current_path() / (x64 ? "config64.json" : "config32.json"); configpath = std::filesystem::current_path() / "config.json";
try try
{ {
configs = nlohmann::json::parse(readfile(configpath.c_str())); configs = nlohmann::json::parse(readfile(configpath.c_str()));
@ -35,9 +35,9 @@ confighelper::confighelper()
configs = {}; configs = {};
} }
if (configs.find("plugins") == configs.end()) if (configs.find(pluginkey) == configs.end())
{ {
configs["plugins"] = {}; configs[pluginkey] = {};
} }
} }
confighelper::~confighelper() confighelper::~confighelper()

View File

@ -32,4 +32,7 @@ T safequeryjson(const nlohmann::json &js, const std::string &key, const T &defau
} }
return js[key]; return js[key];
} }
constexpr auto pluginkey = x64 ? "plugins64" : "plugins32";
#endif #endif

View File

@ -148,53 +148,47 @@ bool Pluginmanager::dispatch(TextThread &thread, std::wstring &sentence)
void Pluginmanager::add(const pluginitem &item) void Pluginmanager::add(const pluginitem &item)
{ {
configs->configs["plugins"].push_back(item.dump()); configs->configs[pluginkey].push_back(item.dump());
} }
int Pluginmanager::count() int Pluginmanager::count()
{ {
return configs->configs["plugins"].size(); return configs->configs[pluginkey].size();
} }
pluginitem Pluginmanager::get(int i) pluginitem Pluginmanager::get(int i)
{ {
return pluginitem{configs->configs["plugins"][i]}; return pluginitem{configs->configs[pluginkey][i]};
} }
void Pluginmanager::set(int i, const pluginitem &item) void Pluginmanager::set(int i, const pluginitem &item)
{ {
configs->configs["plugins"][i] = item.dump(); configs->configs[pluginkey][i] = item.dump();
} }
pluginitem::pluginitem(const nlohmann::json &js) pluginitem::pluginitem(const nlohmann::json &js)
{ {
path = js["path"]; path = js["path"];
isQt = safequeryjson(js, "isQt", false); isQt = safequeryjson(js, "isQt", false);
isref = safequeryjson(js, "isref", false);
enable = safequeryjson(js, "enable", true); enable = safequeryjson(js, "enable", true);
vissetting = safequeryjson(js, "vissetting", true); vissetting = safequeryjson(js, "vissetting", true);
} }
std::wstring pluginitem::wpath() std::wstring pluginitem::wpath()
{ {
auto wp = StringToWideString(path); auto wp = StringToWideString(path);
if (isref)
return std::filesystem::absolute(wp); return std::filesystem::absolute(wp);
else
return wp;
} }
std::pair<std::wstring, bool> castabs2ref(const std::wstring &p) std::wstring castabs2ref(const std::wstring &p)
{ {
auto curr = std::filesystem::current_path().wstring(); auto curr = std::filesystem::current_path().wstring();
if (startWith(p, curr)) if (startWith(p, curr))
{ {
return {p.substr(curr.size() + 1), true}; return p.substr(curr.size() + 1);
} }
return {p, false}; return p;
} }
pluginitem::pluginitem(const std::wstring &pabs, bool _isQt) pluginitem::pluginitem(const std::wstring &pabs, bool _isQt)
{ {
isQt = _isQt; isQt = _isQt;
auto [p, _isref] = castabs2ref(pabs); path = WideStringToString(castabs2ref(pabs));
isref = _isref;
path = WideStringToString(p);
enable = true; enable = true;
vissetting = true; vissetting = true;
} }
@ -203,7 +197,6 @@ nlohmann::json pluginitem::dump() const
return { return {
{"path", path}, {"path", path},
{"isQt", isQt}, {"isQt", isQt},
{"isref", isref},
{"enable", enable}, {"enable", enable},
{"vissetting", vissetting}}; {"vissetting", vissetting}};
} }
@ -268,7 +261,7 @@ void Pluginmanager::remove(const std::wstring &wss)
unload(wss); unload(wss);
auto s = WideStringToString(wss); auto s = WideStringToString(wss);
auto &plgs = configs->configs["plugins"]; auto &plgs = configs->configs[pluginkey];
auto it = std::remove_if(plgs.begin(), plgs.end(), [&](auto &t) auto it = std::remove_if(plgs.begin(), plgs.end(), [&](auto &t)
{ {
std::string p=t["path"]; std::string p=t["path"];
@ -282,7 +275,7 @@ std::optional<std::wstring> Pluginmanager::selectpluginfile()
} }
void Pluginmanager::swaprank(int a, int b) void Pluginmanager::swaprank(int a, int b)
{ {
auto &plgs = configs->configs["plugins"]; auto &plgs = configs->configs[pluginkey];
auto _b = plgs[b]; auto _b = plgs[b];
plgs[b] = plgs[a]; plgs[b] = plgs[a];
plgs[a] = _b; plgs[a] = _b;

View File

@ -16,7 +16,6 @@ struct pluginitem
{ {
std::string path; std::string path;
bool isQt; bool isQt;
bool isref;
bool enable; bool enable;
bool vissetting; bool vissetting;
pluginitem(const nlohmann::json &); pluginitem(const nlohmann::json &);