diff --git a/src/config.cc b/src/config.cc index d50e375..35f7289 100644 --- a/src/config.cc +++ b/src/config.cc @@ -10,12 +10,12 @@ using namespace std; //TODO: remove MainConfig::MainConfig() { find_or_create_config_files(); try { - boost::property_tree::json_parser::read_json(Singleton::config_dir() + "config.json", cfg); + boost::property_tree::json_parser::read_json(Singleton::config_json(), cfg); update_config_file(); retrieve_config(); } catch(const std::exception &e) { - Singleton::terminal()->print("Error reading "+Singleton::config_dir() + "config.json: "+e.what()+"\n"); + Singleton::terminal()->print("Error reading "+ Singleton::config_json()+": "+e.what()+"\n"); std::stringstream ss; ss << configjson; boost::property_tree::read_json(ss, cfg); @@ -27,7 +27,8 @@ void MainConfig::find_or_create_config_files() { std::vector files = {"config.json", "plugins.py"}; boost::filesystem::create_directories(boost::filesystem::path(Singleton::config_dir())); for (auto &file : files) { - auto path = boost::filesystem::path(Singleton::config_dir() + file); + auto path = Singleton::config_dir(); + path /= file; if (!boost::filesystem::is_regular_file(path)) { if (file == "config.json") filesystem::write(path, configjson); if (file == "plugins.py") filesystem::write(path, pluginspy); @@ -35,16 +36,16 @@ void MainConfig::find_or_create_config_files() { } boost::filesystem::create_directories(boost::filesystem::path(Singleton::style_dir())); - boost::filesystem::path juci_style_path=Singleton::style_dir(); - juci_style_path+="juci-light.xml"; + auto juci_style_path=Singleton::style_dir(); + juci_style_path/="juci-light.xml"; if(!boost::filesystem::exists(juci_style_path)) filesystem::write(juci_style_path, juci_light_style); juci_style_path=Singleton::style_dir(); - juci_style_path+="juci-dark.xml"; + juci_style_path/="juci-dark.xml"; if(!boost::filesystem::exists(juci_style_path)) filesystem::write(juci_style_path, juci_dark_style); juci_style_path=Singleton::style_dir(); - juci_style_path+="juci-dark-blue.xml"; + juci_style_path/="juci-dark-blue.xml"; if(!boost::filesystem::exists(juci_style_path)) filesystem::write(juci_style_path, juci_dark_blue_style); } @@ -105,8 +106,9 @@ void MainConfig::update_config_file() { cfg_ok=false; } cfg_ok&=check_config_file(default_cfg); - if(!cfg_ok) - boost::property_tree::write_json(Singleton::config_dir()+"config.json", cfg); + if(!cfg_ok) { + boost::property_tree::write_json(Singleton::config_json(), cfg); + } } void MainConfig::GenerateSource() { diff --git a/src/filesystem.cc b/src/filesystem.cc index 43357ed..7ea66a3 100644 --- a/src/filesystem.cc +++ b/src/filesystem.cc @@ -26,7 +26,7 @@ std::string safe_get_env(const std::string &env) { /** * Returns home folder, empty on error */ -std::string filesystem::get_home_folder() { +boost::filesystem::path filesystem::get_home_folder() { auto home=safe_get_env("HOME"); if(home.empty()) home=safe_get_env("AppData"); @@ -43,13 +43,13 @@ std::string filesystem::get_home_folder() { /** * Returns tmp folder, empty on error. */ -std::string filesystem::get_tmp_folder() { +boost::filesystem::path filesystem::get_tmp_folder() { boost::system::error_code code; auto path = boost::filesystem::temp_directory_path(code); if (code.value()!=0) { return ""; } - return path.string(); + return path; } int filesystem::read(const std::string &path, Glib::RefPtr text_buffer) { diff --git a/src/filesystem.h b/src/filesystem.h index 1a81a7d..ab2921d 100644 --- a/src/filesystem.h +++ b/src/filesystem.h @@ -25,7 +25,7 @@ public: static bool write(const std::string &path, Glib::RefPtr text_buffer); static bool write(const boost::filesystem::path &path, Glib::RefPtr text_buffer) { return write(path.string(), text_buffer); } - static std::string get_home_folder(); - static std::string get_tmp_folder(); + static boost::filesystem::path get_home_folder(); + static boost::filesystem::path get_tmp_folder(); }; #endif // JUCI_SOURCEFILE_H_ diff --git a/src/juci.cc b/src/juci.cc index a01c77f..6348538 100644 --- a/src/juci.cc +++ b/src/juci.cc @@ -5,7 +5,9 @@ using namespace std; //TODO: remove void app::init_logging() { boost::log::add_common_attributes(); - boost::log::add_file_log(boost::log::keywords::file_name = Singleton::log_dir() + "juci.log", + auto log_dir = Singleton::log_dir(); + log_dir /= "juci.log"; + boost::log::add_file_log(boost::log::keywords::file_name = log_dir, boost::log::keywords::auto_flush = true); JINFO("Logging initalized"); } diff --git a/src/singletons.cc b/src/singletons.cc index 8ace5c8..1a032f6 100644 --- a/src/singletons.cc +++ b/src/singletons.cc @@ -39,9 +39,8 @@ Gtk::Label *Singleton::info() { return info_.get(); } -std::string Singleton::create_config_path(const std::string &subfolder) { - boost::filesystem::path home; - home = filesystem::get_home_folder(); +boost::filesystem::path Singleton::create_config_path(const std::string &subfolder) { + auto home = filesystem::get_home_folder(); if(home.empty()) { Singleton::terminal()->print("Could not find/write to home directory. Using defaults, no settings will be saved."); home = filesystem::get_tmp_folder(); @@ -53,11 +52,15 @@ std::string Singleton::create_config_path(const std::string &subfolder) { } } home /= subfolder; - return home.string(); + return home; } -std::string Singleton::config_dir() { return create_config_path(".juci/config"); } -std::string Singleton::log_dir() { return create_config_path(".juci/log"); } -std::string Singleton::style_dir() { return create_config_path(".juci/styles"); } - +boost::filesystem::path Singleton::config_dir() { return create_config_path(".juci/config"); } +boost::filesystem::path Singleton::log_dir() { return create_config_path(".juci/log"); } +boost::filesystem::path Singleton::style_dir() { return create_config_path(".juci/styles"); } +std::string Singleton::config_json() { + auto conf_dir = Singleton::config_dir(); + conf_dir /= "config.json"; // to ensure correct paths on windows + return conf_dir.string(); +} diff --git a/src/singletons.h b/src/singletons.h index f22f57b..3ac440d 100644 --- a/src/singletons.h +++ b/src/singletons.h @@ -27,10 +27,11 @@ public: static std::unique_ptr directories_; static std::unique_ptr terminal_; }; - static std::string create_config_path(const std::string &subfolder); - static std::string config_dir(); - static std::string log_dir(); - static std::string style_dir(); + static boost::filesystem::path create_config_path(const std::string &subfolder); + static boost::filesystem::path config_dir(); + static boost::filesystem::path log_dir(); + static boost::filesystem::path style_dir(); + static std::string config_json(); static Terminal *terminal(); static Directories *directories(); static Gtk::Label *status(); diff --git a/src/source.cc b/src/source.cc index d52806c..3e9e8a7 100644 --- a/src/source.cc +++ b/src/source.cc @@ -295,7 +295,7 @@ void Source::View::set_tab_char_and_size(char tab_char, unsigned tab_size) { void Source::View::configure() { //TODO: Move this to notebook? Might take up too much memory doing this for every tab. auto style_scheme_manager=Gsv::StyleSchemeManager::get_default(); - style_scheme_manager->prepend_search_path(Singleton::style_dir()); + style_scheme_manager->prepend_search_path(Singleton::style_dir().string()); if(Singleton::Config::source()->style.size()>0) { auto scheme = style_scheme_manager->get_scheme(Singleton::Config::source()->style); diff --git a/src/window.cc b/src/window.cc index 462f5db..31974da 100644 --- a/src/window.cc +++ b/src/window.cc @@ -259,13 +259,13 @@ void Window::create_menu() { } }); menu.action_group->add(Gtk::Action::create("Preferences", "Preferences..."), Gtk::AccelKey(menu.key_map["preferences"]), [this]() { - notebook.open(Singleton::config_dir()+"config.json"); + notebook.open(Singleton::config_json()); }); menu.action_group->add(Gtk::Action::create("FileSave", "Save"), Gtk::AccelKey(menu.key_map["save"]), [this]() { if(notebook.save_current()) { if(notebook.get_current_page()!=-1) { - if(notebook.get_current_view()->file_path==Singleton::config_dir()+"config.json") { + if(notebook.get_current_view()->file_path==Singleton::config_json()) { configure(); for(int c=0;cconfigure();