From 6fa41b5fdec27c25b8a3126a3291a87a80d264c5 Mon Sep 17 00:00:00 2001 From: Matteo Paonessa Date: Sun, 6 Nov 2022 16:20:00 +0100 Subject: [PATCH] Windows build fix + libcaesium 0.9.3 --- .gitignore | 11 +++++++++++ CMakeLists.txt | 4 ++-- README.md | 6 ++++-- src/error.c | 8 ++++---- src/error.h | 4 ++-- src/helper.c | 40 ++++++++++++++++++---------------------- src/helper.h | 9 ++++++++- src/main.c | 1 + src/utils.c | 7 ++++--- 9 files changed, 54 insertions(+), 36 deletions(-) diff --git a/.gitignore b/.gitignore index 20a92cb..2e0414c 100644 --- a/.gitignore +++ b/.gitignore @@ -171,4 +171,15 @@ Module.symvers Mkfile.old dkms.conf +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps build \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 41079a8..ccd0de0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,9 @@ -cmake_minimum_required(VERSION 2.8.11) +cmake_minimum_required(VERSION 3.16) project(caesiumclt) # The version number. set(VERSION_MAJOR 0) -set(VERSION_MINOR 17) +set(VERSION_MINOR 18) set(VERSION_PATCH 0) configure_file( diff --git a/README.md b/README.md index 8db5a30..8d2528b 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ ## Caesium CommandLineTools -###### caesium-clt - v0.17.0-beta (build 20221001) +###### caesium-clt - v0.18.0-beta (build 20221001) ###### REQUIREMENTS -* [libcaesium](https://github.com/Lymphatus/libcaesium) >= 0.9.2 +* [libcaesium](https://github.com/Lymphatus/libcaesium) >= 0.9.3 ###### Included libraries * [optparse](https://github.com/skeeto/optparse) @@ -81,6 +81,8 @@ $ caesiumclt -q 0 -RS -o ~/output/ ~/Pictures ---------- ###### CHANGELOG +* 0.18.0-beta - Fixed Windows build + libcaesium 0.9.3 +* 0.17.0-beta - libcaesium 0.9.2 * 0.16.0-beta - Using libcaesium Rust library * 0.15.2-beta - Fixed Windows -RS bug * 0.15.1-beta - Fixed rename bug on Windows + "Compressing..." message diff --git a/src/error.c b/src/error.c index 25e8e3f..8508a23 100644 --- a/src/error.c +++ b/src/error.c @@ -25,12 +25,12 @@ void display_error(error_level level, int code) { char *error_level = ((level) ? "[WARNING]" : "[ERROR]"); - print_to_console(stderr, verbose, "%s %d: %s\n", + print_to_console(stderr, verbose, "%s %s (code: %d)\n", error_level, - code, - get_error_message(code)); + get_error_message(code), + code); - if (level == ERROR) { + if (level == CS_ERROR) { exit(-code); } } diff --git a/src/error.h b/src/error.h index 4a85c11..a058f19 100644 --- a/src/error.h +++ b/src/error.h @@ -20,8 +20,8 @@ typedef enum error_level { - ERROR = 0, - WARNING = 1 + CS_ERROR = 0, + CS_WARNING = 1 } error_level; void display_error(error_level level, int code); diff --git a/src/helper.c b/src/helper.c index 24155e2..4542f40 100644 --- a/src/helper.c +++ b/src/helper.c @@ -19,11 +19,6 @@ #include #include #include - -#ifdef _WIN32 -#include -#endif - #include "helper.h" #include "vendor/optparse.h" #include "utils.h" @@ -59,7 +54,7 @@ cclt_options parse_arguments(char **argv, C_CSParameters *options) { case 'q': quality = (int) strtol(opts.optarg, (char **) NULL, 10); if (quality < 0 || quality > 100) { - display_error(ERROR, 1); + display_error(CS_ERROR, 1); } if (quality == 0) { options->optimize = true; @@ -78,7 +73,7 @@ cclt_options parse_arguments(char **argv, C_CSParameters *options) { snprintf(parameters.output_folder, strlen(opts.optarg) + 1, "%s", opts.optarg); } else { #ifdef _WIN32 - _fullpath(parameters.output_folder, opts.optarg, MAX_PATH); + _fullpath(parameters.output_folder, opts.optarg, MAX_PATH_SIZE); #else char *computedPath = realpath(opts.optarg, parameters.output_folder); if (computedPath == NULL) { @@ -88,13 +83,13 @@ cclt_options parse_arguments(char **argv, C_CSParameters *options) { computedPath = realpath(opts.optarg, parameters.output_folder); if (computedPath == NULL) { //Just throw an error here - display_error(ERROR, 16); + display_error(CS_ERROR, 16); } } else { - display_error(ERROR, 17); + display_error(CS_ERROR, 17); } } else { - display_error(ERROR, 16); + display_error(CS_ERROR, 16); } } #endif @@ -134,7 +129,7 @@ cclt_options parse_arguments(char **argv, C_CSParameters *options) { case '?': default: print_to_console(stderr, verbose, "%s: %s\n", argv[0], opts.errmsg); - display_error(ERROR, 2); + display_error(CS_ERROR, 2); } } //Remaining arguments @@ -146,7 +141,7 @@ cclt_options parse_arguments(char **argv, C_CSParameters *options) { while ((arg = optparse_arg(&opts))) { if (folders_flag) { - display_error(WARNING, 8); + display_error(CS_WARNING, 8); break; } @@ -163,7 +158,7 @@ cclt_options parse_arguments(char **argv, C_CSParameters *options) { } } else { #ifdef _WIN32 - _fullpath(resolved_path, arg, MAX_PATH); + _fullpath(resolved_path, arg, MAX_PATH_SIZE); #else realpath(arg, resolved_path); #endif @@ -185,10 +180,10 @@ cclt_options parse_arguments(char **argv, C_CSParameters *options) { snprintf(parameters.input_folder, strlen(resolved_path) + 1, "%s", resolved_path); scan_folder(resolved_path, ¶meters, parameters.recursive); if (parameters.files_count == 0) { - display_error(WARNING, 3); + display_error(CS_WARNING, 3); } } else { - display_error(WARNING, 9); + display_error(CS_WARNING, 9); } } else { files_flag = true; @@ -206,22 +201,22 @@ cclt_options parse_arguments(char **argv, C_CSParameters *options) { if (strstr(parameters.output_folder, parameters.input_folder) != NULL && strcmp(parameters.output_folder, parameters.input_folder) != 0 && parameters.recursive) { - display_error(ERROR, 12); + display_error(CS_ERROR, 12); } } //-R and -S set warnings if (parameters.recursive && !folders_flag) { - display_error(WARNING, 10); + display_error(CS_WARNING, 10); parameters.recursive = false; } if (!parameters.recursive && parameters.keep_structure) { - display_error(WARNING, 11); + display_error(CS_WARNING, 11); parameters.keep_structure = false; } //If there are files and folders, we cannot keep the structure if (parameters.keep_structure && (!folders_flag && parameters.files_count > 1)) { - display_error(WARNING, 4); + display_error(CS_WARNING, 4); parameters.keep_structure = false; } return parameters; @@ -233,7 +228,7 @@ int start_compression(cclt_options *options, struct C_CSParameters parameters) { off_t output_file_size; //Create the output folder if it does not exist if (mkpath(options->output_folder) == -1) { - display_error(ERROR, 5); + display_error(CS_ERROR, 5); } for (int i = 0; i < options->files_count; i++) { @@ -312,7 +307,8 @@ int start_compression(cclt_options *options, struct C_CSParameters parameters) { fflush(stdout); //Prevent compression if running in dry mode if (!options->dry_run) { - if (c_compress(options->input_files[i], output_full_path, parameters)) { + C_CSResult compression_result = c_compress(options->input_files[i], output_full_path, parameters); + if (compression_result.success) { compressed_files++; output_file_size = get_file_size(output_full_path); @@ -331,7 +327,7 @@ int start_compression(cclt_options *options, struct C_CSParameters parameters) { human_output_size, ((float) output_file_size - (float) input_file_size) * 100 / (float) input_file_size); } else { - print_to_console(stderr, verbose, "\nCompression failed\n"); + print_to_console(stderr, verbose, "\nCompression failed: %s\n", compression_result.error_message); options->input_total_size -= get_file_size(options->input_files[i]); } } diff --git a/src/helper.h b/src/helper.h index 63cd15b..c931e3a 100644 --- a/src/helper.h +++ b/src/helper.h @@ -18,6 +18,8 @@ #ifndef CAESIUM_CLT_HELPER_H #define CAESIUM_CLT_HELPER_H +#include + #ifdef _WIN32 #define MAX_PATH_SIZE _MAX_PATH #else @@ -46,7 +48,12 @@ typedef struct C_CSParameters { int height; } C_CSParameters; -extern bool c_compress(const char *i, const char *o, struct C_CSParameters params); +typedef struct C_CSResult { + bool success; + const char *error_message; +} C_CSResult; + +extern C_CSResult c_compress(const char *i, const char *o, struct C_CSParameters params); typedef struct cclt_options { diff --git a/src/main.c b/src/main.c index 6db24bb..97228d7 100755 --- a/src/main.c +++ b/src/main.c @@ -20,6 +20,7 @@ #include #include "utils.h" #include "shared.h" +#include int main(int argc, char *argv[]) { diff --git a/src/utils.c b/src/utils.c index f2f45dc..83d478b 100644 --- a/src/utils.c +++ b/src/utils.c @@ -65,7 +65,7 @@ bool is_directory(const char *path) { tinydir_file file; if (tinydir_file_open(&file, path) == -1) { - display_error(ERROR, 6); + display_error(CS_ERROR, 6); } return (bool) file.is_dir; @@ -199,7 +199,8 @@ char *get_filename(char *full_path) { off_t get_file_size(const char *path) { FILE *f = fopen(path, "rb"); if (f == NULL) { - display_error(WARNING, 7); + perror("Cannot open output file"); + display_error(CS_WARNING, 7); return 0; } fseek(f, 0, SEEK_END); @@ -247,7 +248,7 @@ overwrite_policy parse_overwrite_policy(const char *overwrite_string) { } else if (strcmp(overwrite_string, "all") == 0) { return all; } - display_error(WARNING, 15); + display_error(CS_WARNING, 15); return bigger; }