More clever extract from zip

This commit is contained in:
p.kosyh 2010-06-04 07:27:10 +00:00
parent 915c25d1de
commit 17389b83af
3 changed files with 46 additions and 17 deletions

View file

@ -2375,14 +2375,14 @@ int game_from_disk(void)
#ifdef _USE_UNPACK
p = game_local_games_path(1);
fprintf(stderr,"Trying to install: %s\n", g);
if (!unpack(g, p) && zip_game_dirname[0]) {
if (games_replace(p, zip_game_dirname)) {
p = getpath(p, zip_game_dirname);
remove_dir(p);
free(p);
if (!unpack(g, p)) {
if (!zip_game_dirname[0])
return -1;
}
if (games_replace(p, zip_game_dirname))
goto clean;
p = zip_game_dirname;
} else if (zip_game_dirname[0]) { /* error, needs to clean */
goto clean;
#else
if (0) {
#endif
@ -2395,6 +2395,14 @@ int game_from_disk(void)
game_error(p);
}
return 0;
#ifdef _USE_UNPACK
clean:
p = getpath(p, zip_game_dirname);
fprintf(stderr, "Cleaning: '%s'...\n", p);
remove_dir(p);
free(p);
return -1;
#endif
}
int game_loop(void)

View file

@ -30,8 +30,15 @@ static int setup_zip(const char *file, char *p)
if (!p)
return -1;
fprintf(stderr,"Trying to install: %s\n", file);
if (unpack(file, p))
if (unpack(file, p)) {
if (zip_game_dirname[0]) {
p = getpath(p, zip_game_dirname);
fprintf(stderr, "Cleaning: '%s'...\n", p);
remove_dir(p);
free(p);
}
return -1;
}
game_sw = zip_game_dirname;
games_sw = p;
return 0;

View file

@ -38,6 +38,7 @@
#endif
#include "unzip.h"
#include "util.h"
#define CASESENSITIVITY (0)
#define WRITEBUFFERSIZE (8192)
@ -191,19 +192,24 @@ const char *password;
}
if ((*filename_withoutpath) == '\0') {
if (zip_game_dirname[0] && strncmp(zip_game_dirname,
filename_inzip, strlen(zip_game_dirname))) {
err = -1;
fprintf(stderr, "Too many dirs in zip...\n");
goto out;
}
printf("creating directory: %s\n", filename_inzip);
mymkdir(filename_inzip);
if (!*zip_game_dirname) {
int s = strlen(filename_inzip);
if (s && (filename_inzip[s - 1] == '/' || filename_inzip[s - 1] == '\\'))
s --;
memcpy(zip_game_dirname, filename_inzip, s);
zip_game_dirname[s] = 0;
}
if (!*zip_game_dirname)
strcpy(zip_game_dirname, filename_inzip);
} else {
const char *write_filename;
int skip = 0;
if (!*zip_game_dirname) {
err = -1;
fprintf(stderr, "No dir in zip...\n");
goto out;
}
write_filename = filename_inzip;
err = unzOpenCurrentFilePassword(uf, password);
@ -271,6 +277,14 @@ const char *password;
unzCloseCurrentFile(uf); /* don't lose the error */
}
if (*zip_game_dirname) {
int s = strlen(zip_game_dirname);
unix_path(zip_game_dirname);
if (s && (zip_game_dirname[s - 1] == '/'))
s --;
zip_game_dirname[s] = 0;
}
out:
free(buf);
return err;
}
@ -288,7 +302,7 @@ const char *password;
for (i = 0; i < gi.number_entry; i++) {
if (do_extract_currentfile(uf, password) != UNZ_OK)
break;
return -1;
if ((i + 1) < gi.number_entry) {
err = unzGoToNextFile(uf);
@ -296,7 +310,7 @@ const char *password;
printf
("error %d with zipfile in unzGoToNextFile\n",
err);
break;
return -1;
}
}
}