Browse Source

Deduce home instead of setting it

merge-requests/365/head
Jørgen Lien Sellæg 10 years ago
parent
commit
23be4f05d5
  1. 16
      src/singletons.h
  2. 17
      src/sourcefile.cc
  3. 1
      src/sourcefile.h

16
src/singletons.h

@ -10,12 +10,7 @@
#include "menu.h" #include "menu.h"
#include <gtkmm.h> #include <gtkmm.h>
#include <string> #include <string>
#include "sourcefile.h"
#ifdef _WIN32
#define HOME "AppData"
#else
#define HOME "HOME"
#endif
class Singleton { class Singleton {
public: public:
@ -32,9 +27,12 @@ public:
static std::unique_ptr<Directories::Config> directories_; static std::unique_ptr<Directories::Config> directories_;
static std::unique_ptr<Terminal::Config> terminal_; static std::unique_ptr<Terminal::Config> terminal_;
}; };
static std::string config_dir() { return std::string(getenv(HOME)) + "/.juci/config/"; } static std::string create_config_path(const std::string &subfolder) {
static std::string log_dir() { return std::string(getenv(HOME)) + "/.juci/log/"; } return juci::filesystem::get_home_folder() + subfolder;
static std::string style_dir() { return std::string(getenv(HOME)) + "/.juci/styles/"; } }
static std::string config_dir() { return create_config_path("/.juci/config/"); }
static std::string log_dir() { return create_config_path("/.juci/log/"); }
static std::string style_dir() { return create_config_path("/.juci/styles/"); }
static Terminal *terminal(); static Terminal *terminal();
static Directories *directories(); static Directories *directories();
static Gtk::Label *status(); static Gtk::Label *status();

17
src/sourcefile.cc

@ -15,6 +15,23 @@ std::string juci::filesystem::read(const std::string &path) {
return ss.str(); return ss.str();
} }
std::string safe_get_env(const std::string &env) {
auto ptr = std::getenv(env.c_str());
return nullptr==ptr ? "" : std::string(ptr);
}
std::string juci::filesystem::get_home_folder() {
auto home=safe_get_env("HOME");
if(home.empty())
home=safe_get_env("AppData");
auto status = boost::filesystem::status(home);
if((status.permissions() & 0222)>=2) {
return home;
} else {
throw new std::exception;
}
}
int juci::filesystem::read(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) { int juci::filesystem::read(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) {
std::ifstream input(path, std::ofstream::binary); std::ifstream input(path, std::ofstream::binary);

1
src/sourcefile.h

@ -25,6 +25,7 @@ namespace juci {
static bool write(const boost::filesystem::path &path) { return write(path, ""); }; static bool write(const boost::filesystem::path &path) { return write(path, ""); };
static bool write(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer); static bool write(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer);
static bool write(const boost::filesystem::path &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) { return write(path.string(), text_buffer); } static bool write(const boost::filesystem::path &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) { return write(path.string(), text_buffer); }
static std::string get_home_folder();
}; };
} // namepace juci } // namepace juci
#endif // JUCI_SOURCEFILE_H_ #endif // JUCI_SOURCEFILE_H_

Loading…
Cancel
Save