change:三方库改成Boost库。
This commit is contained in:
parent
4c45249d0d
commit
ae0e878482
7
.vscode/settings.json
vendored
7
.vscode/settings.json
vendored
@ -17,12 +17,11 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"args": [
|
"args": [
|
||||||
"/f", "mfile", "/i", "mico", "/c", "mc", "/m", "mm"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
// "cmake.configureSettings": {
|
"cmake.configureSettings": {
|
||||||
// "CMAKE_TOOLCHAIN_FILE": "${env:VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
|
"CMAKE_TOOLCHAIN_FILE": "${env:VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
|
||||||
// },
|
},
|
||||||
"cmake.options.statusBarVisibility": "visible",
|
"cmake.options.statusBarVisibility": "visible",
|
||||||
"cmake.generator": "Ninja",
|
"cmake.generator": "Ninja",
|
||||||
"C_Cpp.default.compileCommands": "${workspaceRoot}/build/compile_commands.json",
|
"C_Cpp.default.compileCommands": "${workspaceRoot}/build/compile_commands.json",
|
||||||
|
@ -4,6 +4,9 @@ project(PackBinary LANGUAGES CXX)
|
|||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
set(APEEND_THID_LIB_DIR "$ENV{HOME}/mlib/boost")
|
||||||
|
list(APPEND CMAKE_PREFIX_PATH ${APEEND_THID_LIB_DIR})
|
||||||
|
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
add_compile_options(/source-charset:utf-8)
|
add_compile_options(/source-charset:utf-8)
|
||||||
endif()
|
endif()
|
||||||
@ -16,10 +19,11 @@ set(SOURCES_FILE
|
|||||||
cmd_parse.cpp public.hpp
|
cmd_parse.cpp public.hpp
|
||||||
pack.h pack.cpp
|
pack.h pack.cpp
|
||||||
install.h install.cpp
|
install.h install.cpp
|
||||||
logic.h logic.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
find_package(Poco REQUIRED Foundation Util)
|
set(Boost_USE_STATIC_LIBS OFF)
|
||||||
|
find_package(Boost REQUIRED program_options)
|
||||||
|
include_directories(${Boost_INCLUDE_DIR})
|
||||||
|
|
||||||
add_executable(PackBinary ${SOURCES_FILE})
|
add_executable(PackBinary ${SOURCES_FILE})
|
||||||
target_link_libraries(PackBinary PRIVATE Poco::Foundation Poco::Util)
|
target_link_libraries(PackBinary PRIVATE ${Boost_LIBRARIES})
|
160
cmd_parse.cpp
160
cmd_parse.cpp
@ -1,150 +1,38 @@
|
|||||||
#include "cmd_parse.h"
|
#include "cmd_parse.h"
|
||||||
#include "logic.h"
|
#include <iostream>
|
||||||
#include <Poco/File.h>
|
|
||||||
|
|
||||||
void CPackBinaryCmd::initialize(Poco::Util::Application& self)
|
CCmdParse::CCmdParse()
|
||||||
{
|
{
|
||||||
ServerApplication::initialize(self);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPackBinaryCmd::uninitialize()
|
bool CCmdParse::cmdParse(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
ServerApplication::uninitialize();
|
cmd::options_description desc("options");
|
||||||
}
|
desc.add_options()("help,h", "produce help message")(
|
||||||
|
"dirs,d", cmd::value<std::vector<std::string>>()->multitoken(),
|
||||||
|
"set search dirs")("mode,m", cmd::value<int>()->default_value(-1),
|
||||||
|
"设置执行模式,0-打包,1-安装");
|
||||||
|
|
||||||
void CPackBinaryCmd::defineOptions(Poco::Util::OptionSet& options)
|
cmd::variables_map vm;
|
||||||
{
|
cmd::store(cmd::parse_command_line(argc, argv, desc), vm);
|
||||||
ServerApplication::defineOptions(options);
|
cmd::notify(vm);
|
||||||
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")
|
if (vm.count("help")) {
|
||||||
.required(false)
|
std::cout << desc;
|
||||||
.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("purpose", "p", "purpose dir")
|
|
||||||
.required(false)
|
|
||||||
.repeatable(false)
|
|
||||||
.argument("purpose dir")
|
|
||||||
.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 == "purpose") {
|
|
||||||
result_.purpose_dir = 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, size = " << result_.lib_dirs.size() << std::endl;
|
|
||||||
|
|
||||||
for (const auto& item : result_.lib_dirs) {
|
|
||||||
std::cout << ">>" << item << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (result_.mode) {
|
|
||||||
case 0: {
|
|
||||||
Poco::File file(result_.binary);
|
|
||||||
if (!file.exists()) {
|
|
||||||
std::cout << "binary file not exist." << std::endl;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (vm.count("mode")) {
|
||||||
|
result_.mode = vm["mode"].as<int>();
|
||||||
|
}
|
||||||
|
if (vm.count("dir")) {
|
||||||
|
result_.lib_dirs = vm["dir"].as<std::vector<std::string>>();
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case 1: {
|
|
||||||
return true;
|
bool CCmdParse::checkArgs()
|
||||||
}
|
{
|
||||||
default:
|
|
||||||
std::cout << "不合法的mode内容。" << std::endl;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
40
cmd_parse.h
40
cmd_parse.h
@ -1,42 +1,18 @@
|
|||||||
#ifndef CMD_PARSE_HEADER
|
#ifndef CMD_PARSE_HEADER
|
||||||
#define 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"
|
#include "public.hpp"
|
||||||
|
#include <boost/program_options.hpp>
|
||||||
|
|
||||||
// Poco::Util::Validator* month = new Poco::Util::RegExpValidator(
|
namespace cmd = boost::program_options;
|
||||||
// "[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
|
class CCmdParse
|
||||||
// BY-SA
|
|
||||||
// 版权协议,转载请附上原文出处链接和本声明。
|
|
||||||
|
|
||||||
// 原文链接:https://blog.csdn.net/hwjcmozw/article/details/42963633
|
|
||||||
|
|
||||||
class CPackBinaryCmd : public Poco::Util::ServerApplication
|
|
||||||
{
|
{
|
||||||
protected:
|
public:
|
||||||
void initialize(Poco::Util::Application& self) override;
|
CCmdParse();
|
||||||
void uninitialize() override;
|
public:
|
||||||
void defineOptions(Poco::Util::OptionSet& options) override;
|
bool cmdParse(int argc, char* argv[]);
|
||||||
void handleHelp(const std::string& name, const std::string& value);
|
bool checkArgs();
|
||||||
void handleInput(const std::string& name, const std::string& value);
|
|
||||||
int main(const std::vector<std::string>& args) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool validCheck();
|
|
||||||
private:
|
private:
|
||||||
CmdResult result_;
|
CmdResult result_;
|
||||||
};
|
};
|
||||||
|
20
logic.cpp
20
logic.cpp
@ -1,20 +0,0 @@
|
|||||||
#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
15
logic.h
@ -1,15 +0,0 @@
|
|||||||
#ifndef LOGIC_HEADER
|
|
||||||
#define LOGIC_HEADER
|
|
||||||
|
|
||||||
#include "public.hpp"
|
|
||||||
|
|
||||||
class CMainLogic
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CMainLogic() = default;
|
|
||||||
~CMainLogic() = default;
|
|
||||||
public:
|
|
||||||
bool run(const CmdResult& result);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
10
main.cpp
10
main.cpp
@ -4,6 +4,12 @@
|
|||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
CPackBinaryCmd app;
|
CCmdParse parse;
|
||||||
return app.run(argc, argv);
|
if (!parse.cmdParse(argc, argv)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
10
pack.cpp
10
pack.cpp
@ -1,5 +1,6 @@
|
|||||||
#include "pack.h"
|
#include "pack.h"
|
||||||
#include <Poco/StringTokenizer.h>
|
#include <iostream>
|
||||||
|
#include <boost/algorithm/string.hpp>
|
||||||
|
|
||||||
bool CPackBinary::startPack(const CmdResult& result)
|
bool CPackBinary::startPack(const CmdResult& result)
|
||||||
{
|
{
|
||||||
@ -29,9 +30,10 @@ CPackBinary::getDepends(const std::string& path,
|
|||||||
}
|
}
|
||||||
fclose(pf);
|
fclose(pf);
|
||||||
|
|
||||||
Poco::StringTokenizer token(output, "\t");
|
std::vector<std::string> split;
|
||||||
for (const auto& item : token) {
|
boost::split(split, output, boost::is_any_of("\t"));
|
||||||
std::cout << item << std::endl;
|
for (const auto& item : split) {
|
||||||
|
std::cout << item << "\n";
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
1
pack.h
1
pack.h
@ -2,7 +2,6 @@
|
|||||||
#define PACK_HEADER
|
#define PACK_HEADER
|
||||||
|
|
||||||
#include "public.hpp"
|
#include "public.hpp"
|
||||||
#include <Poco/String.h>
|
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
class CPackBinary
|
class CPackBinary
|
||||||
|
@ -11,7 +11,8 @@ struct CmdResult {
|
|||||||
std::string category;
|
std::string category;
|
||||||
std::vector<std::string> lib_dirs;
|
std::vector<std::string> lib_dirs;
|
||||||
bool valid{false};
|
bool valid{false};
|
||||||
int mode{0};
|
int mode{-1};
|
||||||
|
bool help_{false};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
x
Reference in New Issue
Block a user