4 void saveSGC(gchar
*dir
, gchar
*path
) {
5 if (dir
!= NULL
&& path
!= NULL
) {
6 gchar
*wordlist
= g_build_path(G_DIR_SEPARATOR_S
, path
, "wordlist.txt", NULL
);
7 // g_debug("%s", wordlist);
8 if (wordlist
!= NULL
) {
9 if (g_access(wordlist
, R_OK
) == 0) {
10 gchar
*filename
= g_strjoin(NULL
, dir
, ".sgc", NULL
);
11 gchar
*zippath
= g_build_path(G_DIR_SEPARATOR_S
, DISTPATH
, filename
, NULL
);
14 // g_debug("%s", zippath);
16 if (zippath
!= NULL
) {
19 g_mkdir_with_parents(DISTPATH
, 0755);
20 if ((za
= zip_open(zippath
, ZIP_CREATE
, &err
)) != NULL
) {
22 if ((dirpath
= g_dir_open(path
, 0, NULL
)) != NULL
) {
24 struct zip_source
*zs
;
25 while ((file
= g_dir_read_name(dirpath
)) != NULL
) {
26 gchar
*pathtofile
= g_build_path(G_DIR_SEPARATOR_S
, path
, file
, NULL
);
27 if ((zs
=zip_source_file(za
, pathtofile
, 0, -1)) != NULL
) {
28 zip_add(za
, file
, zs
);
30 g_debug("%s %s", pathtofile
, zip_strerror(za
));
46 gboolean
openSGC(gchar
*oldfilename
) {
49 gboolean toreturn
= FALSE
;
51 if (oldfilename
== NULL
|| (za
= zip_open(oldfilename
, 0, &err
)) == NULL
) {
52 /* Kan bestand niet openen */
54 if (zip_name_locate(za
, "wordlist.txt", 0) == -1) {
55 /* Geen valide bestand */
63 gchar
*filename
= g_path_get_basename(oldfilename
);
64 int end
= strlen(filename
);
66 if (g_str_has_suffix(filename
, ".sgc") ||
67 g_str_has_suffix(filename
, ".SGC")) {
71 name
= g_malloc(end
* sizeof(gchar
));
75 g_strlcpy(name
, filename
, end
);
78 base
= g_build_path(G_DIR_SEPARATOR_S
, WORDLISTS
, name
, NULL
);
80 g_mkdir_with_parents(base
, 0755);
82 for (i
= 0; i
< zip_get_num_files(za
); i
++) {
83 if ((zf
= zip_fopen_index(za
, i
, 0)) != NULL
&&
84 (zip_stat_index(za
, i
, 0, &zs
)) != -1) {
85 data
= g_malloc(sizeof(char) * zs
.size
);
90 if ((test
= zip_fread(zf
, data
, zs
.size
)) == zs
.size
) {
91 gchar
*dir
= g_build_path(G_DIR_SEPARATOR_S
, base
, zs
.name
, NULL
);
92 g_file_set_contents(dir
, data
, zs
.size
, NULL
);