4 void saveSGC(const 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
*path
= g_build_path(G_DIR_SEPARATOR_S
, g_getenv(STORAGE
), STOREAS
, DISTPATH
, NULL
);
13 gchar
*zippath
= g_build_path(G_DIR_SEPARATOR_S
, path
, filename
, NULL
);
15 // g_debug("%s", zippath);
17 if (zippath
!= NULL
) {
20 g_mkdir_with_parents(path
, 0755);
21 if ((za
= zip_open(zippath
, ZIP_CREATE
, &err
)) != NULL
) {
23 if ((dirpath
= g_dir_open(path
, 0, NULL
)) != NULL
) {
25 struct zip_source
*zs
;
26 while ((file
= g_dir_read_name(dirpath
)) != NULL
) {
27 gchar
*pathtofile
= g_build_path(G_DIR_SEPARATOR_S
, path
, file
, NULL
);
28 if ((zs
=zip_source_file(za
, pathtofile
, 0, -1)) != NULL
) {
29 zip_add(za
, file
, zs
);
31 g_debug("%s %s", pathtofile
, zip_strerror(za
));
50 gboolean
openSGC(gchar
*oldfilename
) {
53 gboolean toreturn
= FALSE
;
55 if (oldfilename
== NULL
|| (za
= zip_open(oldfilename
, 0, &err
)) == NULL
) {
56 /* Kan bestand niet openen */
58 if (zip_name_locate(za
, "wordlist.txt", 0) == -1) {
59 /* Geen valide bestand */
67 gchar
*filename
= g_path_get_basename(oldfilename
);
68 int end
= strlen(filename
);
70 if (g_str_has_suffix(filename
, ".sgc") ||
71 g_str_has_suffix(filename
, ".SGC")) {
75 name
= g_malloc(end
* sizeof(gchar
));
79 g_strlcpy(name
, filename
, end
);
82 base
= g_build_path(G_DIR_SEPARATOR_S
, g_getenv(STORAGE
), STOREAS
, WORDLISTS
, name
, NULL
);
84 g_mkdir_with_parents(base
, 0755);
86 for (i
= 0; i
< zip_get_num_files(za
); i
++) {
87 if ((zf
= zip_fopen_index(za
, i
, 0)) != NULL
&&
88 (zip_stat_index(za
, i
, 0, &zs
)) != -1) {
89 data
= g_malloc(sizeof(char) * zs
.size
);
94 if ((test
= zip_fread(zf
, data
, zs
.size
)) == zs
.size
) {
95 gchar
*dir
= g_build_path(G_DIR_SEPARATOR_S
, base
, zs
.name
, NULL
);
96 g_file_set_contents(dir
, data
, zs
.size
, NULL
);