More clever extract from zip
This commit is contained in:
parent
915c25d1de
commit
17389b83af
|
@ -2375,14 +2375,14 @@ int game_from_disk(void)
|
||||||
#ifdef _USE_UNPACK
|
#ifdef _USE_UNPACK
|
||||||
p = game_local_games_path(1);
|
p = game_local_games_path(1);
|
||||||
fprintf(stderr,"Trying to install: %s\n", g);
|
fprintf(stderr,"Trying to install: %s\n", g);
|
||||||
if (!unpack(g, p) && zip_game_dirname[0]) {
|
if (!unpack(g, p)) {
|
||||||
if (games_replace(p, zip_game_dirname)) {
|
if (!zip_game_dirname[0])
|
||||||
p = getpath(p, zip_game_dirname);
|
|
||||||
remove_dir(p);
|
|
||||||
free(p);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
if (games_replace(p, zip_game_dirname))
|
||||||
|
goto clean;
|
||||||
p = zip_game_dirname;
|
p = zip_game_dirname;
|
||||||
|
} else if (zip_game_dirname[0]) { /* error, needs to clean */
|
||||||
|
goto clean;
|
||||||
#else
|
#else
|
||||||
if (0) {
|
if (0) {
|
||||||
#endif
|
#endif
|
||||||
|
@ -2395,6 +2395,14 @@ int game_from_disk(void)
|
||||||
game_error(p);
|
game_error(p);
|
||||||
}
|
}
|
||||||
return 0;
|
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)
|
int game_loop(void)
|
||||||
|
|
|
@ -30,8 +30,15 @@ static int setup_zip(const char *file, char *p)
|
||||||
if (!p)
|
if (!p)
|
||||||
return -1;
|
return -1;
|
||||||
fprintf(stderr,"Trying to install: %s\n", file);
|
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;
|
return -1;
|
||||||
|
}
|
||||||
game_sw = zip_game_dirname;
|
game_sw = zip_game_dirname;
|
||||||
games_sw = p;
|
games_sw = p;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "unzip.h"
|
#include "unzip.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
#define CASESENSITIVITY (0)
|
#define CASESENSITIVITY (0)
|
||||||
#define WRITEBUFFERSIZE (8192)
|
#define WRITEBUFFERSIZE (8192)
|
||||||
|
@ -191,19 +192,24 @@ const char *password;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((*filename_withoutpath) == '\0') {
|
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);
|
printf("creating directory: %s\n", filename_inzip);
|
||||||
mymkdir(filename_inzip);
|
mymkdir(filename_inzip);
|
||||||
if (!*zip_game_dirname) {
|
if (!*zip_game_dirname)
|
||||||
int s = strlen(filename_inzip);
|
strcpy(zip_game_dirname, 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;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
const char *write_filename;
|
const char *write_filename;
|
||||||
int skip = 0;
|
int skip = 0;
|
||||||
|
if (!*zip_game_dirname) {
|
||||||
|
err = -1;
|
||||||
|
fprintf(stderr, "No dir in zip...\n");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
write_filename = filename_inzip;
|
write_filename = filename_inzip;
|
||||||
|
|
||||||
err = unzOpenCurrentFilePassword(uf, password);
|
err = unzOpenCurrentFilePassword(uf, password);
|
||||||
|
@ -271,6 +277,14 @@ const char *password;
|
||||||
unzCloseCurrentFile(uf); /* don't lose the error */
|
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);
|
free(buf);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -288,7 +302,7 @@ const char *password;
|
||||||
|
|
||||||
for (i = 0; i < gi.number_entry; i++) {
|
for (i = 0; i < gi.number_entry; i++) {
|
||||||
if (do_extract_currentfile(uf, password) != UNZ_OK)
|
if (do_extract_currentfile(uf, password) != UNZ_OK)
|
||||||
break;
|
return -1;
|
||||||
|
|
||||||
if ((i + 1) < gi.number_entry) {
|
if ((i + 1) < gi.number_entry) {
|
||||||
err = unzGoToNextFile(uf);
|
err = unzGoToNextFile(uf);
|
||||||
|
@ -296,7 +310,7 @@ const char *password;
|
||||||
printf
|
printf
|
||||||
("error %d with zipfile in unzGoToNextFile\n",
|
("error %d with zipfile in unzGoToNextFile\n",
|
||||||
err);
|
err);
|
||||||
break;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue