more of cellar's internals are now aware of steam bottles
This commit is contained in:
parent
de049cea1a
commit
e77b61b1d9
@ -22,6 +22,14 @@ namespace cellar {
|
|||||||
bottle_steam
|
bottle_steam
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum bottle_manager {
|
||||||
|
manager_error,
|
||||||
|
manager_cellar,
|
||||||
|
manager_steam
|
||||||
|
};
|
||||||
|
|
||||||
|
extern std::string bottle_home;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bottles are the internal name for WINE prefixes. In addition to standard WINE contents,
|
* Bottles are the internal name for WINE prefixes. In addition to standard WINE contents,
|
||||||
* bottles contain a configuration file managed by cellar, which labels the bottle as well
|
* bottles contain a configuration file managed by cellar, which labels the bottle as well
|
||||||
@ -31,6 +39,7 @@ namespace cellar {
|
|||||||
public:
|
public:
|
||||||
// public members
|
// public members
|
||||||
bottle_type type;
|
bottle_type type;
|
||||||
|
bottle_manager manager;
|
||||||
json config;
|
json config;
|
||||||
string path;
|
string path;
|
||||||
string canonical_path;
|
string canonical_path;
|
||||||
|
@ -21,6 +21,8 @@ namespace cellar {
|
|||||||
cog.outl("extern void {0} (int, vector<string>);".format(item[1]))
|
cog.outl("extern void {0} (int, vector<string>);".format(item[1]))
|
||||||
]]]*/
|
]]]*/
|
||||||
//[[[end]]]
|
//[[[end]]]
|
||||||
|
|
||||||
|
extern void setup_bottle_home();
|
||||||
}
|
}
|
||||||
namespace commands {
|
namespace commands {
|
||||||
extern map<string, cellar::commands::CommandFunction> bottles_commands();
|
extern map<string, cellar::commands::CommandFunction> bottles_commands();
|
||||||
|
@ -17,6 +17,7 @@ void cellar::bottles::print_active_bottle(int argc, vector<string> argv) {
|
|||||||
string bottlepath = active_bottle.canonical_path;
|
string bottlepath = active_bottle.canonical_path;
|
||||||
stringstream outstr;
|
stringstream outstr;
|
||||||
bool cellar_managed = true;
|
bool cellar_managed = true;
|
||||||
|
bool external_managed = false;
|
||||||
if (active_bottle.type == bottle_symlink) {
|
if (active_bottle.type == bottle_symlink) {
|
||||||
outstr << "symlink to ";
|
outstr << "symlink to ";
|
||||||
string homedir = getenv("HOME");
|
string homedir = getenv("HOME");
|
||||||
@ -24,6 +25,8 @@ void cellar::bottles::print_active_bottle(int argc, vector<string> argv) {
|
|||||||
if (active_bottle.canonical_path.substr(0, bottlerack.length()) == bottlerack) {
|
if (active_bottle.canonical_path.substr(0, bottlerack.length()) == bottlerack) {
|
||||||
bottlepath.replace(0, bottlerack.length() + 1, ""); // should convert "/home/someone/.wine.example" to ".wine.example"
|
bottlepath.replace(0, bottlerack.length() + 1, ""); // should convert "/home/someone/.wine.example" to ".wine.example"
|
||||||
active_bottle = bottlemap[bottlepath];
|
active_bottle = bottlemap[bottlepath];
|
||||||
|
active_bottle.set_config("manager", "cellar");
|
||||||
|
active_bottle.save_config();
|
||||||
} else {
|
} else {
|
||||||
outstr << active_bottle.canonical_path;
|
outstr << active_bottle.canonical_path;
|
||||||
cellar_managed = false;
|
cellar_managed = false;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -33,6 +34,21 @@ Bottle::Bottle() {
|
|||||||
// strings handle themselves
|
// strings handle themselves
|
||||||
config = json({});
|
config = json({});
|
||||||
type = bottle_anonymous;
|
type = bottle_anonymous;
|
||||||
|
manager = manager_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string cellar::bottles::bottle_home;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets up bottle home.
|
||||||
|
* Called once from early mainloop.
|
||||||
|
* @todo Have this not be an effectively hardcoded path. Respect xdg paths.
|
||||||
|
*/
|
||||||
|
void cellar::bottles::setup_bottle_home() {
|
||||||
|
stringstream sstr_bottle_home;
|
||||||
|
sstr_bottle_home << std::getenv("HOME");
|
||||||
|
sstr_bottle_home << "/.local/share/cellar/bottles";
|
||||||
|
bottle_home = sstr_bottle_home.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,20 +61,39 @@ Bottle::Bottle(string patharg) {
|
|||||||
config = json({});
|
config = json({});
|
||||||
path = patharg;
|
path = patharg;
|
||||||
|
|
||||||
boost::filesystem::file_status path_status = boost::filesystem::symlink_status(path);
|
//boost::filesystem::file_status path_status = boost::filesystem::symlink_status(path);
|
||||||
bool symlink = boost::filesystem::is_symlink(path_status);
|
//bool symlink = boost::filesystem::is_symlink(path_status);
|
||||||
|
auto path_status = std::filesystem::path(path);
|
||||||
|
auto path_canon = std::filesystem::canonical(path_status);
|
||||||
|
canonical_path = path_canon.string();
|
||||||
|
|
||||||
if (symlink) {
|
if (std::filesystem::is_symlink(path_canon)) {
|
||||||
boost::filesystem::path realpath = boost::filesystem::canonical(path);
|
|
||||||
canonical_path = realpath.string();
|
|
||||||
type = bottle_symlink;
|
type = bottle_symlink;
|
||||||
} else {
|
} else {
|
||||||
canonical_path = path;
|
|
||||||
try {
|
try {
|
||||||
if (load_config()) {
|
load_config();
|
||||||
type = bottle_labelled;
|
auto cur_manager = get_config("manager");
|
||||||
} else {
|
if (cur_manager == "cellar") {
|
||||||
type = bottle_anonymous;
|
manager = manager_cellar;
|
||||||
|
|
||||||
|
if (get_config("name") != "") {
|
||||||
|
type = bottle_labelled;
|
||||||
|
} else {
|
||||||
|
type = bottle_anonymous;
|
||||||
|
}
|
||||||
|
} else if (path_canon.parent_path() == bottle_home) {
|
||||||
|
manager = manager_cellar;
|
||||||
|
set_config("manager", "cellar"); // migrate from older cellar (or correct for something weird happening)
|
||||||
|
save_config();
|
||||||
|
|
||||||
|
if (get_config("name") != "") {
|
||||||
|
type = bottle_labelled;
|
||||||
|
} else {
|
||||||
|
type = bottle_anonymous;
|
||||||
|
}
|
||||||
|
} else if (cur_manager == "steam") {
|
||||||
|
type = bottle_steam;
|
||||||
|
manager = manager_steam;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const exception &exc) {
|
catch (const exception &exc) {
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "nlohmann/json.hpp"
|
#include "nlohmann/json.hpp"
|
||||||
|
|
||||||
#include "bottles.hpp"
|
#include "bottles.hpp"
|
||||||
|
#include "internal/bottles.hpp"
|
||||||
#include "cellar.hpp"
|
#include "cellar.hpp"
|
||||||
#include "commands.hpp"
|
#include "commands.hpp"
|
||||||
#include "output.hpp"
|
#include "output.hpp"
|
||||||
@ -45,6 +46,7 @@ int main(int argc, char* argv[]) {
|
|||||||
cout << "\n(try \"cellar help\" if you're confused)" << endl;
|
cout << "\n(try \"cellar help\" if you're confused)" << endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
cellar::bottles::setup_bottle_home();
|
||||||
try {
|
try {
|
||||||
const string desc = "bottle management tool for WINE connoisseurs";
|
const string desc = "bottle management tool for WINE connoisseurs";
|
||||||
const string versionstr = version::short_version();
|
const string versionstr = version::short_version();
|
||||||
@ -70,7 +72,7 @@ int main(int argc, char* argv[]) {
|
|||||||
dryrun = dryrunarg.getValue();
|
dryrun = dryrunarg.getValue();
|
||||||
verbose = dryrun || verbosearg.getValue();
|
verbose = dryrun || verbosearg.getValue();
|
||||||
|
|
||||||
// BULLSHIT: trying to use str.format on this string causes bizarre compiler errors
|
// TODO: i'm sure stdlib has come a long way in formatting strings since this ancient hack was put in
|
||||||
/*[[[cog
|
/*[[[cog
|
||||||
import cog
|
import cog
|
||||||
|
|
||||||
@ -103,7 +105,7 @@ int main(int argc, char* argv[]) {
|
|||||||
if (bottlechoice.substr(0,1) == "/" || bottlechoice.substr(0,1) == ".") { // absolute or relative path
|
if (bottlechoice.substr(0,1) == "/" || bottlechoice.substr(0,1) == ".") { // absolute or relative path
|
||||||
bottles::active_bottle = bottles::Bottle(bottlechoice);
|
bottles::active_bottle = bottles::Bottle(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)
|
} 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
|
// this is a naive replacement and will fail if the user tries something like ~nicole/.wine
|
||||||
// i'm figuring at that point if you're doing that, you'll also recognize if your shell
|
// i'm figuring at that point if you're doing that, you'll also recognize if your shell
|
||||||
// isn't actually expanding your path...
|
// isn't actually expanding your path...
|
||||||
bottlechoice.replace(0,1,getenv("HOME"));
|
bottlechoice.replace(0,1,getenv("HOME"));
|
||||||
|
@ -46,6 +46,7 @@ std::map<std::string, cellar::bottles::Bottle> cellar::steam::get_app_bottles()
|
|||||||
auto curbottle = cellar::bottles::Bottle((pth_appid / "pfx").string());
|
auto curbottle = cellar::bottles::Bottle((pth_appid / "pfx").string());
|
||||||
curbottle.type = cellar::bottles::bottle_steam;
|
curbottle.type = cellar::bottles::bottle_steam;
|
||||||
curbottle.set_config("name", str_gamename);
|
curbottle.set_config("name", str_gamename);
|
||||||
|
curbottle.set_config("manager", "steam");
|
||||||
curbottle.save_config();
|
curbottle.save_config();
|
||||||
result[std::string("steam:" + pth_appid.filename().string())] = curbottle;
|
result[std::string("steam:" + pth_appid.filename().string())] = curbottle;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user