idf flying

This commit is contained in:
p.kosyh 2011-04-19 09:26:54 +00:00
parent 7cba06836a
commit 0ce0974a54
6 changed files with 48 additions and 13 deletions

View file

@ -175,7 +175,19 @@ int game_select(const char *name)
static char *game_name(const char *path, const char *d_name)
{
char *l;
char *p = getfilepath(path, MAIN_FILE);
char *p;
if (idf_magic(path)) {
idf_t idf = idf_init(path);
idff_t idff = idf_open(idf, MAIN_FILE);
l = lookup_lang_tag_idf(idff, "Name", "--");
idf_close(idff);
idf_done(idf);
if (l)
return l;
goto err;
}
p = getfilepath(path, MAIN_FILE);
if (!p)
goto err;
l = lookup_lang_tag(p, "Name", "--");

View file

@ -473,6 +473,8 @@ idff_t idf_open(idf_t idf, const char *fname)
idfd_t *dir = NULL;
idff_t fil = NULL;
char *p;
if (!idf || !fname)
return NULL;
p = strdup(fname);
if (!p)
return NULL;

View file

@ -109,7 +109,8 @@ char *open_file_dialog(void)
file_filter_zip = gtk_file_filter_new();
gtk_file_filter_add_pattern(file_filter_zip, "*.zip");
gtk_file_filter_add_pattern(file_filter_zip, "main.lua");
gtk_file_filter_set_name(file_filter_zip, "main.lua; *.zip");
gtk_file_filter_add_pattern(file_filter_zip, "*.idf");
gtk_file_filter_set_name(file_filter_zip, "main.lua; *.zip; *.idf");
/*
file_filter_lua = gtk_file_filter_new();

View file

@ -390,23 +390,28 @@ void unix_path(char *path)
return;
}
char *lookup_tag(const char *fname, const char *tag, const char *comm)
static char *lookup_tag_all(const char *tag, const char *comm, char *(*getl)(void *p, char *s, int size), void *fp)
{
int brk = 0;
char *l; char line[1024];
while ((l = getl(fp, line, sizeof(line))) && !brk) {
l = parse_tag(l, tag, comm, &brk);
if (l)
return l;
}
return NULL;
}
char *lookup_tag(const char *fname, const char *tag, const char *comm)
{
char *l;
FILE *fd = fopen(fname, "rb");
if (!fd)
return NULL;
while ((l = fgets(line, sizeof(line), fd)) && !brk) {
l = parse_tag(l, tag, comm, &brk);
if (l) {
fclose(fd);
return l;
}
}
l = lookup_tag_all(tag, comm, file_gets, fd);
fclose(fd);
return NULL;
return l;
}
char *lookup_lang_tag(const char *fname, const char *tag, const char *comm)
@ -420,6 +425,19 @@ char *lookup_lang_tag(const char *fname, const char *tag, const char *comm)
return l;
}
char *lookup_lang_tag_idf(idff_t idf, const char *tag, const char *comm)
{
char lang_tag[1024];
char *l;
if (!idf)
return NULL;
snprintf(lang_tag, sizeof(lang_tag), "%s(%s)", tag, opt_lang);
l = lookup_tag_all(lang_tag, comm, idff_gets, idf);
if (!l)
l = lookup_tag_all(tag, comm, idff_gets, idf);
return l;
}
char *parse_tag(char *line, const char *tag, const char *comm, int *brk)
{
char *l = line;

View file

@ -24,6 +24,8 @@ char *getfilepath(const char *d, const char *n);
extern char *lookup_tag(const char *fname, const char *tag, const char *comm);
extern char *lookup_lang_tag(const char *fname, const char *tag, const char *comm);
extern char *lookup_lang_tag_idf(idff_t idf, const char *tag, const char *comm);
extern int parse_esc_string(const char *v, void *data);
extern int parse_string(const char *v, void *data);
extern int parse_int(const char *v, void *data);

View file

@ -261,7 +261,7 @@ char *open_file_dialog(void)
ofn.lpstrFile = szFile ;
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = sizeof( szFile );
ofn.lpstrFilter = "*.*\0*.*\0main.lua;*.zip\0main.lua;*.zip\0\0";
ofn.lpstrFilter = "*.*\0*.*\0main.lua;*.zip;*.idf\0main.lua;*.zip;*.idf\0\0";
ofn.nFilterIndex = 2;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;