From dcbe6dd4684a2e9dca18e13e2577c49210aaa68b Mon Sep 17 00:00:00 2001 From: s13bby Date: Fri, 4 Sep 2026 01:42:41 +0600 Subject: [PATCH] =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=BE:=20=D0=BF=D0=B5=D1=80=D0=B5=D1=88=D0=B5=D0=BB=20=D0=BD?= =?UTF-8?q?=D0=B0=20=D1=81++.=20=D1=82=D0=BA=20=D0=BF=D1=80=D0=BE=D1=89?= =?UTF-8?q?=D0=B5=20=D0=B1=D1=83=D0=B4=D0=B5=D1=82=20=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=B0=D1=82=D1=8C=20=D1=81=20=D1=84=D0=BE=D1=82?= =?UTF-8?q?=D0=BE.=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB=20=D1=81?= =?UTF-8?q?=D0=BA=D1=80=D0=B8=D0=BF=D1=82=20=D1=81=D0=B1=D0=BE=D1=80=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=BF=D0=BE=D0=B4=20c++?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.sh | 2 +- main.c => main.cpp | 58 +++++++++++++++++++++++++++------------------- 2 files changed, 35 insertions(+), 25 deletions(-) rename main.c => main.cpp (75%) diff --git a/build.sh b/build.sh index a1d0027..25725cb 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,6 @@ #!/bin/bash echo "начинаю сборку" -gcc main.c libs/argparse.c -o zenith-cli -lcurl +g++ main.cpp libs/argparse.c -o zenith-cli -lcurl echo "сборкa завершена" \ No newline at end of file diff --git a/main.c b/main.cpp similarity index 75% rename from main.c rename to main.cpp index e52a232..116dfd2 100644 --- a/main.c +++ b/main.cpp @@ -1,11 +1,14 @@ -#include -#include -#include -#include +#include +#include +#include +#include -#include "libs/argparse.h" #include "curl/curl.h" +extern "C" { + #include "libs/argparse.h" +} + struct Scheme{ char fg_color[8]; char sub_fg_color[8]; @@ -63,16 +66,13 @@ int download_wall(const char* link, const char* path){ return 0; } +namespace fs = std::filesystem; + int main(int argc, const char **argv) { - const char* link = NULL; - const char* user_home = getenv("HOME"); - const char* filename = "wallpaper.jpg"; - char* raw_scheme_path = NULL; - char* raw_wall_path = NULL; - - char wall_output[512]; - char path[512]; + const char* link = nullptr; + const char* raw_scheme_path = nullptr; + const char* raw_wall_path = nullptr; int is_pastel = 0; @@ -90,20 +90,30 @@ int main(int argc, const char **argv) { }; struct argparse argparse; - argparse_init(&argparse, options, NULL, 0); + argparse_init(&argparse, options, nullptr, 0); argc = argparse_parse(&argparse, argc, argv); - if (raw_wall_path == NULL){ - wall_output[0] = '.'; - wall_output[1] = '/'; - } - else if (raw_wall_path[0] == '~'){ - snprintf(wall_output, sizeof(wall_output), \ - "%s%s", user_home, raw_wall_path + 1); - } - snprintf(path, sizeof(path), "%s%s", wall_output, filename); + fs::path target_dir; - download_wall(link, path); + if (raw_wall_path == nullptr || std::string(raw_wall_path).empty()){ + target_dir = fs::current_path(); + } + else{ + std::string path_str(raw_wall_path); + if (path_str[0] == '~'){ + const char* user_home = std::getenv("HOME"); + if (user_home){ + path_str.replace(0, 1, user_home); + } + } + target_dir = fs::path(path_str); + } + + fs::path full_path = target_dir / "wallpaper.jpg"; + + std::cout << full_path << std::endl; + + // download_wall(link, path); return 0; }