700cef9963
обработка ~/ в аргументе пути. ОБЯЗАТЕЛЬНО указывать в пути в конце /
123 lines
3.3 KiB
C
123 lines
3.3 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "libs/argparse.h"
|
|
#include "curl/curl.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;
|
|
}
|
|
|
|
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];
|
|
|
|
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, NULL, 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);
|
|
|
|
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="~/"
|
|
*/ |