mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-09 20:29:10 +02:00
Factor out directory finding from prefix detection
This will also be used to locate the `yabridge.tmol` configuration file.
This commit is contained in:
@@ -0,0 +1,52 @@
|
|||||||
|
// yabridge: a Wine VST bridge
|
||||||
|
// Copyright (C) 2020 Robbert van der Helm
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starting from the starting file or directory, go up in the directory
|
||||||
|
* hierarchy until we find a file named `filename`.
|
||||||
|
*
|
||||||
|
* @param filename The name of the file we're looking for. This can also be a
|
||||||
|
* directory name since directories are also files.
|
||||||
|
* @param starting_from The directory to start searching in. If this is a file,
|
||||||
|
* then start searching in the directory the file is located in.
|
||||||
|
* @param predicate The predicate to use to check if the path matches a file.
|
||||||
|
* Needed as an easy way to limit the search to directories only since C++17
|
||||||
|
* does not have any built in coroutines or generators.
|
||||||
|
*
|
||||||
|
* @return The path to the *file* found, or `std::nullopt` if the file could not
|
||||||
|
* be found.
|
||||||
|
*/
|
||||||
|
template <typename F = bool(const std::filesystem::path&)>
|
||||||
|
std::optional<std::filesystem::path> find_dominating_file(
|
||||||
|
const std::string& filename,
|
||||||
|
std::filesystem::path starting_dir,
|
||||||
|
F predicate = std::filesystem::exists) {
|
||||||
|
while (starting_dir != "") {
|
||||||
|
const std::filesystem::path candidate = starting_dir / filename;
|
||||||
|
if (predicate(candidate)) {
|
||||||
|
return candidate;
|
||||||
|
}
|
||||||
|
|
||||||
|
starting_dir = starting_dir.parent_path();
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
+9
-10
@@ -28,6 +28,8 @@
|
|||||||
// Generated inside of build directory
|
// Generated inside of build directory
|
||||||
#include <src/common/config/config.h>
|
#include <src/common/config/config.h>
|
||||||
|
|
||||||
|
#include <../common/configuration.h>
|
||||||
|
|
||||||
namespace bp = boost::process;
|
namespace bp = boost::process;
|
||||||
namespace fs = boost::filesystem;
|
namespace fs = boost::filesystem;
|
||||||
|
|
||||||
@@ -53,16 +55,13 @@ std::string create_logger_prefix(const fs::path& socket_path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::optional<fs::path> find_wineprefix() {
|
std::optional<fs::path> find_wineprefix() {
|
||||||
// Try to locate the Wine prefix the plugin's .dll file is located in by
|
// We need these string conversions because Boost still doesn't use
|
||||||
// finding the first parent directory that contains a directory named
|
// std::filesystem paths
|
||||||
// `dosdevices`
|
std::optional<std::filesystem::path> dosdevices_dir =
|
||||||
fs::path wineprefix_path = find_vst_plugin();
|
find_dominating_file("dosdevices", find_vst_plugin().string(),
|
||||||
while (wineprefix_path != "") {
|
std::filesystem::is_directory);
|
||||||
if (fs::is_directory(wineprefix_path / "dosdevices")) {
|
if (dosdevices_dir.has_value()) {
|
||||||
return wineprefix_path;
|
return dosdevices_dir->parent_path().string();
|
||||||
}
|
|
||||||
|
|
||||||
wineprefix_path = wineprefix_path.parent_path();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
|||||||
+2
-1
@@ -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
|
* 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?`
|
* @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.
|
* directory), or `std::nullopt` if it is not inside of a wine prefix.
|
||||||
|
|||||||
Reference in New Issue
Block a user