Added wirekit installation requirement checks

This commit is contained in:
York Jasper Niebuhr 2025-08-17 12:05:46 +02:00
parent 93e7ee7973
commit bdf88ad778
3 changed files with 29 additions and 3 deletions

View File

@ -2,6 +2,7 @@
#include <filesystem> #include <filesystem>
#include <list> #include <list>
#include <string> #include <string>
#include <functional>
class InstallManager { class InstallManager {
static constexpr const char* INSTALL_PATH = ".rewire/wirekits"; // Relative to home directory static constexpr const char* INSTALL_PATH = ".rewire/wirekits"; // Relative to home directory
@ -20,7 +21,8 @@ public:
operator bool() const; operator bool() const;
bool install(const char* from, const char* to); bool install(const char* from, const char* to,
std::function<bool(const std::filesystem::path&)> check = {});
bool uninstall(const char* name); bool uninstall(const char* name);
bool get(const char* name, std::filesystem::path& path) const; bool get(const char* name, std::filesystem::path& path) const;
std::list<std::string> installs() const; std::list<std::string> installs() const;

View File

@ -41,7 +41,7 @@ InstallManager::operator bool() const {
return m_valid; return m_valid;
} }
bool InstallManager::install(const char* from, const char* to) { bool InstallManager::install(const char* from, const char* to, std::function<bool(const std::filesystem::path&)> check) {
if (!m_valid || !from) if (!m_valid || !from)
return false; return false;
@ -65,6 +65,10 @@ bool InstallManager::install(const char* from, const char* to) {
if (!std::filesystem::exists(src) || !std::filesystem::is_regular_file(src)) if (!std::filesystem::exists(src) || !std::filesystem::is_regular_file(src))
return false; return false;
std::filesystem::path src_absolute = std::filesystem::absolute(src);
if (!check(src_absolute))
return false;
return std::filesystem::copy_file(src, install_dst, std::filesystem::copy_options::overwrite_existing); return std::filesystem::copy_file(src, install_dst, std::filesystem::copy_options::overwrite_existing);
} }

View File

@ -52,7 +52,27 @@ int launch_install(int argc, char** argv) {
return 1; return 1;
} }
if (!im.install(argv[2], (argc == 4 ? argv[3] : nullptr))) { auto kitcheck = [](const std::filesystem::path& kit) -> bool {
DL tmp_dl { kit };
if (!tmp_dl) {
std::cout << "Failed to check wirekit requirements for installation!" << std::endl;
return false;
}
if (!tmp_dl.resolve("wirekit_prepare")) {
std::cout << "Wirekit must implement \"wirekit_prepare\" to be installed!" << std::endl;
return false;
}
if (!tmp_dl.resolve("wirekit_command_start")) {
std::cout << "Wirekit must implement \"wirekit_command_start\" to be installed!" << std::endl;
return false;
}
return true;
};
if (!im.install(argv[2], (argc == 4 ? argv[3] : nullptr), kitcheck)) {
std::cout << "Failed to install wirekit!" << std::endl; std::cout << "Failed to install wirekit!" << std::endl;
return 1; return 1;
} }