From 97dbf2c6ce42ae4a60b4ca0eb9a50272cd0410e5 Mon Sep 17 00:00:00 2001 From: engsr6982 <109733049+engsr6982@users.noreply.github.com> Date: Tue, 16 Apr 2024 22:08:07 +0800 Subject: [PATCH] format all --- src/File/Config.cpp | 47 +++++++++++++++++++++++++++++++++++++ src/{Form => File}/Config.h | 0 src/Form/Mapping.h | 5 ++-- src/Form/index.cpp | 3 ++- src/Permission/Permission.h | 2 +- 5 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 src/File/Config.cpp rename src/{Form => File}/Config.h (100%) diff --git a/src/File/Config.cpp b/src/File/Config.cpp new file mode 100644 index 0000000..13541a6 --- /dev/null +++ b/src/File/Config.cpp @@ -0,0 +1,47 @@ +#include "Config.h" +#include "entry/Entry.h" + +#include +#include +#include + +namespace tls::config { + +S_Config cfg; // init Config + +#define CONFIG_FILE_NAME "Config.json" +using ll::i18n_literals::operator""_tr; + + +bool loadConfig() { + auto& mSelf = entry::entry::getInstance().getSelf(); + auto filePath = mSelf.getConfigDir() / CONFIG_FILE_NAME; + auto& logger = mSelf.getLogger(); + // init file + std::filesystem::path p = filePath; + if (!std::filesystem::exists(p)) { + logger.info("Saving default configurations"); + writeConfig(cfg); + } + // loading + if (!ll::config::loadConfig(cfg, filePath)) { + logger.warn("Unable to load configuration from {}"_tr(filePath)); + return false; + } + return true; +} + +bool writeConfig(S_Config newCfg) { + auto& mSelf = entry::entry::getInstance().getSelf(); + auto configFilePath = mSelf.getConfigDir() / CONFIG_FILE_NAME; + auto& logger = mSelf.getLogger(); + + if (!ll::config::saveConfig(newCfg, configFilePath)) { + logger.error("Cannot save configurations to {}"_tr(configFilePath)); + return false; + } + return true; +} +bool writeConfig() { return writeConfig(cfg); } + +} // namespace tls::config \ No newline at end of file diff --git a/src/Form/Config.h b/src/File/Config.h similarity index 100% rename from src/Form/Config.h rename to src/File/Config.h diff --git a/src/Form/Mapping.h b/src/Form/Mapping.h index 76dc2f9..562e9fb 100644 --- a/src/Form/Mapping.h +++ b/src/Form/Mapping.h @@ -1,11 +1,12 @@ +#include "mc/world/actor/player/Player.h" #include #include #include -#include "mc/world/actor/player/Player.h" + namespace tls::form { extern std::unordered_map> mapping; bool initMapping(); -} \ No newline at end of file +} // namespace tls::form \ No newline at end of file diff --git a/src/Form/index.cpp b/src/Form/index.cpp index 8072a6b..7ff77d2 100644 --- a/src/Form/index.cpp +++ b/src/Form/index.cpp @@ -1,10 +1,11 @@ +#include "Form/index.h" #include "Api/Api.h" #include "Entry/Entry.h" #include "Entry/PluginInfo.h" #include "File/file.h" -#include "Form/index.h" #include "Form/Mapping.h" + #include #include #include diff --git a/src/Permission/Permission.h b/src/Permission/Permission.h index 5659d23..acd09dc 100644 --- a/src/Permission/Permission.h +++ b/src/Permission/Permission.h @@ -34,4 +34,4 @@ enum Permission { void initPermission(); -} // namespace tls::perm \ No newline at end of file +} // namespace tls::perms \ No newline at end of file