diff --git a/CMakeLists.txt b/CMakeLists.txt index b6eca1e..48020da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,7 @@ set(PROJECT_SOURCES MainWidget.cpp MainWidget.h MainWidget.ui + packqt.qrc ) if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) diff --git a/MainWidget.cpp b/MainWidget.cpp index dc1324b..8465cdf 100644 --- a/MainWidget.cpp +++ b/MainWidget.cpp @@ -1,10 +1,12 @@ #include "MainWidget.h" #include "./ui_MainWidget.h" +#include +#include MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget) { ui->setupUi(this); - setWindowTitle("打包Qt工具"); + setWindowTitle("打包Qt工具 v0.9"); connect_operator(); control_init(); } @@ -251,11 +253,31 @@ void MainWidget::generate() } // 复制platform文件夹 - // fs::path qt_platform(ui->edQtDir->text().trimmed().toStdString()); - // qt_platform.append("plugins/platforms"); - // copy_dir(qt_platform.string(), out_dir.string()); + copy_dir(qt_platform.string(), out_dir.string()); // 复制主体文件 fs::path out_binary = fs::path(out_dir).append(fs::path(binary_.toStdString()).filename()); fs::copy_file(binary_.toStdString(), out_binary, fs::copy_options::overwrite_existing); + + // 生成一个启动文件夹 + QFile file("://resource/run.sh"); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + return; + } + QTextStream in(&file); + // 读取文件内容 + QString content = in.readAll(); + file.close(); + + std::string run_sh = content.toStdString(); + boost::replace_all(run_sh, "replace_string", fs::path(binary_.toStdString()).filename().string()); + + std::string out_sh = fs::path(out_dir).append("run.sh").string(); + std::ofstream out(out_sh, std::ios::out); + if (!out.is_open()) { + return; + } + out << run_sh; + out.close(); + system(std::string("chmod +x " + out_sh).c_str()); } \ No newline at end of file diff --git a/packqt.qrc b/packqt.qrc new file mode 100644 index 0000000..628c697 --- /dev/null +++ b/packqt.qrc @@ -0,0 +1,5 @@ + + + resource/run.sh + + diff --git a/resource/run.sh b/resource/run.sh new file mode 100644 index 0000000..0ec1945 --- /dev/null +++ b/resource/run.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# 获取脚本所在目录的绝对路径 +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +# 将脚本所在目录添加到 LD_LIBRARY_PATH 环境变量 +export LD_LIBRARY_PATH="$SCRIPT_DIR" + +# 执行其他操作 +./replace_string \ No newline at end of file