equal
deleted
inserted
replaced
1 /* $Id$ */ |
1 /* $Id$ */ |
2 |
2 |
3 /** @file newgrf_config.cpp */ |
3 /** @file newgrf_config.cpp Finding NewGRFs and configuring them. */ |
4 |
4 |
5 #include "stdafx.h" |
5 #include "stdafx.h" |
6 #include "openttd.h" |
6 #include "openttd.h" |
7 #include "debug.h" |
7 #include "debug.h" |
8 #include "variables.h" |
8 #include "variables.h" |
15 #include "string_func.h" |
15 #include "string_func.h" |
16 |
16 |
17 #include "fileio.h" |
17 #include "fileio.h" |
18 #include "fios.h" |
18 #include "fios.h" |
19 #include <sys/stat.h> |
19 #include <sys/stat.h> |
20 |
|
21 #ifdef WIN32 |
|
22 # include <io.h> |
|
23 #endif /* WIN32 */ |
|
24 |
20 |
25 |
21 |
26 GRFConfig *_all_grfs; |
22 GRFConfig *_all_grfs; |
27 GRFConfig *_grfconfig; |
23 GRFConfig *_grfconfig; |
28 GRFConfig *_grfconfig_newgame; |
24 GRFConfig *_grfconfig_newgame; |
337 |
333 |
338 return added; |
334 return added; |
339 } |
335 } |
340 |
336 |
341 /* Scan a path for NewGRFs */ |
337 /* Scan a path for NewGRFs */ |
342 static uint ScanPath(const char *path, int basepath_length) |
338 static uint ScanPath(const char *path, size_t basepath_length) |
343 { |
339 { |
344 extern bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb); |
340 extern bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb); |
345 |
341 |
346 uint num = 0; |
342 uint num = 0; |
347 struct stat sb; |
343 struct stat sb; |
434 |
430 |
435 /* Sort the linked list using quicksort. |
431 /* Sort the linked list using quicksort. |
436 * For that we first have to make an array, the qsort and |
432 * For that we first have to make an array, the qsort and |
437 * then remake the linked list. */ |
433 * then remake the linked list. */ |
438 GRFConfig **to_sort = MallocT<GRFConfig*>(num); |
434 GRFConfig **to_sort = MallocT<GRFConfig*>(num); |
439 if (to_sort == NULL) return; // No memory, then don't sort |
|
440 |
435 |
441 uint i = 0; |
436 uint i = 0; |
442 for (GRFConfig *p = _all_grfs; p != NULL; p = p->next, i++) { |
437 for (GRFConfig *p = _all_grfs; p != NULL; p = p->next, i++) { |
443 to_sort[i] = p; |
438 to_sort[i] = p; |
444 } |
439 } |
450 for (i = 1; i < num; i++) { |
445 for (i = 1; i < num; i++) { |
451 to_sort[i - 1]->next = to_sort[i]; |
446 to_sort[i - 1]->next = to_sort[i]; |
452 } |
447 } |
453 to_sort[num - 1]->next = NULL; |
448 to_sort[num - 1]->next = NULL; |
454 _all_grfs = to_sort[0]; |
449 _all_grfs = to_sort[0]; |
|
450 |
|
451 free(to_sort); |
455 } |
452 } |
456 |
453 |
457 |
454 |
458 /* Find a NewGRF in the scanned list, if md5sum is NULL, we don't care about it*/ |
455 /* Find a NewGRF in the scanned list, if md5sum is NULL, we don't care about it*/ |
459 const GRFConfig *FindGRFConfig(uint32 grfid, const uint8 *md5sum) |
456 const GRFConfig *FindGRFConfig(uint32 grfid, const uint8 *md5sum) |