Compare commits

...

10 Commits

11 changed files with 82 additions and 23 deletions

1
.gitignore vendored
View File

@ -1,4 +1,3 @@
*.in
*.o
*.so
*/.deps

View File

@ -46,7 +46,7 @@ include_directories("${CMAKE_CURRENT_BINARY_DIR}/include")
set(src "${CMAKE_SOURCE_DIR}/src")
lava_create_gutlib(
SUBDIRS bottles config launch
SUBDIRS bottles config launch paths
DEPENDS cog)
lava_create_executable(TARGET cellar

View File

@ -2,8 +2,6 @@
### bottle management tool for WINE connoisseurs
*(this software is considered unfinished, use at own risk)*
(notice: https://github.com/lavacano201014/cellar is a mirror. The upstream repository is at [vcs.lavacano.net/cellar.git](http://vcs.lavacano.net/?p=cellar.git), and bugs are officially tracked at [mantis.lavacano.net](http://mantis.lavacano.net))
## Installation
$ mkdir build && cd build

View File

@ -34,4 +34,4 @@ TODO: Generate this.
## COPYRIGHT
Copyright © 2017 Nicholas O'Connor. Provided under the terms of the MIT license: https://opensource.org/licenses/MIT
Copyright © 2017-2019 Nicholas O'Connor. Provided under the terms of the MIT license: https://opensource.org/licenses/MIT

View File

@ -1,6 +1,6 @@
/* This file contains string definitions for ANSI color sequences
* it was written by Nicholas "Lavacano" O'Connor and is available
* to all under the MIT license.
* it was written by Nicole O'Connor and is available to all
* under the MIT license.
*
* Usage:
* std::cout << ansicol::red_bold << "I am bold red text!" << ansicol::reset << std::endl;

5
include/cmake.hpp.in Executable file
View File

@ -0,0 +1,5 @@
#pragma once
#cmakedefine IS_GIT_REPO "@IS_GIT_REPO@"
#cmakedefine GIT_COMMIT_HASH "@GIT_COMMIT_HASH@"
#cmakedefine GIT_BRANCH "@GIT_BRANCH@"

View File

@ -5,5 +5,6 @@
namespace cellar {
namespace paths {
extern std::string translate(std::string in_path, bool lazy = false);
extern std::string resolve_drive_letter(std::string in_path);
}
}

View File

@ -30,8 +30,10 @@ void cellar::bottles::create_bottle(int argc, vector<string> argv) {
cmdparse.parse(argv);
// sanity check: make sure ~/.local/share/cellar/bottles exists
string homepath = getenv("HOME");
if (!boost::filesystem::exists(homepath + "/.local/share/cellar/bottles")) { boost::filesystem::create_directories(homepath + "/.local/share/cellar/bottles"); }
string bottlechoice = bottlearg.getValue();
string fullbottlepath;
if (bottlechoice.substr(0,1) == "/" || bottlechoice.substr(0,1) == ".") { // absolute or relative path

View File

@ -93,7 +93,7 @@ int main(int argc, char* argv[]) {
bottles::active_bottle = bottles::Bottle(env_wineprefix);
} else {
string homepath = getenv("HOME");
string fullbottlepath = homepath + "/.local/share/cellar/bottles/" + bottlearg.getValue();
string fullbottlepath = homepath + "/.wine";
bottles::active_bottle = bottles::Bottle(fullbottlepath);
}

View File

@ -18,28 +18,31 @@ using namespace cellar;
string cellar::paths::translate(std::string in_path, bool lazy) {
bool windows_input;
static regex drive_letter(R"([a-zA-Z]:\\)");
static regex drive_letter_rgx(R"([a-zA-Z]:\\)");
windows_input = regex_match(in_path.substr(0, 3), drive_letter);
windows_input = regex_match(in_path.substr(0, 3), drive_letter_rgx);
if (!lazy) {
output::warning("non-lazy path translation is not implemented yet");
}
if (windows_input) {
// lazy
if (boost::algorithm::to_lower_copy(in_path.substr(0,1)) != "z") {
throw invalid_argument("lazy path translation isn't possible for drive letters other than Z:");
}
string out_path = in_path.substr(2, in_path.size() - 2);
size_t slashpos = out_path.find("\\");
while (slashpos != std::string::npos) {
out_path.replace(slashpos, 1, "/");
slashpos = out_path.find("\\");
}
if (lazy) {
if (boost::algorithm::to_lower_copy(in_path.substr(0,1)) != "z") {
throw invalid_argument("lazy path translation isn't possible for drive letters other than Z:");
}
string out_path = in_path.substr(2, in_path.size() - 2);
size_t slashpos = out_path.find("\\");
while (slashpos != std::string::npos) {
out_path.replace(slashpos, 1, "/");
slashpos = out_path.find("\\");
}
return out_path;
return out_path;
} else {
return paths::resolve_drive_letter(in_path);
}
} else {
// lazy
string out_path = "Z:";

View File

@ -0,0 +1,51 @@
#include <exception>
#include <regex>
#include <string>
#include <unistd.h>
#include <boost/algorithm/string.hpp>
#include "bottles.hpp"
#include "output.hpp"
#include "paths.hpp"
using namespace std;
string cellar::paths::resolve_drive_letter(string in_path) {
bool windows_input;
static regex drive_letter_rgx(R"([a-zA-Z]:\\)");
windows_input = regex_match(in_path.substr(0, 3), drive_letter_rgx);
string out_path = "";
if (windows_input) {
string drive_letter = boost::algorithm::to_lower_copy(in_path.substr(0, 2));
string link_path = "";
link_path.append(bottles::active_bottle.canonical_path);
link_path.append("/dosdevices/");
link_path.append(drive_letter);
char stringbuffer[512];
ssize_t bufflen = readlink(link_path.c_str(), stringbuffer, sizeof(stringbuffer) - 1);
if (bufflen != -1) {
stringbuffer[bufflen] = '\0';
out_path.append(stringbuffer);
} else {
throw runtime_error("readlink isn't having it");
}
string rest_of_path = in_path.substr(3, in_path.size() - 2);
size_t slashpos = rest_of_path.find("\\");
while (slashpos != std::string::npos) {
rest_of_path.replace(0, 1, "/");
slashpos = rest_of_path.find("\\");
}
out_path.append(rest_of_path);
}
return out_path;
}