idf go on
This commit is contained in:
parent
9df74e9c32
commit
b49a40e934
|
@ -135,6 +135,8 @@ int game_select(const char *name)
|
|||
if (oldgame != curgame_dir) {
|
||||
idf_done(game_idf);
|
||||
game_idf = idf_init(g->path);
|
||||
if (game_idf)
|
||||
idf_only(game_idf, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -244,7 +246,10 @@ int games_replace(const char *path, const char *dir)
|
|||
return -1;
|
||||
g = game_lookup(dir);
|
||||
if (g) {
|
||||
p = getpath(path, dir);
|
||||
if (g->idf)
|
||||
p = getfilepath(path, dir);
|
||||
else
|
||||
p = getpath(path, dir);
|
||||
if (!p)
|
||||
return -1;
|
||||
free(g->path);
|
||||
|
@ -2926,11 +2931,12 @@ int game_from_disk(void)
|
|||
strcpy(dir, p);
|
||||
strcpy(base, p);
|
||||
d = dir; b = base;
|
||||
|
||||
i = strlen(d);
|
||||
if (i && d[i - 1] != '/') { /* file */
|
||||
d = dirname(d);
|
||||
strcpy(b, d);
|
||||
if (!idf_magic(d)) {
|
||||
d = dirname(d);
|
||||
strcpy(b, d);
|
||||
}
|
||||
}
|
||||
d = dirname(d);
|
||||
b = basename(b);
|
||||
|
|
|
@ -21,6 +21,7 @@ struct _idf_t {
|
|||
FILE *fd;
|
||||
char *path;
|
||||
cache_t dir;
|
||||
int idfonly;
|
||||
};
|
||||
|
||||
void idf_done(idf_t idf)
|
||||
|
@ -96,6 +97,7 @@ idf_t idf_init(const char *fname)
|
|||
idf->path = strdup(fname);
|
||||
if (!idf->path)
|
||||
goto err;
|
||||
idf->idfonly = 0;
|
||||
idf->fd = fopen(fp, "rb");
|
||||
idf->dir = cache_init(-1, free);
|
||||
if (!idf->fd || !idf->dir)
|
||||
|
@ -273,8 +275,15 @@ int idf_create(const char *file, const char *path)
|
|||
s = strlen(it->path);
|
||||
if (fwrite(&s, 1, 1, fd) != 1)
|
||||
goto err;
|
||||
if (fwrite(it->path, 1, s, fd) != s)
|
||||
p = strdup(it->path);
|
||||
if (!p)
|
||||
goto err;
|
||||
tolow(p); /* in idf always lowcase */
|
||||
if (fwrite(p, 1, s, fd) != s) {
|
||||
free(p);
|
||||
goto err;
|
||||
}
|
||||
free(p);
|
||||
if (write_word(fd, off) < 0)
|
||||
goto err;
|
||||
if (write_word(fd, it->size) < 0)
|
||||
|
@ -448,12 +457,29 @@ int idf_error(idff_t idf)
|
|||
return ferror(idf->fd);
|
||||
}
|
||||
|
||||
int idf_only(idf_t idf, int fl)
|
||||
{ int i;
|
||||
if (!idf)
|
||||
return -1;
|
||||
if (fl == -1)
|
||||
return idf->idfonly;
|
||||
i = idf->idfonly;
|
||||
idf->idfonly = fl;
|
||||
return i;
|
||||
}
|
||||
|
||||
idff_t idf_open(idf_t idf, const char *fname)
|
||||
{
|
||||
idfd_t *dir = NULL;
|
||||
idff_t fil = NULL;
|
||||
char *p;
|
||||
p = strdup(fname);
|
||||
if (!p)
|
||||
return NULL;
|
||||
tolow(p);
|
||||
if (idf)
|
||||
dir = cache_lookup(idf->dir, fname);
|
||||
dir = cache_lookup(idf->dir, p);
|
||||
free(p);
|
||||
if (!dir)
|
||||
return NULL;
|
||||
|
||||
|
@ -506,9 +532,11 @@ SDL_RWops *RWFromIdf(idf_t idf, const char *fname)
|
|||
idff_t fil = NULL;
|
||||
SDL_RWops *n;
|
||||
fil = idf_open(idf, fname);
|
||||
if (!fil)
|
||||
return SDL_RWFromFile(dirpath(fname), "rb");
|
||||
|
||||
if (!fil) {
|
||||
if (!idf || !idf->idfonly)
|
||||
return SDL_RWFromFile(dirpath(fname), "rb");
|
||||
return NULL;
|
||||
}
|
||||
n = SDL_AllocRW();
|
||||
if (!n)
|
||||
goto err;
|
||||
|
|
|
@ -24,5 +24,6 @@ extern int idf_error(idff_t idf);
|
|||
extern int idf_access(idf_t idf, const char *fname);
|
||||
extern char *idf_gets(idff_t idf, char *b, int size);
|
||||
extern int idf_magic(const char *fname);
|
||||
extern int idf_only(idf_t idf, int fl);
|
||||
|
||||
#endif
|
|
@ -231,9 +231,9 @@ static void games_menu(void)
|
|||
else
|
||||
snprintf(tmp, sizeof(tmp), "<l><a:%s>%s</a></l>", games[i].dir, games[i].name);
|
||||
if (strncmp(GAMES_PATH, games[i].path, strlen(GAMES_PATH))
|
||||
&& !access(games[i].path, W_OK))
|
||||
&& !access(games[i].path, W_OK)) {
|
||||
snprintf(tmp + strlen(tmp), sizeof(tmp), " [<a:/remove_%d>X</a>]\n", i);
|
||||
else
|
||||
} else
|
||||
strcat(tmp, "\n");
|
||||
|
||||
strcat(menu_buff, tmp);
|
||||
|
|
|
@ -585,7 +585,7 @@ int game_theme_optimize(void)
|
|||
static int game_theme_update_data(void)
|
||||
{
|
||||
struct game_theme *t = &game_theme;
|
||||
|
||||
int idf = idf_only(game_idf, 0);
|
||||
if (t->font_name && (t->changed & CHANGED_FONT)) {
|
||||
fnt_free(t->font);
|
||||
if (!(t->font = fnt_load(t->font_name, FONT_SZ(t->font_size))))
|
||||
|
@ -683,8 +683,10 @@ static int game_theme_update_data(void)
|
|||
fprintf(stderr,"Can't init theme. Not all required elements are defined.\n");
|
||||
goto err;
|
||||
}
|
||||
idf_only(game_idf, idf);
|
||||
return 0;
|
||||
err:
|
||||
idf_only(game_idf, idf);
|
||||
t->changed = 0;
|
||||
return -1;
|
||||
}
|
||||
|
@ -894,19 +896,19 @@ int game_theme_load(const char *name)
|
|||
{
|
||||
struct theme *theme;
|
||||
char cwd[PATH_MAX];
|
||||
int rc = -1;
|
||||
int rel = theme_relative;
|
||||
getdir(cwd, sizeof(cwd));
|
||||
setdir(game_cwd);
|
||||
theme = theme_lookup(name);
|
||||
theme_relative = 0;
|
||||
if (!theme || setdir(theme->path) || theme_load(THEME_FILE)) {
|
||||
setdir(cwd);
|
||||
theme_relative = rel;
|
||||
return -1;
|
||||
}
|
||||
if (!theme || setdir(theme->path) || theme_load(THEME_FILE))
|
||||
goto err;
|
||||
rc = 0;
|
||||
err:
|
||||
setdir(cwd);
|
||||
theme_relative = rel;
|
||||
return 0;
|
||||
return rc;
|
||||
}
|
||||
|
||||
int game_theme_select(const char *name)
|
||||
|
|
|
@ -304,7 +304,7 @@ char *sdl_path(char *p)
|
|||
unix_path(p);
|
||||
return p;
|
||||
}
|
||||
#if 1
|
||||
#if 0
|
||||
int setdir(const char *path)
|
||||
{
|
||||
return chdir(path);
|
||||
|
|
Loading…
Reference in a new issue