Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
b93639697c | |||
b5e518e887 | |||
40466ed3b4 | |||
74031eb1e0 | |||
489f4fff58 | |||
b5b11a6056 | |||
a3fa22a4fd | |||
c2b028e78d | |||
60d7f3a8cd | |||
ee51cba780 | |||
da67e39364 |
@ -1,34 +1,17 @@
|
||||
# .clang-format
|
||||
|
||||
# 风格格式化
|
||||
BasedOnStyle: LLVM
|
||||
# 4 空格缩进
|
||||
IndentWidth: 4
|
||||
# 连续对齐变量的声明
|
||||
AlignConsecutiveDeclarations: true
|
||||
# 指针左侧对齐
|
||||
PointerAlignment: Left
|
||||
# 访问说明符(public、private等)的偏移
|
||||
BasedOnStyle: LLVM
|
||||
IndentWidth: 4
|
||||
PointerAlignment: Left
|
||||
AccessModifierOffset: -4
|
||||
# 大括号
|
||||
BreakBeforeBraces: Custom
|
||||
BraceWrapping:
|
||||
# 函数定义后面大括号在新行
|
||||
AfterFunction: true
|
||||
# class定义后面
|
||||
AfterClass: true
|
||||
|
||||
# 去除C++11的列表初始化的大括号{后和}前的空格
|
||||
Cpp11BracedListStyle: true
|
||||
# 允许重新排版注释
|
||||
ReflowComments: true
|
||||
# 允许排序#include
|
||||
SortIncludes: true
|
||||
# 在尾随的评论前添加的空格数(只适用于//)
|
||||
SpacesBeforeTrailingComments: 3
|
||||
# tab宽度
|
||||
TabWidth: 4
|
||||
# 构造函数的初始化列表要么都在同一行,要么都各自一行
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
# 每行字符的限制,0表示没有限制
|
||||
ColumnLimit: 150
|
||||
ColumnLimit: 110
|
||||
AllowShortBlocksOnASingleLine: Never
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AllowShortEnumsOnASingleLine: false
|
||||
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
[submodule "ofen"]
|
||||
path = ofen
|
||||
url = https://www.sinxmiao.cn/taynpg/ofen
|
119
.vscode/settings.json
vendored
119
.vscode/settings.json
vendored
@ -1,8 +1,9 @@
|
||||
{
|
||||
"files.autoSave": "onFocusChange",
|
||||
"editor.fontSize": 16,
|
||||
"editor.fontFamily": "'Operator Mono Lig', 'Operator Mono Lig', 'Operator Mono Lig'",
|
||||
"editor.fontSize": 14,
|
||||
"editor.fontFamily": "'Source Code Pro', 'Source Code Pro', 'Source Code Pro'",
|
||||
"cmake.configureOnOpen": true,
|
||||
"terminal.integrated.fontFamily": "Source Code Pro",
|
||||
"cmake.debugConfig": {
|
||||
"console": "integratedTerminal",
|
||||
"setupCommands": [
|
||||
@ -19,29 +20,109 @@
|
||||
"visualizerFile": "${workspaceRoot}/.vscode/qt6.natvis"
|
||||
},
|
||||
"cmake.environment": {
|
||||
"PATH": "${env:PATH};/home/typ/Qt5.14.2/5.14.2/gcc_64/bin"
|
||||
"PATH": "${env:PATH};C:/Qt/6.7.2/bin;C:/Qt/Qt5.14.2/5.14.2/msvc2017_64/bin;D:/Qt/Qt5.14.2/5.14.2/msvc2017_64/bin"
|
||||
},
|
||||
"cmake.options.statusBarVisibility": "visible",
|
||||
"cmake.generator": "Ninja",
|
||||
"C_Cpp.intelliSenseEngine": "disabled",
|
||||
"clangd.arguments": [
|
||||
"--header-insertion=never",
|
||||
"--all-scopes-completion",
|
||||
"--completion-style=detailed",
|
||||
"--clang-tidy",
|
||||
"-j=4",
|
||||
"--pch-storage=memory",
|
||||
"--compile-commands-dir=build",
|
||||
"--background-index",
|
||||
"--ranking-model=heuristics",
|
||||
"--function-arg-placeholders=false",
|
||||
"--query-driver=/usr/bin/g++"
|
||||
],
|
||||
"C_Cpp.default.compileCommands": "${workspaceRoot}/build/compile_commands.json",
|
||||
"C_Cpp.default.cppStandard": "c++17",
|
||||
"editor.inlayHints.enabled": "off",
|
||||
"editor.unicodeHighlight.allowedLocales": {
|
||||
"ja": true,
|
||||
"zh-hant": true,
|
||||
"zh-hans": true
|
||||
},
|
||||
"files.associations": {
|
||||
"algorithm": "cpp",
|
||||
"atomic": "cpp",
|
||||
"cctype": "cpp",
|
||||
"chrono": "cpp",
|
||||
"cmath": "cpp",
|
||||
"cstdarg": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cstring": "cpp",
|
||||
"ctime": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"exception": "cpp",
|
||||
"filesystem": "cpp",
|
||||
"functional": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"iomanip": "cpp",
|
||||
"ios": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"iostream": "cpp",
|
||||
"istream": "cpp",
|
||||
"iterator": "cpp",
|
||||
"limits": "cpp",
|
||||
"list": "cpp",
|
||||
"locale": "cpp",
|
||||
"map": "cpp",
|
||||
"memory": "cpp",
|
||||
"mutex": "cpp",
|
||||
"new": "cpp",
|
||||
"numeric": "cpp",
|
||||
"ostream": "cpp",
|
||||
"ratio": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"string": "cpp",
|
||||
"string_view": "cpp",
|
||||
"system_error": "cpp",
|
||||
"thread": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"utility": "cpp",
|
||||
"variant": "cpp",
|
||||
"vector": "cpp",
|
||||
"xfacet": "cpp",
|
||||
"xhash": "cpp",
|
||||
"xiosbase": "cpp",
|
||||
"xlocale": "cpp",
|
||||
"xlocbuf": "cpp",
|
||||
"xlocinfo": "cpp",
|
||||
"xlocmes": "cpp",
|
||||
"xlocmon": "cpp",
|
||||
"xlocnum": "cpp",
|
||||
"xloctime": "cpp",
|
||||
"xmemory": "cpp",
|
||||
"xmemory0": "cpp",
|
||||
"xstddef": "cpp",
|
||||
"xstring": "cpp",
|
||||
"xtr1common": "cpp",
|
||||
"xtree": "cpp",
|
||||
"xutility": "cpp",
|
||||
"qtablewidget": "cpp",
|
||||
"qmenu": "cpp",
|
||||
"qmessagebox": "cpp",
|
||||
"qaction": "cpp",
|
||||
"codecvt": "cpp",
|
||||
"qregexp": "cpp",
|
||||
"qregularexpression": "cpp",
|
||||
"array": "cpp",
|
||||
"bit": "cpp",
|
||||
"charconv": "cpp",
|
||||
"clocale": "cpp",
|
||||
"compare": "cpp",
|
||||
"concepts": "cpp",
|
||||
"condition_variable": "cpp",
|
||||
"format": "cpp",
|
||||
"forward_list": "cpp",
|
||||
"future": "cpp",
|
||||
"optional": "cpp",
|
||||
"sstream": "cpp",
|
||||
"stop_token": "cpp",
|
||||
"regex": "cpp",
|
||||
"*.tcc": "cpp",
|
||||
"cwctype": "cpp",
|
||||
"deque": "cpp",
|
||||
"memory_resource": "cpp",
|
||||
"random": "cpp",
|
||||
"fstream": "cpp",
|
||||
"cinttypes": "cpp"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,12 +1,24 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(packqt VERSION 0.1 LANGUAGES CXX)
|
||||
project(binpack VERSION 0.1 LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_PREFIX_PATH
|
||||
"/home/typ/Qt5.14.2/5.14.2/gcc_64"
|
||||
"/home/typ/Dev/Boost"
|
||||
"/home/yun/Qt5.14.2/5.14.2/gcc_64"
|
||||
"/home/yun/Dev/Boost"
|
||||
# 获取环境变量 HOME
|
||||
if (UNIX)
|
||||
set(USER_HOME $ENV{HOME})
|
||||
else()
|
||||
set(USER_HOME "C:/Qt")
|
||||
endif()
|
||||
|
||||
# 打印用户目录
|
||||
message(STATUS "User home directory: ${USER_HOME}")
|
||||
|
||||
set(CMAKE_PREFIX_PATH
|
||||
${CMAKE_PREFIX_PATH}
|
||||
"${USER_HOME}/Qt5.14.2/5.14.2/gcc_64/"
|
||||
"${USER_HOME}/Qt5.14.2/5.14.2/msvc2017_64/"
|
||||
"D:/Qt/Qt5.14.2/5.14.2/msvc2017_64/"
|
||||
"C:/Qt/6.7.2"
|
||||
"/opt/homebrew/Cellar/qt/6.7.0_2/"
|
||||
)
|
||||
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
@ -27,9 +39,7 @@ 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})
|
||||
add_subdirectory(ofen)
|
||||
|
||||
set(PROJECT_SOURCES
|
||||
main.cpp
|
||||
@ -39,41 +49,41 @@ set(PROJECT_SOURCES
|
||||
adddesktop.ui
|
||||
adddesktop.h
|
||||
adddesktop.cpp
|
||||
packqt.qrc
|
||||
binpack.qrc
|
||||
)
|
||||
|
||||
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
||||
qt_add_executable(packqt
|
||||
qt_add_executable(binpack
|
||||
MANUAL_FINALIZATION
|
||||
${PROJECT_SOURCES}
|
||||
)
|
||||
# Define target properties for Android with Qt 6 as:
|
||||
# set_property(TARGET packqt APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
|
||||
# set_property(TARGET binpack APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
|
||||
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
|
||||
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
|
||||
else()
|
||||
if(ANDROID)
|
||||
add_library(packqt SHARED
|
||||
add_library(binpack SHARED
|
||||
${PROJECT_SOURCES}
|
||||
)
|
||||
# Define properties for Android with Qt 5 after find_package() calls as:
|
||||
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
|
||||
else()
|
||||
add_executable(packqt
|
||||
add_executable(binpack
|
||||
${PROJECT_SOURCES}
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
target_link_libraries(packqt PRIVATE Qt${QT_VERSION_MAJOR}::Widgets ${Boost_LIBRARIES})
|
||||
target_link_libraries(binpack PRIVATE Qt${QT_VERSION_MAJOR}::Widgets ofen)
|
||||
|
||||
# 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
|
||||
# explicit, fixed bundle identifier manually though.
|
||||
if(${QT_VERSION} VERSION_LESS 6.1.0)
|
||||
set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.packqt)
|
||||
set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.binpack)
|
||||
endif()
|
||||
set_target_properties(packqt PROPERTIES
|
||||
set_target_properties(binpack PROPERTIES
|
||||
${BUNDLE_ID_OPTION}
|
||||
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
|
||||
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
|
||||
@ -82,12 +92,12 @@ set_target_properties(packqt PROPERTIES
|
||||
)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
install(TARGETS packqt
|
||||
install(TARGETS binpack
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
|
||||
if(QT_VERSION_MAJOR EQUAL 6)
|
||||
qt_finalize_executable(packqt)
|
||||
qt_finalize_executable(binpack)
|
||||
endif()
|
||||
|
@ -3,22 +3,28 @@
|
||||
#include "adddesktop.h"
|
||||
#include <QTextStream>
|
||||
#include <fstream>
|
||||
#include <of_path.h>
|
||||
#include <of_str.h>
|
||||
|
||||
using namespace ofen;
|
||||
MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setWindowTitle("packqt v1.0.2");
|
||||
setWindowTitle("binpack v1.0.5");
|
||||
connect_operator();
|
||||
control_init();
|
||||
}
|
||||
|
||||
MainWidget::~MainWidget() { delete ui; }
|
||||
MainWidget::~MainWidget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void MainWidget::connect_operator()
|
||||
{
|
||||
connect(ui->btnSelcetBinary, &QPushButton::clicked, this, [=]() { SelectFile(this, ui->edBinary, "请选择Qt二进制文件", "所有文件 (*)"); });
|
||||
connect(ui->btnSelcetBinary, &QPushButton::clicked, this,
|
||||
[=]() { SelectFile(this, ui->edBinary, "请选择二进制文件", "所有文件 (*)"); });
|
||||
connect(ui->btnSelectOut, &QPushButton::clicked, this, [=]() { SelectDirectory(this, ui->edOutDir); });
|
||||
connect(ui->btnSelectQt, &QPushButton::clicked, this, [=]() { SelectDirectory(this, ui->edQtDir); });
|
||||
connect(ui->btnAddEnv, &QPushButton::clicked, this, [=]() { add_env_btn(); });
|
||||
connect(ui->btnDelEnv, &QPushButton::clicked, this, [=]() { del_env_btn(); });
|
||||
connect(ui->btnGenerate, &QPushButton::clicked, this, [=]() { generate(); });
|
||||
@ -29,7 +35,6 @@ void MainWidget::connect_operator()
|
||||
void MainWidget::control_init()
|
||||
{
|
||||
ui->plainTextEdit->setReadOnly(true);
|
||||
ui->edQtDir->setText(QDir::homePath() + "/Qt5.14.2/5.14.2/gcc_64");
|
||||
ui->edOutDir->setText(QDir::homePath() + "/program");
|
||||
#if !defined(NDEBUG)
|
||||
#endif
|
||||
@ -73,7 +78,7 @@ bool MainWidget::copy_dir(const std::string& source_dir, const std::string& des_
|
||||
return false;
|
||||
}
|
||||
|
||||
fs::path des_parent_dir = fs::path(des_dir).append(fs::path(source_dir).filename());
|
||||
fs::path des_parent_dir = fs::path(des_dir).append(fs::path(source_dir).filename().string());
|
||||
if (!fs::exists(des_parent_dir)) {
|
||||
fs::create_directories(des_parent_dir);
|
||||
}
|
||||
@ -86,7 +91,7 @@ bool MainWidget::copy_dir(const std::string& source_dir, const std::string& des_
|
||||
fs::path path = paths.front();
|
||||
paths.pop_front();
|
||||
|
||||
fs::path destination(boost::replace_all_copy(path.string(), source_dir, des_parent_dir.string()));
|
||||
fs::path destination(COfStr::replace(path.string(), source_dir, des_parent_dir.string()));
|
||||
if (fs::is_directory(path)) {
|
||||
if (!fs::exists(destination)) {
|
||||
fs::create_directories(destination);
|
||||
@ -101,10 +106,11 @@ bool MainWidget::copy_dir(const std::string& source_dir, const std::string& des_
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<std::string> MainWidget::get_depend_on(const std::string& name, const std::vector<std::string>& env)
|
||||
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{};
|
||||
std::string cmd{};
|
||||
|
||||
if (!env.empty()) {
|
||||
cmd.append("export LD_LIBRARY_PATH=$LD_LIBRARY_PATH");
|
||||
@ -113,7 +119,7 @@ std::vector<std::string> MainWidget::get_depend_on(const std::string& name, cons
|
||||
}
|
||||
}
|
||||
cmd.append(" && ldd " + name);
|
||||
char buffer[1024]{};
|
||||
char buffer[1024]{};
|
||||
FILE* pf = nullptr;
|
||||
if ((pf = popen(cmd.c_str(), "r")) == nullptr) {
|
||||
return vec;
|
||||
@ -123,7 +129,7 @@ std::vector<std::string> MainWidget::get_depend_on(const std::string& name, cons
|
||||
result.append(buffer);
|
||||
}
|
||||
|
||||
boost::split(vec, result, boost::is_any_of("\t"));
|
||||
vec = COfStr::split(result, "\t");
|
||||
return vec;
|
||||
}
|
||||
|
||||
@ -135,20 +141,19 @@ std::list<std::string> MainWidget::handle_result(const std::vector<std::string>&
|
||||
continue;
|
||||
}
|
||||
|
||||
if (boost::contains(data, "not found")) {
|
||||
if (data.find("not found") == 0) {
|
||||
simple_log(QString::fromStdString("未找到依赖:" + data), false);
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string tdata = boost::replace_all_copy(data, "=>", "");
|
||||
std::vector<std::string> vt;
|
||||
boost::split(vt, tdata, boost::is_any_of(" "));
|
||||
std::string tdata = COfStr::replace(data, "=>", "");
|
||||
std::vector<std::string> vt = COfStr::split(tdata, " ");
|
||||
if (vt.size() != 4) {
|
||||
// QString info = "原始数据:" + QString::fromStdString(data);
|
||||
// simple_log(info, false);
|
||||
continue;
|
||||
}
|
||||
if (boost::starts_with(vt[2], "/lib")) {
|
||||
if (vt[2].find("/lib") == 0) {
|
||||
continue;
|
||||
}
|
||||
ret.push_back(vt[2]);
|
||||
@ -169,7 +174,7 @@ void MainWidget::del_env_btn()
|
||||
QString MainWidget::SelectDirectory(QWidget* parent, QLineEdit* pEdit, const QString& pre_path)
|
||||
{
|
||||
QString start_path = pre_path;
|
||||
QDir folder(start_path);
|
||||
QDir folder(start_path);
|
||||
if (start_path.isEmpty() || !folder.exists()) {
|
||||
start_path = QDir::homePath();
|
||||
}
|
||||
@ -209,7 +214,10 @@ bool MainWidget::isOk(QWidget* parent, const QString& title, const QString& cont
|
||||
}
|
||||
}
|
||||
|
||||
void MainWidget::message(QWidget* parent, const QString& content) { QMessageBox::information(parent, "提示", content); }
|
||||
void MainWidget::message(QWidget* parent, const QString& content)
|
||||
{
|
||||
QMessageBox::information(parent, "提示", content);
|
||||
}
|
||||
|
||||
void MainWidget::cmd_exec(const std::string& cmd)
|
||||
{
|
||||
@ -239,14 +247,6 @@ void MainWidget::generate()
|
||||
std::vector<std::string> dynamic_so{};
|
||||
std::copy(result.begin(), result.end(), std::back_inserter(dynamic_so));
|
||||
|
||||
// 处理 platform文件夹
|
||||
std::list<fs::path> platform{};
|
||||
fs::path qt_platform(ui->edQtDir->text().trimmed().toStdString());
|
||||
qt_platform.append("plugins/platforms");
|
||||
for (const auto& entry : fs::directory_iterator(qt_platform)) {
|
||||
result.push_back(entry.path().string());
|
||||
}
|
||||
|
||||
while (!result.empty()) {
|
||||
std::string bin = result.front();
|
||||
result.pop_front();
|
||||
@ -269,24 +269,20 @@ void MainWidget::generate()
|
||||
}
|
||||
|
||||
for (const auto& data : dynamic_so) {
|
||||
std::string purpose = fs::path(out_dir).append(fs::path(data).filename()).string();
|
||||
std::string purpose = fs::path(out_dir).append(fs::path(data).filename().string()).string();
|
||||
fs::copy_file(data, purpose, fs::copy_options::overwrite_existing);
|
||||
}
|
||||
|
||||
// 复制platform文件夹
|
||||
copy_dir(qt_platform.string(), out_dir.string());
|
||||
|
||||
// 复制主体文件
|
||||
fs::path out_binary = fs::path(out_dir).append(fs::path(binary_.toStdString()).filename());
|
||||
fs::path out_binary = fs::path(out_dir).append(fs::path(binary_.toStdString()).filename().string());
|
||||
fs::copy_file(binary_.toStdString(), out_binary, fs::copy_options::overwrite_existing);
|
||||
if (!add_run_sh(out_dir.string(), filename)) {
|
||||
if (!add_run_sh(out_dir.string(), filename, std::vector<std::string>())) {
|
||||
return;
|
||||
}
|
||||
message(this, "完成");
|
||||
}
|
||||
|
||||
|
||||
bool MainWidget::add_run_sh(const std::string& out_dir, const std::string& exe_name)
|
||||
bool MainWidget::add_run_sh(const std::string& out_dir, const std::string& exe_name, const std::vector<std::string>& exports)
|
||||
{
|
||||
// 生成一个启动文件夹
|
||||
QFile file("://resource/run.sh");
|
||||
@ -299,9 +295,15 @@ bool MainWidget::add_run_sh(const std::string& out_dir, const std::string& exe_n
|
||||
file.close();
|
||||
|
||||
std::string run_sh = content.toStdString();
|
||||
boost::replace_all(run_sh, "replace_string", exe_name);
|
||||
run_sh = COfStr::replace(run_sh, "replace_string", exe_name);
|
||||
// REPLACE_EXPORT
|
||||
|
||||
std::string out_sh = fs::path(out_dir).append("run.sh").string();
|
||||
std::string outs{};
|
||||
for (const auto& item : exports) {
|
||||
outs = outs + "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:" + item + "\n";
|
||||
}
|
||||
run_sh = COfStr::replace(run_sh, "REPLACE_EXPORT", outs);
|
||||
std::string out_sh = fs::path(out_dir).append(exe_name + ".sh").string();
|
||||
std::ofstream out(out_sh, std::ios::out);
|
||||
if (!out.is_open()) {
|
||||
return false;
|
||||
@ -310,4 +312,4 @@ bool MainWidget::add_run_sh(const std::string& out_dir, const std::string& exe_n
|
||||
out.close();
|
||||
cmd_exec(std::string("chmod +x " + out_sh));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
13
MainWidget.h
13
MainWidget.h
@ -6,12 +6,11 @@
|
||||
#include <QLineEdit>
|
||||
#include <QMessageBox>
|
||||
#include <QWidget>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
@ -46,10 +45,10 @@ private:
|
||||
public:
|
||||
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);
|
||||
static void cmd_exec(const std::string& cmd);
|
||||
static bool add_run_sh(const std::string& out_dir, const std::string& exe_name);
|
||||
static bool isOk(QWidget* parent, const QString& title, const QString& content);
|
||||
static void message(QWidget* parent, const QString& content);
|
||||
static void cmd_exec(const std::string& cmd);
|
||||
static bool add_run_sh(const std::string& out_dir, const std::string& exe_name, const std::vector<std::string>& exports);
|
||||
|
||||
private:
|
||||
Ui::MainWidget* ui;
|
||||
|
@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1057</width>
|
||||
<height>778</height>
|
||||
<width>965</width>
|
||||
<height>591</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -60,44 +60,6 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Qt路径(选到bin的父目录):</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="edQtDir"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnSelectQt">
|
||||
<property name="text">
|
||||
<string>选择</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<item>
|
||||
@ -142,7 +104,7 @@
|
||||
<item>
|
||||
<widget class="QGroupBox" name="gboxEnv">
|
||||
<property name="title">
|
||||
<string>2.LD_LIBRARY_PATH配置</string>
|
||||
<string>2.要搜寻的LD_LIBRARY_PATH位置</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
|
14
README.md
14
README.md
@ -1,13 +1,19 @@
|
||||
# packqt
|
||||
# binpack
|
||||
|
||||
- 用于打包`Linux`下的`Qt`程序。
|
||||
- 用于打包`Linux`下的二进制程序。
|
||||
- 给二进制文件添加快捷方式。
|
||||
|
||||
## 简要说明
|
||||
|
||||
- 仅用于Linux系统,实测是在Ubuntu。
|
||||
- 仅用于Linux系统。
|
||||
- 仅用于相同目标Linux版本的打包,如在Ubuntu20.04上开发的程序打包后丢在Ubuntu20.04的客户机上。
|
||||
|
||||
## 示例图
|
||||
|
||||

|
||||
### 1.打包
|
||||
|
||||

|
||||
|
||||
### 2.安装到菜单栏
|
||||
|
||||

|
||||
|
@ -2,6 +2,9 @@
|
||||
#include "ui_adddesktop.h"
|
||||
#include <QTextStream>
|
||||
#include <fstream>
|
||||
#include <of_str.h>
|
||||
|
||||
using namespace ofen;
|
||||
|
||||
AddDesktop::AddDesktop(QWidget* parent) : QDialog(parent), ui(new Ui::AddDesktop)
|
||||
{
|
||||
@ -36,9 +39,13 @@ AddDesktop::AddDesktop(QWidget* parent) : QDialog(parent), ui(new Ui::AddDesktop
|
||||
connect(ui->ckUseDefault, &QCheckBox::toggled, this, &AddDesktop::checkchange);
|
||||
connect(ui->btnSelectBinary, &QPushButton::clicked, this,
|
||||
[=]() { MainWidget::SelectFile(this, ui->edBinary, "请选择二进制文件", "所有文件 (*)"); });
|
||||
connect(ui->btnSelectIco, &QPushButton::clicked, this,
|
||||
[=]() { MainWidget::SelectFile(this, ui->edIco, "请选择ico图标文件", "ico图标(*.ico);;svg图标(*.svg);;所有文件 (*)"); });
|
||||
connect(ui->btnSelectIco, &QPushButton::clicked, this, [=]() {
|
||||
MainWidget::SelectFile(this, ui->edIco, "请选择ico图标文件",
|
||||
"png图标(*.png);;ico图标(*.ico);;svg图标(*.svg);;所有文件 (*)");
|
||||
});
|
||||
connect(ui->btnInstall, &QPushButton::clicked, this, &AddDesktop::install_to_desktop);
|
||||
connect(ui->envAdd, &QPushButton::clicked, this, &AddDesktop::add_env_btn);
|
||||
connect(ui->envDel, &QPushButton::clicked, this, &AddDesktop::del_env_btn);
|
||||
}
|
||||
|
||||
void AddDesktop::checkchange()
|
||||
@ -65,9 +72,21 @@ void AddDesktop::install_to_desktop()
|
||||
return;
|
||||
}
|
||||
std::string binaryName = fs::path(binaryPath).filename().string();
|
||||
fs::path sh_path = fs::path(binaryPath).parent_path().append("run.sh");
|
||||
fs::path sh_path = fs::path(binaryPath).parent_path().append(binaryName + ".sh");
|
||||
|
||||
std::string cmodBin = "chmod +x " + binaryPath;
|
||||
std::string cmodSh = "chmod +x " + sh_path.string();
|
||||
MainWidget::cmd_exec(cmodBin);
|
||||
MainWidget::cmd_exec(cmodSh);
|
||||
|
||||
std::vector<std::string> evs{};
|
||||
int env_cnt = ui->listWidget->count();
|
||||
for (int i = 0; i < env_cnt; ++i) {
|
||||
evs.push_back(ui->listWidget->item(i)->text().toStdString());
|
||||
}
|
||||
|
||||
if (!fs::exists(sh_path)) {
|
||||
MainWidget::add_run_sh(sh_path.parent_path().string(), binaryName);
|
||||
MainWidget::add_run_sh(sh_path.parent_path().string(), binaryName, evs);
|
||||
}
|
||||
fs::path tmp = fs::path(QDir::homePath().toStdString()).append(".config");
|
||||
if (!fs::exists(tmp)) {
|
||||
@ -75,21 +94,21 @@ void AddDesktop::install_to_desktop()
|
||||
}
|
||||
|
||||
QTextStream stream(&file);
|
||||
QString content = stream.readAll();
|
||||
QString content = stream.readAll();
|
||||
file.close();
|
||||
std::string ct = content.toStdString();
|
||||
boost::replace_all(ct, "re_name", binaryName);
|
||||
boost::replace_all(ct, "re_describe", binaryName);
|
||||
boost::replace_all(ct, "re_path", "sh " + sh_path.string());
|
||||
ct = COfStr::replace(ct, "re_name", binaryName);
|
||||
ct = COfStr::replace(ct, "re_describe", binaryName);
|
||||
ct = COfStr::replace(ct, "re_path", "sh " + sh_path.string());
|
||||
|
||||
fs::path default_ico_path = fs::path(tmp).append("packqt");
|
||||
fs::path default_ico_path = fs::path(tmp).append("binpack");
|
||||
if (!fs::exists(default_ico_path)) {
|
||||
fs::create_directories(default_ico_path);
|
||||
}
|
||||
if (ui->ckUseDefault->isChecked()) {
|
||||
default_ico_path.append("Tools.svg");
|
||||
QFile::copy("://resource/Tools.svg", QString::fromStdString(default_ico_path.string()));
|
||||
boost::replace_all(ct, "re_icon", default_ico_path.string());
|
||||
ct = COfStr::replace(ct, "re_icon", default_ico_path.string());
|
||||
|
||||
} else {
|
||||
std::string icn = ui->edIco->text().trimmed().toStdString();
|
||||
@ -97,12 +116,12 @@ void AddDesktop::install_to_desktop()
|
||||
MainWidget::message(this, "图标路径为空");
|
||||
return;
|
||||
}
|
||||
default_ico_path.append(fs::path(icn).filename());
|
||||
boost::replace_all(ct, "re_icon", default_ico_path.string());
|
||||
default_ico_path.append(fs::path(icn).filename().string());
|
||||
ct = COfStr::replace(ct, "re_icon", default_ico_path.string());
|
||||
fs::copy_file(icn, default_ico_path, fs::copy_options::overwrite_existing);
|
||||
}
|
||||
|
||||
boost::replace_all(ct, "re_category", ui->cbCategories->currentText().toStdString());
|
||||
ct = COfStr::replace(ct, "re_category", ui->cbCategories->currentText().toStdString());
|
||||
tmp.append(binaryName + ".desktop");
|
||||
;
|
||||
std::ofstream out(tmp.string(), std::ios::out);
|
||||
@ -117,4 +136,25 @@ void AddDesktop::install_to_desktop()
|
||||
MainWidget::message(this, "完成");
|
||||
}
|
||||
|
||||
AddDesktop::~AddDesktop() { delete ui; }
|
||||
AddDesktop::~AddDesktop()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void AddDesktop::add_env_btn()
|
||||
{
|
||||
QString env = MainWidget::SelectDirectory(this, nullptr);
|
||||
if (env.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
ui->listWidget->addItem(env);
|
||||
}
|
||||
|
||||
void AddDesktop::del_env_btn()
|
||||
{
|
||||
QListWidgetItem* item = ui->listWidget->currentItem();
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
delete ui->listWidget->takeItem(ui->listWidget->currentRow());
|
||||
}
|
||||
|
@ -16,6 +16,10 @@ public:
|
||||
explicit AddDesktop(QWidget *parent = nullptr);
|
||||
~AddDesktop();
|
||||
|
||||
private:
|
||||
void add_env_btn();
|
||||
void del_env_btn();
|
||||
|
||||
private:
|
||||
void checkchange();
|
||||
void install_to_desktop();
|
||||
|
@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>429</width>
|
||||
<height>259</height>
|
||||
<width>485</width>
|
||||
<height>411</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -124,6 +124,47 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_7">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>附加环境目录:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_5">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="envAdd">
|
||||
<property name="text">
|
||||
<string>添加</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="envDel">
|
||||
<property name="text">
|
||||
<string>删除</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="listWidget"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||
<item>
|
||||
|
2
build.sh
Executable file
2
build.sh
Executable file
@ -0,0 +1,2 @@
|
||||
cmake -Bbuild -DCMAKE_BUILD_TYPE=Release
|
||||
cmake --build build --config Release
|
BIN
img/show.png
BIN
img/show.png
Binary file not shown.
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 33 KiB |
BIN
img/show2.png
Normal file
BIN
img/show2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 26 KiB |
1
ofen
Submodule
1
ofen
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 71948320b735e33db511f756b5df83ef3ddcf2c7
|
BIN
resource/binpack.png
Normal file
BIN
resource/binpack.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
@ -10,7 +10,8 @@ cd "$SCRIPT_DIR" || exit
|
||||
echo "当前目录是:$SCRIPT_DIR"
|
||||
|
||||
# 将脚本所在目录添加到 LD_LIBRARY_PATH 环境变量
|
||||
export LD_LIBRARY_PATH="$SCRIPT_DIR"
|
||||
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"$SCRIPT_DIR"
|
||||
REPLACE_EXPORT
|
||||
|
||||
# 定义 replace_string 脚本的绝对路径
|
||||
REPLACE_STRING_SCRIPT="$SCRIPT_DIR/replace_string"
|
||||
|
Loading…
x
Reference in New Issue
Block a user