diff --git a/.clang-format b/.clang-format index 7a1da28..c7a6a80 100644 --- a/.clang-format +++ b/.clang-format @@ -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 \ No newline at end of file +ColumnLimit: 110 +AllowShortBlocksOnASingleLine: Never +AllowShortFunctionsOnASingleLine: None +AllowShortEnumsOnASingleLine: false diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..f5e7bbc --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "ofen"] + path = ofen + url = https://www.sinxmiao.cn/taynpg/ofen diff --git a/.vscode/settings.json b/.vscode/settings.json index 2318425..2137cc5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,8 +1,9 @@ { "files.autoSave": "onFocusChange", - "editor.fontSize": 16, - "editor.fontFamily": "'Operator Mono Lig', 'Operator Mono Lig', 'Operator Mono Lig'", + "editor.fontSize": 13, + "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++14", "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" } -} - +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 6232892..6b7c562 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,24 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.16) 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" - "/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 @@ -65,7 +75,7 @@ else() endif() endif() -target_link_libraries(packqt PRIVATE Qt${QT_VERSION_MAJOR}::Widgets ${Boost_LIBRARIES}) +target_link_libraries(packqt 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 diff --git a/MainWidget.cpp b/MainWidget.cpp index 5e06833..ba6871e 100644 --- a/MainWidget.cpp +++ b/MainWidget.cpp @@ -3,7 +3,10 @@ #include "adddesktop.h" #include #include +#include +#include +using namespace ofen; MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget) { ui->setupUi(this); @@ -12,11 +15,15 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget 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, "请选择Qt二进制文件", "所有文件 (*)"); }); 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(); }); @@ -73,7 +80,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 +93,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 +108,11 @@ bool MainWidget::copy_dir(const std::string& source_dir, const std::string& des_ return true; } -std::vector MainWidget::get_depend_on(const std::string& name, const std::vector& env) +std::vector MainWidget::get_depend_on(const std::string& name, + const std::vector& env) { std::vector vec; - std::string cmd{}; + std::string cmd{}; if (!env.empty()) { cmd.append("export LD_LIBRARY_PATH=$LD_LIBRARY_PATH"); @@ -113,7 +121,7 @@ std::vector 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 +131,7 @@ std::vector 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 +143,19 @@ std::list MainWidget::handle_result(const std::vector& 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 vt; - boost::split(vt, tdata, boost::is_any_of(" ")); + std::string tdata = COfStr::replace(data, "=>", ""); + std::vector 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 +176,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 +216,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) { @@ -241,7 +251,7 @@ void MainWidget::generate() // 处理 platform文件夹 std::list platform{}; - fs::path qt_platform(ui->edQtDir->text().trimmed().toStdString()); + 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()); @@ -269,7 +279,7 @@ 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); } @@ -277,7 +287,7 @@ void MainWidget::generate() 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)) { return; @@ -285,7 +295,6 @@ void MainWidget::generate() message(this, "完成"); } - bool MainWidget::add_run_sh(const std::string& out_dir, const std::string& exe_name) { // 生成一个启动文件夹 @@ -299,9 +308,10 @@ 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); - std::string out_sh = fs::path(out_dir).append(exe_name + ".sh").string(); + run_sh = COfStr::replace(run_sh, "replace_string", exe_name); + + 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; diff --git a/MainWidget.h b/MainWidget.h index 5c9d85c..9d1deaa 100644 --- a/MainWidget.h +++ b/MainWidget.h @@ -6,12 +6,11 @@ #include #include #include -#include -#include +#include #include #include -namespace fs = boost::filesystem; +namespace fs = std::filesystem; QT_BEGIN_NAMESPACE namespace Ui { diff --git a/adddesktop.cpp b/adddesktop.cpp index 15cbc1a..125559d 100644 --- a/adddesktop.cpp +++ b/adddesktop.cpp @@ -2,6 +2,9 @@ #include "ui_adddesktop.h" #include #include +#include + +using namespace ofen; AddDesktop::AddDesktop(QWidget* parent) : QDialog(parent), ui(new Ui::AddDesktop) { @@ -36,8 +39,10 @@ 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图标文件", "png图标(*.png);;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); } @@ -65,7 +70,7 @@ void AddDesktop::install_to_desktop() return; } std::string binaryName = fs::path(binaryPath).filename().string(); - fs::path sh_path = fs::path(binaryPath).parent_path().append(binaryName + ".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(); @@ -81,12 +86,12 @@ 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"); if (!fs::exists(default_ico_path)) { @@ -95,7 +100,7 @@ void AddDesktop::install_to_desktop() 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(); @@ -103,12 +108,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); @@ -123,4 +128,7 @@ void AddDesktop::install_to_desktop() MainWidget::message(this, "完成"); } -AddDesktop::~AddDesktop() { delete ui; } +AddDesktop::~AddDesktop() +{ + delete ui; +} diff --git a/ofen b/ofen new file mode 160000 index 0000000..7194832 --- /dev/null +++ b/ofen @@ -0,0 +1 @@ +Subproject commit 71948320b735e33db511f756b5df83ef3ddcf2c7