From b88702f94a3dba6e18e70cf932818ed45fda8fa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Wed, 29 Jul 2015 19:48:41 +0200 Subject: [PATCH] Make install working --- CMakeLists.txt | 3 ++- src/config.cc | 21 +++++++++++++-------- src/juci.cc | 2 +- src/menu.cc | 1 + src/menu.h | 1 - src/singletons.h | 4 +++- 6 files changed, 20 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b69577..6229322 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,4 +16,5 @@ add_subdirectory("src") install( DIRECTORY "config" "plugins" DESTINATION ${juci_config_folder} - USE_SOURCE_PERMISSIONS) \ No newline at end of file + USE_SOURCE_PERMISSIONS) +install(CODE "FILE(MAKE_DIRECTORY ${juci_config_filder}/log)") diff --git a/src/config.cc b/src/config.cc index f0d942b..b71cbf5 100644 --- a/src/config.cc +++ b/src/config.cc @@ -3,11 +3,12 @@ #include "logging.h" #include #include +#include + MainConfig::MainConfig() { INFO("Reading config file"); - std::string path(getenv("HOME")); // TODO WINDOWS - boost::property_tree::json_parser::read_json(path + "/.juci/config/config.json", cfg_); + boost::property_tree::json_parser::read_json(Singleton::config_dir() + "config.json", cfg_); INFO("Config file read"); GenerateSource(); GenerateKeybindings(); @@ -74,13 +75,17 @@ void MainConfig::GenerateTerminalCommands() { } void MainConfig::GenerateKeybindings() { - auto menu=Singleton::menu(); - DEBUG("Fetching keybindings"); + auto menu = Singleton::menu(); + boost::filesystem::path path(Singleton::config_dir() + "menu.xml"); + if (!boost::filesystem::is_regular_file(path)) { + std::cerr << "menu.xml not found" << std::endl; + throw; + } + std::ifstream input(path.string()); std::string line; - std::ifstream menu_xml("menu.xml"); - if (menu_xml.is_open()) { - while (getline(menu_xml, line)) - menu->ui+=line; + if (input.is_open()) { + while (getline(input, line)) + menu->ui += line; } boost::property_tree::ptree keys_json = cfg_.get_child("keybindings"); for (auto &i : keys_json) { diff --git a/src/juci.cc b/src/juci.cc index bd38c4b..a6326dc 100644 --- a/src/juci.cc +++ b/src/juci.cc @@ -3,7 +3,7 @@ void init_logging() { add_common_attributes(); - add_file_log(keywords::file_name = "juci.log", + add_file_log(keywords::file_name = Singleton::log_dir() + "juci.log", keywords::auto_flush = true); INFO("Logging initalized"); } diff --git a/src/menu.cc b/src/menu.cc index 6a08595..d20b74d 100644 --- a/src/menu.cc +++ b/src/menu.cc @@ -1,4 +1,5 @@ #include "menu.h" +#include "logging.h" #include Menu::Menu() : box(Gtk::ORIENTATION_VERTICAL) { diff --git a/src/menu.h b/src/menu.h index af5aa92..40e3cb3 100644 --- a/src/menu.h +++ b/src/menu.h @@ -4,7 +4,6 @@ #include #include #include -#include "logging.h" class Menu { public: diff --git a/src/singletons.h b/src/singletons.h index be8240a..15bc60d 100644 --- a/src/singletons.h +++ b/src/singletons.h @@ -6,6 +6,7 @@ #include "terminal.h" #include "notebook.h" #include "menu.h" +#include class Singleton { public: @@ -19,7 +20,8 @@ public: static std::unique_ptr terminal_; static std::unique_ptr directories_; }; - + static std::string config_dir() { return std::string(getenv("HOME")) + "/.juci/config/"; } + static std::string log_dir() { return std::string(getenv("HOME")) + "/.juci/log/"; } static Terminal::Controller *terminal(); static Menu *menu(); private: