OpenTTD
fios.cpp
Go to the documentation of this file.
1 /* $Id$ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8  */
9 
15 #include "stdafx.h"
16 #include "fios.h"
17 #include "fileio_func.h"
18 #include "tar_type.h"
19 #include "screenshot.h"
20 #include "string_func.h"
21 #include <sys/stat.h>
22 
23 #ifndef _WIN32
24 # include <unistd.h>
25 #endif /* _WIN32 */
26 
27 #include "table/strings.h"
28 
29 #include "safeguards.h"
30 
31 /* Variables to display file lists */
32 static char *_fios_path;
33 static const char *_fios_path_last;
34 SortingBits _savegame_sort_order = SORT_BY_DATE | SORT_DESCENDING;
35 
36 /* OS-specific functions are taken from their respective files (win32/unix/os2 .c) */
37 extern bool FiosIsRoot(const char *path);
38 extern bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb);
39 extern bool FiosIsHiddenFile(const struct dirent *ent);
40 extern void FiosGetDrives(FileList &file_list);
41 extern bool FiosGetDiskFreeSpace(const char *path, uint64 *tot);
42 
43 /* get the name of an oldstyle savegame */
44 extern void GetOldSaveGameName(const char *file, char *title, const char *last);
45 
52 int CDECL CompareFiosItems(const FiosItem *da, const FiosItem *db)
53 {
54  int r = 0;
55 
56  if ((_savegame_sort_order & SORT_BY_NAME) == 0 && da->mtime != db->mtime) {
57  r = da->mtime < db->mtime ? -1 : 1;
58  } else {
59  r = strcasecmp(da->title, db->title);
60  }
61 
62  if (_savegame_sort_order & SORT_DESCENDING) r = -r;
63  return r;
64 }
65 
66 FileList::~FileList()
67 {
68  this->Clear();
69 }
70 
77 {
78  this->Clear();
79 
80  assert(fop == SLO_LOAD || fop == SLO_SAVE);
81  switch (abstract_filetype) {
82  case FT_NONE:
83  break;
84 
85  case FT_SAVEGAME:
86  FiosGetSavegameList(fop, *this);
87  break;
88 
89  case FT_SCENARIO:
90  FiosGetScenarioList(fop, *this);
91  break;
92 
93  case FT_HEIGHTMAP:
94  FiosGetHeightmapList(fop, *this);
95  break;
96 
97  default:
98  NOT_REACHED();
99  }
100 }
101 
108 const FiosItem *FileList::FindItem(const char *file)
109 {
110  for (const FiosItem *item = this->Begin(); item != this->End(); item++) {
111  if (strcmp(file, item->name) == 0) return item;
112  if (strcmp(file, item->title) == 0) return item;
113  }
114 
115  /* If no name matches, try to parse it as number */
116  char *endptr;
117  int i = strtol(file, &endptr, 10);
118  if (file == endptr || *endptr != '\0') i = -1;
119 
120  if (IsInsideMM(i, 0, this->Length())) return this->Get(i);
121 
122  /* As a last effort assume it is an OpenTTD savegame and
123  * that the ".sav" part was not given. */
124  char long_file[MAX_PATH];
125  seprintf(long_file, lastof(long_file), "%s.sav", file);
126  for (const FiosItem *item = this->Begin(); item != this->End(); item++) {
127  if (strcmp(long_file, item->name) == 0) return item;
128  if (strcmp(long_file, item->title) == 0) return item;
129  }
130 
131  return NULL;
132 }
133 
141 StringID FiosGetDescText(const char **path, uint64 *total_free)
142 {
143  *path = _fios_path;
144  return FiosGetDiskFreeSpace(*path, total_free) ? STR_SAVELOAD_BYTES_FREE : STR_ERROR_UNABLE_TO_READ_DRIVE;
145 }
146 
152 const char *FiosBrowseTo(const FiosItem *item)
153 {
154  switch (item->type) {
155  case FIOS_TYPE_DRIVE:
156 #if defined(_WIN32) || defined(__OS2__)
157  seprintf(_fios_path, _fios_path_last, "%c:" PATHSEP, item->title[0]);
158 #endif
159  break;
160 
161  case FIOS_TYPE_INVALID:
162  break;
163 
164  case FIOS_TYPE_PARENT: {
165  /* Check for possible NULL ptr (not required for UNIXes, but AmigaOS-alikes) */
166  char *s = strrchr(_fios_path, PATHSEPCHAR);
167  if (s != NULL && s != _fios_path) {
168  s[0] = '\0'; // Remove last path separator character, so we can go up one level.
169  }
170  s = strrchr(_fios_path, PATHSEPCHAR);
171  if (s != NULL) {
172  s[1] = '\0'; // go up a directory
173 #if defined(__MORPHOS__) || defined(__AMIGAOS__)
174  /* On MorphOS or AmigaOS paths look like: "Volume:directory/subdirectory" */
175  } else if ((s = strrchr(_fios_path, ':')) != NULL) {
176  s[1] = '\0';
177 #endif
178  }
179  break;
180  }
181 
182  case FIOS_TYPE_DIR:
183  strecat(_fios_path, item->name, _fios_path_last);
184  strecat(_fios_path, PATHSEP, _fios_path_last);
185  break;
186 
187  case FIOS_TYPE_DIRECT:
188  seprintf(_fios_path, _fios_path_last, "%s", item->name);
189  break;
190 
191  case FIOS_TYPE_FILE:
192  case FIOS_TYPE_OLDFILE:
193  case FIOS_TYPE_SCENARIO:
194  case FIOS_TYPE_OLD_SCENARIO:
195  case FIOS_TYPE_PNG:
196  case FIOS_TYPE_BMP:
197  return item->name;
198  }
199 
200  return NULL;
201 }
202 
211 static void FiosMakeFilename(char *buf, const char *path, const char *name, const char *ext, const char *last)
212 {
213  const char *period;
214 
215  /* Don't append the extension if it is already there */
216  period = strrchr(name, '.');
217  if (period != NULL && strcasecmp(period, ext) == 0) ext = "";
218 #if defined(__MORPHOS__) || defined(__AMIGAOS__)
219  if (path != NULL) {
220  unsigned char sepchar = path[(strlen(path) - 1)];
221 
222  if (sepchar != ':' && sepchar != '/') {
223  seprintf(buf, last, "%s" PATHSEP "%s%s", path, name, ext);
224  } else {
225  seprintf(buf, last, "%s%s%s", path, name, ext);
226  }
227  } else {
228  seprintf(buf, last, "%s%s", name, ext);
229  }
230 #else
231  seprintf(buf, last, "%s" PATHSEP "%s%s", path, name, ext);
232 #endif
233 }
234 
241 void FiosMakeSavegameName(char *buf, const char *name, const char *last)
242 {
243  const char *extension = (_game_mode == GM_EDITOR) ? ".scn" : ".sav";
244 
245  FiosMakeFilename(buf, _fios_path, name, extension, last);
246 }
247 
254 void FiosMakeHeightmapName(char *buf, const char *name, const char *last)
255 {
256  char ext[5];
257  ext[0] = '.';
258  strecpy(ext + 1, GetCurrentScreenshotExtension(), lastof(ext));
259 
260  FiosMakeFilename(buf, _fios_path, name, ext, last);
261 }
262 
268 bool FiosDelete(const char *name)
269 {
270  char filename[512];
271 
272  FiosMakeSavegameName(filename, name, lastof(filename));
273  return unlink(filename) == 0;
274 }
275 
276 typedef FiosType fios_getlist_callback_proc(SaveLoadOperation fop, const char *filename, const char *ext, char *title, const char *last);
277 
281 class FiosFileScanner : public FileScanner {
283  fios_getlist_callback_proc *callback_proc;
285 public:
292  FiosFileScanner(SaveLoadOperation fop, fios_getlist_callback_proc *callback_proc, FileList &file_list) :
293  fop(fop), callback_proc(callback_proc), file_list(file_list)
294  {}
295 
296  /* virtual */ bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename);
297 };
298 
305 bool FiosFileScanner::AddFile(const char *filename, size_t basepath_length, const char *tar_filename)
306 {
307  const char *ext = strrchr(filename, '.');
308  if (ext == NULL) return false;
309 
310  char fios_title[64];
311  fios_title[0] = '\0'; // reset the title;
312 
313  FiosType type = this->callback_proc(this->fop, filename, ext, fios_title, lastof(fios_title));
314  if (type == FIOS_TYPE_INVALID) return false;
315 
316  for (const FiosItem *fios = file_list.Begin(); fios != file_list.End(); fios++) {
317  if (strcmp(fios->name, filename) == 0) return false;
318  }
319 
320  FiosItem *fios = file_list.Append();
321 #ifdef _WIN32
322  struct _stat sb;
323  if (_tstat(OTTD2FS(filename), &sb) == 0) {
324 #else
325  struct stat sb;
326  if (stat(filename, &sb) == 0) {
327 #endif
328  fios->mtime = sb.st_mtime;
329  } else {
330  fios->mtime = 0;
331  }
332 
333  fios->type = type;
334  strecpy(fios->name, filename, lastof(fios->name));
335 
336  /* If the file doesn't have a title, use its filename */
337  const char *t = fios_title;
338  if (StrEmpty(fios_title)) {
339  t = strrchr(filename, PATHSEPCHAR);
340  t = (t == NULL) ? filename : (t + 1);
341  }
342  strecpy(fios->title, t, lastof(fios->title));
343  str_validate(fios->title, lastof(fios->title));
344 
345  return true;
346 }
347 
348 
356 static void FiosGetFileList(SaveLoadOperation fop, fios_getlist_callback_proc *callback_proc, Subdirectory subdir, FileList &file_list)
357 {
358  struct stat sb;
359  struct dirent *dirent;
360  DIR *dir;
361  FiosItem *fios;
362  int sort_start;
363  char d_name[sizeof(fios->name)];
364 
365  file_list.Clear();
366 
367  /* A parent directory link exists if we are not in the root directory */
368  if (!FiosIsRoot(_fios_path)) {
369  fios = file_list.Append();
370  fios->type = FIOS_TYPE_PARENT;
371  fios->mtime = 0;
372  strecpy(fios->name, "..", lastof(fios->name));
373  strecpy(fios->title, ".. (Parent directory)", lastof(fios->title));
374  }
375 
376  /* Show subdirectories */
377  if ((dir = ttd_opendir(_fios_path)) != NULL) {
378  while ((dirent = readdir(dir)) != NULL) {
379  strecpy(d_name, FS2OTTD(dirent->d_name), lastof(d_name));
380 
381  /* found file must be directory, but not '.' or '..' */
382  if (FiosIsValidFile(_fios_path, dirent, &sb) && S_ISDIR(sb.st_mode) &&
383  (!FiosIsHiddenFile(dirent) || strncasecmp(d_name, PERSONAL_DIR, strlen(d_name)) == 0) &&
384  strcmp(d_name, ".") != 0 && strcmp(d_name, "..") != 0) {
385  fios = file_list.Append();
386  fios->type = FIOS_TYPE_DIR;
387  fios->mtime = 0;
388  strecpy(fios->name, d_name, lastof(fios->name));
389  seprintf(fios->title, lastof(fios->title), "%s" PATHSEP " (Directory)", d_name);
390  str_validate(fios->title, lastof(fios->title));
391  }
392  }
393  closedir(dir);
394  }
395 
396  /* Sort the subdirs always by name, ascending, remember user-sorting order */
397  {
398  SortingBits order = _savegame_sort_order;
399  _savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING;
400  QSortT(file_list.files.Begin(), file_list.files.Length(), CompareFiosItems);
401  _savegame_sort_order = order;
402  }
403 
404  /* This is where to start sorting for the filenames */
405  sort_start = file_list.Length();
406 
407  /* Show files */
408  FiosFileScanner scanner(fop, callback_proc, file_list);
409  if (subdir == NO_DIRECTORY) {
410  scanner.Scan(NULL, _fios_path, false);
411  } else {
412  scanner.Scan(NULL, subdir, true, true);
413  }
414 
415  QSortT(file_list.Get(sort_start), file_list.Length() - sort_start, CompareFiosItems);
416 
417  /* Show drives */
418  FiosGetDrives(file_list);
419 
420  file_list.Compact();
421 }
422 
431 static void GetFileTitle(const char *file, char *title, const char *last, Subdirectory subdir)
432 {
433  char buf[MAX_PATH];
434  strecpy(buf, file, lastof(buf));
435  strecat(buf, ".title", lastof(buf));
436 
437  FILE *f = FioFOpenFile(buf, "r", subdir);
438  if (f == NULL) return;
439 
440  size_t read = fread(title, 1, last - title, f);
441  assert(title + read <= last);
442  title[read] = '\0';
443  str_validate(title, last);
444  FioFCloseFile(f);
445 }
446 
458 FiosType FiosGetSavegameListCallback(SaveLoadOperation fop, const char *file, const char *ext, char *title, const char *last)
459 {
460  /* Show savegame files
461  * .SAV OpenTTD saved game
462  * .SS1 Transport Tycoon Deluxe preset game
463  * .SV1 Transport Tycoon Deluxe (Patch) saved game
464  * .SV2 Transport Tycoon Deluxe (Patch) saved 2-player game */
465 
466  /* Don't crash if we supply no extension */
467  if (ext == NULL) return FIOS_TYPE_INVALID;
468 
469  if (strcasecmp(ext, ".sav") == 0) {
470  GetFileTitle(file, title, last, SAVE_DIR);
471  return FIOS_TYPE_FILE;
472  }
473 
474  if (fop == SLO_LOAD) {
475  if (strcasecmp(ext, ".ss1") == 0 || strcasecmp(ext, ".sv1") == 0 ||
476  strcasecmp(ext, ".sv2") == 0) {
477  if (title != NULL) GetOldSaveGameName(file, title, last);
478  return FIOS_TYPE_OLDFILE;
479  }
480  }
481 
482  return FIOS_TYPE_INVALID;
483 }
484 
492 {
493  static char *fios_save_path = NULL;
494  static char *fios_save_path_last = NULL;
495 
496  if (fios_save_path == NULL) {
497  fios_save_path = MallocT<char>(MAX_PATH);
498  fios_save_path_last = fios_save_path + MAX_PATH - 1;
499  FioGetDirectory(fios_save_path, fios_save_path_last, SAVE_DIR);
500  }
501 
502  _fios_path = fios_save_path;
503  _fios_path_last = fios_save_path_last;
504 
506 }
507 
519 static FiosType FiosGetScenarioListCallback(SaveLoadOperation fop, const char *file, const char *ext, char *title, const char *last)
520 {
521  /* Show scenario files
522  * .SCN OpenTTD style scenario file
523  * .SV0 Transport Tycoon Deluxe (Patch) scenario
524  * .SS0 Transport Tycoon Deluxe preset scenario */
525  if (strcasecmp(ext, ".scn") == 0) {
526  GetFileTitle(file, title, last, SCENARIO_DIR);
527  return FIOS_TYPE_SCENARIO;
528  }
529 
530  if (fop == SLO_LOAD) {
531  if (strcasecmp(ext, ".sv0") == 0 || strcasecmp(ext, ".ss0") == 0 ) {
532  GetOldSaveGameName(file, title, last);
533  return FIOS_TYPE_OLD_SCENARIO;
534  }
535  }
536 
537  return FIOS_TYPE_INVALID;
538 }
539 
547 {
548  static char *fios_scn_path = NULL;
549  static char *fios_scn_path_last = NULL;
550 
551  /* Copy the default path on first run or on 'New Game' */
552  if (fios_scn_path == NULL) {
553  fios_scn_path = MallocT<char>(MAX_PATH);
554  fios_scn_path_last = fios_scn_path + MAX_PATH - 1;
555  FioGetDirectory(fios_scn_path, fios_scn_path_last, SCENARIO_DIR);
556  }
557 
558  _fios_path = fios_scn_path;
559  _fios_path_last = fios_scn_path_last;
560 
561  char base_path[MAX_PATH];
562  FioGetDirectory(base_path, lastof(base_path), SCENARIO_DIR);
563 
564  Subdirectory subdir = (fop == SLO_LOAD && strcmp(base_path, _fios_path) == 0) ? SCENARIO_DIR : NO_DIRECTORY;
565  FiosGetFileList(fop, &FiosGetScenarioListCallback, subdir, file_list);
566 }
567 
568 static FiosType FiosGetHeightmapListCallback(SaveLoadOperation fop, const char *file, const char *ext, char *title, const char *last)
569 {
570  /* Show heightmap files
571  * .PNG PNG Based heightmap files
572  * .BMP BMP Based heightmap files
573  */
574 
575  FiosType type = FIOS_TYPE_INVALID;
576 
577 #ifdef WITH_PNG
578  if (strcasecmp(ext, ".png") == 0) type = FIOS_TYPE_PNG;
579 #endif /* WITH_PNG */
580 
581  if (strcasecmp(ext, ".bmp") == 0) type = FIOS_TYPE_BMP;
582 
583  if (type == FIOS_TYPE_INVALID) return FIOS_TYPE_INVALID;
584 
585  TarFileList::iterator it = _tar_filelist[SCENARIO_DIR].find(file);
586  if (it != _tar_filelist[SCENARIO_DIR].end()) {
587  /* If the file is in a tar and that tar is not in a heightmap
588  * directory we are for sure not supposed to see it.
589  * Examples of this are pngs part of documentation within
590  * collections of NewGRFs or 32 bpp graphics replacement PNGs.
591  */
592  bool match = false;
593  Searchpath sp;
594  FOR_ALL_SEARCHPATHS(sp) {
595  char buf[MAX_PATH];
596  FioAppendDirectory(buf, lastof(buf), sp, HEIGHTMAP_DIR);
597 
598  if (strncmp(buf, it->second.tar_filename, strlen(buf)) == 0) {
599  match = true;
600  break;
601  }
602  }
603 
604  if (!match) return FIOS_TYPE_INVALID;
605  }
606 
607  GetFileTitle(file, title, last, HEIGHTMAP_DIR);
608 
609  return type;
610 }
611 
618 {
619  static char *fios_hmap_path = NULL;
620  static char *fios_hmap_path_last = NULL;
621 
622  if (fios_hmap_path == NULL) {
623  fios_hmap_path = MallocT<char>(MAX_PATH);
624  fios_hmap_path_last = fios_hmap_path + MAX_PATH - 1;
625  FioGetDirectory(fios_hmap_path, fios_hmap_path_last, HEIGHTMAP_DIR);
626  }
627 
628  _fios_path = fios_hmap_path;
629  _fios_path_last = fios_hmap_path_last;
630 
631  char base_path[MAX_PATH];
632  FioGetDirectory(base_path, lastof(base_path), HEIGHTMAP_DIR);
633 
634  Subdirectory subdir = strcmp(base_path, _fios_path) == 0 ? HEIGHTMAP_DIR : NO_DIRECTORY;
635  FiosGetFileList(fop, &FiosGetHeightmapListCallback, subdir, file_list);
636 }
637 
642 const char *FiosGetScreenshotDir()
643 {
644  static char *fios_screenshot_path = NULL;
645 
646  if (fios_screenshot_path == NULL) {
647  fios_screenshot_path = MallocT<char>(MAX_PATH);
648  FioGetDirectory(fios_screenshot_path, fios_screenshot_path + MAX_PATH - 1, SCREENSHOT_DIR);
649  }
650 
651  return fios_screenshot_path;
652 }
653 
654 #if defined(ENABLE_NETWORK)
655 #include "network/network_content.h"
656 #include "3rdparty/md5/md5.h"
657 
660  uint32 scenid;
661  uint8 md5sum[16];
662  char filename[MAX_PATH];
663 
664  bool operator == (const ScenarioIdentifier &other) const
665  {
666  return this->scenid == other.scenid &&
667  memcmp(this->md5sum, other.md5sum, sizeof(this->md5sum)) == 0;
668  }
669 
670  bool operator != (const ScenarioIdentifier &other) const
671  {
672  return !(*this == other);
673  }
674 };
675 
679 class ScenarioScanner : protected FileScanner, public SmallVector<ScenarioIdentifier, 8> {
680  bool scanned;
681 public:
683  ScenarioScanner() : scanned(false) {}
684 
689  void Scan(bool rescan)
690  {
691  if (this->scanned && !rescan) return;
692 
693  this->FileScanner::Scan(".id", SCENARIO_DIR, true, true);
694  this->scanned = true;
695  }
696 
697  /* virtual */ bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename)
698  {
699  FILE *f = FioFOpenFile(filename, "r", SCENARIO_DIR);
700  if (f == NULL) return false;
701 
703  int fret = fscanf(f, "%i", &id.scenid);
704  FioFCloseFile(f);
705  if (fret != 1) return false;
706  strecpy(id.filename, filename, lastof(id.filename));
707 
708  Md5 checksum;
709  uint8 buffer[1024];
710  char basename[MAX_PATH];
711  size_t len, size;
712 
713  /* open the scenario file, but first get the name.
714  * This is safe as we check on extension which
715  * must always exist. */
716  strecpy(basename, filename, lastof(basename));
717  *strrchr(basename, '.') = '\0';
718  f = FioFOpenFile(basename, "rb", SCENARIO_DIR, &size);
719  if (f == NULL) return false;
720 
721  /* calculate md5sum */
722  while ((len = fread(buffer, 1, (size > sizeof(buffer)) ? sizeof(buffer) : size, f)) != 0 && size != 0) {
723  size -= len;
724  checksum.Append(buffer, len);
725  }
726  checksum.Finish(id.md5sum);
727 
728  FioFCloseFile(f);
729 
730  this->Include(id);
731  return true;
732  }
733 };
734 
737 
744 const char *FindScenario(const ContentInfo *ci, bool md5sum)
745 {
746  _scanner.Scan(false);
747 
748  for (ScenarioIdentifier *id = _scanner.Begin(); id != _scanner.End(); id++) {
749  if (md5sum ? (memcmp(id->md5sum, ci->md5sum, sizeof(id->md5sum)) == 0)
750  : (id->scenid == ci->unique_id)) {
751  return id->filename;
752  }
753  }
754 
755  return NULL;
756 }
757 
764 bool HasScenario(const ContentInfo *ci, bool md5sum)
765 {
766  return (FindScenario(ci, md5sum) != NULL);
767 }
768 
773 {
774  _scanner.Scan(true);
775 }
776 
777 #endif /* ENABLE_NETWORK */
FiosType
Elements of a file system that are recognized.
Definition: fileio_type.h:69
bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename)
Try to add a fios item set with the given filename.
Definition: fios.cpp:305
AbstractFileType
The different abstract types of files that the system knows about.
Definition: fileio_type.h:18
Basic data to distinguish a scenario.
Definition: fios.cpp:659
uint32 unique_id
Unique ID; either GRF ID or shortname.
Definition: tcp_content.h:77
Scanner to find the unique IDs of scenarios.
Definition: fios.cpp:679
FiosType FiosGetSavegameListCallback(SaveLoadOperation fop, const char *file, const char *ext, char *title, const char *last)
Callback for FiosGetFileList.
Definition: fios.cpp:458
static char * strecat(char *dst, const char *src, const char *last)
Appends characters from one string to another.
Definition: depend.cpp:99
const char * FS2OTTD(const TCHAR *name)
Convert to OpenTTD&#39;s encoding from that of the local environment.
Definition: win32.cpp:565
Subdirectory
The different kinds of subdirectories OpenTTD uses.
Definition: fileio_type.h:110
void FioFCloseFile(FILE *f)
Close a file in a safe way.
Definition: fileio.cpp:334
Structs, typedefs and macros used for TAR file handling.
void Clear()
Remove all items from the list.
Definition: fios.h:186
static bool IsInsideMM(const T x, const uint min, const uint max)
Checks if a value is in an interval.
Definition: math_func.hpp:266
uint8 md5sum[16]
MD5 checksum of file.
Definition: fios.cpp:661
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
Definition: string.cpp:409
uint Scan(const char *extension, Subdirectory sd, bool tars=true, bool recursive=true)
Scan for files with the given extension in the given search path.
Definition: fileio.cpp:1419
#define FOR_ALL_SEARCHPATHS(sp)
Iterator for all the search paths.
Definition: fileio_func.h:49
Subdirectory of scenario for heightmaps.
Definition: fileio_type.h:115
Subdirectory for all screenshots.
Definition: fileio_type.h:125
const T * Begin() const
Get the pointer to the first item (const)
const FiosItem * Begin() const
Get a pointer to the first file information.
Definition: fios.h:139
void FiosGetSavegameList(SaveLoadOperation fop, FileList &file_list)
Get a list of savegames.
Definition: fios.cpp:491
Functions for Standard In/Out file operations.
#define lastof(x)
Get the last element of an fixed size array.
Definition: depend.cpp:50
Simple vector template class.
Functions to make screenshots.
Searchpath
Types of searchpaths OpenTTD might use.
Definition: fileio_type.h:133
uint32 scenid
ID for the scenario (generated by content).
Definition: fios.cpp:660
void FiosGetScenarioList(SaveLoadOperation fop, FileList &file_list)
Get a list of scenarios.
Definition: fios.cpp:546
const T * End() const
Get the pointer behind the last valid item (const)
File is being saved.
Definition: fileio_type.h:52
Deals with finding savegames.
Definition: fios.h:105
StringID FiosGetDescText(const char **path, uint64 *total_free)
Get descriptive texts.
Definition: fios.cpp:141
Helper for scanning for files with a given name.
Definition: fileio_func.h:74
const FiosItem * FindItem(const char *file)
Find file information of a file by its name from the file list.
Definition: fios.cpp:108
SmallVector< FiosItem, 32 > files
The list of files.
Definition: fios.h:200
old or new savegame
Definition: fileio_type.h:20
old or new scenario
Definition: fileio_type.h:21
bool HasScenario(const ContentInfo *ci, bool md5sum)
Check whether we&#39;ve got a given scenario based on its unique ID.
Definition: fios.cpp:764
FiosFileScanner(SaveLoadOperation fop, fios_getlist_callback_proc *callback_proc, FileList &file_list)
Create the scanner.
Definition: fios.cpp:292
uint Length() const
Get the number of files in the list.
Definition: fios.h:130
Functions related to low-level strings.
Base directory for all scenarios.
Definition: fileio_type.h:114
bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename)
Add a file with the given filename.
Definition: fios.cpp:697
const FiosItem * End() const
Get a pointer behind the last file information.
Definition: fios.h:148
const char * FindScenario(const ContentInfo *ci, bool md5sum)
Find a given scenario based on its unique ID.
Definition: fios.cpp:744
static ScenarioScanner _scanner
Scanner for scenarios.
Definition: fios.cpp:736
bool scanned
Whether we&#39;ve already scanned.
Definition: fios.cpp:680
void FiosMakeSavegameName(char *buf, const char *name, const char *last)
Make a save game or scenario filename from a name.
Definition: fios.cpp:241
nothing to do
Definition: fileio_type.h:19
uint Length() const
Get the number of items in the list.
bool operator!=(const MultiMapIterator< Tmap_iter1, Tlist_iter1, Tkey, Tvalue1, Tcompare > &iter1, const MultiMapIterator< Tmap_iter2, Tlist_iter2, Tkey, Tvalue2, Tcompare > &iter2)
Inverse of operator==().
Definition: multimap.hpp:222
Definition: win32.cpp:93
void str_validate(char *str, const char *last, StringValidationSettings settings)
Scans the string for valid characters and if it finds invalid ones, replaces them with a question mar...
Definition: string.cpp:196
static void FiosMakeFilename(char *buf, const char *path, const char *name, const char *ext, const char *last)
Construct a filename from its components in destination buffer buf.
Definition: fios.cpp:211
FILE * FioFOpenFile(const char *filename, const char *mode, Subdirectory subdir, size_t *filesize)
Opens a OpenTTD file somewhere in a personal or global directory.
Definition: fileio.cpp:465
A path without any base directory.
Definition: fileio_type.h:127
Definition of base types and functions in a cross-platform compatible way.
A number of safeguards to prevent using unsafe methods.
void Scan(bool rescan)
Scan, but only if it&#39;s needed.
Definition: fios.cpp:689
void ScanScenarios()
Force a (re)scan of the scenarios.
Definition: fios.cpp:772
Base directory for all savegames.
Definition: fileio_type.h:112
bool operator==(const MultiMapIterator< Tmap_iter1, Tlist_iter1, Tkey, Tvalue1, Tcompare > &iter1, const MultiMapIterator< Tmap_iter2, Tlist_iter2, Tkey, Tvalue2, Tcompare > &iter2)
Compare two MultiMap iterators.
Definition: multimap.hpp:205
void BuildFileList(AbstractFileType abstract_filetype, SaveLoadOperation fop)
Construct a file list with the given kind of files, for the stated purpose.
Definition: fios.cpp:76
const FiosItem * Get(uint index) const
Get a pointer to the indicated file information.
Definition: fios.h:157
FileList & file_list
Destination of the found files.
Definition: fios.cpp:284
Part of the network protocol handling content distribution.
static void GetFileTitle(const char *file, char *title, const char *last, Subdirectory subdir)
Get the title of a file, which (if exists) is stored in a file named the same as the data file but wi...
Definition: fios.cpp:431
File is being loaded.
Definition: fileio_type.h:51
int CDECL CompareFiosItems(const FiosItem *da, const FiosItem *db)
Compare two FiosItem&#39;s.
Definition: fios.cpp:52
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
byte md5sum[16]
The MD5 checksum.
Definition: tcp_content.h:78
const TCHAR * OTTD2FS(const char *name, bool console_cp)
Convert from OpenTTD&#39;s encoding to that of the local environment.
Definition: win32.cpp:583
SaveLoadOperation
Operation performed on the file.
Definition: fileio_type.h:49
void Compact()
Compact the list down to the smallest block size boundary.
Definition: fios.h:192
bool FiosDelete(const char *name)
Delete a file.
Definition: fios.cpp:268
void FiosGetHeightmapList(SaveLoadOperation fop, FileList &file_list)
Get a list of heightmaps.
Definition: fios.cpp:617
static void FiosGetFileList(SaveLoadOperation fop, fios_getlist_callback_proc *callback_proc, Subdirectory subdir, FileList &file_list)
Fill the list of the files in a directory, according to some arbitrary rule.
Definition: fios.cpp:356
void FiosMakeHeightmapName(char *buf, const char *name, const char *last)
Construct a filename for a height map.
Definition: fios.cpp:254
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:59
Declarations for savegames operations.
List of file information.
Definition: fios.h:113
const char * FiosBrowseTo(const FiosItem *item)
Browse to a new path based on the passed item, starting at #_fios_path.
Definition: fios.cpp:152
static FiosType FiosGetScenarioListCallback(SaveLoadOperation fop, const char *file, const char *ext, char *title, const char *last)
Callback for FiosGetFileList.
Definition: fios.cpp:519
Scanner to scan for a particular type of FIOS file.
Definition: fios.cpp:281
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
Definition: depend.cpp:68
const char * GetCurrentScreenshotExtension()
Get filename extension of current screenshot file format.
Definition: screenshot.cpp:574
static DIR * ttd_opendir(const char *path)
A wrapper around opendir() which will convert the string from OPENTTD encoding to that of the filesys...
Definition: fileio_func.h:148
heightmap file
Definition: fileio_type.h:22
SaveLoadOperation fop
The kind of file we are looking for.
Definition: fios.cpp:282
FiosItem * Append()
Construct a new entry in the file list.
Definition: fios.h:121
ScenarioScanner()
Initialise.
Definition: fios.cpp:683
const char * FiosGetScreenshotDir()
Get the directory for screenshots.
Definition: fios.cpp:642
static void QSortT(T *base, uint num, int(CDECL *comparator)(const T *, const T *), bool desc=false)
Type safe qsort()
Definition: sort_func.hpp:28
Container for all important information about a piece of content.
Definition: tcp_content.h:58