idf go on

This commit is contained in:
p.kosyh 2011-04-19 07:51:18 +00:00
parent 9df74e9c32
commit b49a40e934
6 changed files with 56 additions and 19 deletions

View file

@ -135,6 +135,8 @@ int game_select(const char *name)
if (oldgame != curgame_dir) { if (oldgame != curgame_dir) {
idf_done(game_idf); idf_done(game_idf);
game_idf = idf_init(g->path); 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; return -1;
g = game_lookup(dir); g = game_lookup(dir);
if (g) { if (g) {
p = getpath(path, dir); if (g->idf)
p = getfilepath(path, dir);
else
p = getpath(path, dir);
if (!p) if (!p)
return -1; return -1;
free(g->path); free(g->path);
@ -2926,11 +2931,12 @@ int game_from_disk(void)
strcpy(dir, p); strcpy(dir, p);
strcpy(base, p); strcpy(base, p);
d = dir; b = base; d = dir; b = base;
i = strlen(d); i = strlen(d);
if (i && d[i - 1] != '/') { /* file */ if (i && d[i - 1] != '/') { /* file */
d = dirname(d); if (!idf_magic(d)) {
strcpy(b, d); d = dirname(d);
strcpy(b, d);
}
} }
d = dirname(d); d = dirname(d);
b = basename(b); b = basename(b);

View file

@ -21,6 +21,7 @@ struct _idf_t {
FILE *fd; FILE *fd;
char *path; char *path;
cache_t dir; cache_t dir;
int idfonly;
}; };
void idf_done(idf_t idf) void idf_done(idf_t idf)
@ -96,6 +97,7 @@ idf_t idf_init(const char *fname)
idf->path = strdup(fname); idf->path = strdup(fname);
if (!idf->path) if (!idf->path)
goto err; goto err;
idf->idfonly = 0;
idf->fd = fopen(fp, "rb"); idf->fd = fopen(fp, "rb");
idf->dir = cache_init(-1, free); idf->dir = cache_init(-1, free);
if (!idf->fd || !idf->dir) if (!idf->fd || !idf->dir)
@ -273,8 +275,15 @@ int idf_create(const char *file, const char *path)
s = strlen(it->path); s = strlen(it->path);
if (fwrite(&s, 1, 1, fd) != 1) if (fwrite(&s, 1, 1, fd) != 1)
goto err; goto err;
if (fwrite(it->path, 1, s, fd) != s) p = strdup(it->path);
if (!p)
goto err; 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) if (write_word(fd, off) < 0)
goto err; goto err;
if (write_word(fd, it->size) < 0) if (write_word(fd, it->size) < 0)
@ -448,12 +457,29 @@ int idf_error(idff_t idf)
return ferror(idf->fd); 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) idff_t idf_open(idf_t idf, const char *fname)
{ {
idfd_t *dir = NULL; idfd_t *dir = NULL;
idff_t fil = NULL; idff_t fil = NULL;
char *p;
p = strdup(fname);
if (!p)
return NULL;
tolow(p);
if (idf) if (idf)
dir = cache_lookup(idf->dir, fname); dir = cache_lookup(idf->dir, p);
free(p);
if (!dir) if (!dir)
return NULL; return NULL;
@ -506,9 +532,11 @@ SDL_RWops *RWFromIdf(idf_t idf, const char *fname)
idff_t fil = NULL; idff_t fil = NULL;
SDL_RWops *n; SDL_RWops *n;
fil = idf_open(idf, fname); fil = idf_open(idf, fname);
if (!fil) if (!fil) {
return SDL_RWFromFile(dirpath(fname), "rb"); if (!idf || !idf->idfonly)
return SDL_RWFromFile(dirpath(fname), "rb");
return NULL;
}
n = SDL_AllocRW(); n = SDL_AllocRW();
if (!n) if (!n)
goto err; goto err;

View file

@ -24,5 +24,6 @@ extern int idf_error(idff_t idf);
extern int idf_access(idf_t idf, const char *fname); extern int idf_access(idf_t idf, const char *fname);
extern char *idf_gets(idff_t idf, char *b, int size); extern char *idf_gets(idff_t idf, char *b, int size);
extern int idf_magic(const char *fname); extern int idf_magic(const char *fname);
extern int idf_only(idf_t idf, int fl);
#endif #endif

View file

@ -231,9 +231,9 @@ static void games_menu(void)
else else
snprintf(tmp, sizeof(tmp), "<l><a:%s>%s</a></l>", games[i].dir, games[i].name); 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)) 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); snprintf(tmp + strlen(tmp), sizeof(tmp), " [<a:/remove_%d>X</a>]\n", i);
else } else
strcat(tmp, "\n"); strcat(tmp, "\n");
strcat(menu_buff, tmp); strcat(menu_buff, tmp);

View file

@ -585,7 +585,7 @@ int game_theme_optimize(void)
static int game_theme_update_data(void) static int game_theme_update_data(void)
{ {
struct game_theme *t = &game_theme; struct game_theme *t = &game_theme;
int idf = idf_only(game_idf, 0);
if (t->font_name && (t->changed & CHANGED_FONT)) { if (t->font_name && (t->changed & CHANGED_FONT)) {
fnt_free(t->font); fnt_free(t->font);
if (!(t->font = fnt_load(t->font_name, FONT_SZ(t->font_size)))) 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"); fprintf(stderr,"Can't init theme. Not all required elements are defined.\n");
goto err; goto err;
} }
idf_only(game_idf, idf);
return 0; return 0;
err: err:
idf_only(game_idf, idf);
t->changed = 0; t->changed = 0;
return -1; return -1;
} }
@ -894,19 +896,19 @@ int game_theme_load(const char *name)
{ {
struct theme *theme; struct theme *theme;
char cwd[PATH_MAX]; char cwd[PATH_MAX];
int rc = -1;
int rel = theme_relative; int rel = theme_relative;
getdir(cwd, sizeof(cwd)); getdir(cwd, sizeof(cwd));
setdir(game_cwd); setdir(game_cwd);
theme = theme_lookup(name); theme = theme_lookup(name);
theme_relative = 0; theme_relative = 0;
if (!theme || setdir(theme->path) || theme_load(THEME_FILE)) { if (!theme || setdir(theme->path) || theme_load(THEME_FILE))
setdir(cwd); goto err;
theme_relative = rel; rc = 0;
return -1; err:
}
setdir(cwd); setdir(cwd);
theme_relative = rel; theme_relative = rel;
return 0; return rc;
} }
int game_theme_select(const char *name) int game_theme_select(const char *name)

View file

@ -304,7 +304,7 @@ char *sdl_path(char *p)
unix_path(p); unix_path(p);
return p; return p;
} }
#if 1 #if 0
int setdir(const char *path) int setdir(const char *path)
{ {
return chdir(path); return chdir(path);