ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
file.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 //=============================================================================
23 //
24 // Platform-independent File functions
25 //
26 //=============================================================================
27 
28 #ifndef AGS_SHARED_UTIL_FILE_H
29 #define AGS_SHARED_UTIL_FILE_H
30 
31 #include "ags/shared/core/platform.h"
32 #include "ags/shared/util/string.h"
33 
34 namespace AGS3 {
35 namespace AGS {
36 namespace Shared {
37 
38 // Forward declarations
39 class Stream;
40 
41 enum FileOpenMode {
42  kFile_Open, // Open existing file
43  kFile_Create, // Create new file, or open existing one
44  kFile_CreateAlways // Always create a new file, replacing any existing one
45 };
46 
47 enum FileWorkMode {
48  kFile_Read,
49  kFile_Write,
50  kFile_ReadWrite
51 };
52 
53 namespace File {
54 // Tells if the given path is a directory
55 bool IsDirectory(const String &directory);
56 // Tells if the given path is a file
57 bool IsFile(const String &filename);
58 // Tells if the given path is file or directory;
59 // may be used to check if it's valid to use
60 bool IsFileOrDir(const String &filename);
61 // Returns size of a file, or -1 if no such file found
62 soff_t GetFileSize(const String &filename);
63 // Tests if file could be opened for reading
64 bool TestReadFile(const String &filename);
65 // Opens a file for writing or creates new one if it does not exist; deletes file if it was created during test
66 bool TestWriteFile(const String &filename);
67 // Create new empty file and deletes it; returns TRUE if was able to create file
68 bool TestCreateFile(const String &filename);
69 // Deletes existing file; returns TRUE if was able to delete one
70 bool DeleteFile(const String &filename);
71 // Renames existing file to the new name; returns TRUE on success
72 bool RenameFile(const String &old_name, const String &new_name);
73 // Copies a file from src_path to dst_path; returns TRUE on success
74 bool CopyFile(const String &src_path, const String &dst_path, bool overwrite);
75 
76 // Sets FileOpenMode and FileWorkMode values corresponding to C-style file open mode string
77 bool GetFileModesFromCMode(const String &cmode, FileOpenMode &open_mode, FileWorkMode &work_mode);
78 // Gets C-style file mode from FileOpenMode and FileWorkMode
79 String GetCMode(FileOpenMode open_mode, FileWorkMode work_mode);
80 
81 // Opens file in the given mode
82 Stream *OpenFile(const String &filename, FileOpenMode open_mode, FileWorkMode work_mode);
83 // Opens file for reading restricted to the arbitrary offset range
84 Stream *OpenFile(const String &filename, soff_t start_off, soff_t end_off);
85 // Convenience helpers
86 // Create a totally new file, overwrite existing one
87 inline Stream *CreateFile(const String &filename) {
88  return OpenFile(filename, kFile_CreateAlways, kFile_Write);
89 }
90 // Open existing file for reading
91 inline Stream *OpenFileRead(const String &filename) {
92  return OpenFile(filename, kFile_Open, kFile_Read);
93 }
94 // Open existing file for writing (append) or create if it does not exist
95 inline Stream *OpenFileWrite(const String &filename) {
96  return OpenFile(filename, kFile_Create, kFile_Write);
97 }
98 
99 // Opens stdin stream for reading
100 Stream *OpenStdin();
101 // Opens stdout stream for writing
102 Stream *OpenStdout();
103 // Opens stderr stream for writing
104 Stream *OpenStderr();
105 
106 // Case insensitive find file
107 String FindFileCI(const String &dir_name, const String &file_name);
108 // Case insensitive file open: looks up for the file using FindFileCI
109 Stream *OpenFileCI(const String &file_name,
110  FileOpenMode open_mode = kFile_Open,
111  FileWorkMode work_mode = kFile_Read);
112 
113 } // namespace File
114 
115 } // namespace Shared
116 } // namespace AGS
117 } // namespace AGS3
118 
119 #endif
Definition: achievements_tables.h:27
Definition: ags.h:40