изменено: перешел на с++. тк проще будет работать с фото. изменил скрипт сборки под c++
This commit is contained in:
@@ -0,0 +1,133 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "curl/curl.h"
|
||||
|
||||
extern "C" {
|
||||
#include "libs/argparse.h"
|
||||
}
|
||||
|
||||
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){
|
||||
//s->bg_color
|
||||
}
|
||||
|
||||
int download_wall(const char* link, const char* path){
|
||||
CURL* curl;
|
||||
FILE* fp;
|
||||
CURLcode res;
|
||||
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
curl = curl_easy_init();
|
||||
|
||||
if(curl) {
|
||||
fp = fopen(path, "wb");
|
||||
|
||||
if(fp == NULL) {
|
||||
fprintf(stderr, \
|
||||
"ошибка: не удалось создать или открыть файл %s\n", path);
|
||||
|
||||
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) {
|
||||
fprintf(stderr, "ошибка скачивания: %s\n", \
|
||||
curl_easy_strerror(res));
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
int main(int argc, const char **argv) {
|
||||
|
||||
const char* link = nullptr;
|
||||
const char* raw_scheme_path = nullptr;
|
||||
const char* raw_wall_path = nullptr;
|
||||
|
||||
int is_pastel = 0;
|
||||
|
||||
struct argparse_option options[] = {
|
||||
OPT_HELP(),
|
||||
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),
|
||||
OPT_END(),
|
||||
};
|
||||
|
||||
struct argparse argparse;
|
||||
argparse_init(&argparse, options, nullptr, 0);
|
||||
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();
|
||||
}
|
||||
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;
|
||||
}
|
||||
/*
|
||||
|
||||
аргументы
|
||||
zenith-cli --link="link" -p/--pastel --scheme-output="path" --wall-output="path"
|
||||
|
||||
примеры использования
|
||||
|
||||
если передать пустую строку, то файл сохранится в директории утилиты
|
||||
./zenith-cli --link="https://w.wallhaven.cc/full/gw/wallhaven-gwd313.jpg" --wall-output=""
|
||||
|
||||
ОБЯЗАТЕЛЬНО указывать в пути в конце /. потом мб добавлю проверку и автодополнение
|
||||
./zenith-cli --link="https://w.wallhaven.cc/full/gw/wallhaven-gwd313.jpg" --wall-output="/home/ivan/"
|
||||
./zenith-cli --link="https://w.wallhaven.cc/full/gw/wallhaven-gwd313.jpg" --wall-output="~/"
|
||||
*/
|
||||
Reference in New Issue
Block a user