2017-03-13 19:03:07 -07:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <fstream>
|
2017-03-22 19:02:14 -07:00
|
|
|
#include <map>
|
2017-03-13 19:03:07 -07:00
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
|
|
|
#include <vector>
|
|
|
|
|
2025-01-18 23:09:28 -08:00
|
|
|
#include <boost/filesystem.hpp>
|
2018-03-13 20:06:15 -07:00
|
|
|
#include "nlohmann/json.hpp"
|
2017-03-13 19:03:07 -07:00
|
|
|
|
|
|
|
#include "bottles.hpp"
|
2025-01-27 16:51:54 -08:00
|
|
|
#include "cmake.hpp"
|
2017-03-23 13:17:07 -07:00
|
|
|
#include "internal/bottles.hpp"
|
2017-03-13 19:03:07 -07:00
|
|
|
#include "fs.hpp"
|
2017-03-23 18:51:11 -07:00
|
|
|
#include "output.hpp"
|
2025-01-27 16:51:54 -08:00
|
|
|
#ifdef ENABLE_STEAM
|
|
|
|
#include "steam.hpp"
|
|
|
|
#endif
|
2017-03-13 19:03:07 -07:00
|
|
|
|
|
|
|
using namespace std;
|
2017-03-23 18:51:11 -07:00
|
|
|
using namespace cellar;
|
2017-03-22 19:02:14 -07:00
|
|
|
using namespace cellar::bottles;
|
2017-03-13 19:03:07 -07:00
|
|
|
|
2017-03-23 12:06:29 -07:00
|
|
|
using CommandFunction = cellar::commands::CommandFunction;
|
2017-03-13 19:03:07 -07:00
|
|
|
using json = nlohmann::json;
|
|
|
|
|
2017-03-22 19:02:14 -07:00
|
|
|
Bottle::Bottle() {
|
|
|
|
// define a null bottle
|
|
|
|
// strings handle themselves
|
|
|
|
config = json({});
|
|
|
|
type = bottle_anonymous;
|
|
|
|
}
|
|
|
|
|
2017-03-24 17:58:24 -07:00
|
|
|
Bottle::Bottle(string patharg) {
|
2017-03-24 21:50:32 -07:00
|
|
|
output::statement("loading bottle from " + patharg, true);
|
2017-03-24 17:58:24 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-28 12:41:25 -07:00
|
|
|
map<string, Bottle> cellar::bottles::get_bottles() {
|
2017-03-22 19:02:14 -07:00
|
|
|
map<string, Bottle> result;
|
2017-03-13 19:03:07 -07:00
|
|
|
|
|
|
|
string homepath = getenv("HOME");
|
2018-03-13 20:06:15 -07:00
|
|
|
vector<string> homedir = fs::listdir(homepath + "/.local/share/cellar/bottles");
|
2017-03-13 19:03:07 -07:00
|
|
|
for (string item : homedir) {
|
2018-03-13 20:06:15 -07:00
|
|
|
string fullitem = homepath + "/.local/share/cellar/bottles/" + item;
|
|
|
|
Bottle output(fullitem);
|
2017-03-13 19:03:07 -07:00
|
|
|
|
2018-03-13 20:06:15 -07:00
|
|
|
result[item] = output;
|
2017-03-13 19:03:07 -07:00
|
|
|
}
|
|
|
|
|
2025-01-27 16:51:54 -08:00
|
|
|
#ifdef ENABLE_STEAM
|
|
|
|
map<string, Bottle> bottles_proton = cellar::steam::get_app_bottles();
|
|
|
|
for (auto item : bottles_proton) {
|
|
|
|
result.insert_or_assign(item.first, item.second);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-03-13 19:03:07 -07:00
|
|
|
return result;
|
|
|
|
}
|
2017-03-23 00:02:38 -07:00
|
|
|
|
2017-03-28 12:41:25 -07:00
|
|
|
string cellar::bottles::resolve_bottle(string bottlechoice) {
|
|
|
|
string result;
|
|
|
|
if (bottlechoice.substr(0,1) == "/" || bottlechoice.substr(0,1) == ".") { // absolute or relative path
|
|
|
|
result = bottlechoice;
|
|
|
|
} else if (bottlechoice.substr(0,1) == "~") { // "absolute" path in home directory, not expanded by the shell for some reason (i've seen some shit)
|
|
|
|
// this is a naive replacement and will fail if the user tries something like ~nick/.wine
|
|
|
|
// i'm figuring at that point if you're doing that, you'll also recognize if your shell
|
|
|
|
// isn't actually expanding your path...
|
|
|
|
bottlechoice.replace(0,1,getenv("HOME"));
|
|
|
|
// or at least you'll think to use verbose mode to make sure it's loading the right directory
|
|
|
|
output::warning("your shell didn't expand your given path properly, doing a naive replacement", true);
|
|
|
|
result = bottlechoice;
|
|
|
|
} else {
|
|
|
|
string homepath = getenv("HOME");
|
2018-03-13 20:06:15 -07:00
|
|
|
string fullbottlepath = homepath + "/.local/share/cellar/bottles" + bottlechoice;
|
2017-03-28 12:41:25 -07:00
|
|
|
result = fullbottlepath;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-03-23 15:13:52 -07:00
|
|
|
void cellar::bottles::print_bottles(int argc, vector<string> argv) {
|
2017-03-23 00:02:38 -07:00
|
|
|
map<string, Bottle> bottles = get_bottles();
|
|
|
|
|
2017-03-23 18:51:11 -07:00
|
|
|
stringstream outstr;
|
|
|
|
|
2017-03-23 00:02:38 -07:00
|
|
|
for (auto item : bottles) {
|
2018-03-13 20:06:15 -07:00
|
|
|
if (item.first == ".wine" || item.first == ".local/share/cellar/bottles/template") {
|
|
|
|
// .wine is considered to be "active", and .local/share/cellar/bottles/template is used as a template
|
2017-03-23 14:23:58 -07:00
|
|
|
// and therefore treated specially
|
|
|
|
continue;
|
|
|
|
}
|
2017-03-23 00:02:38 -07:00
|
|
|
Bottle bottle = item.second;
|
2017-03-23 18:51:11 -07:00
|
|
|
outstr << item.first << " - ";
|
2017-03-23 00:02:38 -07:00
|
|
|
switch (bottle.type) {
|
|
|
|
case bottle_anonymous:
|
2017-03-23 18:51:11 -07:00
|
|
|
outstr << "anonymous wine bottle";
|
2017-03-23 00:02:38 -07:00
|
|
|
break;
|
|
|
|
case bottle_symlink:
|
2017-03-23 18:51:11 -07:00
|
|
|
outstr << "symlink to " << bottle.canonical_path;
|
2017-03-23 00:02:38 -07:00
|
|
|
break;
|
|
|
|
case bottle_labelled:
|
2017-03-23 18:51:11 -07:00
|
|
|
outstr << bottle.config["name"];
|
2017-03-23 00:02:38 -07:00
|
|
|
break;
|
|
|
|
default:
|
2017-03-23 18:51:11 -07:00
|
|
|
outstr << "broken or unsupported wine bottle";
|
2017-03-23 00:02:38 -07:00
|
|
|
}
|
2017-03-23 18:51:11 -07:00
|
|
|
output::statement(outstr.str());
|
|
|
|
outstr.str("");
|
2017-03-23 00:02:38 -07:00
|
|
|
}
|
|
|
|
}
|