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/>.
10 /** @file fileio_type.h Types for Standard In/Out file operations */
15 #include "core/enum_type.hpp"
17 /** The different abstract types of files that the system knows about. */
18 enum AbstractFileType
{
19 FT_NONE
, ///< nothing to do
20 FT_SAVEGAME
, ///< old or new savegame
21 FT_SCENARIO
, ///< old or new scenario
22 FT_HEIGHTMAP
, ///< heightmap file
24 FT_INVALID
= 7, ///< Invalid or unknown file type.
25 FT_NUMBITS
= 3, ///< Number of bits required for storing a #AbstractFileType value.
26 FT_MASK
= (1 << FT_NUMBITS
) - 1, ///< Bitmask for extracting an abstract file type.
29 /** Kinds of files in each #AbstractFileType. */
30 enum DetailedFileType
{
31 /* Save game and scenario files. */
32 DFT_OLD_GAME_FILE
, ///< Old save game or scenario file.
33 DFT_GAME_FILE
, ///< Save game or scenario file.
35 /* Heightmap files. */
36 DFT_HEIGHTMAP_BMP
, ///< BMP file.
37 DFT_HEIGHTMAP_PNG
, ///< PNG file.
40 DFT_FIOS_DRIVE
, ///< A drive (letter) entry.
41 DFT_FIOS_PARENT
, ///< A parent directory entry.
42 DFT_FIOS_DIR
, ///< A directory entry.
43 DFT_FIOS_DIRECT
, ///< Direct filename.
45 DFT_INVALID
= 255, ///< Unknown or invalid file.
48 /** Operation performed on the file. */
49 enum SaveLoadOperation
{
50 SLO_CHECK
, ///< Load file for checking and/or preview.
51 SLO_LOAD
, ///< File is being loaded.
52 SLO_SAVE
, ///< File is being saved.
54 SLO_INVALID
, ///< Unknown file operation.
58 * Construct an enum value for #FiosType as a combination of an abstract and a detailed file type.
59 * @param abstract Abstract file type (one of #AbstractFileType).
60 * @param detailed Detailed file type (one of #DetailedFileType).
62 #define MAKE_FIOS_TYPE(abstract, detailed) ((abstract) | ((detailed) << FT_NUMBITS))
65 * Elements of a file system that are recognized.
66 * Values are a combination of #AbstractFileType and #DetailedFileType.
67 * @see GetAbstractFileType GetDetailedFileType
70 FIOS_TYPE_DRIVE
= MAKE_FIOS_TYPE(FT_NONE
, DFT_FIOS_DRIVE
),
71 FIOS_TYPE_PARENT
= MAKE_FIOS_TYPE(FT_NONE
, DFT_FIOS_PARENT
),
72 FIOS_TYPE_DIR
= MAKE_FIOS_TYPE(FT_NONE
, DFT_FIOS_DIR
),
73 FIOS_TYPE_DIRECT
= MAKE_FIOS_TYPE(FT_NONE
, DFT_FIOS_DIRECT
),
75 FIOS_TYPE_FILE
= MAKE_FIOS_TYPE(FT_SAVEGAME
, DFT_GAME_FILE
),
76 FIOS_TYPE_OLDFILE
= MAKE_FIOS_TYPE(FT_SAVEGAME
, DFT_OLD_GAME_FILE
),
77 FIOS_TYPE_SCENARIO
= MAKE_FIOS_TYPE(FT_SCENARIO
, DFT_GAME_FILE
),
78 FIOS_TYPE_OLD_SCENARIO
= MAKE_FIOS_TYPE(FT_SCENARIO
, DFT_OLD_GAME_FILE
),
79 FIOS_TYPE_PNG
= MAKE_FIOS_TYPE(FT_HEIGHTMAP
, DFT_HEIGHTMAP_PNG
),
80 FIOS_TYPE_BMP
= MAKE_FIOS_TYPE(FT_HEIGHTMAP
, DFT_HEIGHTMAP_BMP
),
82 FIOS_TYPE_INVALID
= MAKE_FIOS_TYPE(FT_INVALID
, DFT_INVALID
),
88 * Extract the abstract file type from a #FiosType.
89 * @param fios_type Type to query.
90 * @return The Abstract file type of the \a fios_type.
92 inline AbstractFileType
GetAbstractFileType(FiosType fios_type
)
94 return static_cast<AbstractFileType
>(fios_type
& FT_MASK
);
98 * Extract the detailed file type from a #FiosType.
99 * @param fios_type Type to query.
100 * @return The Detailed file type of the \a fios_type.
102 inline DetailedFileType
GetDetailedFileType(FiosType fios_type
)
104 return static_cast<DetailedFileType
>(fios_type
>> FT_NUMBITS
);
108 * The different kinds of subdirectories OpenTTD uses
111 BASE_DIR
, ///< Base directory for all subdirectories
112 SAVE_DIR
, ///< Base directory for all savegames
113 AUTOSAVE_DIR
, ///< Subdirectory of save for autosaves
114 SCENARIO_DIR
, ///< Base directory for all scenarios
115 HEIGHTMAP_DIR
, ///< Subdirectory of scenario for heightmaps
116 OLD_GM_DIR
, ///< Old subdirectory for the music
117 OLD_DATA_DIR
, ///< Old subdirectory for the data.
118 BASESET_DIR
, ///< Subdirectory for all base data (base sets, intro game)
119 NEWGRF_DIR
, ///< Subdirectory for all NewGRFs
120 LANG_DIR
, ///< Subdirectory for all translation files
121 AI_DIR
, ///< Subdirectory for all %AI files
122 AI_LIBRARY_DIR
,///< Subdirectory for all %AI libraries
123 GAME_DIR
, ///< Subdirectory for all game scripts
124 GAME_LIBRARY_DIR
, ///< Subdirectory for all GS libraries
125 SCREENSHOT_DIR
, ///< Subdirectory for all screenshots
126 NUM_SUBDIRS
, ///< Number of subdirectories
127 NO_DIRECTORY
, ///< A path without any base directory
131 * Types of searchpaths OpenTTD might use
135 SP_WORKING_DIR
= SP_FIRST_DIR
, ///< Search in the working directory
136 #if defined(WITH_XDG_BASEDIR) && defined(WITH_PERSONAL_DIR)
137 SP_PERSONAL_DIR_XDG
, ///< Search in the personal directory from the XDG specification
139 SP_PERSONAL_DIR
, ///< Search in the personal directory
140 SP_SHARED_DIR
, ///< Search in the shared directory, like 'Shared Files' under Windows
141 SP_BINARY_DIR
, ///< Search in the directory where the binary resides
142 SP_INSTALLATION_DIR
, ///< Search in the installation directory
143 SP_APPLICATION_BUNDLE_DIR
, ///< Search within the application bundle
144 SP_AUTODOWNLOAD_DIR
, ///< Search within the autodownload directory
148 DECLARE_POSTFIX_INCREMENT(Searchpath
)
150 #endif /* FILEIO_TYPE_H */