add:基本完成安装功能。

This commit is contained in:
taynpg 2024-10-31 14:46:47 +08:00
parent ae78cc98a8
commit 4fe2b55804
3 changed files with 58 additions and 2 deletions

View File

@ -27,4 +27,4 @@ find_package(Boost REQUIRED program_options filesystem)
include_directories(${Boost_INCLUDE_DIR})
add_executable(PackBinary ${SOURCES_FILE})
target_link_libraries(PackBinary PRIVATE ${Boost_LIBRARIES})
target_link_libraries(PackBinary PRIVATE ${Boost_LIBRARIES} dl)

View File

@ -1,9 +1,63 @@
#include "install.h"
#include "resource.h"
#include <boost/algorithm/string.hpp>
#include <boost/filesystem.hpp>
#include <fstream>
#include <iostream>
namespace fs = boost::filesystem;
bool CInstallBinary::startInstall(const CmdResult& result)
{
CResource res;
auto shell_template = res.getShellTemplate();
return false;
auto desktop_tempte = res.getDesktopTemplate();
auto file_name = fs::path(result.binary).filename().string();
// 写临时文件
char* home = std::getenv("HOME");
fs::path homep(home);
fs::path work_path = fs::path(homep).append(".config").append("PackBinary");
fs::create_directories(work_path);
fs::path temp_shell = fs::path(result.binary).parent_path().append(file_name + "_run.sh");
fs::path temp_desktop = fs::path(work_path).append(file_name + ".desktop");
// fs::path dest_dir = fs::path(result.purpose_dir).append(file_name);
// fs::create_directories(dest_dir);
auto write_file = [](const std::string& content,
const std::string& file) -> bool {
std::ofstream of(file);
if (!of.is_open()) {
std::cerr << "file not opened: " << file << std::endl;
return false;
}
of << content;
of.close();
return true;
};
boost::replace_all(shell_template, "replace_str", file_name);
boost::replace_all(desktop_tempte, "re_name", file_name);
boost::replace_all(desktop_tempte, "re_describe", "default");
boost::replace_all(desktop_tempte, "re_path", temp_shell.string());
boost::replace_all(desktop_tempte, "re_icon", result.ico);
boost::replace_all(desktop_tempte, "re_category", result.category);
if (!write_file(shell_template, temp_shell.string())) {
return false;
}
std::string cmd("chmod +x " + temp_shell.string());
std::system(cmd.c_str());
if (!write_file(desktop_tempte, temp_desktop.string())) {
return false;
}
cmd.clear();
cmd = "pkexec cp " + temp_desktop.string() + " /usr/share/applications";
std::system(cmd.c_str());
return true;
}

View File

@ -1,9 +1,11 @@
#include <iostream>
#include "cmd_parse.h"
#include <boost/dll.hpp>
int main(int argc, char** argv)
{
std::cout << boost::dll::program_location().string() << std::endl;
if (argc == 1) {
std::cout << "请使用 -h 或者 --help 查看帮助。" << std::endl;
return 0;