开始写主逻辑部分
This commit is contained in:
parent
fa0b08c548
commit
3fed1d9180
@ -4,6 +4,7 @@ project(packqt VERSION 0.1 LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_PREFIX_PATH
|
||||
"/home/typ/Qt5.14.2/5.14.2/gcc_64"
|
||||
"/home/typ/Dev/Boost"
|
||||
)
|
||||
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
@ -24,6 +25,10 @@ if (MSVC)
|
||||
add_compile_options(-D_CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
|
||||
set(Boost_USE_STATIC_LIBS ON)
|
||||
find_package(Boost REQUIRED filesystem)
|
||||
include_directories(${Boost_INCLUDE_DIR})
|
||||
|
||||
set(PROJECT_SOURCES
|
||||
main.cpp
|
||||
MainWidget.cpp
|
||||
@ -54,7 +59,7 @@ else()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
target_link_libraries(packqt PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
|
||||
target_link_libraries(packqt PRIVATE Qt${QT_VERSION_MAJOR}::Widgets ${Boost_LIBRARIES})
|
||||
|
||||
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
|
||||
# If you are developing for iOS or macOS you should consider setting an
|
||||
|
@ -6,6 +6,7 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget
|
||||
ui->setupUi(this);
|
||||
setWindowTitle("打包Qt工具");
|
||||
connect_operator();
|
||||
control_init();
|
||||
}
|
||||
|
||||
MainWidget::~MainWidget() { delete ui; }
|
||||
@ -20,6 +21,16 @@ void MainWidget::connect_operator()
|
||||
connect(ui->btnGenerate, &QPushButton::clicked, this, [=]() { generate(); });
|
||||
}
|
||||
|
||||
void MainWidget::control_init()
|
||||
{
|
||||
ui->plainTextEdit->setEnabled(false);
|
||||
#if !defined (NDEBUG)
|
||||
ui->edBinary->setText("/home/typ/Downloads/build-QXmlEdit-Desktop_Qt_5_14_2_GCC_64bit-Release/build/qxmledit");
|
||||
ui->edQtDir->setText("/home/typ/Qt5.14.2/5.14.2/gcc_64");
|
||||
ui->edOutDir->setText("/home/typ/testpack");
|
||||
#endif
|
||||
}
|
||||
|
||||
void MainWidget::add_env_btn()
|
||||
{
|
||||
QString env = SelectDirectory(this, nullptr);
|
||||
@ -29,9 +40,55 @@ void MainWidget::add_env_btn()
|
||||
ui->listWidget->addItem(env);
|
||||
}
|
||||
|
||||
void MainWidget::generate()
|
||||
{
|
||||
void MainWidget::simple_log(const QString& info) { ui->plainTextEdit->appendPlainText(info + "\n"); }
|
||||
|
||||
std::vector<std::string> MainWidget::get_depend_on(const std::string& name, const std::vector<std::string>& env)
|
||||
{
|
||||
std::vector<std::string> vec;
|
||||
std::string cmd{};
|
||||
|
||||
if (!env.empty()) {
|
||||
cmd.append("export LD_LIBRARY_PATH=$LD_LIBRARY_PATH");
|
||||
for (const auto& data : env) {
|
||||
cmd.append(":" + data);
|
||||
}
|
||||
}
|
||||
cmd.append(" && ldd " + name);
|
||||
char buffer[1024]{};
|
||||
FILE* pf = nullptr;
|
||||
if ((pf = popen(cmd.c_str(), "r")) == nullptr) {
|
||||
return vec;
|
||||
}
|
||||
std::string result{};
|
||||
while (std::fgets(buffer, sizeof(buffer), pf)) {
|
||||
result.append(buffer);
|
||||
}
|
||||
|
||||
boost::split(vec, result, boost::is_any_of("\t"));
|
||||
return vec;
|
||||
}
|
||||
|
||||
std::vector<std::string> MainWidget::handle_result(const std::vector<std::string>& vec)
|
||||
{
|
||||
std::vector<std::string> ret;
|
||||
for (const auto& data : vec) {
|
||||
if (data.empty()) {
|
||||
continue;
|
||||
}
|
||||
std::string tdata = boost::replace_all_copy(data, "=>", "");
|
||||
std::vector<std::string> vt;
|
||||
boost::split(vt, tdata, boost::is_any_of(" "));
|
||||
if (vt.size() != 4) {
|
||||
QString info = "长度不对,原始数据:\n" + QString::fromStdString(data);
|
||||
simple_log(info);
|
||||
continue;
|
||||
}
|
||||
if (boost::starts_with(vt[2], "/lib")) {
|
||||
continue;
|
||||
}
|
||||
ret.push_back(vt[2]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void MainWidget::del_env_btn()
|
||||
@ -85,3 +142,23 @@ bool MainWidget::isOk(QWidget* parent, const QString& title, const QString& cont
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWidget::message(QWidget* parent, const QString& content) { QMessageBox::information(parent, "提示", content); }
|
||||
|
||||
void MainWidget::generate()
|
||||
{
|
||||
ui->plainTextEdit->clear();
|
||||
envs_.clear();
|
||||
|
||||
binary_ = ui->edBinary->text().trimmed();
|
||||
fs::path binary_dir = fs::path(binary_.toStdString()).parent_path();
|
||||
envs_.push_back(binary_dir.string());
|
||||
|
||||
int env_cnt = ui->listWidget->count();
|
||||
for (int i = 0; i < env_cnt; ++i) {
|
||||
envs_.push_back(ui->listWidget->item(i)->text().toStdString());
|
||||
}
|
||||
|
||||
auto retPrevious = get_depend_on(binary_.toStdString(), envs_);
|
||||
auto result = handle_result(retPrevious);
|
||||
}
|
17
MainWidget.h
17
MainWidget.h
@ -6,6 +6,12 @@
|
||||
#include <QLineEdit>
|
||||
#include <QMessageBox>
|
||||
#include <QWidget>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
@ -23,16 +29,27 @@ public:
|
||||
|
||||
private:
|
||||
void connect_operator();
|
||||
void control_init();
|
||||
void add_env_btn();
|
||||
void del_env_btn();
|
||||
void generate();
|
||||
void simple_log(const QString& info);
|
||||
|
||||
private:
|
||||
std::vector<std::string> get_depend_on(const std::string& name, const std::vector<std::string>& env);
|
||||
std::vector<std::string> handle_result(const std::vector<std::string>& vec);
|
||||
|
||||
private:
|
||||
static QString SelectDirectory(QWidget* parent, QLineEdit* pEdit, const QString& pre_path = "");
|
||||
static QString SelectFile(QWidget* parent, QLineEdit* pEdit, const QString& info, const QString& filter);
|
||||
static bool isOk(QWidget* parent, const QString& title, const QString& content);
|
||||
static void message(QWidget* parent, const QString& content);
|
||||
|
||||
private:
|
||||
Ui::MainWidget* ui;
|
||||
|
||||
private:
|
||||
QString binary_{};
|
||||
std::vector<std::string> envs_{};
|
||||
};
|
||||
#endif // MAINWIDGET_H
|
||||
|
@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1026</width>
|
||||
<height>739</height>
|
||||
<width>1057</width>
|
||||
<height>778</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -179,6 +179,9 @@
|
||||
<item>
|
||||
<widget class="QListWidget" name="listWidget"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="plainTextEdit"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_8">
|
||||
<item>
|
||||
|
Loading…
x
Reference in New Issue
Block a user