2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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 /** @file fileio_type.h Types for Standard In/Out file operations */
13 #include "core/enum_type.hpp"
15 /** The different abstract types of files that the system knows about. */
16 enum AbstractFileType
{
17 FT_NONE
, ///< nothing to do
18 FT_SAVEGAME
, ///< old or new savegame
19 FT_SCENARIO
, ///< old or new scenario
20 FT_HEIGHTMAP
, ///< heightmap file
22 FT_INVALID
= 7, ///< Invalid or unknown file type.
23 FT_NUMBITS
= 3, ///< Number of bits required for storing a #AbstractFileType value.
24 FT_MASK
= (1 << FT_NUMBITS
) - 1, ///< Bitmask for extracting an abstract file type.
27 /** Kinds of files in each #AbstractFileType. */
28 enum DetailedFileType
{
29 /* Save game and scenario files. */
30 DFT_OLD_GAME_FILE
, ///< Old save game or scenario file.
31 DFT_GAME_FILE
, ///< Save game or scenario file.
33 /* Heightmap files. */
34 DFT_HEIGHTMAP_BMP
, ///< BMP file.
35 DFT_HEIGHTMAP_PNG
, ///< PNG file.
38 DFT_FIOS_DRIVE
, ///< A drive (letter) entry.
39 DFT_FIOS_PARENT
, ///< A parent directory entry.
40 DFT_FIOS_DIR
, ///< A directory entry.
41 DFT_FIOS_DIRECT
, ///< Direct filename.
43 DFT_INVALID
= 255, ///< Unknown or invalid file.
46 /** Operation performed on the file. */
47 enum SaveLoadOperation
{
48 SLO_CHECK
, ///< Load file for checking and/or preview.
49 SLO_LOAD
, ///< File is being loaded.
50 SLO_SAVE
, ///< File is being saved.
52 SLO_INVALID
, ///< Unknown file operation.
56 * Construct an enum value for #FiosType as a combination of an abstract and a detailed file type.
57 * @param abstract Abstract file type (one of #AbstractFileType).
58 * @param detailed Detailed file type (one of #DetailedFileType).
60 #define MAKE_FIOS_TYPE(abstract, detailed) ((abstract) | ((detailed) << FT_NUMBITS))
63 * Elements of a file system that are recognized.
64 * Values are a combination of #AbstractFileType and #DetailedFileType.
65 * @see GetAbstractFileType GetDetailedFileType
68 FIOS_TYPE_DRIVE
= MAKE_FIOS_TYPE(FT_NONE
, DFT_FIOS_DRIVE
),
69 FIOS_TYPE_PARENT
= MAKE_FIOS_TYPE(FT_NONE
, DFT_FIOS_PARENT
),
70 FIOS_TYPE_DIR
= MAKE_FIOS_TYPE(FT_NONE
, DFT_FIOS_DIR
),
71 FIOS_TYPE_DIRECT
= MAKE_FIOS_TYPE(FT_NONE
, DFT_FIOS_DIRECT
),
73 FIOS_TYPE_FILE
= MAKE_FIOS_TYPE(FT_SAVEGAME
, DFT_GAME_FILE
),
74 FIOS_TYPE_OLDFILE
= MAKE_FIOS_TYPE(FT_SAVEGAME
, DFT_OLD_GAME_FILE
),
75 FIOS_TYPE_SCENARIO
= MAKE_FIOS_TYPE(FT_SCENARIO
, DFT_GAME_FILE
),
76 FIOS_TYPE_OLD_SCENARIO
= MAKE_FIOS_TYPE(FT_SCENARIO
, DFT_OLD_GAME_FILE
),
77 FIOS_TYPE_PNG
= MAKE_FIOS_TYPE(FT_HEIGHTMAP
, DFT_HEIGHTMAP_PNG
),
78 FIOS_TYPE_BMP
= MAKE_FIOS_TYPE(FT_HEIGHTMAP
, DFT_HEIGHTMAP_BMP
),
80 FIOS_TYPE_INVALID
= MAKE_FIOS_TYPE(FT_INVALID
, DFT_INVALID
),
86 * Extract the abstract file type from a #FiosType.
87 * @param fios_type Type to query.
88 * @return The Abstract file type of the \a fios_type.
90 inline AbstractFileType
GetAbstractFileType(FiosType fios_type
)
92 return static_cast<AbstractFileType
>(static_cast<uint
>(fios_type
) & FT_MASK
);
96 * Extract the detailed file type from a #FiosType.
97 * @param fios_type Type to query.
98 * @return The Detailed file type of the \a fios_type.
100 inline DetailedFileType
GetDetailedFileType(FiosType fios_type
)
102 return static_cast<DetailedFileType
>(fios_type
>> FT_NUMBITS
);
106 * The different kinds of subdirectories OpenTTD uses
109 BASE_DIR
, ///< Base directory for all subdirectories
110 SAVE_DIR
, ///< Base directory for all savegames
111 AUTOSAVE_DIR
, ///< Subdirectory of save for autosaves
112 SCENARIO_DIR
, ///< Base directory for all scenarios
113 HEIGHTMAP_DIR
, ///< Subdirectory of scenario for heightmaps
114 OLD_GM_DIR
, ///< Old subdirectory for the music
115 OLD_DATA_DIR
, ///< Old subdirectory for the data.
116 BASESET_DIR
, ///< Subdirectory for all base data (base sets, intro game)
117 NEWGRF_DIR
, ///< Subdirectory for all NewGRFs
118 LANG_DIR
, ///< Subdirectory for all translation files
119 AI_DIR
, ///< Subdirectory for all %AI files
120 AI_LIBRARY_DIR
,///< Subdirectory for all %AI libraries
121 GAME_DIR
, ///< Subdirectory for all game scripts
122 GAME_LIBRARY_DIR
, ///< Subdirectory for all GS libraries
123 SCREENSHOT_DIR
, ///< Subdirectory for all screenshots
124 SOCIAL_INTEGRATION_DIR
, ///< Subdirectory for all social integration plugins
125 NUM_SUBDIRS
, ///< Number of subdirectories
126 NO_DIRECTORY
, ///< A path without any base directory
130 * Types of searchpaths OpenTTD might use
132 enum Searchpath
: unsigned {
134 SP_WORKING_DIR
= SP_FIRST_DIR
, ///< Search in the working directory
136 SP_PERSONAL_DIR_XDG
, ///< Search in the personal directory from the XDG specification
138 SP_PERSONAL_DIR
, ///< Search in the personal directory
139 SP_SHARED_DIR
, ///< Search in the shared directory, like 'Shared Files' under Windows
140 SP_BINARY_DIR
, ///< Search in the directory where the binary resides
141 SP_INSTALLATION_DIR
, ///< Search in the installation directory
142 SP_APPLICATION_BUNDLE_DIR
, ///< Search within the application bundle
143 SP_AUTODOWNLOAD_DIR
, ///< Search within the autodownload directory
144 SP_AUTODOWNLOAD_PERSONAL_DIR
, ///< Search within the autodownload directory located in the personal directory
145 SP_AUTODOWNLOAD_PERSONAL_DIR_XDG
, ///< Search within the autodownload directory located in the personal directory (XDG variant)
149 DECLARE_POSTFIX_INCREMENT(Searchpath
)
151 #endif /* FILEIO_TYPE_H */