# fios.h

Go to the documentation of this file.

    00001 /* $Id: fios.h 13871 2008-07-29 22:37:54Z rubidium $ */
    00002
    00005 #ifndef FIOS_H
    00006 #define FIOS_H
    00007
    00008 #include "strings_type.h"
    00009
    00010 enum {
    00017   CONFIG_SLOT    =  0,
    00019   SOUND_SLOT     =  1,
    00021   FIRST_GRF_SLOT =  2,
    00023   LAST_GRF_SLOT  = 63,
    00025   MAX_FILE_SLOTS = 64
    00026 };
    00027
    00028 enum SaveLoadDialogMode{
    00029   SLD_LOAD_GAME,
    00030   SLD_LOAD_SCENARIO,
    00031   SLD_SAVE_GAME,
    00032   SLD_SAVE_SCENARIO,
    00033   SLD_LOAD_HEIGHTMAP,
    00034   SLD_NEW_GAME,
    00035 };
    00036
    00037 /* The different types of files been handled by the system */
    00038 enum FileType {
    00039   FT_NONE,
    00040   FT_SAVEGAME,
    00041   FT_SCENARIO,
    00042   FT_HEIGHTMAP,
    00043 };
    00044
    00045 enum FiosType {
    00046   FIOS_TYPE_DRIVE        =   0,
    00047   FIOS_TYPE_PARENT       =   1,
    00048   FIOS_TYPE_DIR          =   2,
    00049   FIOS_TYPE_FILE         =   3,
    00050   FIOS_TYPE_OLDFILE      =   4,
    00051   FIOS_TYPE_SCENARIO     =   5,
    00052   FIOS_TYPE_OLD_SCENARIO =   6,
    00053   FIOS_TYPE_DIRECT       =   7,
    00054   FIOS_TYPE_PNG          =   8,
    00055   FIOS_TYPE_BMP          =   9,
    00056   FIOS_TYPE_INVALID      = 255,
    00057 };
    00058
    00059 /* Deals with finding savegames */
    00060 struct FiosItem {
    00061   byte type;
    00062   uint64 mtime;
    00063   char title[64];
    00064   char name[256 - 12 - 64];
    00065 };
    00066
    00067 /* Deals with the type of the savegame, independent of extension */
    00068 struct SmallFiosItem {
    00069   int mode;
    00070   FileType filetype;
    00071   char name[MAX_PATH];
    00072   char title[255];
    00073 };
    00074
    00075 /* Variables to display file lists */
    00076 extern FiosItem *_fios_list;
    00077 extern int _fios_num;
    00078 extern SmallFiosItem _file_to_saveload;
    00079 extern SaveLoadDialogMode _saveload_mode;
    00080
    00081 /* Launch save/load dialog */
    00082 void ShowSaveLoadDialog(SaveLoadDialogMode mode);
    00083
    00084 /* Get a list of savegames */
    00085 FiosItem *FiosGetSavegameList(int mode);
    00086 /* Get a list of scenarios */
    00087 FiosItem *FiosGetScenarioList(int mode);
    00088 /* Get a list of Heightmaps */
    00089 FiosItem *FiosGetHeightmapList(int mode);
    00090 /* Free the list of savegames */
    00091 void FiosFreeSavegameList();
    00092 /* Browse to. Returns a filename w/path if we reached a file. */
    00093 char *FiosBrowseTo(const FiosItem *item);
    00094 /* Return path, free space and stringID */
    00095 StringID FiosGetDescText(const char **path, uint32 *total_free);
    00096 /* Delete a name */
    00097 bool FiosDelete(const char *name);
    00098 /* Make a filename from a name */
    00099 void FiosMakeSavegameName(char *buf, const char *name, size_t size);
    00100 /* Allocate a new FiosItem */
    00101 FiosItem *FiosAlloc();
    00102 /* Determines type of savegame (or tells it is not a savegame) */
    00103 byte FiosGetSavegameListCallback(int mode, const char *file, const char *ext, char *title);
    00104
    00105 int CDECL compare_FiosItems(const void *a, const void *b);
    00106
    00107 /* Implementation of opendir/readdir/closedir for Windows */
    00108 #if defined(WIN32)
    00109 #include <windows.h>
    00110 struct DIR;
    00111
    00112 struct dirent { // XXX - only d_name implemented
    00113   TCHAR *d_name; // name of found file
    00114   /* little hack which will point to parent DIR struct which will
    00115    * save us a call to GetFileAttributes if we want information
    00116    * about the file (for example in function fio_bla) */
    00117   DIR *dir;
    00118 };
    00119
    00120 struct DIR {
    00121   HANDLE hFind;
    00122   /* the dirent returned by readdir.
    00123    * note: having only one global instance is not possible because
    00124    * multiple independent opendir/readdir sequences must be supported. */
    00125   dirent ent;
    00126   WIN32_FIND_DATA fd;
    00127   /* since opendir calls FindFirstFile, we need a means of telling the
    00128    * first call to readdir that we already have a file.
    00129    * that's the case iff this is true */
    00130   bool at_first_entry;
    00131 };
    00132
    00133 DIR *opendir(const TCHAR *path);
    00134 struct dirent *readdir(DIR *d);
    00135 int closedir(DIR *d);
    00136 #else
    00137 /* Use system-supplied opendir/readdir/closedir functions */
    00138 # include <sys/types.h>
    00139 # include <dirent.h>
    00140 #endif /* defined(WIN32) */
    00141
    00149 static inline DIR *ttd_opendir(const char *path)
    00150 {
    00151   return opendir(OTTD2FS(path));
    00152 }
    00153
    00154 #endif /* FIOS_H */