Darkvater@4218: /* $Id$ */ Darkvater@4218: belugas@6505: /** @file fios.h Declarations for savegames operations */ belugas@6505: Darkvater@4218: #ifndef FIOS_H Darkvater@4218: #define FIOS_H Darkvater@4218: rubidium@8760: #include "strings_type.h" skidd13@11019: #include "core/smallvec_type.hpp" rubidium@8760: rubidium@8301: enum { rubidium@8301: /** rubidium@8301: * Slot used for the GRF scanning and such. This slot cannot be reused rubidium@8301: * as it will otherwise cause issues when pressing "rescan directories". rubidium@8301: * It can furthermore not be larger than LAST_GRF_SLOT as that complicates rubidium@8301: * the testing for "too much NewGRFs". rubidium@8301: */ rubidium@8301: CONFIG_SLOT = 0, rubidium@8301: /** Slot for the sound. */ rubidium@8301: SOUND_SLOT = 1, rubidium@8301: /** First slot useable for (New)GRFs used during the game. */ rubidium@8301: FIRST_GRF_SLOT = 2, rubidium@8301: /** Last slot useable for (New)GRFs used during the game. */ rubidium@8301: LAST_GRF_SLOT = 63, rubidium@8301: /** Maximum number of slots. */ rubidium@8301: MAX_FILE_SLOTS = 64 rubidium@8301: }; rubidium@8301: belugas@8645: enum SaveLoadDialogMode{ belugas@8645: SLD_LOAD_GAME, belugas@8645: SLD_LOAD_SCENARIO, belugas@8645: SLD_SAVE_GAME, belugas@8645: SLD_SAVE_SCENARIO, belugas@8645: SLD_LOAD_HEIGHTMAP, belugas@8645: SLD_NEW_GAME, belugas@8645: }; belugas@8645: belugas@8648: /* The different types of files been handled by the system */ belugas@8648: enum FileType { belugas@8648: FT_NONE, ///< nothing to do belugas@8648: FT_SAVEGAME, ///< old or new savegame belugas@8648: FT_SCENARIO, ///< old or new scenario belugas@8648: FT_HEIGHTMAP, ///< heightmap file belugas@8648: }; belugas@8648: peter1138@10307: enum FiosType { peter1138@10307: FIOS_TYPE_DRIVE, peter1138@10307: FIOS_TYPE_PARENT, peter1138@10307: FIOS_TYPE_DIR, peter1138@10307: FIOS_TYPE_FILE, peter1138@10307: FIOS_TYPE_OLDFILE, peter1138@10307: FIOS_TYPE_SCENARIO, peter1138@10307: FIOS_TYPE_OLD_SCENARIO, peter1138@10307: FIOS_TYPE_DIRECT, peter1138@10307: FIOS_TYPE_PNG, peter1138@10307: FIOS_TYPE_BMP, peter1138@10307: FIOS_TYPE_INVALID = 255, Darkvater@4223: }; Darkvater@4223: belugas@8647: /* Deals with finding savegames */ belugas@8647: struct FiosItem { peter1138@10307: FiosType type; belugas@8647: uint64 mtime; belugas@8647: char title[64]; belugas@8647: char name[256 - 12 - 64]; belugas@8647: }; belugas@8647: belugas@8647: /* Deals with the type of the savegame, independent of extension */ belugas@8647: struct SmallFiosItem { belugas@8647: int mode; ///< savegame/scenario type (old, new) belugas@8648: FileType filetype; ///< what type of file are we dealing with belugas@8647: char name[MAX_PATH]; ///< name belugas@8647: char title[255]; ///< internal name of the game belugas@8647: }; belugas@8647: rubidium@10770: enum { rubidium@10770: SORT_ASCENDING = 0, rubidium@10770: SORT_DESCENDING = 1, rubidium@10770: SORT_BY_DATE = 0, rubidium@10770: SORT_BY_NAME = 2 rubidium@10770: }; rubidium@10770: Darkvater@4223: /* Variables to display file lists */ skidd13@10808: extern SmallVector _fios_items; ///< defined in fios.cpp belugas@8647: extern SmallFiosItem _file_to_saveload; belugas@8645: extern SaveLoadDialogMode _saveload_mode; ///< defined in misc_gui.cpp rubidium@10770: extern byte _savegame_sort_order; belugas@8645: belugas@8645: /* Launch save/load dialog */ belugas@8645: void ShowSaveLoadDialog(SaveLoadDialogMode mode); Darkvater@4223: belugas@6505: /* Get a list of savegames */ skidd13@10808: void FiosGetSavegameList(SaveLoadDialogMode mode); belugas@6505: /* Get a list of scenarios */ skidd13@10808: void FiosGetScenarioList(SaveLoadDialogMode mode); belugas@6505: /* Get a list of Heightmaps */ skidd13@10808: void FiosGetHeightmapList(SaveLoadDialogMode mode); belugas@6505: /* Free the list of savegames */ rubidium@6573: void FiosFreeSavegameList(); belugas@6505: /* Browse to. Returns a filename w/path if we reached a file. */ Darkvater@4223: char *FiosBrowseTo(const FiosItem *item); belugas@6505: /* Return path, free space and stringID */ Darkvater@4223: StringID FiosGetDescText(const char **path, uint32 *total_free); belugas@6505: /* Delete a name */ Darkvater@4223: bool FiosDelete(const char *name); belugas@6505: /* Make a filename from a name */ Darkvater@4223: void FiosMakeSavegameName(char *buf, const char *name, size_t size); Darkvater@4223: Darkvater@4223: int CDECL compare_FiosItems(const void *a, const void *b); Darkvater@4223: Darkvater@4218: /* Implementation of opendir/readdir/closedir for Windows */ Darkvater@4218: #if defined(WIN32) Darkvater@4218: #include rubidium@6574: struct DIR; Darkvater@4218: rubidium@6574: struct dirent { // XXX - only d_name implemented Darkvater@6577: TCHAR *d_name; // name of found file Darkvater@4218: /* little hack which will point to parent DIR struct which will Darkvater@4218: * save us a call to GetFileAttributes if we want information belugas@6505: * about the file (for example in function fio_bla) */ Darkvater@4218: DIR *dir; rubidium@6574: }; Darkvater@4218: Darkvater@4218: struct DIR { Darkvater@4218: HANDLE hFind; Darkvater@4218: /* the dirent returned by readdir. Darkvater@4218: * note: having only one global instance is not possible because Darkvater@4218: * multiple independent opendir/readdir sequences must be supported. */ Darkvater@4218: dirent ent; Darkvater@6577: WIN32_FIND_DATA fd; Darkvater@4218: /* since opendir calls FindFirstFile, we need a means of telling the Darkvater@4218: * first call to readdir that we already have a file. Darkvater@4218: * that's the case iff this is true */ Darkvater@4218: bool at_first_entry; Darkvater@4218: }; Darkvater@4218: Darkvater@6577: DIR *opendir(const TCHAR *path); Darkvater@4218: struct dirent *readdir(DIR *d); Darkvater@4218: int closedir(DIR *d); Darkvater@6414: #else Darkvater@6414: /* Use system-supplied opendir/readdir/closedir functions */ Darkvater@6414: # include Darkvater@6414: # include Darkvater@4218: #endif /* defined(WIN32) */ Darkvater@4218: Darkvater@6412: /** Darkvater@6412: * A wrapper around opendir() which will convert the string from Darkvater@6412: * OPENTTD encoding to that of the filesystem. For all purposes this Darkvater@6412: * function behaves the same as the original opendir function Darkvater@6412: * @param path string to open directory of Darkvater@6412: * @return DIR pointer Darkvater@6412: */ Darkvater@6412: static inline DIR *ttd_opendir(const char *path) Darkvater@6412: { Darkvater@6412: return opendir(OTTD2FS(path)); Darkvater@6412: } Darkvater@6412: Darkvater@4218: #endif /* FIOS_H */