Windows build fix + libcaesium 0.9.3

This commit is contained in:
Matteo Paonessa 2022-11-06 16:20:00 +01:00
parent 51fea36403
commit 6fa41b5fde
9 changed files with 54 additions and 36 deletions

11
.gitignore vendored
View File

@ -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

View File

@ -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(

View File

@ -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

View File

@ -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);
}
}

View File

@ -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);

View File

@ -19,11 +19,6 @@
#include <stdio.h>
#include <string.h>
#include <errno.h>
#ifdef _WIN32
#include <direct.h>
#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, &parameters, 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]);
}
}

View File

@ -18,6 +18,8 @@
#ifndef CAESIUM_CLT_HELPER_H
#define CAESIUM_CLT_HELPER_H
#include <stdbool.h>
#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
{

View File

@ -20,6 +20,7 @@
#include <stdio.h>
#include "utils.h"
#include "shared.h"
#include <stdbool.h>
int main(int argc, char *argv[])
{

View File

@ -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;
}