]> gerrit.simantics Code Review - simantics/fmil.git/blob - org.simantics.fmil.core/native/FMILibrary/src/ZIP/src/fmi_zip_unzip.c
Switch to full JavaSE-11+ compatibility
[simantics/fmil.git] / org.simantics.fmil.core / native / FMILibrary / src / ZIP / src / fmi_zip_unzip.c
1 /*
2     Copyright (C) 2012 Modelon AB
3
4     This program is free software: you can redistribute it and/or modify
5     it under the terms of the BSD style license.
6
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.
11
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>.
14 */
15
16 #ifdef __cplusplus 
17 extern "C" {
18 #endif
19
20 #include <stdio.h>
21 #include <stdlib.h>
22
23 #include <miniunz.h>
24
25 #include <JM/jm_types.h>
26 #include <JM/jm_callbacks.h>
27 #include <JM/jm_portability.h>
28
29 static const char* module = "FMIZIP";
30
31 jm_status_enu_t fmi_zip_unzip(const char* zip_file_path, const char* output_folder, jm_callbacks* callbacks)
32 {
33         /*
34         Usage : miniunz [-e] [-x] [-v] [-l] [-o] [-p password] file.zip [file_to_extr.] [-d extractdir]
35           -e  Extract without pathname (junk paths)
36           -x  Extract with pathname
37           -v  list files
38           -l  list files
39           -d  directory to extract into
40           -o  overwrite files without prompting
41           -p  extract crypted file using password
42         */
43
44         /* A call to minunz may change the current directory and therefore we must change it back */
45         char cd[FILENAME_MAX];
46
47         int argc = 6;
48         const char *argv[6];
49         int status;
50
51         jm_log_verbose(callbacks, module, "Unpacking FMU into %s", output_folder);
52
53         argv[0]="miniunz";
54         argv[1]="-x";
55         argv[2]="-o";
56         argv[3]=zip_file_path;
57         argv[4]="-d";
58         argv[5]=output_folder;
59         
60
61         /* Temporary save the current directory */
62         if (jm_portability_get_current_working_directory(cd, sizeof(cd) / sizeof(char)) == jm_status_error) {
63                 jm_log_fatal(callbacks, module, "Could not get Current Directory");\r
64                 return jm_status_error;
65         }
66
67         /* Unzip */
68         status = miniunz(argc, (char**)argv);
69
70         /* Reset the current directory */
71         if (jm_portability_set_current_working_directory(cd) == jm_status_error) {\r
72                 jm_log_warning(callbacks, module, "Could not restore Current Directory after unpacking");\r
73                 return jm_status_warning;\r
74         }
75
76         /* Return error status */
77         if (status == 0) {
78                 return jm_status_success;
79         } else {
80                 jm_log_fatal(callbacks, "FMIZIP", "Unpacking of FMU %s into %s failed", zip_file_path, output_folder);
81                 return jm_status_error; 
82         }
83 }
84
85 #ifdef __cplusplus 
86 }
87 #endif