Files
zenith-cli/main.cpp
T

118 lines
2.8 KiB
C++
Raw Normal View History

#include <iostream>
#include <string>
#include <filesystem>
#include <cstdlib>
2026-09-02 15:28:15 +06:00
2026-09-03 21:00:32 +06:00
#include "curl/curl.h"
2026-09-02 15:28:15 +06:00
extern "C" {
#include "libs/argparse.h"
}
namespace fs = std::filesystem;
2026-09-02 15:28:15 +06:00
struct Scheme{
char fg_color[8];
char sub_fg_color[8];
char bg_color[8];
char sub_bg_color[8];
char accent[8];
char sub_accent[8];
};
void write_pallete(const struct Scheme *s){
2026-09-03 21:00:32 +06:00
//s->bg_color
2026-09-02 15:28:15 +06:00
}
2026-09-03 21:50:18 +06:00
int download_wall(const char* link, const char* path){
CURL* curl;
FILE* fp;
2026-09-03 21:00:32 +06:00
CURLcode res;
2026-09-02 15:28:15 +06:00
2026-09-03 21:00:32 +06:00
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl) {
2026-09-03 21:50:18 +06:00
fp = fopen(path, "wb");
2026-09-03 21:00:32 +06:00
if(fp == NULL) {
2026-09-03 21:50:18 +06:00
fprintf(stderr, \
"ошибка: не удалось создать или открыть файл %s\n", path);
2026-09-03 21:00:32 +06:00
curl_easy_cleanup(curl);
curl_global_cleanup();
return 1;
}
curl_easy_setopt(curl, CURLOPT_URL, link);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
res = curl_easy_perform(curl);
if(res != CURLE_OK) {
2026-09-03 21:50:18 +06:00
fprintf(stderr, "ошибка скачивания: %s\n", \
curl_easy_strerror(res));
2026-09-03 21:00:32 +06:00
}
fclose(fp);
curl_easy_cleanup(curl);
}
curl_global_cleanup();
return 0;
}
int main(int argc, const char **argv) {
2026-09-03 21:50:18 +06:00
const char* link = nullptr;
const char* raw_scheme_path = nullptr;
const char* raw_wall_path = nullptr;
2026-09-03 21:50:18 +06:00
int is_pastel = 0;
2026-09-03 21:00:32 +06:00
struct argparse_option options[] = {
OPT_HELP(),
2026-09-03 21:50:18 +06:00
OPT_STRING(0,"link", &link, \
"ссылка на изображение с сайта wallhave.cc", NULL, 0, 0),
OPT_BOOLEAN('p', "pastel", &is_pastel, \
"создать пастельные палитры", NULL, 0, 0),
OPT_STRING(0,"scheme-output", &raw_scheme_path,\
"директория для сохранения палитр", NULL, 0, 0),
OPT_STRING(0,"wall-output", &raw_wall_path, \
"директория для сохранения обоев", NULL, 0, 0),
2026-09-03 21:00:32 +06:00
OPT_END(),
};
struct argparse argparse;
argparse_init(&argparse, options, nullptr, 0);
2026-09-03 21:00:32 +06:00
argc = argparse_parse(&argparse, argc, argv);
fs::path target_dir;
if (raw_wall_path == nullptr || std::string(raw_wall_path).empty()){
target_dir = fs::current_path();
2026-09-03 21:50:18 +06:00
}
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);
2026-09-03 21:50:18 +06:00
}
std::string full_path_str(target_dir / "wallpaper.jpg");
const char* full_path = full_path_str.c_str();
download_wall(link, full_path);
2026-09-03 21:00:32 +06:00
return 0;
}