쓸데없는 공유 라이브러리 제거 및 콘솔 실행 커맨드 안정화

This commit is contained in:
2025-08-31 02:22:36 +09:00
parent f846dd7195
commit f3974bb86f
7 changed files with 125 additions and 98 deletions

View File

@@ -14,11 +14,11 @@ if(WIN32)
set(OPENSSL_INCLUDE_DIR "${OPENSSL_ROOT_DIR}/include")
if(CMAKE_BUILD_TYPE STREQUAL Debug)
set(OPENSSL_CRYPTO_LIBRARY "${OPENSSL_ROOT_DIR}/lib/VC/x64/MDd/libcrypto.lib")
set(OPENSSL_SSL_LIBRARY "${OPENSSL_ROOT_DIR}/lib/VC/x64/MDd/libssl.lib")
set(OPENSSL_CRYPTO_LIBRARY "${OPENSSL_ROOT_DIR}/lib/VC/x64/MTd/libcrypto.lib")
set(OPENSSL_SSL_LIBRARY "${OPENSSL_ROOT_DIR}/lib/VC/x64/MTd/libssl.lib")
else()
set(OPENSSL_CRYPTO_LIBRARY "${OPENSSL_ROOT_DIR}/lib/VC/x64/MD/libcrypto.lib")
set(OPENSSL_SSL_LIBRARY "${OPENSSL_ROOT_DIR}/lib/VC/x64/MD/libssl.lib")
set(OPENSSL_CRYPTO_LIBRARY "${OPENSSL_ROOT_DIR}/lib/VC/x64/MT/libcrypto.lib")
set(OPENSSL_SSL_LIBRARY "${OPENSSL_ROOT_DIR}/lib/VC/x64/MT/libssl.lib")
endif()
endif()
@@ -31,8 +31,8 @@ FetchContent_Declare(
URL "https://github.com/boostorg/boost/releases/download/boost-1.89.0/boost-1.89.0-cmake.7z"
DOWNLOAD_EXTRACT_TIMESTAMP ON
CMAKE_ARGS
-DBOOST_USE_STATIC_LIBS=OFF # DLL 사용
-DBOOST_USE_STATIC_RUNTIME=OFF # /MD, /MDd 사용
-DBOOST_USE_STATIC_LIBS=ON
-DBOOST_USE_STATIC_RUNTIME=ON
)
message(STATUS "Fetching and making available Boost...")
FetchContent_MakeAvailable(Boost)
@@ -52,13 +52,11 @@ FetchContent_MakeAvailable(dpp)
# -------------------------------------------------------------
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
set(FFMPEG_URL "https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-lgpl-shared.zip")
set(FFMPEG_SHA256HASH "SHA256=c95a9d4e030f694f33c85a7611204383a0bca906514a08d83d3858496b122f76")
set(FFMPEG_ARCHIVE_NAME "ffmpeg-windows")
set(FFMPEG_LIB_DIR "lib")
set(FFMPEG_INCLUDE_DIR "include")
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
set(FFMPEG_URL "https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-linux64-lgpl-shared.tar.xz")
set(FFMPEG_SHA256HASH "SHA256=ebf6b197ffe52d798504895b4c2b84114ad5d2b406ac76e18374b44d1184ade3")
set(FFMPEG_ARCHIVE_NAME "ffmpeg-linux")
set(FFMPEG_LIB_DIR "lib")
set(FFMPEG_INCLUDE_DIR "include")
@@ -69,7 +67,6 @@ endif()
FetchContent_Declare(
ffmpeg
URL ${FFMPEG_URL}
URL_HASH ${FFMPEG_SHA256HASH}
DOWNLOAD_EXTRACT_TIMESTAMP ON
SOURCE_DIR ${CMAKE_BINARY_DIR}/${FFMPEG_ARCHIVE_NAME}
)
@@ -136,20 +133,6 @@ target_include_directories(${BOT_NAME} PRIVATE ${FFMPEG_INCLUDE_PATH})
target_precompile_headers(${BOT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include/precomp.h")
add_custom_command(TARGET ${BOT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"$<TARGET_FILE_DIR:Boost::filesystem>"
"$<TARGET_FILE_DIR:${BOT_NAME}>"
COMMENT "Copying Boost.Filesystem DLL/so files to output directory"
)
add_custom_command(TARGET ${BOT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"$<TARGET_FILE_DIR:Boost::process>"
"$<TARGET_FILE_DIR:${BOT_NAME}>"
COMMENT "Copying Boost.Process DLL/so files to output directory"
)
add_custom_command(TARGET ${BOT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CMAKE_BINARY_DIR}/${FFMPEG_ARCHIVE_NAME}/bin"

View File

@@ -7,31 +7,31 @@ namespace utils {
// @brief 명령어가 실행 가능한지 체크합니다
// @param cmd 실행할 명령
// @return int error_code
int ValidateCommand(std::string cmd);
int ValidateCommand(boost::asio::io_context& ctx, std::string cmd, const std::vector<std::string>& args = std::vector<std::string>());
// @brief 명령어를 쉘에서 실행하고 결과를 EOF 전까지 읽어 반환합니다
// @param cmd 실행할 명령
// @param args 아규먼트
// @return int error_code
int ExecuteCommand(
int ExecuteCommand(boost::asio::io_context& ctx,
const std::string& cmd,
const std::vector<std::string>& args = std::vector<std::string>());
// @brief 명령어를 쉘에서 실행하고 결과를 EOF 전까지 읽어 반환합니다
// @param cmd 실행할 명령
// @param result 실행결과
// @return int error_code
int ExecuteCommand(const std::string& cmd, std::string& result);
int ExecuteCommand(boost::asio::io_context& ctx, const std::string& cmd, std::string& result);
// @brief 명령어를 쉘에서 실행하고 결과를 EOF 전까지 읽어 반환합니다
// @param cmd 실행할 명령
// @param args 아규먼트
// @param result 실행결과
// @return int error_code
int ExecuteCommand(const std::string& cmd, const std::vector<std::string>& args,
int ExecuteCommand(boost::asio::io_context& ctx, const std::string& cmd, const std::vector<std::string>& args,
std::string& result);
// @brief 명령어를 쉘에서 실행하고 결과를 파이프로 연결하여 반환합니다
// @param cmd 실행할 명령
// @param args 아규먼트
// @return boost::process::popen
boost::process::popen OpenPipe(
boost::process::popen OpenPipe(boost::asio::io_context& ctx,
const std::string& cmd,
const std::vector<std::string>& args = std::vector<std::string>());
} // namespace utils

View File

@@ -7,7 +7,7 @@ namespace utils {
int InstallYtdlp();
int CheckUpdate();
int CheckUpdate(boost::asio::io_context& ctx);
} // namespace utils

View File

@@ -3,33 +3,54 @@
#include "utils/update_checker.h"
int main(int argc, char* argv[]) {
boost::asio::io_context ctx;
boost::system::error_code ec;
char buf[16384];
char buf[8192];
std::string output;
utils::CheckUpdate();
utils::CheckUpdate(ctx);
// utils::ExecuteCommand("yt-dlp", {"-U"}, output);
// std::cout << output;
#ifdef WIN32
/*try {
auto ytdlp_pipe = utils::OpenPipe(ctx,
"yt-dlp.exe", { "-o", "-", "--quiet", "--ignore-errors", "-f", "bestaudio",
"https://youtu.be/9_bTl2vvYQg?si=IVhvpDhnpPvziwQR" });
// auto ytdlp_pipe = utils::OpenPipe(
// "yt-dlp", {"-o", "-", "--quiet", "--ignore-errors", "-f", "bestaudio",
// "https://youtu.be/9_bTl2vvYQg?si=IVhvpDhnpPvziwQR"});
while (true) {
boost::system::error_code read_ec;
size_t bytes_read =
boost::asio::read(ytdlp_pipe, boost::asio::buffer(buf, 8192),
read_ec);
if (bytes_read > 0) {
std::cout.write(buf, bytes_read);
}
if (read_ec == boost::asio::error::eof || read_ec) {
break;
}
}
}
catch (const boost::process::system_error& e) {
std::string error = e.what();
return -1;
}*/
#else
auto ytdlp_pipe = utils::OpenPipe(
"yt-dlp", { "-o", "-", "--quiet", "--ignore-errors", "-f", "bestaudio",
"https://youtu.be/9_bTl2vvYQg?si=IVhvpDhnpPvziwQR" });
// while (true) {
// boost::system::error_code read_ec;
// size_t bytes_read =
// boost::asio::read(ytdlp_pipe, boost::asio::buffer(buf, 16384),
// read_ec);
// if (bytes_read > 0) {
// std::cout.write(buf, bytes_read);
// }
// if (read_ec == boost::asio::error::eof || read_ec) {
// break;
// }
// }
while (true) {
boost::system::error_code read_ec;
size_t bytes_read =
boost::asio::read(ytdlp_pipe, boost::asio::buffer(buf, 16384),
read_ec);
if (bytes_read > 0) {
std::cout.write(buf, bytes_read);
}
if (read_ec == boost::asio::error::eof || read_ec) {
break;
}
}
#endif
return 0;
}

View File

@@ -4,50 +4,48 @@
namespace utils {
int ValidateCommand(std::string cmd) {
int ValidateCommand(boost::asio::io_context& ctx, std::string cmd, const std::vector<std::string>& args) {
try {
ExecuteCommand(cmd);
ExecuteCommand(ctx, cmd, args);
} catch (const boost::process::system_error& e) {
return -1;
}
return 0;
}
int ExecuteCommand(const std::string& cmd,
int ExecuteCommand(boost::asio::io_context& ctx, const std::string& cmd,
const std::vector<std::string>& args) {
std::string ignored;
return ExecuteCommand(cmd, args, ignored);
return ExecuteCommand(ctx, cmd, args, ignored);
}
int ExecuteCommand(const std::string& cmd, std::string& result) {
int ExecuteCommand(boost::asio::io_context& ctx, const std::string& cmd, std::string& result) {
std::vector<std::string> ignored;
return ExecuteCommand(cmd, ignored, result);
return ExecuteCommand(ctx, cmd, ignored, result);
}
int ExecuteCommand(const std::string& cmd, const std::vector<std::string>& args,
int ExecuteCommand(boost::asio::io_context& ctx, const std::string& cmd, const std::vector<std::string>& args,
std::string& result) {
try {
boost::system::error_code ec;
boost::asio::io_context ctx;
boost::process::popen proc(
ctx, cmd, args, boost::process::process_stdio{ {}, nullptr, nullptr });
boost::asio::read(proc, boost::asio::dynamic_buffer(result), ec);
if (ec != boost::asio::error::eof) {
return -1;
}
proc.wait();
return proc.exit_code();
}
catch (const boost::process::system_error& e) {
return -1;
}
}
boost::process::popen OpenPipe(const std::string& cmd,
boost::process::popen OpenPipe(boost::asio::io_context& ctx, const std::string& cmd,
const std::vector<std::string>& args) {
boost::asio::io_context ctx;
boost::process::popen proc(
ctx, cmd, args, boost::process::process_stdio{{}, nullptr, nullptr});
return proc;
return boost::process::popen(
ctx, cmd, args, boost::process::process_stdio{nullptr, nullptr, nullptr});
};
} // namespace utils

View File

@@ -55,8 +55,17 @@ void DownloadFileFromHTTPS(std::string url, std::string filename) {
boost::beast::http::write(stream, req);
boost::beast::flat_buffer buffer;
boost::beast::http::response<boost::beast::http::dynamic_body> res;
boost::beast::http::read(stream, buffer, res);
// 응답 파서 만들기
boost::beast::http::response_parser<boost::beast::http::dynamic_body> parser;
// body 제한 해제 (무제한)
parser.body_limit((std::numeric_limits<std::uint64_t>::max)());
// 응답 읽기
boost::beast::http::read(stream, buffer, parser);
auto res = parser.release();
int status = res.result_int();
if (status / 100 == 3) {

View File

@@ -22,28 +22,44 @@ int InstallYtdlp() {
return 0;
}
int CheckUpdate() {
char buf[16384];
static int FindNewLinePos(std::string& string, int start_pos) {
int newline_pos = start_pos;
while (newline_pos < string.size()) {
if (string[newline_pos] == '\n') {
return newline_pos;
}
newline_pos++;
}
return newline_pos;
}
if (ValidateCommand("yt-dlp") != 0) {
int CheckUpdate(boost::asio::io_context& ctx) {
std::string output = "";
int old_newline_pos = 0;
int newline_pos = 0;
#ifdef WIN32
if (ExecuteCommand(ctx, "yt-dlp.exe", { "--version", "--newline" }, output) != 0) {
InstallYtdlp();
return 0;
ExecuteCommand(ctx, "yt-dlp.exe", { "--version", "--newline" }, output);
}
auto ytdlp_pipe = utils::OpenPipe("yt-dlp", {"-U"});
while (true) {
boost::system::error_code read_ec;
size_t bytes_read =
boost::asio::read(ytdlp_pipe, boost::asio::buffer(buf, 16384), read_ec);
if (bytes_read > 0) {
BOOST_LOG_TRIVIAL(info) << buf;
}
if (read_ec == boost::asio::error::eof || read_ec) {
break;
BOOST_LOG_TRIVIAL(info) << "yt-dlp version: " << output.substr(0, output.size()-1);
output = "";
ExecuteCommand(ctx, "yt-dlp.exe", { "-U", "--newline" }, output);
#else
if (ExecuteCommand(ctx, "yt-dlp", { "--version", "--newline" }, output) != 0) {
InstallYtdlp();
ExecuteCommand(ctx, "yt-dlp", { "--version", "--newline" }, output);
}
BOOST_LOG_TRIVIAL(info) << "yt-dlp version: " << output.substr(0, output.size()-1);
output = "";
ExecuteCommand(ctx, "yt-dlp", { "-U", "--newline" }, output);
#endif
while (newline_pos < output.size()) {
old_newline_pos = newline_pos;
newline_pos = FindNewLinePos(output, newline_pos);
BOOST_LOG_TRIVIAL(info) << output.substr(old_newline_pos, newline_pos - 1);
newline_pos++;
}
return 0;