The new zip file implementation is ready, still need to put the messages returned by it in debug mode

This commit is contained in:
gunnar_g 2011-02-16 20:57:48 +00:00
parent 883a0f60b4
commit 8d9b2e203a
3 changed files with 25 additions and 10 deletions

View File

@ -846,7 +846,7 @@ file_decompress(const gchar *filename)
gchar *dirname = g_path_get_dirname(filename), gchar *dirname = g_path_get_dirname(filename),
*basename = g_path_get_basename(filename), *basename = g_path_get_basename(filename),
*pwd = g_get_current_dir(); *pwd = g_get_current_dir();
gchar extracted_file[256];
chdir(dirname); chdir(dirname);
uLong i; uLong i;
@ -861,7 +861,7 @@ file_decompress(const gchar *filename)
for (i=0;i<gi.number_entry;i++) for (i=0;i<gi.number_entry;i++)
{ {
if (do_extract_currentfile(uf) != UNZ_OK) if (do_extract_currentfile(uf, extracted_file) != UNZ_OK)
break; break;
if ((i+1)<gi.number_entry) if ((i+1)<gi.number_entry)
@ -875,12 +875,9 @@ file_decompress(const gchar *filename)
} }
} }
GPtrArray *files_to_remove = file_dir_get_contents(dirname, basename, "");
file_remove_files(files_to_remove);
chdir(pwd); chdir(pwd);
g_string_free(buf, TRUE); g_string_free(buf, TRUE);
free_gchar_array(&files_to_remove);
g_free(dirname); g_free(dirname);
g_free(basename); g_free(basename);
@ -1024,9 +1021,9 @@ file_load_text_from_saves(const gchar *filename)
return g_strdup(buf); return g_strdup(buf);
} }
int do_extract_currentfile(unzFile uf) int do_extract_currentfile(unzFile uf, gchar *extracted_file)
{ {
char filename_inzip[256]; gchar filename_inzip[256];
int err=UNZ_OK; int err=UNZ_OK;
FILE *fout=NULL; FILE *fout=NULL;
void* buf; void* buf;
@ -1034,6 +1031,9 @@ int do_extract_currentfile(unzFile uf)
unz_file_info file_info; unz_file_info file_info;
err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0); err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
// copy the filename to extracted file
g_sprintf(extracted_file, "%s", filename_inzip);
if (err!=UNZ_OK) if (err!=UNZ_OK)
{ {
printf("error %d with zipfile in unzGetCurrentFileInfo\n",err); printf("error %d with zipfile in unzGetCurrentFileInfo\n",err);

View File

@ -118,7 +118,7 @@ void
file_store_text_in_saves(const gchar *filename, const gchar *text); file_store_text_in_saves(const gchar *filename, const gchar *text);
int int
do_extract_currentfile(unzFile uf); do_extract_currentfile(unzFile uf, gchar *extracted_file);
int int
do_compress_currentfile(zipFile zf, char* fileToZip); do_compress_currentfile(zipFile zf, char* fileToZip);

View File

@ -27,6 +27,7 @@
#include "callbacks.h" #include "callbacks.h"
#include "file.h" #include "file.h"
#include "free.h"
#include "gui.h" #include "gui.h"
#include "game_gui.h" #include "game_gui.h"
#include "language.h" #include "language.h"
@ -197,6 +198,7 @@ load_save_load_game(const gchar* filename, gboolean create_main_window)
gchar *prefix = (g_str_has_suffix(basename, const_str("string_fs_save_suffix"))) ? gchar *prefix = (g_str_has_suffix(basename, const_str("string_fs_save_suffix"))) ?
g_strndup(basename, strlen(basename) - strlen(const_str("string_fs_save_suffix"))) : g_strndup(basename, strlen(basename) - strlen(const_str("string_fs_save_suffix"))) :
g_strdup(basename); g_strdup(basename);
gchar *pwd = g_get_current_dir();
if(g_str_has_suffix(filename, "last_save")) if(g_str_has_suffix(filename, "last_save"))
{ {
@ -319,8 +321,21 @@ load_save_load_game(const gchar* filename, gboolean create_main_window)
gui_show_progress(1, _("Done."), gui_show_progress(1, _("Done."),
PIC_TYPE_LOAD); PIC_TYPE_LOAD);
g_string_sprintf(buf, "%s%s%s___*", dirname, G_DIR_SEPARATOR_S, prefix); chdir(dirname);
g_remove(buf->str); GPtrArray *files = file_dir_get_contents(dirname, prefix, "");
// Remove the zipfile from the list
gint i;
for(i=0;i<files->len;i++)
{
if (g_strcmp0((gchar*)g_ptr_array_index(files, i),basename)==0){
g_ptr_array_remove_index_fast(files, i);
}
}
file_remove_files(files);
chdir(pwd);
g_free(pwd);
free_gchar_array(&files);
misc_string_assign(&save_file, fullname); misc_string_assign(&save_file, fullname);