스타일 정리 및 컴파일 오류 제거

This commit is contained in:
2025-08-31 02:29:42 +09:00
parent f3974bb86f
commit e26d20a869
6 changed files with 97 additions and 89 deletions

View File

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

View File

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

View File

@@ -13,16 +13,14 @@ int main(int argc, char* argv[]) {
#ifdef WIN32 #ifdef WIN32
/*try { /*try {
auto ytdlp_pipe = utils::OpenPipe(ctx, auto ytdlp_pipe = utils::OpenPipe(ctx,
"yt-dlp.exe", { "-o", "-", "--quiet", "--ignore-errors", "-f", "bestaudio", "yt-dlp.exe", { "-o", "-", "--quiet", "--ignore-errors", "-f",
"https://youtu.be/9_bTl2vvYQg?si=IVhvpDhnpPvziwQR" }); "bestaudio", "https://youtu.be/9_bTl2vvYQg?si=IVhvpDhnpPvziwQR" });
while (true) { while (true) {
boost::system::error_code read_ec; boost::system::error_code read_ec;
size_t bytes_read = size_t bytes_read =
boost::asio::read(ytdlp_pipe, boost::asio::buffer(buf, 8192), boost::asio::read(ytdlp_pipe, boost::asio::buffer(buf,
read_ec); 8192), read_ec); if (bytes_read > 0) { std::cout.write(buf, bytes_read);
if (bytes_read > 0) {
std::cout.write(buf, bytes_read);
} }
if (read_ec == boost::asio::error::eof || read_ec) { if (read_ec == boost::asio::error::eof || read_ec) {
break; break;
@@ -35,14 +33,14 @@ int main(int argc, char* argv[]) {
}*/ }*/
#else #else
auto ytdlp_pipe = utils::OpenPipe( auto ytdlp_pipe = utils::OpenPipe(
"yt-dlp", { "-o", "-", "--quiet", "--ignore-errors", "-f", "bestaudio", ctx, "yt-dlp",
{"-o", "-", "--quiet", "--ignore-errors", "-f", "bestaudio",
"https://youtu.be/9_bTl2vvYQg?si=IVhvpDhnpPvziwQR"}); "https://youtu.be/9_bTl2vvYQg?si=IVhvpDhnpPvziwQR"});
while (true) { while (true) {
boost::system::error_code read_ec; boost::system::error_code read_ec;
size_t bytes_read = size_t bytes_read =
boost::asio::read(ytdlp_pipe, boost::asio::buffer(buf, 16384), boost::asio::read(ytdlp_pipe, boost::asio::buffer(buf, 8192), read_ec);
read_ec);
if (bytes_read > 0) { if (bytes_read > 0) {
std::cout.write(buf, bytes_read); std::cout.write(buf, bytes_read);
} }

View File

@@ -4,7 +4,8 @@
namespace utils { namespace utils {
int ValidateCommand(boost::asio::io_context& ctx, std::string cmd, const std::vector<std::string>& args) { int ValidateCommand(boost::asio::io_context& ctx, std::string cmd,
const std::vector<std::string>& args) {
try { try {
ExecuteCommand(ctx, cmd, args); ExecuteCommand(ctx, cmd, args);
} catch (const boost::process::system_error& e) { } catch (const boost::process::system_error& e) {
@@ -19,13 +20,14 @@ int ExecuteCommand(boost::asio::io_context& ctx, const std::string& cmd,
return ExecuteCommand(ctx, cmd, args, ignored); return ExecuteCommand(ctx, cmd, args, ignored);
} }
int ExecuteCommand(boost::asio::io_context& ctx, 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; std::vector<std::string> ignored;
return ExecuteCommand(ctx, cmd, ignored, result); return ExecuteCommand(ctx, cmd, ignored, result);
} }
int ExecuteCommand(boost::asio::io_context& ctx, const std::string& cmd, const std::vector<std::string>& args, int ExecuteCommand(boost::asio::io_context& ctx, const std::string& cmd,
std::string& result) { const std::vector<std::string>& args, std::string& result) {
try { try {
boost::system::error_code ec; boost::system::error_code ec;
boost::process::popen proc( boost::process::popen proc(
@@ -36,13 +38,13 @@ int ExecuteCommand(boost::asio::io_context& ctx, const std::string& cmd, const s
proc.wait(); proc.wait();
return proc.exit_code(); return proc.exit_code();
} } catch (const boost::process::system_error& e) {
catch (const boost::process::system_error& e) {
return -1; return -1;
} }
} }
boost::process::popen OpenPipe(boost::asio::io_context& ctx, const std::string& cmd, boost::process::popen OpenPipe(boost::asio::io_context& ctx,
const std::string& cmd,
const std::vector<std::string>& args) { const std::vector<std::string>& args) {
return boost::process::popen( return boost::process::popen(
ctx, cmd, args, boost::process::process_stdio{nullptr, nullptr, nullptr}); ctx, cmd, args, boost::process::process_stdio{nullptr, nullptr, nullptr});

View File

@@ -57,7 +57,8 @@ void DownloadFileFromHTTPS(std::string url, std::string filename) {
boost::beast::flat_buffer buffer; boost::beast::flat_buffer buffer;
// 응답 파서 만들기 // 응답 파서 만들기
boost::beast::http::response_parser<boost::beast::http::dynamic_body> parser; boost::beast::http::response_parser<boost::beast::http::dynamic_body>
parser;
// body 제한 해제 (무제한) // body 제한 해제 (무제한)
parser.body_limit((std::numeric_limits<std::uint64_t>::max)()); parser.body_limit((std::numeric_limits<std::uint64_t>::max)());

View File

@@ -6,7 +6,7 @@
namespace utils { namespace utils {
int InstallYtdlp() { int InstallYtdlp(boost::asio::io_context& ctx) {
BOOST_LOG_TRIVIAL(warning) << "ytdlp is unavailable. downloading ytdlp..."; BOOST_LOG_TRIVIAL(warning) << "ytdlp is unavailable. downloading ytdlp...";
#ifdef WIN32 #ifdef WIN32
DownloadFileFromHTTPS( DownloadFileFromHTTPS(
@@ -16,7 +16,8 @@ int InstallYtdlp() {
DownloadFileFromHTTPS( DownloadFileFromHTTPS(
"https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp", "https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp",
"yt-dlp"); "yt-dlp");
ExecuteCommand(boost::process::environment::find_executable("chmod").c_str(), ExecuteCommand(ctx,
boost::process::environment::find_executable("chmod").string(),
{"+x", "yt-dlp"}); {"+x", "yt-dlp"});
#endif #endif
return 0; return 0;
@@ -39,19 +40,22 @@ int CheckUpdate(boost::asio::io_context& ctx) {
int newline_pos = 0; int newline_pos = 0;
#ifdef WIN32 #ifdef WIN32
if (ExecuteCommand(ctx, "yt-dlp.exe", { "--version", "--newline" }, output) != 0) { if (ExecuteCommand(ctx, "yt-dlp.exe", {"--version", "--newline"}, output) !=
InstallYtdlp(); 0) {
InstallYtdlp(ctx);
ExecuteCommand(ctx, "yt-dlp.exe", {"--version", "--newline"}, output); ExecuteCommand(ctx, "yt-dlp.exe", {"--version", "--newline"}, output);
} }
BOOST_LOG_TRIVIAL(info) << "yt-dlp version: " << output.substr(0, output.size()-1); BOOST_LOG_TRIVIAL(info) << "yt-dlp version: "
<< output.substr(0, output.size() - 1);
output = ""; output = "";
ExecuteCommand(ctx, "yt-dlp.exe", {"-U", "--newline"}, output); ExecuteCommand(ctx, "yt-dlp.exe", {"-U", "--newline"}, output);
#else #else
if (ExecuteCommand(ctx, "yt-dlp", {"--version", "--newline"}, output) != 0) { if (ExecuteCommand(ctx, "yt-dlp", {"--version", "--newline"}, output) != 0) {
InstallYtdlp(); InstallYtdlp(ctx);
ExecuteCommand(ctx, "yt-dlp", {"--version", "--newline"}, output); ExecuteCommand(ctx, "yt-dlp", {"--version", "--newline"}, output);
} }
BOOST_LOG_TRIVIAL(info) << "yt-dlp version: " << output.substr(0, output.size()-1); BOOST_LOG_TRIVIAL(info) << "yt-dlp version: "
<< output.substr(0, output.size() - 1);
output = ""; output = "";
ExecuteCommand(ctx, "yt-dlp", {"-U", "--newline"}, output); ExecuteCommand(ctx, "yt-dlp", {"-U", "--newline"}, output);
#endif #endif