File Utilities
The XPLMUtilities file APIs provide some basic file and path functions for use with X-Plane.
Directory Separators
The XPLM has two modes it can work in:
-
X-Plane native paths: all paths are UTF8 strings, using the unix forward slash (/) as the directory separating character. In native path mode, you use the same path format for all three operating systems.
-
Legacy OS paths: the directroy separator is \ for Windows, : for OS X, and / for Linux; OS paths are encoded in MacRoman for OS X using legacy HFS conventions, use the application code page for multi-byte encoding on Unix using DOS path conventions, and use UTF-8 for Linux.
While legacy OS paths are the default, we strongly encourage you to opt in to native paths using the XPLMEnableFeature API.
-
All OS X plugins should enable native paths all of the time; if you do not do this, you will have to convert all paths back from HFS to Unix (and deal with MacRoman) - code written using native paths and the C file APIs "just works" on OS X.
-
For Linux plugins, there is no difference between the two encodings.
-
Windows plugins will need to convert the UTF8 file paths to UTF16 for use with the "wide" APIs. While it might seem tempting to stick with legacy OS paths (and just use the "ANSI" Windows APIs), X-Plane is fully unicode-capable, and will often be installed in paths where the user's directories have no ACP encoding.
Full and Relative Paths
Some of these APIs use full paths, but others use paths relative to the user's X-Plane installation. This is documented on a per-API basis.
XPLMDataFileType
enum XPLM200
These enums define types of data files you can load or unload using the SDK.
| Name | Value | Description |
|---|---|---|
| xplm_DataFile_Situation | 1 | A situation (.sit) file, which starts off a flight in a given configuration. |
| xplm_DataFile_ReplayMovie | 2 | A situation movie (.smo) file, which replays a past flight. |
XPLMGetSystemPath
function
This function returns the full path to the X-System folder. Note that this is a directory path, so it ends in a trailing : or / .
The buffer you pass should be at least 512 characters long. The path is returned using the current native or OS path conventions.
XPLM_API void XPLMGetSystemPath(
char * outSystemPath
);
XPLMGetPrefsPath
function
This routine returns a full path to a file that is within X-Plane's preferences directory. (You should remove the file name back to the last directory separator to get the preferences directory using XPLMExtractFileAndPath).
The buffer you pass should be at least 512 characters long. The path is returned using the current native or OS path conventions.
XPLM_API void XPLMGetPrefsPath(
char * outPrefsPath
);
XPLMGetDirectorySeparator
function
This routine returns a string with one char and a null terminator that is the directory separator for the current platform. This allows you to write code that concatenates directory paths without having to #ifdef for platform. The character returned will reflect the current file path mode.
XPLM_API const char *XPLMGetDirectorySeparator(void);
XPLMExtractFileAndPath
function
Given a full path to a file, this routine separates the path from the file. If the path is a partial directory (e.g. ends in : or / ) the trailing directory separator is removed. This routine works in-place; a pointer to the file part of the buffer is returned; the original buffer still starts with the path and is null terminated with no trailing separator.
XPLM_API char * XPLMExtractFileAndPath(
char * inFullPath
);
XPLMGetDirectoryContents
function
This routine returns a list of files in a directory (specified by a full path, no trailing : or / ). The output is returned as a list of NULL terminated strings. An index array (if specified) is filled with pointers into the strings. The last file is indicated by a zero-length string (and NULL in the indices). This routine will return true if you had capacity for all files or false if you did not. You can also skip a given number of files.
-
inDirectoryPath - a null terminated C string containing the full path to the directory with no trailing directory char.
-
inFirstReturn - the zero-based index of the first file in the directory to return. (Usually zero to fetch all in one pass.)
-
outFileNames - a buffer to receive a series of sequential null terminated C-string file names. A zero-length C string will be appended to the very end.
-
inFileNameBufSize - the size of the file name buffer in bytes.
-
outIndices - a pointer to an array of character pointers that will become an index into the directory. The last file will be followed by a NULL value. Pass NULL if you do not want indexing information.
-
inIndexCount - the max size of the index in entries.
-
outTotalFiles - if not NULL, this is filled in with the number of files in the directory.
-
outReturnedFiles - if not NULL, the number of files returned by this iteration.
Return value: 1 if all info could be returned, 0 if there was a buffer overrun.
WARNING: Before X-Plane 7 this routine did not properly iterate through directories. If X-Plane 6 compatibility is needed, use your own code to iterate directories.
XPLM_API int XPLMGetDirectoryContents(
const char * inDirectoryPath,
int inFirstReturn,
char * outFileNames,
int inFileNameBufSize,
char * * outIndices, /* Can be NULL */
int inIndexCount,
int * outTotalFiles, /* Can be NULL */
int * outReturnedFiles /* Can be NULL */
);
XPLMLoadDataFile
function XPLM200
Loads a data file of a given type. Paths must be relative to the X-System folder. To clear the replay, pass a NULL file name (this is only valid with replay movies, not sit files).
XPLM_API int XPLMLoadDataFile(
XPLMDataFileType inFileType,
const char * inFilePath /* Can be NULL */
);
XPLMSaveDataFile
function XPLM200
Saves the current situation or replay; paths are relative to the X-System folder.
XPLM_API int XPLMSaveDataFile(
XPLMDataFileType inFileType,
const char * inFilePath
);