Top |
#define | fileusage_Data |
#define | fileusage_SavedGame |
#define | fileusage_Transcript |
#define | fileusage_InputRecord |
#define | fileusage_TextMode |
#define | fileusage_BinaryMode |
You deal with disk files using file references. Each fileref is an opaque C structure pointer; see Opaque Objects.
A file reference contains platform-specific information about the name and location of the file, and possibly its type, if the platform has a notion of file type. It also includes a flag indication whether the file is a text file or binary file.
Note that this is different from the standard C I/O library, in which you specify text or binary mode when the file is opened.
A fileref does not have to refer to a file which actually exists. You can create a fileref for a nonexistent file, and then open it in write mode to create a new file.
You always provide a usage argument when you create a fileref. The usage indicates the file type and the mode (text or binary.) It must be the logical-or of a file-type constant and a mode constant. These values are used when you create a new file, and also to filter file lists when the player is selecting a file to load.
In general, you should use text mode if the player expects to read the file
with a platform-native text editor; you should use binary mode if the file is
to be read back by your program, or if the data must be stored exactly. Text
mode is appropriate for fileusage_Transcript
; binary mode is appropriate for
fileusage_SavedGame
and probably for fileusage_InputRecord
. fileusage_Data
files may be text or binary, depending on what you use them for.
#define fileusage_Data (0x00)
Any other kind of file (preferences, statistics, arbitrary data.)
#define fileusage_Transcript (0x02)
A file which contains a stream of text from the game (often an echo stream from a window.)
#define fileusage_TextMode (0x100)
The file contents will be transformed to a platform-native text file as they are written out. Newlines may be converted to linefeeds or linefeed-plus-carriage-return combinations; Latin-1 characters may be converted to native character codes. When reading a file in text mode, native line breaks will be converted back to newline (0x0A) characters, and native character codes may be converted to Latin-1 or UTF-8.
Line breaks will always be converted; other conversions are more questionable. If you write out a file in text mode, and then read it back in text mode, high-bit characters (128 to 255) may be transformed or lost.