265 } |
265 } |
266 |
266 |
267 return res; |
267 return res; |
268 } |
268 } |
269 |
269 |
270 static bool ScanPathAddGrf(const char *filename) |
270 static bool ScanPathAddGrf(const char *filename, Subdirectory subdir) |
271 { |
271 { |
272 GRFConfig *c = CallocT<GRFConfig>(1); |
272 GRFConfig *c = CallocT<GRFConfig>(1); |
273 c->filename = strdup(filename); |
273 c->filename = strdup(filename); |
|
274 |
|
275 // flag GRFs that are loaded from cache |
|
276 if (subdir == CACHE_DIR) |
|
277 SetBit(c->flags, GCF_CACHE); |
274 |
278 |
275 bool added = true; |
279 bool added = true; |
276 if (FillGRFDetails(c, false)) { |
280 if (FillGRFDetails(c, false)) { |
277 if (_all_grfs == NULL) { |
281 if (_all_grfs == NULL) { |
278 _all_grfs = c; |
282 _all_grfs = c; |
312 |
316 |
313 return added; |
317 return added; |
314 } |
318 } |
315 |
319 |
316 /* Scan a path for NewGRFs */ |
320 /* Scan a path for NewGRFs */ |
317 static uint ScanPath(const char *path, size_t basepath_length) |
321 static uint ScanPath(const char *path, size_t basepath_length, Subdirectory subdir) |
318 { |
322 { |
319 extern bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb); |
323 extern bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb); |
320 |
324 |
321 uint num = 0; |
325 uint num = 0; |
322 struct stat sb; |
326 struct stat sb; |
335 |
339 |
336 if (sb.st_mode & S_IFDIR) { |
340 if (sb.st_mode & S_IFDIR) { |
337 /* Directory */ |
341 /* Directory */ |
338 if (strcmp(d_name, ".") == 0 || strcmp(d_name, "..") == 0) continue; |
342 if (strcmp(d_name, ".") == 0 || strcmp(d_name, "..") == 0) continue; |
339 AppendPathSeparator(filename, lengthof(filename)); |
343 AppendPathSeparator(filename, lengthof(filename)); |
340 num += ScanPath(filename, basepath_length); |
344 num += ScanPath(filename, basepath_length, subdir); |
341 } else if (sb.st_mode & S_IFREG) { |
345 } else if (sb.st_mode & S_IFREG) { |
342 /* File */ |
346 /* File */ |
343 char *ext = strrchr(filename, '.'); |
347 char *ext = strrchr(filename, '.'); |
344 |
348 |
345 /* If no extension or extension isn't .grf, skip the file */ |
349 /* If no extension or extension isn't .grf, skip the file */ |
346 if (ext == NULL) continue; |
350 if (ext == NULL) continue; |
347 if (strcasecmp(ext, ".grf") != 0) continue; |
351 if (strcasecmp(ext, ".grf") != 0) continue; |
348 |
352 |
349 if (ScanPathAddGrf(filename + basepath_length)) num++; |
353 if (ScanPathAddGrf(filename + basepath_length, subdir)) num++; |
350 } |
354 } |
351 } |
355 } |
352 |
356 |
353 closedir(dir); |
357 closedir(dir); |
354 |
358 |
363 |
367 |
364 /* If no extension or extension isn't .grf, skip the file */ |
368 /* If no extension or extension isn't .grf, skip the file */ |
365 if (ext == NULL) return false; |
369 if (ext == NULL) return false; |
366 if (strcasecmp(ext, ".grf") != 0) return false; |
370 if (strcasecmp(ext, ".grf") != 0) return false; |
367 |
371 |
368 if (ScanPathAddGrf(filename)) num++; |
372 if (ScanPathAddGrf(filename, (*tar).second.tar->subdir)) num++; |
369 |
373 |
370 return num; |
374 return num; |
371 } |
375 } |
372 |
376 |
373 /** |
377 /** |
396 ClearGRFConfigList(&_all_grfs); |
400 ClearGRFConfigList(&_all_grfs); |
397 |
401 |
398 DEBUG(grf, 1, "Scanning for NewGRFs"); |
402 DEBUG(grf, 1, "Scanning for NewGRFs"); |
399 FOR_ALL_SEARCHPATHS(sp) { |
403 FOR_ALL_SEARCHPATHS(sp) { |
400 FioAppendDirectory(path, MAX_PATH, sp, DATA_DIR); |
404 FioAppendDirectory(path, MAX_PATH, sp, DATA_DIR); |
401 num += ScanPath(path, strlen(path)); |
405 num += ScanPath(path, strlen(path), DATA_DIR); |
402 } |
406 } |
403 FOR_ALL_TARS(tar) { |
407 FOR_ALL_TARS(tar) { |
404 num += ScanTar(tar); |
408 num += ScanTar(tar); |
405 } |
409 } |
406 |
410 |