Added wirekit installation requirement checks
This commit is contained in:
parent
93e7ee7973
commit
bdf88ad778
@ -2,6 +2,7 @@
|
||||
#include <filesystem>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
class InstallManager {
|
||||
static constexpr const char* INSTALL_PATH = ".rewire/wirekits"; // Relative to home directory
|
||||
@ -20,7 +21,8 @@ public:
|
||||
|
||||
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 get(const char* name, std::filesystem::path& path) const;
|
||||
std::list<std::string> installs() const;
|
||||
|
||||
@ -41,7 +41,7 @@ InstallManager::operator bool() const {
|
||||
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)
|
||||
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))
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
22
src/main.cpp
22
src/main.cpp
@ -52,7 +52,27 @@ int launch_install(int argc, char** argv) {
|
||||
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;
|
||||
return 1;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user