From 155629c12718248200b6ad6a2da7606c7b9173fc Mon Sep 17 00:00:00 2001 From: taynpg Date: Sun, 27 Oct 2024 15:51:46 +0800 Subject: [PATCH] =?UTF-8?q?first=EF=BC=9A=E5=88=9D=E7=89=88=E6=A1=86?= =?UTF-8?q?=E6=9E=B6=E6=90=AD=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .clang-format | 17 ++++++ .gitignore | 4 ++ .vscode/settings.json | 107 ++++++++++++++++++++++++++++++++++++ CMakeLists.txt | 25 +++++++++ README.md | 3 ++ cmd_parse.cpp | 122 ++++++++++++++++++++++++++++++++++++++++++ cmd_parse.h | 44 +++++++++++++++ install.cpp | 6 +++ install.h | 16 ++++++ logic.cpp | 20 +++++++ logic.h | 15 ++++++ main.cpp | 9 ++++ pack.cpp | 6 +++ pack.h | 15 ++++++ public.hpp | 16 ++++++ 15 files changed, 425 insertions(+) create mode 100644 .clang-format create mode 100644 .gitignore create mode 100644 .vscode/settings.json create mode 100644 CMakeLists.txt create mode 100644 README.md create mode 100644 cmd_parse.cpp create mode 100644 cmd_parse.h create mode 100644 install.cpp create mode 100644 install.h create mode 100644 logic.cpp create mode 100644 logic.h create mode 100644 main.cpp create mode 100644 pack.cpp create mode 100644 pack.h create mode 100644 public.hpp diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..402f22e --- /dev/null +++ b/.clang-format @@ -0,0 +1,17 @@ +BasedOnStyle: LLVM +IndentWidth: 4 +PointerAlignment: Left +AccessModifierOffset: -4 +BreakBeforeBraces: Custom +BraceWrapping: + AfterFunction: true + AfterClass: true +Cpp11BracedListStyle: true +ReflowComments: true +SpacesBeforeTrailingComments: 3 +TabWidth: 4 +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ColumnLimit: 80 +AllowShortBlocksOnASingleLine: Never +AllowShortFunctionsOnASingleLine: None +AllowShortEnumsOnASingleLine: false diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5b861d3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +build +.vs +.cache +cmake-* \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..5f4a7a3 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,107 @@ +{ + "files.autoSave": "onFocusChange", + "editor.fontSize": 14, + "editor.fontFamily": "'FiraCode Nerd Font Mono', 'FiraCode Nerd Font Mono', 'FiraCode Nerd Font Mono'", + "cmake.configureOnOpen": true, + "cmake.debugConfig": { + "console": "integratedTerminal", + "setupCommands": [ + { + "description": "-gdb-set charset utf-8", + "text": "-gdb-set charset UTF-8" + }, + { + "description": "Enable gdb pretty-printing", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ], + "args": [ + "/f", "mfile", "/i", "mico", "/c", "mc", "/m", "mm" + ] + }, + "cmake.configureSettings": { + "CMAKE_TOOLCHAIN_FILE": "${env:VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" + }, + "cmake.options.statusBarVisibility": "visible", + "cmake.generator": "Ninja", + "C_Cpp.default.compileCommands": "${workspaceRoot}/build/compile_commands.json", + "C_Cpp.default.cppStandard": "c++17", + "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools", + "editor.inlayHints.enabled": "off", + "editor.unicodeHighlight.allowedLocales": { + "ja": true, + "zh-hant": true, + "zh-hans": true + }, + "files.associations": { + "algorithm": "cpp", + "atomic": "cpp", + "bit": "cpp", + "cctype": "cpp", + "charconv": "cpp", + "chrono": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "compare": "cpp", + "concepts": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "deque": "cpp", + "exception": "cpp", + "format": "cpp", + "forward_list": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "ios": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "iterator": "cpp", + "limits": "cpp", + "list": "cpp", + "locale": "cpp", + "memory": "cpp", + "new": "cpp", + "optional": "cpp", + "ostream": "cpp", + "ratio": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "string": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "typeinfo": "cpp", + "unordered_set": "cpp", + "utility": "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", + "xstring": "cpp", + "xtr1common": "cpp", + "xutility": "cpp", + "cstdarg": "cpp", + "map": "cpp", + "mutex": "cpp", + "set": "cpp", + "stop_token": "cpp", + "thread": "cpp", + "xtree": "cpp" + } +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..b6c930a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,25 @@ +cmake_minimum_required(VERSION 3.16) + +project(PackBinary LANGUAGES CXX) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +if (MSVC) + add_compile_options(/source-charset:utf-8) +endif() + +message(STATUS "System: ${CMAKE_SYSTEM_NAME}") +message(STATUS "Compiler CXX ID: ${CMAKE_CXX_COMPILER_ID}") + +set(SOURCES_FILE + main.cpp cmd_parse.h + cmd_parse.cpp public.hpp + pack.h pack.cpp + install.h install.cpp + logic.h logic.cpp +) + +find_package(Poco REQUIRED Foundation Util) + +add_executable(PackBinary ${SOURCES_FILE}) +target_link_libraries(PackBinary PRIVATE Poco::Foundation Poco::Util) \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..394df95 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# 介绍 + +打包`Linux`下的二进制文件和安装`Ubuntu`快捷方式。 \ No newline at end of file diff --git a/cmd_parse.cpp b/cmd_parse.cpp new file mode 100644 index 0000000..2a6ad70 --- /dev/null +++ b/cmd_parse.cpp @@ -0,0 +1,122 @@ +#include "cmd_parse.h" +#include "logic.h" + +void CPackBinaryCmd::initialize(Poco::Util::Application& self) +{ + ServerApplication::initialize(self); +} + +void CPackBinaryCmd::uninitialize() +{ + ServerApplication::uninitialize(); +} + +void CPackBinaryCmd::defineOptions(Poco::Util::OptionSet& options) +{ + ServerApplication::defineOptions(options); + options.addOption(Poco::Util::Option("help", "h", "Help Message") + .required(false) + .repeatable(false) + .callback(Poco::Util::OptionCallback( + this, &CPackBinaryCmd::handleHelp))); + + options.addOption(Poco::Util::Option("ico", "i", "ico_file") + .required(false) + .repeatable(false) + .argument("ico_file's full path") + .callback(Poco::Util::OptionCallback( + this, &CPackBinaryCmd::handleInput))); + options.addOption(Poco::Util::Option("file", "f", "binary_file") + .required(false) + .repeatable(false) + // argument 就是 require 什么东西的具体介绍。 + .argument("binary_file's full path") + .binding("nobinding") + .callback(Poco::Util::OptionCallback( + this, &CPackBinaryCmd::handleInput))); + options.addOption(Poco::Util::Option("category", "c", "category name") + .required(false) + .repeatable(false) + .argument("category name") + .callback(Poco::Util::OptionCallback( + this, &CPackBinaryCmd::handleInput))); + options.addOption(Poco::Util::Option("mode", "m", "mode name") + .required(false) + .repeatable(false) + .argument("mode name") + .callback(Poco::Util::OptionCallback( + this, &CPackBinaryCmd::handleInput))); + options.addOption(Poco::Util::Option("ext", "e", "dirs_when_search_lib") + .required(false) + .repeatable(true) + .argument("dirs_when_search_lib") + .callback(Poco::Util::OptionCallback( + this, &CPackBinaryCmd::handleInput))); +} + +void CPackBinaryCmd::handleHelp(const std::string& name, + const std::string& value) +{ + std::string introduce = "" + "PackBinary options:\n" + " -ico 安装快捷方式时的ico文件路径。\n" + " -file 二进制文件。\n" + " -include 搜索的库路径。\n" + " -category 分类名称。\n" + " -mode 执行方式(0-打包,1-安装)。" + ""; + std::cout << introduce << std::endl; + stopOptionsProcessing(); +} + +void CPackBinaryCmd::handleInput(const std::string& name, + const std::string& value) +{ + if (name == "ico") { + result_.ico = value; + return; + } + if (name == "file") { + result_.binary = value; + return; + } + if (name == "ext") { + result_.lib_dirs.push_back(value); + return; + } + if (name == "mode") { + result_.mode = value.empty() ? -1 : std::stoi(value); + return; + } + if (name == "category") { + result_.category = value; + return; + } +} + +int CPackBinaryCmd::main(const std::vector& args) +{ + if (!validCheck()) { + return Application::EXIT_CONFIG; + } + CMainLogic mainLogic; + if (mainLogic.run(result_)) { + return Application::EXIT_OK; + } else { + return Application::EXIT_SOFTWARE; + } +} + +bool CPackBinaryCmd::validCheck() +{ + std::cout << "ico:" << result_.ico << std::endl; + std::cout << "file:" << result_.binary << std::endl; + std::cout << "mode:" << result_.mode << std::endl; + std::cout << "category:" << result_.category << std::endl; + std::cout << "include:" << std::endl; + + for (const auto& item : result_.lib_dirs) { + std::cout << " " << item << std::endl; + } + return false; +} diff --git a/cmd_parse.h b/cmd_parse.h new file mode 100644 index 0000000..7cffbf7 --- /dev/null +++ b/cmd_parse.h @@ -0,0 +1,44 @@ +#ifndef CMD_PARSE_HEADER +#define CMD_PARSE_HEADER + +#include +#include +#include +#include +#include +#include "public.hpp" + +// Poco::Util::Validator* month = new Poco::Util::RegExpValidator( +// "[0-9]{6,8}"); +// options.addOption( +// Option("month", "m", +// "date(yyyymm/yyyymmdd)").required(true).repeatable( +// false).argument("month").validator(month).binding( +// "application.month").callback( +// Poco::Util::OptionCallback < DataLoader +// > (this, &DataLoader::handleMonth))); +// ———————————————— + +// 版权声明:本文为博主原创文章,遵循 CC 4.0 +// BY-SA +// 版权协议,转载请附上原文出处链接和本声明。 + +// 原文链接:https://blog.csdn.net/hwjcmozw/article/details/42963633 + +class CPackBinaryCmd : public Poco::Util::ServerApplication +{ +protected: + void initialize(Poco::Util::Application& self) override; + void uninitialize() override; + void defineOptions(Poco::Util::OptionSet& options) override; + void handleHelp(const std::string& name, const std::string& value); + void handleInput(const std::string& name, const std::string& value); + int main(const std::vector& args) override; + +private: + bool validCheck(); +private: + CmdResult result_; +}; + +#endif \ No newline at end of file diff --git a/install.cpp b/install.cpp new file mode 100644 index 0000000..a439622 --- /dev/null +++ b/install.cpp @@ -0,0 +1,6 @@ +#include "install.h" + +bool CInstallBinary::startInstall(const CmdResult& result) +{ + return false; +} \ No newline at end of file diff --git a/install.h b/install.h new file mode 100644 index 0000000..74f0442 --- /dev/null +++ b/install.h @@ -0,0 +1,16 @@ +#ifndef INSTALL_HEADER +#define INSTALL_HEADER + +#include "public.hpp" + +class CInstallBinary +{ +public: + CInstallBinary() = default; + ~CInstallBinary() = default; +public: + bool startInstall(const CmdResult& result); +}; + + +#endif \ No newline at end of file diff --git a/logic.cpp b/logic.cpp new file mode 100644 index 0000000..420d066 --- /dev/null +++ b/logic.cpp @@ -0,0 +1,20 @@ +#include "logic.h" +#include "install.h" +#include "pack.h" + +bool CMainLogic::run(const CmdResult& result) +{ + switch (result.mode) { + case 0: { + CPackBinary pack; + return pack.startPack(result); + } + case 1: { + CInstallBinary install; + return install.startInstall(result); + } + + default: + return false; + } +} \ No newline at end of file diff --git a/logic.h b/logic.h new file mode 100644 index 0000000..d3e63e4 --- /dev/null +++ b/logic.h @@ -0,0 +1,15 @@ +#ifndef LOGIC_HEADER +#define LOGIC_HEADER + +#include "public.hpp" + +class CMainLogic +{ +public: + CMainLogic() = default; + ~CMainLogic() = default; +public: + bool run(const CmdResult& result); +}; + +#endif \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..fe5bcf5 --- /dev/null +++ b/main.cpp @@ -0,0 +1,9 @@ + +#include +#include "cmd_parse.h" + +int main(int argc, char** argv) +{ + CPackBinaryCmd app; + return app.run(argc, argv); +} diff --git a/pack.cpp b/pack.cpp new file mode 100644 index 0000000..4024b0c --- /dev/null +++ b/pack.cpp @@ -0,0 +1,6 @@ +#include "pack.h" + +bool CPackBinary::startPack(const CmdResult& result) +{ + return false; +} \ No newline at end of file diff --git a/pack.h b/pack.h new file mode 100644 index 0000000..00e7436 --- /dev/null +++ b/pack.h @@ -0,0 +1,15 @@ +#ifndef PACK_HEADER +#define PACK_HEADER + +#include "public.hpp" + +class CPackBinary +{ +public: + CPackBinary() = default; + ~CPackBinary() = default; +public: + bool startPack(const CmdResult& result); +}; + +#endif \ No newline at end of file diff --git a/public.hpp b/public.hpp new file mode 100644 index 0000000..d225ba8 --- /dev/null +++ b/public.hpp @@ -0,0 +1,16 @@ +#ifndef PUBLIC_HEADER +#define PUBLIC_HEADER + +#include +#include + +struct CmdResult { + std::string binary; + std::string ico; + std::string category; + std::vector lib_dirs; + bool valid{false}; + int mode{0}; +}; + +#endif \ No newline at end of file