Esempio n. 1
0
int fill_replayview_menu(MenuData *m) {
	DIR *dir = opendir(get_replays_path());
	struct dirent *e;
	int rpys = 0;
	
	if(!dir) {
		printf("Could't read %s\n", get_replays_path());
		return -1;
	}
	
	char ext[5];
	snprintf(ext, 5, ".%s", REPLAY_EXTENSION);
	
	while((e = readdir(dir))) {
		if(!strendswith(e->d_name, ext))
			continue;
		
		Replay *rpy = malloc(sizeof(Replay));
		if(!replay_load(rpy, e->d_name)) {
			free(rpy);
			continue;
		}
		
		add_menu_entry(m, " ", replayview_run, rpy);
		m->entries[m->ecount-1].freearg = replayview_freearg;
		m->entries[m->ecount-1].draw = replayview_drawitem;
		++rpys;
	}
	
	closedir(dir);
	
	qsort(m->entries, m->ecount, sizeof(MenuEntry), replayview_cmp);
	return rpys;
}
Esempio n. 2
0
char* replay_getpath(char *name, int ext) {
	char *p = (char*)malloc(strlen(get_replays_path()) + strlen(name) + strlen(REPLAY_EXTENSION) + 3);
	if(ext)
		sprintf(p, "%s/%s.%s", get_replays_path(), name, REPLAY_EXTENSION);
	else
		sprintf(p, "%s/%s", get_replays_path(), name);
	return p;
}