Compare commits

..

No commits in common. "e77b61b1d98e7e418837a4096c8dd14c40f3b092" and "d11b690708b0684e02195f3f7cbdebf547d8f17f" have entirely different histories.

8 changed files with 39 additions and 83 deletions

View File

@ -18,18 +18,9 @@ namespace cellar {
bottle_error, bottle_error,
bottle_anonymous, bottle_anonymous,
bottle_labelled, bottle_labelled,
bottle_symlink, bottle_symlink
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
@ -39,7 +30,6 @@ 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;

View File

@ -21,8 +21,6 @@ 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();

View File

@ -1,13 +0,0 @@
#pragma once
#include <map>
#include <string>
#include <vector>
#include "commands.hpp"
namespace cellar {
namespace steam {
extern std::vector<std::string> find_steam_libraries();
}
}

View File

@ -0,0 +1,26 @@
#pragma once
#include <map>
#include <string>
#include <vector>
#include "commands.hpp"
namespace cellar {
namespace steam {
extern std::vector<std::string> find_steam_libraries();
extern void test_command(int argc, std::vector<std::string> argv);
/*[[[cog
import cog
with open("src/steam/commands.txt") as commandsfile:
for line in commandsfile:
item = line.strip().split(" ")
cog.outl("extern void {0} (int, vector<string>);".format(item[1]))
]]]*/
//[[[end]]]
}
namespace commands {
extern std::map<std::string,cellar::commands::CommandFunction> steam_commands();
}
}

View File

@ -17,7 +17,6 @@ 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");
@ -25,8 +24,6 @@ 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;

View File

@ -1,5 +1,4 @@
#include <cstdlib> #include <cstdlib>
#include <filesystem>
#include <fstream> #include <fstream>
#include <map> #include <map>
#include <string> #include <string>
@ -34,21 +33,6 @@ 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();
} }
/** /**
@ -61,40 +45,21 @@ 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 (std::filesystem::is_symlink(path_canon)) { if (symlink) {
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 {
load_config(); if (load_config()) {
auto cur_manager = get_config("manager");
if (cur_manager == "cellar") {
manager = manager_cellar;
if (get_config("name") != "") {
type = bottle_labelled; type = bottle_labelled;
} else { } else {
type = bottle_anonymous; 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) {
type = bottle_error; type = bottle_error;
@ -198,9 +163,6 @@ void cellar::bottles::print_bottles(int argc, vector<string> argv) {
case bottle_labelled: case bottle_labelled:
outstr << bottle.config["name"]; outstr << bottle.config["name"];
break; break;
case bottle_steam:
outstr << "Steam managed bottle for " << bottle.config["name"];
break;
default: default:
outstr << "broken or unsupported wine bottle"; outstr << "broken or unsupported wine bottle";
} }

View File

@ -10,7 +10,6 @@
#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"
@ -46,7 +45,6 @@ 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();
@ -72,7 +70,7 @@ int main(int argc, char* argv[]) {
dryrun = dryrunarg.getValue(); dryrun = dryrunarg.getValue();
verbose = dryrun || verbosearg.getValue(); verbose = dryrun || verbosearg.getValue();
// TODO: i'm sure stdlib has come a long way in formatting strings since this ancient hack was put in // BULLSHIT: trying to use str.format on this string causes bizarre compiler errors
/*[[[cog /*[[[cog
import cog import cog
@ -105,7 +103,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 ~nicole/.wine // 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 // 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"));

View File

@ -44,9 +44,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.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;
} }