部分实现查找依赖。

This commit is contained in:
taynpg 2024-08-13 10:46:29 +08:00
parent 2136171bcc
commit bf194c4c3c
3 changed files with 76 additions and 5 deletions

View File

@ -3,14 +3,81 @@
//
#include "FunctionImp.h"
#include <wx/tokenzr.h>
CFunPack::CFunPack() = default;
bool CFunPack::gen(const wxString& out_dir, const wxArrayString& dirs)
bool CFunPack::gen(const wxString& bin, const wxString& out_dir, const wxArrayString& dirs)
{
auto ret_source = get_depend_on(bin, dirs);
auto result = parse_result(ret_source);
return true;
}
wxArrayString CFunPack::get_depend_on(const wxString& bin, const wxArrayString& dirs)
{
wxArrayString array;
wxString cmd;
if (!dirs.empty()) {
cmd.append("export LD_LIBRARY_PATH=$LD_LIBRARY_PATH");
for (const auto& data : dirs) {
cmd.append(":" + data);
}
}
cmd.append(" && ldd " + bin);
FILE* pf = nullptr;
if ((pf = popen(cmd.c_str(), "r")) == nullptr) {
return array;
}
char buffer[1024]{};
wxString result{};
while (std::fgets(buffer, sizeof(buffer), pf)) {
result.append(buffer);
}
array = wxStringTokenize(result, "\t");
return array;
}
std::list<wxString> CFunPack::parse_result(const wxArrayString& array)
{
std::list<wxString> ret;
wxArrayString simlog;
wxArrayString bk_arry = array;
for (auto& data : bk_arry) {
if (data.empty()) {
continue;
}
if (data.Contains("not found")) {
simlog.push_back(wxT("未找到依赖:" + data));
continue;
}
data.Replace("=>", "");
wxArrayString tokens = wxStringTokenize(data, " ");
wxString dy;
if (tokens.size() == 4) {
dy = tokens[2];
}
if (tokens.size() == 3) {
dy = tokens[1];
}
if (dy.starts_with("/lib")) {
continue;
}
if (!dy.empty()) {
ret.push_back(dy);
}
}
return ret;
}
CFunInstall::CFunInstall()
= default;

View File

@ -5,6 +5,7 @@
#ifndef FUNCTIONIMP_H
#define FUNCTIONIMP_H
#include <wx/arrstr.h>
#include <list>
class CFunPack
{
@ -12,7 +13,9 @@ public:
CFunPack();
public:
bool gen(const wxString& out_dir, const wxArrayString& dirs);
bool gen(const wxString& bin, const wxString& out_dir, const wxArrayString& dirs);
wxArrayString get_depend_on(const wxString& bin, const wxArrayString& dirs);
std::list<wxString> parse_result(const wxArrayString& array);
};
class CFunInstall

View File

@ -129,7 +129,7 @@ void CMainPanel::genResult(wxCommandEvent& event)
arrayStrings.Add(item);
}
wxString out_dir = text_output_ctrl_->GetValue();
if (handle_->gen(out_dir, arrayStrings)) {
if (handle_->gen(text_select_ctrl_->GetValue(), out_dir, arrayStrings)) {
// 显示消息框
wxMessageBox(wxT("成功"), // 消息内容
wxT("成功"), // 标题
@ -175,8 +175,9 @@ void CMainPanel::selectBinaryFile(wxCommandEvent& event)
{
wxFileDialog openFileDialog(
this, _("Open file"), "", "",
"Text files (*.txt)|*.txt|PDF files (*.pdf)|*.pdf|All files (*.*)|*.*",
wxFD_OPEN | wxFD_FILE_MUST_EXIST);
"*",
wxFD_OPEN | wxFD_FILE_MUST_EXIST
);
if (openFileDialog.ShowModal() == wxID_CANCEL)
return;