src/fios.cpp
changeset 6380 f5c826d923ee
parent 6008 1ed2f76ac388
child 6412 a77de25206bc
equal deleted inserted replaced
6379:d3989ef77735 6380:f5c826d923ee
   210 	struct stat sb;
   210 	struct stat sb;
   211 	struct dirent *dirent;
   211 	struct dirent *dirent;
   212 	DIR *dir;
   212 	DIR *dir;
   213 	FiosItem *fios;
   213 	FiosItem *fios;
   214 	int sort_start;
   214 	int sort_start;
       
   215 	char d_name[sizeof(fios->name)];
   215 
   216 
   216 	/* A parent directory link exists if we are not in the root directory */
   217 	/* A parent directory link exists if we are not in the root directory */
   217 	if (!FiosIsRoot(_fios_path) && mode != SLD_NEW_GAME) {
   218 	if (!FiosIsRoot(_fios_path) && mode != SLD_NEW_GAME) {
   218 		fios = FiosAlloc();
   219 		fios = FiosAlloc();
   219 		fios->type = FIOS_TYPE_PARENT;
   220 		fios->type = FIOS_TYPE_PARENT;
   223 	}
   224 	}
   224 
   225 
   225 	/* Show subdirectories */
   226 	/* Show subdirectories */
   226 	if (mode != SLD_NEW_GAME && (dir = opendir(_fios_path)) != NULL) {
   227 	if (mode != SLD_NEW_GAME && (dir = opendir(_fios_path)) != NULL) {
   227 		while ((dirent = readdir(dir)) != NULL) {
   228 		while ((dirent = readdir(dir)) != NULL) {
   228 			const char *d_name = FS2OTTD(dirent->d_name);
   229 			ttd_strlcpy(d_name, FS2OTTD(dirent->d_name), sizeof(d_name));
   229 
   230 
   230 			/* found file must be directory, but not '.' or '..' */
   231 			/* found file must be directory, but not '.' or '..' */
   231 			if (FiosIsValidFile(_fios_path, dirent, &sb) && (sb.st_mode & S_IFDIR) &&
   232 			if (FiosIsValidFile(_fios_path, dirent, &sb) && (sb.st_mode & S_IFDIR) &&
   232 				strcmp(d_name, ".") != 0 && strcmp(d_name, "..") != 0) {
   233 				strcmp(d_name, ".") != 0 && strcmp(d_name, "..") != 0) {
   233 				fios = FiosAlloc();
   234 				fios = FiosAlloc();
   256 	dir = opendir(_fios_path);
   257 	dir = opendir(_fios_path);
   257 	if (dir != NULL) {
   258 	if (dir != NULL) {
   258 		while ((dirent = readdir(dir)) != NULL) {
   259 		while ((dirent = readdir(dir)) != NULL) {
   259 			char fios_title[64];
   260 			char fios_title[64];
   260 			char *t;
   261 			char *t;
   261 			char *d_name = (char*)FS2OTTD(dirent->d_name);
   262 			ttd_strlcpy(d_name, FS2OTTD(dirent->d_name), sizeof(d_name));
   262 			byte type;
       
   263 
   263 
   264 			if (!FiosIsValidFile(_fios_path, dirent, &sb) || !(sb.st_mode & S_IFREG)) continue;
   264 			if (!FiosIsValidFile(_fios_path, dirent, &sb) || !(sb.st_mode & S_IFREG)) continue;
   265 
   265 
   266 			/* File has no extension, skip it */
   266 			/* File has no extension, skip it */
   267 			if ((t = strrchr(d_name, '.')) == NULL) continue;
   267 			if ((t = strrchr(d_name, '.')) == NULL) continue;
   268 			fios_title[0] = '\0'; // reset the title;
   268 			fios_title[0] = '\0'; // reset the title;
   269 
   269 
   270 			type = callback_proc(mode, d_name, t, fios_title);
   270 			byte type = callback_proc(mode, d_name, t, fios_title);
   271 			if (type != FIOS_TYPE_INVALID) {
   271 			if (type != FIOS_TYPE_INVALID) {
   272 				fios = FiosAlloc();
   272 				fios = FiosAlloc();
   273 				fios->mtime = sb.st_mtime;
   273 				fios->mtime = sb.st_mtime;
   274 				fios->type = type;
   274 				fios->type = type;
   275 				ttd_strlcpy(fios->name, d_name, lengthof(fios->name));
   275 				ttd_strlcpy(fios->name, d_name, lengthof(fios->name));