diff --git a/lsfg-vk-common/src/configuration/config.cpp b/lsfg-vk-common/src/configuration/config.cpp index 2ed6028..cee5861 100644 --- a/lsfg-vk-common/src/configuration/config.cpp +++ b/lsfg-vk-common/src/configuration/config.cpp @@ -271,7 +271,7 @@ WatchedConfig::WatchedConfig() : path(findConfigurationFile()) { if (std::getenv("LSFGVK_ENV")) { auto& config = this->configFile; config.global() = parseGlobalConfFromEnv(); - config.profiles().push_back(parseGameConfFromEnv()); + config.profiles() = { parseGameConfFromEnv() }; return; } diff --git a/lsfg-vk-common/src/configuration/detection.cpp b/lsfg-vk-common/src/configuration/detection.cpp index bdefc1e..2a8a5dd 100644 --- a/lsfg-vk-common/src/configuration/detection.cpp +++ b/lsfg-vk-common/src/configuration/detection.cpp @@ -17,11 +17,26 @@ using namespace ls; namespace { + // try to match a profile by name + std::optional matchByName(const std::vector& profiles, const std::string& id) { + for (const auto& profile : profiles) + if (profile.name == id) + return profile; + return std::nullopt; + } // try to match a profile by id - std::optional match(const std::vector& profiles, const std::string& id) { + std::optional matchById(const std::vector& profiles, const std::string& id) { for (const auto& profile : profiles) for (const auto& activation : profile.active_in) - if (activation == id) + if (id == activation) + return profile; + return std::nullopt; + } + // try to match a profile by id + std::optional matchEndsWithId(const std::vector& profiles, const std::string& id) { + for (const auto& profile : profiles) + for (const auto& activation : profile.active_in) + if (activation.ends_with(id)) return profile; return std::nullopt; } @@ -53,13 +68,12 @@ Identification ls::identify() { if (!line.ends_with(".exe")) continue; - size_t pos = line.find_last_of('/'); + size_t pos = line.find_first_of('/'); if (pos == std::string::npos) { pos = line.find_last_of(' '); if (pos == std::string::npos) continue; } - pos += 1; // skip slash or space const std::string wine_executable = line.substr(pos); if (wine_executable.empty()) @@ -94,26 +108,26 @@ std::optional> ls::findProfile( // then override first if (id.override.has_value()) { - const auto profile = match(profiles, id.override.value()); + const auto profile = matchByName(profiles, id.override.value()); if (profile.has_value()) return std::make_pair(IdentType::OVERRIDE, profile.value()); } // then check executable - const auto exe_profile = match(profiles, id.executable); + const auto exe_profile = matchEndsWithId(profiles, id.executable); if (exe_profile.has_value()) return std::make_pair(IdentType::EXECUTABLE, exe_profile.value()); // if present, check wine executable next if (id.wine_executable.has_value()) { - const auto wine_profile = match(profiles, id.wine_executable.value()); + const auto wine_profile = matchEndsWithId(profiles, id.wine_executable.value()); if (wine_profile.has_value()) return std::make_pair(IdentType::WINE_EXECUTABLE, wine_profile.value()); } // finally, fallback to process name if (!id.process_name.empty()) { - const auto proc_profile = match(profiles, id.process_name); + const auto proc_profile = matchById(profiles, id.process_name); if (proc_profile.has_value()) return std::make_pair(IdentType::PROCESS_NAME, proc_profile.value()); }