diff --git a/lib/libimhex/CMakeLists.txt b/lib/libimhex/CMakeLists.txt index 0bbb42957..5586fb18b 100644 --- a/lib/libimhex/CMakeLists.txt +++ b/lib/libimhex/CMakeLists.txt @@ -21,6 +21,7 @@ set(LIBIMHEX_SOURCES source/data_processor/node.cpp source/helpers/utils.cpp + source/helpers/utils_linux.cpp source/helpers/fs.cpp source/helpers/magic.cpp source/helpers/crypto.cpp diff --git a/lib/libimhex/include/hex/helpers/utils_linux.hpp b/lib/libimhex/include/hex/helpers/utils_linux.hpp new file mode 100644 index 000000000..1d4e330ed --- /dev/null +++ b/lib/libimhex/include/hex/helpers/utils_linux.hpp @@ -0,0 +1,9 @@ +#pragma once + +#if defined(OS_LINUX) + +namespace hex { + void executeCmd(const std::vector &argsVector); +} + +#endif diff --git a/lib/libimhex/source/helpers/fs.cpp b/lib/libimhex/source/helpers/fs.cpp index a966fa51f..2cb38754d 100644 --- a/lib/libimhex/source/helpers/fs.cpp +++ b/lib/libimhex/source/helpers/fs.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -43,9 +44,7 @@ namespace hex::fs { hex::format("open {}", wolv::util::toUTF8String(filePath)).c_str() )); #elif defined(OS_LINUX) - hex::unused(system( - hex::format("xdg-open {}", wolv::util::toUTF8String(filePath)).c_str() - )); + executeCmd({"xdg-open", wolv::util::toUTF8String(filePath)}); #endif } @@ -62,9 +61,7 @@ namespace hex::fs { hex::format("open {}", wolv::util::toUTF8String(dirPath)).c_str() )); #elif defined(OS_LINUX) - hex::unused(system( - hex::format("xdg-open {}", wolv::util::toUTF8String(dirPath)).c_str() - )); + executeCmd({"xdg-open", wolv::util::toUTF8String(dirPath)}); #endif } @@ -87,9 +84,7 @@ namespace hex::fs { #elif defined(OS_LINUX) // fallback to only opening the folder for now // TODO actually select the file - hex::unused(system( - hex::format("xdg-open {}", wolv::util::toUTF8String(selectedFilePath.parent_path())).c_str() - )); + executeCmd({"xdg-open", wolv::util::toUTF8String(selectedFilePath.parent_path())}); #endif } diff --git a/lib/libimhex/source/helpers/utils.cpp b/lib/libimhex/source/helpers/utils.cpp index 9e0f26059..4b93238e3 100644 --- a/lib/libimhex/source/helpers/utils.cpp +++ b/lib/libimhex/source/helpers/utils.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -313,14 +314,12 @@ namespace hex { void runCommand(const std::string &command) { #if defined(OS_WINDOWS) - auto result = system(hex::format("start {0}", command).c_str()); + hex::unused(system(hex::format("start {0}", command).c_str())); #elif defined(OS_MACOS) - auto result = system(hex::format("open {0}", command).c_str()); + hex::unused(system(hex::format("open {0}", command).c_str())); #elif defined(OS_LINUX) - auto result = system(hex::format("xdg-open {0}", command).c_str()); + executeCmd({"xdg-open", command}); #endif - - hex::unused(result); } void openWebpage(std::string url) { @@ -332,8 +331,7 @@ namespace hex { #elif defined(OS_MACOS) openWebpageMacos(url.c_str()); #elif defined(OS_LINUX) - auto result = system(hex::format("xdg-open {0}", url).c_str()); - hex::unused(result); + executeCmd({"xdg-open", url}); #else #warning "Unknown OS, can't open webpages" #endif diff --git a/lib/libimhex/source/helpers/utils_linux.cpp b/lib/libimhex/source/helpers/utils_linux.cpp new file mode 100644 index 000000000..0271b4f8c --- /dev/null +++ b/lib/libimhex/source/helpers/utils_linux.cpp @@ -0,0 +1,27 @@ +#if defined(OS_LINUX) + +#include + +#include +#include +#include + +namespace hex { + + void executeCmd(const std::vector &argsVector) { + std::vector cArgsVector; + for (const auto &str : argsVector) { + cArgsVector.push_back(const_cast(str.c_str())); + } + cArgsVector.push_back(nullptr); + + if (fork() == 0) { + execvp(cArgsVector[0], &cArgsVector[0]); + log::error("execvp() failed: {}", strerror(errno)); + exit(EXIT_FAILURE); + } + } + +} + +#endif diff --git a/main/source/window/linux_window.cpp b/main/source/window/linux_window.cpp index 2ea25bd53..75b6ee868 100644 --- a/main/source/window/linux_window.cpp +++ b/main/source/window/linux_window.cpp @@ -7,6 +7,7 @@ #include #include + #include #include #include @@ -37,20 +38,6 @@ namespace hex { return false; } - void executeCmd(const std::vector &argsVector) { - std::vector cArgsVector; - for (const auto &str : argsVector) { - cArgsVector.push_back(const_cast(str.c_str())); - } - cArgsVector.push_back(nullptr); - - if (fork() == 0) { - execvp(cArgsVector[0], &cArgsVector[0]); - log::error("execvp() failed: {}", strerror(errno)); - exit(EXIT_FAILURE); - } - } - void nativeErrorMessage(const std::string &message) { log::fatal(message); if (isFileInPath("zenity")) {