From 9bb631f1e1861c63f38125fffb91081c98a1cfcc Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 3 May 2018 08:29:45 +0200 Subject: Add/remove/list binds, saving to file --- include/Cache.hpp | 4 ++++ include/Chatbar.hpp | 6 ++++++ include/FileUtil.hpp | 3 +++ 3 files changed, 13 insertions(+) (limited to 'include') diff --git a/include/Cache.hpp b/include/Cache.hpp index 429f652..19b811a 100644 --- a/include/Cache.hpp +++ b/include/Cache.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -49,6 +50,9 @@ namespace dchat // Creates directory if it doesn't exist (recursively). Throws boost exception on failure static boost::filesystem::path getDchatDir(); + static void loadBindsFromFile(); + static void replaceBindsInFile(const std::unordered_map &binds); + // Get cached image or downloads it. // Default download file limit is 12MB // Returns ImageByUrlResult describing texture status. diff --git a/include/Chatbar.hpp b/include/Chatbar.hpp index 6ae2190..27b57f9 100644 --- a/include/Chatbar.hpp +++ b/include/Chatbar.hpp @@ -6,6 +6,8 @@ #include #include #include +#include +#include namespace dchat { @@ -32,6 +34,10 @@ namespace dchat void draw(sf::RenderWindow &window); static float getHeight(); + + static bool addBind(const std::string &key, const std::string &value, bool updateFile = true); + static bool removeBind(const std::string &key, bool updateFile = true); + static const std::unordered_map& getBinds(); private: void processChatCommand(const StringView &cmd); private: diff --git a/include/FileUtil.hpp b/include/FileUtil.hpp index 0cfc808..097b607 100644 --- a/include/FileUtil.hpp +++ b/include/FileUtil.hpp @@ -15,4 +15,7 @@ namespace dchat // Throws FileException on error. // Returned value is allocated with malloc and should be free'd by caller. StringView getFileContent(const boost::filesystem::path &filepath); + + // Throws FileException on error + void fileReplace(const boost::filesystem::path &filepath, const StringView data); } -- cgit v1.2.3