OpenTTD Source: src/fileio_type.h Source File

OpenTTD Source 14.1

fileio_type.h
Go to the documentation of this file.
1 /*
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/>.
6 */
7
10 #ifndef FILEIO_TYPE_H
11 #define FILEIO_TYPE_H
12
13 #include "core/enum_type.hpp"
14
16 enum AbstractFileType {
17 FT_NONE,
18 FT_SAVEGAME,
19 FT_SCENARIO,
20 FT_HEIGHTMAP,
21
22 FT_INVALID = 7,
23 FT_NUMBITS = 3,
24 FT_MASK = (1 << FT_NUMBITS) - 1,
25 };
26
28 enum DetailedFileType {
29 /* Save game and scenario files. */
30 DFT_OLD_GAME_FILE,
31 DFT_GAME_FILE,
32
33 /* Heightmap files. */
34 DFT_HEIGHTMAP_BMP,
35 DFT_HEIGHTMAP_PNG,
36
37 /* fios 'files' */
38 DFT_FIOS_DRIVE,
39 DFT_FIOS_PARENT,
40 DFT_FIOS_DIR,
41 DFT_FIOS_DIRECT,
42
43 DFT_INVALID = 255,
44 };
45
47 enum SaveLoadOperation {
48 SLO_CHECK,
49 SLO_LOAD,
50 SLO_SAVE,
51
52 SLO_INVALID,
53 };
54
60 #define MAKE_FIOS_TYPE(abstract, detailed) ((abstract) | ((detailed) << FT_NUMBITS))
61
67 enum FiosType {
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),
72
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),
79
80 FIOS_TYPE_INVALID = MAKE_FIOS_TYPE(FT_INVALID, DFT_INVALID),
81 };
82
83 #undef MAKE_FIOS_TYPE
84
90 inline AbstractFileType GetAbstractFileType(FiosType fios_type)
91 {
92 return static_cast<AbstractFileType>(static_cast<uint>(fios_type) & FT_MASK);
93 }
94
100 inline DetailedFileType GetDetailedFileType(FiosType fios_type)
101 {
102 return static_cast<DetailedFileType>(fios_type >> FT_NUMBITS);
103 }
104
108 enum Subdirectory {
109 BASE_DIR,
110 SAVE_DIR,
111 AUTOSAVE_DIR,
112 SCENARIO_DIR,
113 HEIGHTMAP_DIR,
114 OLD_GM_DIR,
115 OLD_DATA_DIR,
116 BASESET_DIR,
117 NEWGRF_DIR,
118 LANG_DIR,
119 AI_DIR,
120 AI_LIBRARY_DIR,
121 GAME_DIR,
122 GAME_LIBRARY_DIR,
123 SCREENSHOT_DIR,
124 SOCIAL_INTEGRATION_DIR,
125 NUM_SUBDIRS,
126 NO_DIRECTORY,
127 };
128
132 enum Searchpath : unsigned {
133 SP_FIRST_DIR,
134 SP_WORKING_DIR = SP_FIRST_DIR,
135 #ifdef USE_XDG
136 SP_PERSONAL_DIR_XDG,
137 #endif
138 SP_PERSONAL_DIR,
139 SP_SHARED_DIR,
140 SP_BINARY_DIR,
141 SP_INSTALLATION_DIR,
142 SP_APPLICATION_BUNDLE_DIR,
143 SP_AUTODOWNLOAD_DIR,
144 SP_AUTODOWNLOAD_PERSONAL_DIR,
145 SP_AUTODOWNLOAD_PERSONAL_DIR_XDG,
146 NUM_SEARCHPATHS
147 };
148
149 DECLARE_POSTFIX_INCREMENT(Searchpath)
150
151 #endif /* FILEIO_TYPE_H */
SP_AUTODOWNLOAD_DIR
@ SP_AUTODOWNLOAD_DIR
Search within the autodownload directory.
Definition: fileio_type.h:143
FT_SCENARIO
@ FT_SCENARIO
old or new scenario
Definition: fileio_type.h:19
SAVE_DIR
@ SAVE_DIR
Base directory for all savegames.
Definition: fileio_type.h:110
SP_PERSONAL_DIR
@ SP_PERSONAL_DIR
Search in the personal directory.
Definition: fileio_type.h:138
DFT_FIOS_DIR
@ DFT_FIOS_DIR
A directory entry.
Definition: fileio_type.h:40
BASESET_DIR
@ BASESET_DIR
Subdirectory for all base data (base sets, intro game)
Definition: fileio_type.h:116
SaveLoadOperation
SaveLoadOperation
Operation performed on the file.
Definition: fileio_type.h:47
GAME_LIBRARY_DIR
@ GAME_LIBRARY_DIR
Subdirectory for all GS libraries.
Definition: fileio_type.h:122
SCREENSHOT_DIR
@ SCREENSHOT_DIR
Subdirectory for all screenshots.
Definition: fileio_type.h:123
SP_AUTODOWNLOAD_PERSONAL_DIR
@ SP_AUTODOWNLOAD_PERSONAL_DIR
Search within the autodownload directory located in the personal directory.
Definition: fileio_type.h:144
Searchpath
Searchpath
Types of searchpaths OpenTTD might use.
Definition: fileio_type.h:132
SLO_CHECK
@ SLO_CHECK
Load file for checking and/or preview.
Definition: fileio_type.h:48
NUM_SUBDIRS
@ NUM_SUBDIRS
Number of subdirectories.
Definition: fileio_type.h:125
DFT_GAME_FILE
@ DFT_GAME_FILE
Save game or scenario file.
Definition: fileio_type.h:31
HEIGHTMAP_DIR
@ HEIGHTMAP_DIR
Subdirectory of scenario for heightmaps.
Definition: fileio_type.h:113
DFT_FIOS_DRIVE
@ DFT_FIOS_DRIVE
A drive (letter) entry.
Definition: fileio_type.h:38
SP_AUTODOWNLOAD_PERSONAL_DIR_XDG
@ SP_AUTODOWNLOAD_PERSONAL_DIR_XDG
Search within the autodownload directory located in the personal directory (XDG variant)
Definition: fileio_type.h:145
SP_INSTALLATION_DIR
@ SP_INSTALLATION_DIR
Search in the installation directory.
Definition: fileio_type.h:141
AUTOSAVE_DIR
@ AUTOSAVE_DIR
Subdirectory of save for autosaves.
Definition: fileio_type.h:111
GetDetailedFileType
DetailedFileType GetDetailedFileType(FiosType fios_type)
Extract the detailed file type from a FiosType.
Definition: fileio_type.h:100
OLD_GM_DIR
@ OLD_GM_DIR
Old subdirectory for the music.
Definition: fileio_type.h:114
DECLARE_POSTFIX_INCREMENT
#define DECLARE_POSTFIX_INCREMENT(enum_type)
Some enums need to have allowed incrementing (i.e.
Definition: enum_type.hpp:14
AbstractFileType
AbstractFileType
The different abstract types of files that the system knows about.
Definition: fileio_type.h:16
BASE_DIR
@ BASE_DIR
Base directory for all subdirectories.
Definition: fileio_type.h:109
SLO_LOAD
@ SLO_LOAD
File is being loaded.
Definition: fileio_type.h:49
SLO_SAVE
@ SLO_SAVE
File is being saved.
Definition: fileio_type.h:50
FT_NUMBITS
@ FT_NUMBITS
Number of bits required for storing a AbstractFileType value.
Definition: fileio_type.h:23
AI_DIR
@ AI_DIR
Subdirectory for all AI files.
Definition: fileio_type.h:119
SP_APPLICATION_BUNDLE_DIR
@ SP_APPLICATION_BUNDLE_DIR
Search within the application bundle.
Definition: fileio_type.h:142
GAME_DIR
@ GAME_DIR
Subdirectory for all game scripts.
Definition: fileio_type.h:121
SCENARIO_DIR
@ SCENARIO_DIR
Base directory for all scenarios.
Definition: fileio_type.h:112
FT_INVALID
@ FT_INVALID
Invalid or unknown file type.
Definition: fileio_type.h:22
SP_SHARED_DIR
@ SP_SHARED_DIR
Search in the shared directory, like 'Shared Files' under Windows.
Definition: fileio_type.h:139
DFT_OLD_GAME_FILE
@ DFT_OLD_GAME_FILE
Old save game or scenario file.
Definition: fileio_type.h:30
FT_SAVEGAME
@ FT_SAVEGAME
old or new savegame
Definition: fileio_type.h:18
SP_WORKING_DIR
@ SP_WORKING_DIR
Search in the working directory.
Definition: fileio_type.h:134
NEWGRF_DIR
@ NEWGRF_DIR
Subdirectory for all NewGRFs.
Definition: fileio_type.h:117
DFT_FIOS_DIRECT
@ DFT_FIOS_DIRECT
Direct filename.
Definition: fileio_type.h:41
DFT_INVALID
@ DFT_INVALID
Unknown or invalid file.
Definition: fileio_type.h:43
SP_BINARY_DIR
@ SP_BINARY_DIR
Search in the directory where the binary resides.
Definition: fileio_type.h:140
LANG_DIR
@ LANG_DIR
Subdirectory for all translation files.
Definition: fileio_type.h:118
FT_NONE
@ FT_NONE
nothing to do
Definition: fileio_type.h:17
DetailedFileType
DetailedFileType
Kinds of files in each AbstractFileType.
Definition: fileio_type.h:28
NO_DIRECTORY
@ NO_DIRECTORY
A path without any base directory.
Definition: fileio_type.h:126
FT_HEIGHTMAP
@ FT_HEIGHTMAP
heightmap file
Definition: fileio_type.h:20
Subdirectory
Subdirectory
The different kinds of subdirectories OpenTTD uses.
Definition: fileio_type.h:108
FiosType
FiosType
Elements of a file system that are recognized.
Definition: fileio_type.h:67
enum_type.hpp
AI_LIBRARY_DIR
@ AI_LIBRARY_DIR
Subdirectory for all AI libraries.
Definition: fileio_type.h:120
SLO_INVALID
@ SLO_INVALID
Unknown file operation.
Definition: fileio_type.h:52
DFT_FIOS_PARENT
@ DFT_FIOS_PARENT
A parent directory entry.
Definition: fileio_type.h:39
SOCIAL_INTEGRATION_DIR
@ SOCIAL_INTEGRATION_DIR
Subdirectory for all social integration plugins.
Definition: fileio_type.h:124
DFT_HEIGHTMAP_BMP
@ DFT_HEIGHTMAP_BMP
BMP file.
Definition: fileio_type.h:34
GetAbstractFileType
AbstractFileType GetAbstractFileType(FiosType fios_type)
Extract the abstract file type from a FiosType.
Definition: fileio_type.h:90
MAKE_FIOS_TYPE
#define MAKE_FIOS_TYPE(abstract, detailed)
Construct an enum value for FiosType as a combination of an abstract and a detailed file type.
Definition: fileio_type.h:60
OLD_DATA_DIR
@ OLD_DATA_DIR
Old subdirectory for the data.
Definition: fileio_type.h:115
DFT_HEIGHTMAP_PNG
@ DFT_HEIGHTMAP_PNG
PNG file.
Definition: fileio_type.h:35
FT_MASK
@ FT_MASK
Bitmask for extracting an abstract file type.
Definition: fileio_type.h:24