{
struct stat filestat;
if (stat(filename, &filestat) == -1)
+ {
return NO;
+ }
else
+ {
+ if(S_ISREG(filestat.st_mode))
return YES;
+ else
+ return NO;
+ }
}
/* Can we write to this location? */
/* Get all names of sub-directories in a certain directory. */
/* Returns the number of sub-directories found. */
/* Note: The user has to free the allocated space. */
-char ** dsubdirs(char *rel_path, char* expected_file, int* num)
+string_list_type dsubdirs(char *rel_path, char* expected_file)
{
DIR *dirStructP;
struct dirent *direntp;
int i = 0;
- char ** sdirs= NULL;
+ string_list_type sdirs;
char filename[1024];
char path[1024];
+ string_list_init(&sdirs);
sprintf(path,"%s/%s",st_dir,rel_path);
if((dirStructP = opendir(path)) != NULL)
{
continue;
}
- sdirs = (char**) realloc(sdirs, sizeof(char*) * (i+1));
- sdirs[i] = (char*) malloc(sizeof(char) * strlen(direntp->d_name) + 1 );
- strcpy(sdirs[i],direntp->d_name);
- ++i;
+ string_list_add_item(&sdirs,direntp->d_name);
}
}
closedir(dirStructP);
}
}
- sdirs = (char**) realloc(sdirs, sizeof(char*) * (i+1));
- sdirs[i] = (char*) malloc(sizeof(char) * strlen(direntp->d_name) + 1 );
- strcpy(sdirs[i],direntp->d_name);
- ++i;
+ string_list_add_item(&sdirs,direntp->d_name);
+ }
+ }
+ closedir(dirStructP);
+ }
+
+ return sdirs;
+}
+
+string_list_type dfiles(char *rel_path, char* glob, char* exception_str)
+{
+ DIR *dirStructP;
+ struct dirent *direntp;
+ int i = 0;
+ string_list_type sdirs;
+ char filename[1024];
+ char path[1024];
+
+ string_list_init(&sdirs);
+ sprintf(path,"%s/%s",st_dir,rel_path);
+ if((dirStructP = opendir(path)) != NULL)
+ {
+ while((direntp = readdir(dirStructP)) != NULL)
+ {
+ char absolute_filename[1024];
+ struct stat buf;
+
+ sprintf(absolute_filename, "%s/%s", path, direntp->d_name);
+
+ if (stat(absolute_filename, &buf) == 0 && S_ISREG(buf.st_mode))
+ {
+ if(exception_str != NULL)
+ {
+ if(strstr(direntp->d_name,exception_str) != NULL)
+ continue;
+ }
+ if(glob != NULL)
+ if(strstr(direntp->d_name,glob) == NULL)
+ continue;
+
+ string_list_add_item(&sdirs,direntp->d_name);
+ }
+ }
+ closedir(dirStructP);
+ }
+
+ sprintf(path,"%s/%s",DATA_PREFIX,rel_path);
+ if((dirStructP = opendir(path)) != NULL)
+ {
+ while((direntp = readdir(dirStructP)) != NULL)
+ {
+ char absolute_filename[1024];
+ struct stat buf;
+
+ sprintf(absolute_filename, "%s/%s", path, direntp->d_name);
+
+ if (stat(absolute_filename, &buf) == 0 && S_ISREG(buf.st_mode))
+ {
+ if(exception_str != NULL)
+ {
+ if(strstr(direntp->d_name,exception_str) != NULL)
+ continue;
+ }
+ if(glob != NULL)
+ if(strstr(direntp->d_name,glob) == NULL)
+ continue;
+
+ string_list_add_item(&sdirs,direntp->d_name);
}
}
closedir(dirStructP);
}
- *num = i;
return sdirs;
}
strlen("/.supertux") + 1));
strcpy(st_dir, home);
strcat(st_dir, "/.supertux");
+
+ /* Remove .supertux config-file from old SuperTux versions */
+ if(faccessible(st_dir))
+ {
+ remove(st_dir);
+ }
st_save_dir = (char *) malloc(sizeof(char) * (strlen(st_dir) + strlen("/save") + 1));
menu_additem(&main_menu,menu_item_create(MN_GOTO,"Load Game",0,&load_game_menu));
menu_additem(&main_menu,menu_item_create(MN_GOTO,"Options",0,&options_menu));
menu_additem(&main_menu,menu_item_create(MN_ACTION,"Level editor",0,0));
+ menu_additem(&main_menu,menu_item_create(MN_ACTION,"Credits",0,0));
menu_additem(&main_menu,menu_item_create(MN_HL,"",0,0));
menu_additem(&main_menu,menu_item_create(MN_ACTION,"Quit",0,0));
{
if(save == YES)
{
- savegame(slot);
+ savegame(slot - 1);
}
else
{
if(game_started == NO)
- gameloop("whatever",slot,ST_GL_LOAD_GAME);
+ {
+ gameloop("default",slot - 1,ST_GL_LOAD_GAME);
+ show_menu = YES;
+ menu_set_current(&main_menu);
+ }
else
- loadgame(slot);
+ loadgame(slot - 1);
}
st_pause_ticks_stop();
}
text_load(&red_text,DATA_PREFIX "/images/status/letters-red.png", TEXT_TEXT, 16,18);
text_load(&white_text,DATA_PREFIX "/images/status/letters-white.png", TEXT_TEXT, 16,18);
text_load(&white_small_text,DATA_PREFIX "/images/status/letters-white-small.png", TEXT_TEXT, 8,9);
+ text_load(&white_big_text,DATA_PREFIX "/images/status/letters-white-big.png", TEXT_TEXT, 20,23);
text_load(&yellow_nums,DATA_PREFIX "/images/status/numbers.png", TEXT_NUM, 32,32);
/* Load GUI/menu images: */
texture_load(&checkbox, DATA_PREFIX "/images/status/checkbox.png", USE_ALPHA);
texture_load(&checkbox_checked, DATA_PREFIX "/images/status/checkbox-checked.png", USE_ALPHA);
texture_load(&back, DATA_PREFIX "/images/status/back.png", USE_ALPHA);
+ texture_load(&arrow_left, DATA_PREFIX "/images/icons/left.png", USE_ALPHA);
+ texture_load(&arrow_right, DATA_PREFIX "/images/icons/right.png", USE_ALPHA);
/* Set icon image: */
text_free(&blue_text);
text_free(&red_text);
text_free(&white_small_text);
+ text_free(&white_big_text);
/* Free GUI/menu images: */
texture_free(&checkbox);
texture_free(&checkbox_checked);
texture_free(&back);
-
+ texture_free(&arrow_left);
+ texture_free(&arrow_right);
+
/* Free menus */
menu_free(&main_menu);
menu_free(&game_menu);
menu_free(&options_menu);
menu_free(&highscore_menu);
+ menu_free(&save_game_menu);
+ menu_free(&load_game_menu);
}