2 Copyright (C) 2012 Modelon AB
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the BSD style license.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 FMILIB_License.txt file for more details.
12 You should have received a copy of the FMILIB_License.txt file
13 along with this program. If not, contact Modelon AB <http://www.modelon.com>.
20 #include <JM/jm_types.h>
21 #include <JM/jm_callbacks.h>
22 #include <JM/jm_portability.h>
24 jm_status_enu_t fmi_zip_zip(const char* zip_file_path, int n_files_to_zip, const char** files_to_zip, jm_callbacks* callbacks)
26 /* A call to minizip may change the current directory and therefore we must change it back */
27 char cd[FILENAME_MAX];
29 #define N_BASIC_ARGS 4
35 /* Temporary save the current directory */
36 if (jm_portability_get_current_working_directory(cd, sizeof(cd) / sizeof(char)) == jm_status_error) {
37 jm_log(callbacks, "UNZIP", jm_log_level_error, "Could not get Current Directory");
\r
38 return jm_status_error;
41 argc = N_BASIC_ARGS + n_files_to_zip;
42 argv = callbacks->calloc(sizeof(char*), argc);
43 /* Failed to allocate memory, return error */
45 callbacks->logger(NULL, "FMIZIP", jm_log_level_error, "Failed to allocate memory.");
46 return jm_status_error;
49 /* Input arguments to the corresponding minizip main() function call */
51 Usage : minizip [-o] [-a] [-0 to -9] [-p password] [-j] file.zip [files_to_add]
\r
53 -o Overwrite existing file.zip
\r
54 -a Append to existing file.zip
\r
59 -j exclude path. store only the file name.
64 argv[3]=(char*)zip_file_path;
66 /* Append the input argument list with the files to unzip */
67 jm_log_info(callbacks, "FMIZIP", "Will compress following files: \n");
68 for (k = 0; k < n_files_to_zip; k++) {
69 jm_log_info(callbacks, "FMIZIP", "\t%s\n", files_to_zip[k]);
70 argv[N_BASIC_ARGS + k] = (char*)files_to_zip[k];
74 status = minizip(argc, (char**)argv);
76 /* Free allocated memory */
77 callbacks->free(argv);
79 /* Reset the current directory */
80 if (jm_portability_set_current_working_directory(cd) == jm_status_error) {
\r
81 jm_log(callbacks, "UNZIP", jm_log_level_warning, "Could not change back Current Directory");
\r
82 return jm_status_warning;
\r
85 /* Return error status */
87 return jm_status_success;
89 return jm_status_error;