naev 0.12.5
ndata.c File Reference

Wrappers to set up and access game assets (mounted via PhysicsFS). We choose our underlying directories in ndata_setupWriteDir() and ndata_setupReadDirs(). However, conf.c code may have seeded the search path based on command-line arguments. More...

#include "ndata.h"
#include "array.h"
#include "conf.h"
#include "env.h"
#include "log.h"
#include "nfile.h"
#include "nstring.h"
#include "plugin.h"
Include dependency graph for ndata.c:

Go to the source code of this file.

Functions

static void ndata_testVersion (void)
 Test version to see if it matches.
static int ndata_found (void)
 Checks to see if the physfs search path is enough to find game data.
static int ndata_enumerateCallback (void *data, const char *origdir, const char *fname)
 The PHYSFS_EnumerateCallback for ndata_listRecursive.
const char * ndata_primaryPath (void)
 Gets the primary path for where the data is.
void ndata_setupWriteDir (void)
 Gets Naev's data path (for user data such as saves and screenshots)
void ndata_setupReadDirs (void)
 Sets up the PhysicsFS search path.
void * ndata_read (const char *path, size_t *filesize)
 Reads a file from the ndata (will be NUL terminated).
char ** ndata_listRecursive (const char *path)
 Lists all the visible files in a directory, at any depth.
int ndata_backupIfExists (const char *path)
 Backup a file, if it exists.
int ndata_copyIfExists (const char *file1, const char *file2)
 Copy a file, if it exists.
int ndata_matchExt (const char *path, const char *ext)
 Sees if a file matches an extension.
int ndata_getPathDefault (char *path, int len, const char *default_path, const char *filename)
 Tries to see if a file is in a default path before seeing if it is an absolute path.

Detailed Description

Wrappers to set up and access game assets (mounted via PhysicsFS). We choose our underlying directories in ndata_setupWriteDir() and ndata_setupReadDirs(). However, conf.c code may have seeded the search path based on command-line arguments.

Definition in file ndata.c.

Function Documentation

◆ ndata_backupIfExists()

int ndata_backupIfExists ( const char * path)

Backup a file, if it exists.

Parameters
pathPhysicsFS relative pathname to back up.
Returns
0 on success, or if file does not exist, -1 on error.

Definition at line 336 of file ndata.c.

◆ ndata_copyIfExists()

int ndata_copyIfExists ( const char * file1,
const char * file2 )

Copy a file, if it exists.

Parameters
file1PhysicsFS relative pathname to copy from.
file2PhysicsFS relative pathname to copy to.
Returns
0 on success, or if file1 does not exist, -1 on error.

Definition at line 358 of file ndata.c.

◆ ndata_enumerateCallback()

int ndata_enumerateCallback ( void * data,
const char * origdir,
const char * fname )
static

The PHYSFS_EnumerateCallback for ndata_listRecursive.

Definition at line 305 of file ndata.c.

◆ ndata_found()

int ndata_found ( void )
static

Checks to see if the physfs search path is enough to find game data.

Definition at line 70 of file ndata.c.

◆ ndata_getPathDefault()

int ndata_getPathDefault ( char * path,
int len,
const char * default_path,
const char * filename )

Tries to see if a file is in a default path before seeing if it is an absolute path.

Parameters
[out]pathPath found.
lenLength of path.
default_pathDefault path to look in.
filenameName of the file to look for.
Returns
1 if found.

Definition at line 442 of file ndata.c.

◆ ndata_listRecursive()

char ** ndata_listRecursive ( const char * path)

Lists all the visible files in a directory, at any depth.

Will sort by path, and (unlike underlying PhysicsFS) make sure to list each file path only once.

Returns
Array of (allocated) file paths relative to base_dir.

Definition at line 286 of file ndata.c.

◆ ndata_matchExt()

int ndata_matchExt ( const char * path,
const char * ext )

Sees if a file matches an extension.

Parameters
pathPath to check extension of.
extExtension to check.
Returns
1 on match, 0 otherwise.

Definition at line 420 of file ndata.c.

◆ ndata_primaryPath()

const char * ndata_primaryPath ( void )

Gets the primary path for where the data is.

Definition at line 48 of file ndata.c.

◆ ndata_read()

void * ndata_read ( const char * path,
size_t * filesize )

Reads a file from the ndata (will be NUL terminated).

Parameters
pathPath of the file to read.
[out]filesizeStores the size of the file.
Returns
The file data or NULL on error.

Definition at line 207 of file ndata.c.

◆ ndata_setupReadDirs()

void ndata_setupReadDirs ( void )

Sets up the PhysicsFS search path.

Definition at line 155 of file ndata.c.

◆ ndata_setupWriteDir()

void ndata_setupWriteDir ( void )

Gets Naev's data path (for user data such as saves and screenshots)

Definition at line 132 of file ndata.c.

◆ ndata_testVersion()

void ndata_testVersion ( void )
static

Test version to see if it matches.

Definition at line 82 of file ndata.c.