diff --git a/FunctionImp.cpp b/FunctionImp.cpp index 7c84fa1..69e201b 100644 --- a/FunctionImp.cpp +++ b/FunctionImp.cpp @@ -3,14 +3,81 @@ // #include "FunctionImp.h" +#include 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 CFunPack::parse_result(const wxArrayString& array) +{ + std::list 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; diff --git a/FunctionImp.h b/FunctionImp.h index 2d1cf74..e261fcb 100644 --- a/FunctionImp.h +++ b/FunctionImp.h @@ -5,6 +5,7 @@ #ifndef FUNCTIONIMP_H #define FUNCTIONIMP_H #include +#include 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 parse_result(const wxArrayString& array); }; class CFunInstall diff --git a/MainPanel.cpp b/MainPanel.cpp index e12007e..e839eeb 100644 --- a/MainPanel.cpp +++ b/MainPanel.cpp @@ -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;