diff --git a/include/bottles.hpp b/include/bottles.hpp index bbfa88b..993489f 100644 --- a/include/bottles.hpp +++ b/include/bottles.hpp @@ -22,13 +22,21 @@ namespace cellar { }; class Bottle { public: + // public members bottle_type type; json config; string path; string canonical_path; + + // constructors Bottle(); + Bottle(string); + + // methods bool load_config(); bool save_config(); + string get_config(string); + bool set_config(string, string); }; extern map get_bottles(); } diff --git a/src/bottles/bottles.cpp b/src/bottles/bottles.cpp index 4d15838..14ce2d3 100644 --- a/src/bottles/bottles.cpp +++ b/src/bottles/bottles.cpp @@ -29,6 +29,32 @@ Bottle::Bottle() { type = bottle_anonymous; } +Bottle::Bottle(string patharg) { + config = json({}); + path = patharg; + + boost::filesystem::file_status path_status = boost::filesystem::symlink_status(path); + bool symlink = boost::filesystem::is_symlink(path_status); + + if (symlink) { + boost::filesystem::path realpath = boost::filesystem::canonical(path); + canonical_path = realpath.string(); + type = bottle_symlink; + } else { + canonical_path = path; + try { + if (load_config()) { + type = bottle_labelled; + } else { + type = bottle_anonymous; + } + } + catch (const exception &exc) { + type = bottle_error; + } + } +} + DLL_PUBLIC map cellar::bottles::get_bottles() { map result; @@ -36,31 +62,9 @@ DLL_PUBLIC map cellar::bottles::get_bottles() { vector homedir = fs::listdir(homepath); for (string item : homedir) { if (item.substr(0,5) == ".wine") { - Bottle output; - string fullitem = homepath + "/" + item; - output.path = fullitem; + Bottle output(fullitem); - boost::filesystem::file_status fullitem_status = boost::filesystem::symlink_status(fullitem); - bool symlink = boost::filesystem::is_symlink(fullitem_status); - - if (symlink) { - boost::filesystem::path realpath = boost::filesystem::canonical(fullitem); - output.canonical_path = realpath.string(); - output.type = bottle_symlink; - } else { - output.canonical_path = fullitem; - try { - if (output.load_config()) { - output.type = bottle_labelled; - } else { - output.type = bottle_anonymous; - } - } - catch (const exception &exc) { - output.type = bottle_error; - } - } result[item] = output; } }