Factor out directory finding from prefix detection

This will also be used to locate the `yabridge.tmol` configuration file.
This commit is contained in:
Robbert van der Helm
2020-05-14 19:11:17 +02:00
parent e728dbe5a2
commit 9a82e82c87
3 changed files with 63 additions and 11 deletions
+9 -10
View File
@@ -28,6 +28,8 @@
// Generated inside of build directory
#include <src/common/config/config.h>
#include <../common/configuration.h>
namespace bp = boost::process;
namespace fs = boost::filesystem;
@@ -53,16 +55,13 @@ std::string create_logger_prefix(const fs::path& socket_path) {
}
std::optional<fs::path> find_wineprefix() {
// Try to locate the Wine prefix the plugin's .dll file is located in by
// finding the first parent directory that contains a directory named
// `dosdevices`
fs::path wineprefix_path = find_vst_plugin();
while (wineprefix_path != "") {
if (fs::is_directory(wineprefix_path / "dosdevices")) {
return wineprefix_path;
}
wineprefix_path = wineprefix_path.parent_path();
// We need these string conversions because Boost still doesn't use
// std::filesystem paths
std::optional<std::filesystem::path> dosdevices_dir =
find_dominating_file("dosdevices", find_vst_plugin().string(),
std::filesystem::is_directory);
if (dosdevices_dir.has_value()) {
return dosdevices_dir->parent_path().string();
}
return std::nullopt;
+2 -1
View File
@@ -101,7 +101,8 @@ boost::filesystem::path find_vst_plugin();
/**
* Locate the Wine prefix this file is located in, if it is inside of a wine
* prefix.
* prefix. This is done by locating the first parent directory that contains a
* directory named `dosdevices`.
*
* @return Either the path to the Wine prefix (containing the `drive_c?`
* directory), or `std::nullopt` if it is not inside of a wine prefix.