From 4a9b05b4f55d22206f594ce4fb73d8b239629013 Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Tue, 9 Jul 2024 16:28:15 +0300 Subject: [PATCH] boohoo simplify --- include/hyprutils/path/Path.hpp | 3 ++- src/path/Path.cpp | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/include/hyprutils/path/Path.hpp b/include/hyprutils/path/Path.hpp index e03a058..25e71e4 100644 --- a/include/hyprutils/path/Path.hpp +++ b/include/hyprutils/path/Path.hpp @@ -5,7 +5,8 @@ namespace Hyprutils { namespace Path { - bool checkConfigExists(std::string path, std::string programName); + bool checkConfigExists(std::string, std::string); + std::string fullConfigPath(std::string, std::string); std::optional getHome(); std::optional getXdgConfigDirs(); std::optional getXdgConfigHome(); diff --git a/src/path/Path.cpp b/src/path/Path.cpp index 9ad3c59..943440d 100644 --- a/src/path/Path.cpp +++ b/src/path/Path.cpp @@ -5,8 +5,12 @@ using namespace Hyprutils; namespace Hyprutils::Path { + std::string fullConfigPath(std::string path, std::string programName) { + return path + "/hypr/" + programName + ".conf"; + } + bool checkConfigExists(std::string path, std::string programName) { - return std::filesystem::exists(path + "/hypr/" + programName + ".conf"); + return std::filesystem::exists(fullConfigPath(path, programName)); } std::optional getHome() { @@ -15,7 +19,7 @@ namespace Hyprutils::Path { if (!homeDir || !std::filesystem::path(homeDir).is_absolute()) return std::nullopt; - return (std::optional)std::string(homeDir).append("/.config"); + return std::string(homeDir).append("/.config"); } std::optional getXdgConfigDirs() { @@ -24,7 +28,7 @@ namespace Hyprutils::Path { if (!xdgConfigDirs) return std::nullopt; - static const std::optional xdgConfigDirsList = String::CVarList(xdgConfigDirs, 0, ':'); + static const auto xdgConfigDirsList = String::CVarList(xdgConfigDirs, 0, ':'); return xdgConfigDirsList; } @@ -35,7 +39,7 @@ namespace Hyprutils::Path { if (!xdgConfigHome || !std::filesystem::path(xdgConfigHome).is_absolute()) return std::nullopt; - return (std::optional)xdgConfigHome; + return xdgConfigHome; } std::optional findConfig(std::string programName) { @@ -43,7 +47,7 @@ namespace Hyprutils::Path { static const auto xdgConfigHome = getXdgConfigHome(); if (xdgConfigHome.has_value()) { if (checkConfigExists(xdgConfigHome.value(), programName)) - return std::optional(xdgConfigHome.value() + "/hypr/" + programName + ".conf"); + return fullConfigPath(xdgConfigHome.value(), programName); else xdgConfigHomeExists = true; } @@ -52,7 +56,7 @@ namespace Hyprutils::Path { static const auto home = getHome(); if (home.has_value()) { if (checkConfigExists(home.value(), programName)) - return std::optional(home.value() + "/hypr/" + programName + ".conf"); + return fullConfigPath(home.value(), programName); else homeExists = true; } @@ -61,12 +65,12 @@ namespace Hyprutils::Path { if (xdgConfigDirs.has_value()) { for (auto dir : xdgConfigDirs.value()) { if (checkConfigExists(dir, programName)) - return (std::optional)dir; + return fullConfigPath(dir, programName); } } if (checkConfigExists("/etc/xdg", programName)) - return std::optional("/etc/xdg/hypr/" + programName + ".conf"); + return fullConfigPath("/etc/xdg/", programName); if (xdgConfigHomeExists) return xdgConfigHome;