first:初版框架搭建
This commit is contained in:
commit
155629c127
17
.clang-format
Normal file
17
.clang-format
Normal file
@ -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
|
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
build
|
||||
.vs
|
||||
.cache
|
||||
cmake-*
|
107
.vscode/settings.json
vendored
Normal file
107
.vscode/settings.json
vendored
Normal file
@ -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"
|
||||
}
|
||||
}
|
25
CMakeLists.txt
Normal file
25
CMakeLists.txt
Normal file
@ -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)
|
122
cmd_parse.cpp
Normal file
122
cmd_parse.cpp
Normal file
@ -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<CPackBinaryCmd>(
|
||||
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<CPackBinaryCmd>(
|
||||
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<CPackBinaryCmd>(
|
||||
this, &CPackBinaryCmd::handleInput)));
|
||||
options.addOption(Poco::Util::Option("category", "c", "category name")
|
||||
.required(false)
|
||||
.repeatable(false)
|
||||
.argument("category name")
|
||||
.callback(Poco::Util::OptionCallback<CPackBinaryCmd>(
|
||||
this, &CPackBinaryCmd::handleInput)));
|
||||
options.addOption(Poco::Util::Option("mode", "m", "mode name")
|
||||
.required(false)
|
||||
.repeatable(false)
|
||||
.argument("mode name")
|
||||
.callback(Poco::Util::OptionCallback<CPackBinaryCmd>(
|
||||
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<CPackBinaryCmd>(
|
||||
this, &CPackBinaryCmd::handleInput)));
|
||||
}
|
||||
|
||||
void CPackBinaryCmd::handleHelp(const std::string& name,
|
||||
const std::string& value)
|
||||
{
|
||||
std::string introduce = ""
|
||||
"PackBinary options:\n"
|
||||
" -ico <ico_file> 安装快捷方式时的ico文件路径。\n"
|
||||
" -file <binary_file> 二进制文件。\n"
|
||||
" -include <search_lib_dir> 搜索的库路径。\n"
|
||||
" -category <category name> 分类名称。\n"
|
||||
" -mode <mode name> 执行方式(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<std::string>& 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;
|
||||
}
|
44
cmd_parse.h
Normal file
44
cmd_parse.h
Normal file
@ -0,0 +1,44 @@
|
||||
#ifndef CMD_PARSE_HEADER
|
||||
#define CMD_PARSE_HEADER
|
||||
|
||||
#include <Poco/Exception.h>
|
||||
#include <Poco/Util/OptionCallback.h>
|
||||
#include <Poco/Util/OptionProcessor.h>
|
||||
#include <Poco/Util/OptionSet.h>
|
||||
#include <Poco/Util/ServerApplication.h>
|
||||
#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<std::string>& args) override;
|
||||
|
||||
private:
|
||||
bool validCheck();
|
||||
private:
|
||||
CmdResult result_;
|
||||
};
|
||||
|
||||
#endif
|
6
install.cpp
Normal file
6
install.cpp
Normal file
@ -0,0 +1,6 @@
|
||||
#include "install.h"
|
||||
|
||||
bool CInstallBinary::startInstall(const CmdResult& result)
|
||||
{
|
||||
return false;
|
||||
}
|
16
install.h
Normal file
16
install.h
Normal file
@ -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
|
20
logic.cpp
Normal file
20
logic.cpp
Normal file
@ -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;
|
||||
}
|
||||
}
|
15
logic.h
Normal file
15
logic.h
Normal file
@ -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
|
9
main.cpp
Normal file
9
main.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
#include <iostream>
|
||||
#include "cmd_parse.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
CPackBinaryCmd app;
|
||||
return app.run(argc, argv);
|
||||
}
|
6
pack.cpp
Normal file
6
pack.cpp
Normal file
@ -0,0 +1,6 @@
|
||||
#include "pack.h"
|
||||
|
||||
bool CPackBinary::startPack(const CmdResult& result)
|
||||
{
|
||||
return false;
|
||||
}
|
15
pack.h
Normal file
15
pack.h
Normal file
@ -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
|
16
public.hpp
Normal file
16
public.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef PUBLIC_HEADER
|
||||
#define PUBLIC_HEADER
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct CmdResult {
|
||||
std::string binary;
|
||||
std::string ico;
|
||||
std::string category;
|
||||
std::vector<std::string> lib_dirs;
|
||||
bool valid{false};
|
||||
int mode{0};
|
||||
};
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user