cork and uncork respect dryrun
This commit is contained in:
parent
8c148d5608
commit
4a148b7bf6
@ -1,5 +1,7 @@
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/algorithm/string/join.hpp>
|
||||
@ -9,6 +11,7 @@
|
||||
|
||||
#include "bottles.hpp"
|
||||
#include "internal/bottles.hpp"
|
||||
#include "cellar.hpp"
|
||||
#include "launch.hpp"
|
||||
#include "internal/launch.hpp"
|
||||
#include "fs.hpp"
|
||||
@ -40,9 +43,13 @@ void cellar::bottles::cork(string bottlearg, bool remove) {
|
||||
return;
|
||||
}
|
||||
|
||||
boost::filesystem::copy(bottlepath + "/cellar.json", datadir + "/corked/" + bottlearg + ".json");
|
||||
output::statement("copying " + bottlepath + "/cellar.json to cork directory", true);
|
||||
if (!cellar::dryrun) { boost::filesystem::copy(bottlepath + "/cellar.json", corkpath); }
|
||||
|
||||
if (remove) { fs::recursive_remove(bottlepath); }
|
||||
if (remove) {
|
||||
output::statement("removing bottle " + bottlearg + " at " + bottlepath, true);
|
||||
if (!cellar::dryrun) { fs::recursive_remove(bottlepath); }
|
||||
}
|
||||
}
|
||||
|
||||
void cellar::bottles::cork_command(int argc, vector<string> argv) {
|
||||
@ -53,7 +60,8 @@ void cellar::bottles::cork_command(int argc, vector<string> argv) {
|
||||
void cellar::bottles::uncork(string bottlearg) {
|
||||
string homedir = getenv("HOME");
|
||||
string datadir = homedir + "/.local/share/cellar";
|
||||
if (!boost::filesystem::exists(datadir + "/corked/" + bottlearg + ".json")) {
|
||||
string corkjsonpath = datadir + "/corked/" + bottlearg + ".json";
|
||||
if (!boost::filesystem::exists(corkjsonpath)) {
|
||||
output::error("no bottle named " + bottlearg + " to uncork");
|
||||
return;
|
||||
}
|
||||
@ -65,32 +73,61 @@ void cellar::bottles::uncork(string bottlearg) {
|
||||
}
|
||||
|
||||
output::statement("creating wine prefix at " + bottlepath, true);
|
||||
setenv("WINEPREFIX", bottlepath.c_str(), 1);
|
||||
vector<string> createargs = {"cellar create", bottlearg};
|
||||
create_bottle(2, createargs);
|
||||
boost::filesystem::copy(datadir + "/corked/" + bottlearg + ".json", bottlepath + "/cellar.json");
|
||||
if (!cellar::dryrun) {
|
||||
setenv("WINEPREFIX", bottlepath.c_str(), 1);
|
||||
vector<string> createargs = {"cellar create", bottlearg};
|
||||
create_bottle(2, createargs);
|
||||
boost::filesystem::copy(corkjsonpath, bottlepath + "/cellar.json");
|
||||
|
||||
active_bottle = Bottle(bottlepath);
|
||||
active_bottle = Bottle(bottlepath);
|
||||
|
||||
if (active_bottle.config.find("winetricks") != active_bottle.config.end()) {
|
||||
vector<string> winetrickery = active_bottle.config.at("winetricks");
|
||||
output::statement("running winetricks with args: " + boost::algorithm::join(winetrickery, " "));
|
||||
launch::winetricks(winetrickery.size(), winetrickery);
|
||||
}
|
||||
if (active_bottle.config.find("winetricks") != active_bottle.config.end()) {
|
||||
vector<string> winetrickery = active_bottle.config.at("winetricks");
|
||||
output::statement("running winetricks with args: " + boost::algorithm::join(winetrickery, " "));
|
||||
launch::winetricks(winetrickery.size(), winetrickery);
|
||||
}
|
||||
|
||||
if (active_bottle.config.find("pressed") != active_bottle.config.end()) {
|
||||
auto presseddir = boost::filesystem::path(datadir + "/pressed");
|
||||
auto pressed = active_bottle.config.at("pressed");
|
||||
for (auto pressed_iter = pressed.begin(); pressed_iter != pressed.end(); pressed_iter++) {
|
||||
string exec = pressed_iter.key();
|
||||
vector<string> args = pressed_iter.value();
|
||||
if (active_bottle.config.find("pressed") != active_bottle.config.end()) {
|
||||
auto presseddir = boost::filesystem::path(datadir + "/pressed");
|
||||
auto pressed = active_bottle.config.at("pressed");
|
||||
for (auto pressed_iter = pressed.begin(); pressed_iter != pressed.end(); pressed_iter++) {
|
||||
string exec = pressed_iter.key();
|
||||
vector<string> args = pressed_iter.value();
|
||||
|
||||
output::statement("running pressed installer " + exec + " with arguments: " + boost::algorithm::join(args, " "), true);
|
||||
vector<string> subargv;
|
||||
subargv.push_back("wine");
|
||||
subargv.push_back((presseddir / exec).native());
|
||||
for (string arg : args) { subargv.push_back(arg); }
|
||||
launch::popen(subargv);
|
||||
output::statement("running pressed installer " + exec + " with arguments: " + boost::algorithm::join(args, " "), true);
|
||||
vector<string> subargv;
|
||||
subargv.push_back("wine");
|
||||
subargv.push_back((presseddir / exec).native());
|
||||
for (string arg : args) { subargv.push_back(arg); }
|
||||
launch::popen(subargv);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// load config to see what would have been done
|
||||
json config;
|
||||
ifstream configstream(corkjsonpath);
|
||||
stringstream sstr;
|
||||
sstr << configstream.rdbuf();
|
||||
config = json::parse(sstr.str());
|
||||
|
||||
if (config.find("winetricks") != config.end()) {
|
||||
vector<string> winetrickery = config.at("winetricks");
|
||||
output::statement("running winetricks with args: " + boost::algorithm::join(winetrickery, " "));
|
||||
}
|
||||
|
||||
if (config.find("pressed") != config.end()) {
|
||||
auto presseddir = boost::filesystem::path(datadir + "/pressed");
|
||||
auto pressed = active_bottle.config.at("pressed");
|
||||
for (auto pressed_iter = pressed.begin(); pressed_iter != pressed.end(); pressed_iter++) {
|
||||
string exec = pressed_iter.key();
|
||||
vector<string> args = pressed_iter.value();
|
||||
|
||||
output::statement("running pressed installer " + exec + " with arguments: " + boost::algorithm::join(args, " "), true);
|
||||
vector<string> subargv;
|
||||
subargv.push_back("wine");
|
||||
subargv.push_back((presseddir / exec).native());
|
||||
for (string arg : args) { subargv.push_back(arg); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user