diff --git a/.gitignore b/.gitignore index cd531cf..7729ef9 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,5 @@ Module.symvers Mkfile.old dkms.conf +zenith-cli +*.jpg \ No newline at end of file diff --git a/main.c b/main.c index 0fe5a31..e52a232 100644 --- a/main.c +++ b/main.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "libs/argparse.h" #include "curl/curl.h" @@ -20,21 +21,20 @@ void write_pallete(const struct Scheme *s){ //s->bg_color } -int download_wall(const char *link){ - CURL *curl; - FILE *fp; +int download_wall(const char* link, const char* path){ + CURL* curl; + FILE* fp; CURLcode res; - const char *outfilename = "wallpaper.jpg"; - curl_global_init(CURL_GLOBAL_ALL); curl = curl_easy_init(); if(curl) { - fp = fopen(outfilename, "wb"); + fp = fopen(path, "wb"); if(fp == NULL) { - fprintf(stderr, "ошибка: не удалось создать или открыть файл %s\n", outfilename); + fprintf(stderr, \ + "ошибка: не удалось создать или открыть файл %s\n", path); curl_easy_cleanup(curl); curl_global_cleanup(); @@ -49,7 +49,8 @@ int download_wall(const char *link){ res = curl_easy_perform(curl); if(res != CURLE_OK) { - fprintf(stderr, "ошибка скачивания: %s\n", curl_easy_strerror(res)); + fprintf(stderr, "ошибка скачивания: %s\n", \ + curl_easy_strerror(res)); } fclose(fp); @@ -64,16 +65,27 @@ int download_wall(const char *link){ int main(int argc, const char **argv) { const char* link = NULL; - const char* scheme_output = NULL; - const char* wall_output = NULL; - int is_pastel = 0; + 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", &scheme_output, "директория для сохранения палитр", NULL, 0, 0), - OPT_STRING(0,"wall-output", &wall_output, "директория для сохранения обоев", NULL, 0, 0), + 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(), }; @@ -81,12 +93,31 @@ int main(int argc, const char **argv) { argparse_init(&argparse, options, NULL, 0); argc = argparse_parse(&argparse, argc, argv); - download_wall(link); + 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="~/" */ \ No newline at end of file diff --git a/zenith-cli b/zenith-cli deleted file mode 100755 index cdf9365..0000000 Binary files a/zenith-cli and /dev/null differ